Skip to content

Instantly share code, notes, and snippets.

@sanAkel
Last active August 1, 2020 00:25
Show Gist options
  • Save sanAkel/722b353d3ddd6aab0a365d6d5d4ec722 to your computer and use it in GitHub Desktop.
Save sanAkel/722b353d3ddd6aab0a365d6d5d4ec722 to your computer and use it in GitHub Desktop.
Thanks to @yvikhlya for the help!
import xarray as xr
import matplotlib.pyplot as plt
ds=xr.open_mfdataset('/discover/nobackup/sakella/m6_test/holding/geosgcm_surf/*/m6_test.geosgcm_surf.*_1200z.nc4')
frice = ds['FRSEAICE']
frocn = ds['FROCEAN']
ts = ds['TS']
t2m = ds['T2M']
ts.load() # force load into memory
#ts.compute() # creates a new array without changing ts itself.
#ds.resample(...) # to get monthly means
#ds_monthly=ds.resample(time='1M').mean('time') # resample to monthly means to make it faster
ts.sel(lon=-178.0,lat=78.0).plot() # this will be slow unless loaded into memory
plt.show()
ts.sel( lon=slice(-170,178), lat=slice(78,80)).mean().plot() # makes a histogram
plt.show()
ts.sel( lon=slice(-170,178), lat=slice(78,80)).mean( ('lon', 'lat')).plot() # geometric box averaged time series
plt.show
#
frocn.load()
frice.load()
t2m.load()
plt.figure( figsize=(12,8))
plt.subplot(211), ts.sel( lon=slice(-170,178), lat=slice(78,80)).mean( ('lon', 'lat')).plot(ls=':', color='r', label='TS')
plt.subplot(211), t2m.sel( lon=slice(-170,178), lat=slice(78,80)).mean( ('lon', 'lat')).plot(ls='-', color='b', label='T2M')
plt.legend()
plt.title('box av lon: [-170, 178], lat: [78, 80N]')
plt.xlabel(' ')
plt.ylabel('[K]')
plt.subplot(212), frocn.sel( lon=slice(-170,178), lat=slice(78,80)).mean( ('lon', 'lat')).plot(ls=':', color='k', label='fr Ocn')
plt.subplot(212), frice.sel( lon=slice(-170,178), lat=slice(78,80)).mean( ('lon', 'lat')).plot(ls='-', color='b', label='fr Ice')
plt.legend()
#plt.ylabel('[1]')
plt.savefig('test1.png', dpi=100)
#
@sanAkel
Copy link
Author

sanAkel commented Jul 31, 2020

test1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment