def _handler(self, request, response): search = Search( configuration.get_config_value("data", "c3s_cmip5_archive_root")) nc_file = search.search_cmip5( model=request.inputs['model'][0].data, experiment=request.inputs['experiment'][0].data, variable=request.inputs['variable'][0].data, # start_year=request.inputs['year'][0].data, # end_year=request.inputs['year'][0].data, ) if not nc_file: raise Exception("Could not find CMIP5 file.") response.update_status('search done.', 10) # regridding regridder = Regridder(archive_base=configuration.get_config_value( "data", "c3s_cmip5_archive_root"), output_dir=os.path.join(self.workdir, 'outputs')) regridded_file = regridder.regrid(input_file=nc_file, domain_type=GLOBAL) response.outputs['output'].file = regridded_file response.update_status('regridding done.', 60) # plot preview title = "{} {} {}".format( request.inputs['model'][0].data, request.inputs['experiment'][0].data, request.inputs['variable'][0].data, # request.inputs['year'][0].data, ) plotter = Plotter(output_dir=os.path.join(self.workdir, 'out_plot')) preview_file = plotter.plot_preview(regridded_file, title) response.outputs['preview'].file = preview_file response.update_status('plot done.', 80) # run ncdump with open(os.path.join(self.workdir, "nc_dump.txt"), 'w') as fp: response.outputs['ncdump'].file = fp.name fp.writelines(ncdump(regridded_file)) response.update_status('ncdump done.', 90) # done response.update_status("done.", 100) return response
def test_create_output_dir(): regridder = Regridder() assert 'out_regrid/1_deg' in regridder.create_output_dir( domain_type=GLOBAL) assert 'out_regrid/0.5_deg' in regridder.create_output_dir( domain_type=REGIONAL)
def test_regrid_cmip5(): regridder = Regridder(archive_base=C3S_CMIP5_ARCHIVE_BASE) assert '1_deg/tas_Amon_HadGEM2-ES_historical_r1i1p1_186001-186012.nc' \ in regridder.regrid(C3S_CMIP5_NC, GLOBAL)
def test_regrid_cordex(): regridder = Regridder(archive_base=CORDEX_ARCHIVE_BASE) assert '0.5_deg/tasmin_AFR-44i_ECMWF-ERAINT_evaluation_r1i1p1_MOHC-HadRM3P_v1_mon_199001-199012.nc' \ in regridder.regrid(CORDEX_NC, REGIONAL)
def test_validate_regridded_file_cmip5(): regridder = Regridder(archive_base=C3S_CMIP5_ARCHIVE_BASE) regridder.validate_regridded_file(C3S_CMIP5_NC, GLOBAL)
def test_validate_regridded_file_cordex(): regridder = Regridder(archive_base=CORDEX_ARCHIVE_BASE) regridder.validate_regridded_file(CORDEX_NC, REGIONAL)
def test_validate_input_grid(): regridder = Regridder(archive_base=CORDEX_ARCHIVE_BASE) regridder.validate_input_grid(CORDEX_NC)
def test_get_grid_definition_file(): regridder = Regridder(archive_base=CORDEX_ARCHIVE_BASE) assert 'grid_files/ll1deg_grid.nc' in regridder.get_grid_definition_file( C3S_CMIP5_NC, domain_type=GLOBAL) assert 'grid_files/ll0.5deg_AFR-44i.nc' in regridder.get_grid_definition_file( CORDEX_NC, domain_type=REGIONAL)