Author: Sai Nudurupati 19Oct17
Material presented here is extensively mined (copied with permission) from the tutorial (https://github.com/geohackweek/tutorial_contents/blob/master/nDarrays/notebooks/ndarrays_intro.ipynb) presented by Joe Hamman (github: jhamman) at Geohack week (Sep 17) at University of Washington. I have also referred online documentation for 'xarray' (http://xarray.pydata.org/en/stable/)
In [ ]:
# Ignore warnings
import warnings; warnings.simplefilter('ignore')
In [ ]:
%matplotlib inline
In [ ]:
import numpy as np
sst = np.random.random(size=(2, 4, 4))
print sst
# print(sst[:, ::1, ::3]) # indexing
In [ ]:
sst.shape
In [ ]:
print(sst[:, ::1, ::3])
In [ ]:
import pandas as pd
df = pd.read_csv('https://climate.nasa.gov/system/internal_resources/details/original/647_Global_Temperature_Data_File.txt',
sep=r"\s*", names=['year', '1yr', '5yr'], index_col='year')
df.loc[1984: ]
In [ ]:
df.plot()
In [ ]:
import xarray as xr
In [ ]:
ds = xr.open_dataset('3B43.20100101.7A.nc')
At this point Python is just scanning the contents of the file. It is not reading the data into its memory.
In [ ]:
ds
In [ ]:
precipitation = ds['pcp']
In [ ]:
precipitation[0, 0, 0]
In [ ]:
ds['pcp'].loc['2010-01-01']
In [ ]:
ds['pcp'].isel(time=0, latitude=0, longitude=0)
In [ ]:
map_data = ds['pcp'].sel(time='2010-01-01')
In [ ]:
map_data.plot()
In [ ]:
import matplotlib.pyplot as plt
map_data.plot(cmap=plt.cm.Blues)
plt.title('Global Precipitation data')
plt.tight_layout()
plt.show()
In [ ]: