def test_set_domain(): modeltime = hm.set_modeltime( datetime.datetime(2003,6,1), datetime.datetime(2003,6,30), datetime.timedelta(days=1) ) hm.set_domain( 'test_data/qrparm.soil_HWSD_cont_cosbyNew.nc', modeltime, 'field342', is_1d=True, xy_dimname='land' )
def test_open_hmdataarray(): # os.chdir('test/release') modeltime = hm.set_modeltime( datetime.datetime(2003,6,1), datetime.datetime(2003,6,30), datetime.timedelta(days=1) ) domain = hm.set_domain( 'test_data/qrparm.soil_HWSD_cont_cosbyNew.nc', modeltime, 'field342', is_1d=True, xy_dimname='land' ) # domain.mask # domain.starttime # domain.endtime # domain.n_timestep # domain.dt da = hm.open_hmdataarray( 'test_data/SWdown_WFDEI_land_200306.nc', 'SWdown', domain, True, 'land' ) da = da.select( time=slice( datetime.datetime(2003,6,1), datetime.datetime(2003,6,10) ) )
def test_open_hmdataarray(): modeltime = hm.set_modeltime(datetime.datetime(2003, 6, 1, 0, 0), datetime.datetime(2003, 6, 10, 0, 0), datetime.timedelta(days=1)) domain = hm.set_domain('test_data/ghana_landmask_0pt25degree.tif', modeltime) da = hm.open_hmdataarray('test_data/AgMERRA_2003_tavg.nc4', 'tavg', domain) da.select(time=pd.Timestamp(2003, 6, 1), method='nearest')
def preprocessor(debug, outputdir, deterministic, montecarlo, kalmanfilter, config): configuration = AquaCropConfiguration( config, outputdir, debug, deterministic=deterministic, montecarlo=montecarlo, kalmanfilter=kalmanfilter ) modeltime = set_modeltime( pd.Timestamp(configuration.CLOCK['start_time']), pd.Timestamp(configuration.CLOCK['end_time']), pd.Timedelta('1 day') ) z_coords = get_z_coords(configuration) domain = set_domain( configuration.MODEL_GRID['mask'], modeltime, configuration.MODEL_GRID['mask_varname'], configuration.MODEL_GRID['area_varname'], configuration.MODEL_GRID['is_1d'], configuration.MODEL_GRID['xy_dimname'], z_coords, configuration.PSEUDO_COORDS ) # decide whether to preprocess etref # would this be better as an option? if configuration.ETREF['preprocess']: initial_state = None etref_method = configuration.ETREF['method'] if 'PenmanMonteith' in etref_method: etref_fn = run_etref(PenmanMonteith, configuration, modeltime, domain, initial_state) if 'Hargreaves' in etref_method: etref_fn = run_etref(Hargreaves, configuration, modeltime, domain, initial_state) if 'PriestleyTaylor' in etref_method: etref_fn = run_etref(PriestleyTaylor, configuration, modeltime, domain, initial_state) # Update configuration configuration.ETREF['filename'] = etref_fn configuration.ETREF['varname'] = 'etref' if domain.is_1d: configuration.ETREF['is_1d'] = True configuration.ETREF['xy_dimname'] = 'space' clear_cache() return configuration, modeltime, domain
def cli(debug, outputdir, config): # load configuration configuration = ETRefConfiguration(config, outputdir, debug) # create modeltime object print(type(configuration.CLOCK['start_time'])) modeltime = set_modeltime(pd.Timestamp(configuration.CLOCK['start_time']), pd.Timestamp(configuration.CLOCK['end_time']), pd.Timedelta('1 day')) # set model domain domain = set_domain( configuration.MODEL_GRID['mask'], modeltime, configuration.MODEL_GRID['mask_varname'], configuration.MODEL_GRID['area_varname'], configuration.MODEL_GRID['is_1d'], configuration.MODEL_GRID['xy_dimname'] # , # z_coords=None, # pseudo_coords=configuration.PSEUDO_COORDS ) def create_dynamic_model(method): return HmDynamicModel(method, configuration, modeltime, domain, variable_list, initial_state) initial_state = None etref_method = configuration.ET_METHOD['method'] if 'PenmanMonteith' in etref_method: dynamic_model = create_dynamic_model(PenmanMonteith) # dynamic_model = HmDynamicModel( # PenmanMonteith, # configuration, # modeltime, # domain, # variable_list, # initial_state # ) if 'Hargreaves' in etref_method: dynamic_model = create_dynamic_model(Hargreaves) if 'PriestleyTaylor' in etref_method: dynamic_model = create_dynamic_model(PriestleyTaylor) # run model dynamic_framework = HmDynamicFramework(dynamic_model, len(modeltime) + 1) dynamic_framework.setQuiet(True) dynamic_framework.run()
def main(argv): disclaimer.print_disclaimer() # get the full path of the config file provided as system argument config_filename = os.path.abspath(argv[0]) # determine whether to run the model in debug mode debug_mode = False if len(argv) > 2: if (argv[1] == "debug"): debug_mode = True # load configuration configuration = AquaCropConfiguration(config_filename, debug_mode) # create modeltime object modeltime = set_modeltime(pd.Timestamp(configuration.CLOCK['startTime']), pd.Timestamp(configuration.CLOCK['endTime']), pd.Timedelta(configuration.CLOCK['timeDelta'])) # retrieve z coordinate information from config dz_lyr = configuration.SOIL_PROFILE['dzLayer'] z_lyr_bot = np.cumsum(dz_lyr) z_lyr_top = z_lyr_bot - dz_lyr z_lyr_mid = (z_lyr_top + z_lyr_bot) / 2 dz_comp = configuration.SOIL_PROFILE['dzComp'] z_comp_bot = np.cumsum(dz_comp) z_comp_top = z_comp_bot - dz_comp z_comp_mid = (z_comp_top + z_comp_bot) / 2 z_coords = {'layer': z_lyr_mid, 'depth': z_comp_mid} # set model domain domain = set_domain(configuration.MODEL_GRID['mask'], modeltime, configuration.MODEL_GRID['mask_varname'], configuration.MODEL_GRID['area_varname'], configuration.MODEL_GRID['is_1d'], configuration.MODEL_GRID['xy_dimname'], z_coords, configuration.PSEUDO_COORDS) # create dynamic model object initial_state = None dynamic_model = HmDynamicModel(AquaCrop, configuration, modeltime, domain, variable_list, initial_state) # run model dynamic_framework = HmDynamicFramework(dynamic_model, len(modeltime) + 1) dynamic_framework.setQuiet(True) dynamic_framework.run()
def main(): disclaimer.print_disclaimer() iniFileName = os.path.abspath(sys.argv[1]) debug_mode = False if len(sys.argv) > 2: if sys.argv[2] == 'debug': debug_mode = True # configuration = Configuration( # iniFileName=iniFileName, # debug_mode=debug_mode) configuration = ETRefConfiguration(config_filename=iniFileName, debug_mode=debug_mode) modeltime = ModelTime(pd.Timestamp(configuration.CLOCK['startTime']), pd.Timestamp(configuration.CLOCK['endTime']), pd.Timedelta(configuration.CLOCK['timeDelta'])) domain = set_domain(configuration.MODEL_GRID['mask'], modeltime, configuration.MODEL_GRID['mask_varname'], configuration.MODEL_GRID['area_varname'], configuration.MODEL_GRID['is_1d'], configuration.MODEL_GRID['xy_dimname'], configuration.PSEUDO_COORDS) # currTimeStep = ModelTime() # initial_state = None # currTimeStep.getStartEndTimeSteps( # configuration.CLOCK['startTime'], # configuration.CLOCK['endTime']) logger.info('Transient simulation run has started') initial_state = None etref_method = "Hargreaves" # etref_method = 'PenmanMonteith' # etref_method = configuration.RefETMethodSelection if 'PenmanMonteith' in etref_method: run(PenmanMonteith, configuration, modeltime, domain, initial_state) #, 'PenmanMonteith') if 'Hargreaves' in etref_method: run(Hargreaves, configuration, modeltime, domain, initial_state) #, 'Hargreaves') if 'PriestleyTaylor' in etref_method: run(PriestleyTaylor, configuration, modeltime, domain, initial_state) #, 'PriestleyTaylor') clear_cache()
def test_set_domain(): modeltime = hm.set_modeltime(datetime.datetime(2003, 6, 1), datetime.datetime(2003, 6, 30), datetime.timedelta(days=1)) hm.set_domain('test_data/ghana_landmask_0pt25degree.tif', modeltime)
def cli(debug, outputdir, deterministic, montecarlo, kalmanfilter, config): """Example script""" if sum([deterministic, montecarlo, kalmanfilter]) != 1: raise click.UsageError( "Exactly one of 'deterministic', 'monte-carlo', and 'enkf'" " must be specified.") configuration = AquaCropConfiguration(config, outputdir, debug, deterministic=deterministic, montecarlo=montecarlo, kalmanfilter=kalmanfilter) modeltime = set_modeltime(pd.Timestamp(configuration.CLOCK['start_time']), pd.Timestamp(configuration.CLOCK['end_time']), pd.Timedelta('1 day')) # retrieve z coordinate information from config dz_lyr = configuration.SOIL_PROFILE['dzLayer'] z_lyr_bot = np.cumsum(dz_lyr) z_lyr_top = z_lyr_bot - dz_lyr z_lyr_mid = (z_lyr_top + z_lyr_bot) / 2 dz_comp = configuration.SOIL_PROFILE['dzComp'] z_comp_bot = np.cumsum(dz_comp) z_comp_top = z_comp_bot - dz_comp z_comp_mid = (z_comp_top + z_comp_bot) / 2 z_coords = {'layer': z_lyr_mid, 'depth': z_comp_mid} # set model domain # settings_dir = os.path.split(os.path.abspath(config))[0] domain = set_domain( # os.path.join(workdir, configuration.MODEL_GRID['mask']), configuration.MODEL_GRID['mask'], modeltime, configuration.MODEL_GRID['mask_varname'], configuration.MODEL_GRID['area_varname'], configuration.MODEL_GRID['is_1d'], configuration.MODEL_GRID['xy_dimname'], z_coords, configuration.PSEUDO_COORDS) # decide whether to preprocess etref # would this be better as an option? if configuration.ETREF['preprocess']: initial_state = None etref_method = configuration.ETREF['method'] if 'PenmanMonteith' in etref_method: etref_fn = run_etref(PenmanMonteith, configuration, modeltime, domain, initial_state) if 'Hargreaves' in etref_method: etref_fn = run_etref(Hargreaves, configuration, modeltime, domain, initial_state) if 'PriestleyTaylor' in etref_method: etref_fn = run_etref(PriestleyTaylor, configuration, modeltime, domain, initial_state) # Update configuration configuration.ETREF['filename'] = etref_fn configuration.ETREF['varname'] = 'etref' if domain.is_1d: configuration.ETREF['is_1d'] = True configuration.ETREF['xy_dimname'] = 'space' clear_cache() # run model using user-specified model framework initial_state = None modeltime.reset() if deterministic: dynamic_model = HmDynamicModel(AquaCrop, configuration, modeltime, domain, variable_list_crop, initial_state) dynamic_framework = HmDynamicFramework(dynamic_model, lastTimeStep=len(modeltime) + 1, firstTimestep=1) dynamic_framework.setQuiet(True) dynamic_framework.run() elif montecarlo: dynamic_model = HmMonteCarloModel(AquaCrop, configuration, modeltime, domain, variable_list_crop, initial_state) dynamic_framework = HmDynamicFramework(dynamic_model, lastTimeStep=len(modeltime) + 1, firstTimestep=1) dynamic_framework.setQuiet(True) mc_framework = HmMonteCarloFramework( dynamic_framework, nrSamples=int(configuration.MONTE_CARLO['num_samples'])) mc_framework.run() elif kalmanfilter: dynamic_model = AqEnKfModel(AquaCrop, configuration, modeltime, domain, variable_list_crop, initial_state) dynamic_framework = HmDynamicFramework(dynamic_model, lastTimeStep=len(modeltime) + 1, firstTimestep=1) dynamic_framework.setQuiet(True) mc_framework = HmMonteCarloFramework( dynamic_framework, nrSamples=int(configuration.MONTE_CARLO['num_samples'])) enkf_framework = HmEnsKalmanFilterFramework(mc_framework) enkf_framework.setFilterTimesteps( configuration.KALMAN_FILTER['filter_timesteps']) enkf_framework.run()