Compute Sum of Precipitation Events
Download Jupyter Notebook file here
#Compute Sum of Precipitation Events
import cwt, os
class TestWorkflow:
plotter = cwt.initialize()
host ="https://edas.nccs.nasa.gov/wps/cwt"
wps = cwt.WPS( host, log=True,log_file=os.path.expanduser("~/esgf_api.log"), verify=False )
def spatial_sum( self ):
# Set the domain to be Hawaii to San Francisco, from December 15, 2014 to December 20, 2017
domain_data = { 'id': 'd0', 'lat': {'start':-90, 'end':90,'crs':'values'},
'lon': {'start':0, 'end':360, 'crs':'values'},
'time':{'start':'2014-12-15T00:00:00', 'end':'2014-12-20T23:00:00', 'crs':'timestamps'}}
d0 = cwt.Domain.from_dict(domain_data)
# Set the input data to be 6 hourly MERRA2 precipitation data (variable pr)
inputs = cwt.Variable("collection://cip_merra2_6hr", "pr",domain=d0 )
# Set the operation to be "maximum" operating over the xy axes
op_data = { 'name': "xarray.sum", 'axes': "xy" }
op = cwt.Process.from_dict( op_data )
op.set_inputs( inputs )
# Set the operation to be "sum" operating over the time axes
op_data1 = { 'name': "xarray.sum", 'axes': "t" }
op1 = cwt.Process.from_dict( op_data1 )
op1.set_inputs( inputs )
self.wps.execute( op, domains=[d0], async=True )
dataPath = self.wps.download_result(op)
self.wps.execute( op1, domains=[d0], async=True )
dataPaths = self.wps.download_result(op1)
# Plot precipitation over the spatial range plot; precitation vs time can be plotted by uncommenting timeplot line
for dataPath in dataPaths:
# self.plotter.mpl_timeplot(dataPath)
self.plotter.mpl_spaceplot(dataPath)
executor = TestWorkflow()
executor.spatial_sum()
import cwt, os
class TestWorkflow:
plotter = cwt.initialize()
host ="https://edas.nccs.nasa.gov/wps/cwt"
wps = cwt.WPS( host, log=True,log_file=os.path.expanduser("~/esgf_api.log"), verify=False )
def spatial_sum( self ):
# Set the domain to be Hawaii to San Francisco, from December 15, 2014 to December 20, 2017
domain_data = { 'id': 'd0', 'lat': {'start':-90, 'end':90,'crs':'values'},
'lon': {'start':0, 'end':360, 'crs':'values'},
'time':{'start':'2014-12-15T00:00:00', 'end':'2014-12-20T23:00:00', 'crs':'timestamps'}}
d0 = cwt.Domain.from_dict(domain_data)
# Set the input data to be 6 hourly MERRA2 precipitation data (variable pr)
inputs = cwt.Variable("collection://cip_merra2_6hr", "pr",domain=d0 )
# Set the operation to be "maximum" operating over the xy axes
op_data = { 'name': "xarray.sum", 'axes': "xy" }
op = cwt.Process.from_dict( op_data )
op.set_inputs( inputs )
# Set the operation to be "sum" operating over the time axes
op_data1 = { 'name': "xarray.sum", 'axes': "t" }
op1 = cwt.Process.from_dict( op_data1 )
op1.set_inputs( inputs )
self.wps.execute( op, domains=[d0], async=True )
dataPath = self.wps.download_result(op)
self.wps.execute( op1, domains=[d0], async=True )
dataPaths = self.wps.download_result(op1)
# Plot precipitation over the spatial range plot; precitation vs time can be plotted by uncommenting timeplot line
for dataPath in dataPaths:
# self.plotter.mpl_timeplot(dataPath)
self.plotter.mpl_spaceplot(dataPath)
executor = TestWorkflow()
executor.spatial_sum()