# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python [default]
#     language: python
#     name: python2
# ---

import xarray 
import numpy as np

# %matplotlib inline
import matplotlib.pyplot as plt

da=xarray.open_dataset('/home/suvarchal/Software/Datasets/data/etopo05.cdf')

da

da.ROSE.plot.contourf()

ROSEsq=da.ROSE*da.ROSE
da.merge(ROSEsq.to_dataset().rename({'ROSE':'ROSEsq'}),inplace=True)

gpd=da.groupby_bins('ETOPO05_X',bins=180,labels=np.arange(1,360,2))
gpdmnd=gpd.mean(dim='ETOPO05_X')
gpd2=gpdmnd.groupby_bins('ETOPO05_Y',bins=91,labels=np.arange(-90,91,2))
gpdmnd2=gpd2.mean(dim='ETOPO05_Y')

ROSEstd=(gpdmnd2.ROSEsq-gpdmnd2.ROSE*gpdmnd2.ROSE)**(0.5)
ROSEstd=ROSEstd.rename('ROSEstd')

ROSEstd

gpdmnd2.merge(ROSEstd.to_dataset(),inplace=True)

gpdmnd2.rename({'ETOPO05_Y_bins':'Latitude','ETOPO05_X_bins':'Longitude'},inplace=True)

gpdmnd2.to_netcdf('ROSE_2degstd.nc')

ROSEstd.plot.contourf(x='ETOPO05_X_bins',y='ETOPO05_Y_bins')

gpdmnd2.ROSE.plot.contourf(x='ETOPO05_X_bins',y='ETOPO05_Y_bins')

gpdmnd2.ROSEsq.plot.contourf(x='ETOPO05_X_bins',y='ETOPO05_Y_bins')



# +
ROSEsq.rename('ROSEsq')

#gpd=da.groupby_bins('ETOPO05_X',bins=180,labels=np.arange(1,360,2))
#gpdmnd=gpd.mean(dim='ETOPO05_X')
#gpd2=gpdmnd.groupby_bins('ETOPO05_Y',bins=91,labels=np.arange(-90,91,2))
#gpdmnd2=gpd2.mean(dim='ETOPO05_Y')
# -

da


da

# +
#gpdmnd2['ROSE2']=gpdmnd2.rename({'ROSE':'DEM','ETOPO05_Y_bins':'Latitude','ETOPO05_X_bins':'Longitude'})
#gpdmnd2.to_netcdf('tempROSE.nc')

# +
#gpdmnd2.ETOPO05_Y_bins.name='Latitude'
#gpdmnd2.ETOPO05_Y_bins.name='Longitude'
# -

gpdmnd2

gpdmnd2.to_dataset().to_netcdf('tempROSE.nc')

da.rename({'ETOPO05_Y':'Latitude','ETOPO05_X':'Longitude'},inplace=True)

da.to_netcdf('ROSE_05min.nc')



StarcoderdataJupyterScriptsDedupFiltered