How to use runmodule method in Nose

Best Python code snippet using nose

test_jsonfiller.py

Source:test_jsonfiller.py Github

copy

Full Screen

1"""Test the implementation of classes devised for filling json descriptors"""2import json3import numpy4import os5import tempfile6import unittest7from eumopps.catalogue.jsonfiller import FullstaceJsonFiller8from eustace.outputformats import definitions9class TestFullstaceJsonFiller(unittest.TestCase):10 def setUp(self):11 12 self.test_dictionaries = [{'A': 1434}, {'B': 'cat', 'please':456}]13 14 test_template_files = [tempfile.NamedTemporaryFile(prefix=str(index)+'.json', delete=False) for index in range(len(self.test_dictionaries))]15 self.test_template_filenames = [test_template_file.name for test_template_file in test_template_files]16 17 for dictionary, test_template_file in zip(self.test_dictionaries, test_template_files):18 json.dump(dictionary, test_template_file)19 20 self.dictionaries_with_None = [{'A': None}, 21 {'B': [{'cat':3, 'please':None}, {'cato':2}]}, 22 [{'B': {'cat':3, 'please':4}}, {'B': [{'cat':3, 'please':None}, {'dogo':1}]}]]23 24 test_template_file = tempfile.NamedTemporaryFile(prefix='output_grid.json', delete=False)25 26 template_dictionary = {"python_class" : "eumopps.catalogue.operation.Operation",27 "name" : None,28 "runmodule" : {29 "storage_climatology":{"statefilename_read" : {"datasetname" : None, "missing_data":"allowed" },30 "marginal_std_filename_read" : {"datasetname" : None, "missing_data":"allowed" },31 "sample_filename_read" : {"datasetname" : None, "missing_data":"allowed" }},32 "storage_large_scale" :{"statefilename_read" : {"datasetname" : None, "missing_data":"allowed" },33 "marginal_std_filename_read" : {"datasetname" : None, "missing_data":"allowed" },34 "sample_filename_read" : {"datasetname" : None, "missing_data":"allowed" }},35 "storage_local" :{"statefilename_read" : {"datasetname" : None, "missing_data":"allowed" },36 "marginal_std_filename_read" : {"datasetname" : None, "missing_data":"allowed" },37 "sample_filename_read" : {"datasetname" : None, "missing_data":"allowed" }},38 "insitu_biases": None ,39 "global_biases": None,40 "compute_uncertainties": None,41 "method": None,42 "compute_sample": None,43 "sample_size": None},44 "step" : { "python_class" : "eumopps.catalogue.step.StepDaily", "start" : None, "end" : None },45 "newdatasets": [{"name" : None,46 "subsets" : [{"layout" :{"patterns" : None}}]}]}47 48 self.test_template_file = test_template_file.name49 json.dump(template_dictionary, test_template_file)50 51 # To uncomment when more detailed tests on descriptor generation are required52 #self.original_descriptor_file = 'test/test_descriptor.json'53 54 def tearDown(self):55 56 for name in self.test_template_filenames:57 os.remove(name)58 59 os.remove(self.test_template_file)60 def test_init(self):61 current_dir = os.getcwd()62 template = 'test.json'63 date = '19870405'64 bias = 165 filler = FullstaceJsonFiller(3, 66 current_dir, '', current_dir,67 template, template,68 date, date,69 1, 1,70 'A', 'B', 'C', 'D', 71 'E', 'F', 'G', 'H',72 'I', 'J', 73 'K', 'L',74 'M', 'N', 'O')75 76 self.assertEqual(3, filler.n_iterations)77 self.assertEqual(current_dir, filler.inpath)78 self.assertEqual(current_dir, filler.outpath)79 self.assertEqual(template, filler.operation_template)80 self.assertEqual(template, filler.output_grid_template)81 self.assertEqual(date+'000000', filler.start_date)82 self.assertEqual(date+'000000', filler.end_date)83 self.assertEqual(bias, filler.land_biases)84 self.assertEqual(bias, filler.global_biases)85 86 self.assertEqual('A', filler.measurement_climatology_command)87 self.assertEqual('B', filler.measurement_climatology_name)88 self.assertEqual('C', filler.solution_climatology_command)89 self.assertEqual('D', filler.solution_climatology_name)90 self.assertEqual('E', filler.measurement_large_scale_command)91 self.assertEqual('F', filler.measurement_large_scale_name)92 self.assertEqual('G', filler.solution_large_scale_command)93 self.assertEqual('H', filler.solution_large_scale_name)94 95 self.assertEqual('I', filler.local_scale_command)96 self.assertEqual('J', filler.solution_local_scale_name)97 self.assertEqual('K', filler.output_grid_command)98 self.assertEqual('L', filler.output_grid_name)99 100 def test_load_templates(self):101 102 current_dir=''103 template_operation = self.test_template_filenames[0]104 template_grid = self.test_template_filenames[1]105 date = '19870405'106 bias = 1107 filler = FullstaceJsonFiller(3, 108 current_dir, '', current_dir,109 template_operation, template_grid,110 date, date,111 1, 1,112 'A', 'B', 'C', 'D', 113 'E', 'F', 'G', 'H',114 'I', 'J', 115 'K', 'L',116 'M', 'N', 'O')117 filler.load_templates()118 self.assertDictEqual(self.test_dictionaries[0], filler.operation_dict)119 self.assertDictEqual(self.test_dictionaries[1], filler.output_gridding_dict)120 121 def test_fill_output_gridding(self):122 123 current_dir=''124 template_operation = self.test_template_filenames[0]125 template_grid = self.test_template_file126 start_date = '19870405'127 end_date = '19880405'128 bias = 1129 filler = FullstaceJsonFiller(3, 130 current_dir, '', current_dir,131 template_operation, template_grid,132 start_date, end_date,133 1, 1,134 'A', 'B', 'C', 'D', 135 'E', 'F', 'G', 'H',136 'I', 'J', 137 'output_grid', 'eustace_infilled',138 'M', 'N', 'O')139 140 filler.load_templates()141 filler.fill_output_gridding()142 143 self.assertEqual(filler.output_gridding_dict['name'], 'output_grid')144 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'D_2')145 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'H_2')146 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_local']['statefilename_read']['datasetname'], 'J_2') 147 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_climatology']['marginal_std_filename_read']['datasetname'], 'uncertainties_climatology')148 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_large_scale']['marginal_std_filename_read']['datasetname'], 'uncertainties_large_scale')149 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_local']['marginal_std_filename_read']['datasetname'], 'uncertainties_local') 150 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_climatology']['sample_filename_read']['datasetname'], 'sample_climatology')151 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_large_scale']['sample_filename_read']['datasetname'], 'sample_large_scale')152 self.assertEqual(filler.output_gridding_dict['runmodule']['storage_local']['sample_filename_read']['datasetname'], 'sample_local') 153 self.assertEqual(filler.output_gridding_dict['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.output_grid')154 self.assertDictEqual(filler.output_gridding_dict['runmodule']['outputfile'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'eustace_infilled'})155 self.assertEqual(filler.output_gridding_dict['runmodule']['insitu_biases'], 1)156 self.assertEqual(filler.output_gridding_dict['runmodule']['global_biases'], 1)157 self.assertEqual(filler.output_gridding_dict['runmodule']['compute_uncertainties'], 0)158 self.assertEqual(filler.output_gridding_dict['runmodule']['compute_sample'], 0)159 self.assertEqual(filler.output_gridding_dict['step']['start'], start_date+'000000')160 self.assertEqual(filler.output_gridding_dict['step']['end'], end_date+'000000')161 self.assertEqual(filler.output_gridding_dict['newdatasets'][0]['name'], 'eustace_infilled')162 self.assertListEqual(filler.output_gridding_dict['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['eustace_infilled/%Y/', 'eustace_infilled_%Y%m%d.nc'])163 164 def test_fill_single_operation_space(self):165 current_dir=''166 template_operation = self.test_template_file167 template_grid = self.test_template_filenames[0]168 start_date = '19870405'169 end_date = '19880405'170 bias = 1171 filler = FullstaceJsonFiller(3, 172 current_dir, '', current_dir,173 template_operation, template_grid,174 start_date, end_date,175 1, 1,176 'A', 'B', 'C', 'D', 177 'E', 'F', 'G', 'H',178 'local_input_and_solve', 'solution_local', 179 'K', 'L',180 'M', 'N', 'O')181 182 filler.load_templates()183 result = filler.fill_single_operation_space(0, 2)184 self.assertEqual(result['name'], 'local_input_and_solve_0')185 186 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'D_0')187 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'H_0')188 self.assertDictEqual(result['runmodule']['storage_local']['time_index'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })189 self.assertEqual(result['runmodule']['insitu_biases'], 1)190 self.assertEqual(result['runmodule']['global_biases'], 1)191 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)192 self.assertEqual(result['runmodule']['method'], 'EXACT')193 194 self.assertEqual(result['runmodule']['compute_sample'], 0)195 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])196 197 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')198 self.assertEqual(result['runmodule']['component_index'], 2)199 self.assertDictEqual(result['runmodule']['storage_local']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_local_0'})200 self.assertEqual(result['step']['start'], start_date+'000000')201 self.assertEqual(result['step']['end'], end_date+'000000')202 self.assertEqual(len(result['newdatasets']),1)203 self.assertEqual(result['newdatasets'][0]['name'], 'solution_local_0')204 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_local_0/%Y/', 'solution_local_0_%Y%m%d.pickle'])205 result = filler.fill_single_operation_space(2, 2)206 self.assertEqual(result['name'], 'local_input_and_solve_2')207 208 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'D_2')209 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'H_2')210 self.assertDictEqual(result['runmodule']['storage_local']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_local_2'})211 self.assertDictEqual(result['runmodule']['storage_local']['marginal_std_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'uncertainties_local'})212 213 self.assertEqual(result['runmodule']['compute_uncertainties'], 1)214 self.assertEqual(result['runmodule']['method'], 'APPROXIMATED')215 216 self.assertEqual(result['runmodule']['compute_sample'], 1)217 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])218 219 self.assertEqual(len(result['newdatasets']), 3)220 self.assertEqual(result['newdatasets'][0]['name'], 'solution_local_2')221 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_local_2/%Y/', 'solution_local_2_%Y%m%d.pickle'])222 self.assertEqual(result['newdatasets'][1]['name'], 'uncertainties_local')223 self.assertListEqual(result['newdatasets'][1]['subsets'][0]['layout']['patterns'], ['uncertainties_local/%Y/', 'uncertainties_local_%Y%m%d.pickle'])224 self.assertEqual(result['newdatasets'][2]['name'], 'sample_local')225 self.assertListEqual(result['newdatasets'][2]['subsets'][0]['layout']['patterns'], ['sample_local/%Y/', 'sample_local_%Y%m%d.pickle'])226 def test_fill_single_measurement_operation_space_time(self):227 current_dir=''228 template_operation = self.test_template_file229 template_grid = self.test_template_filenames[0]230 start_date = '19870405'231 end_date = '19880405'232 bias = 1233 filler = FullstaceJsonFiller(3, 234 current_dir, '', current_dir,235 template_operation, template_grid,236 start_date, end_date,237 1, 1,238 'climatology_input', 'measurement_climatology', 'C', 'D', 239 'E', 'F', 'G', 'H',240 'I', 'J', 241 'K', 'L',242 'M', 'N', 'O')243 244 filler.load_templates()245 result = filler.fill_single_measurement_operation_space_time(0, 0, filler.measurement_climatology_command, filler.measurement_climatology_name)246 self.assertEqual(result['name'], 'climatology_input_0')247 248 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)249 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)250 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], None)251 self.assertDictEqual(result['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})252 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')253 254 self.assertEqual(result['runmodule']['insitu_biases'], 1)255 self.assertEqual(result['runmodule']['global_biases'], 1)256 257 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)258 self.assertEqual(result['runmodule']['method'], 'EXACT')259 260 self.assertEqual(result['runmodule']['compute_sample'], 0)261 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])262 263 self.assertEqual(result['runmodule']['component_index'], 0)264 self.assertDictEqual(result['runmodule']['storage_climatology']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_climatology_0'})265 self.assertDictEqual(result['runmodule']['storage_climatology']['measurement_time_index_write'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })266 self.assertEqual(result['step']['start'], start_date+'000000')267 self.assertEqual(result['step']['end'], end_date+'000000')268 self.assertEqual(result['newdatasets'][0]['name'], 'measurement_climatology_0')269 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_climatology_0/%Y/', 'measurement_climatology_0_%Y%m%d.pickle'])270 result = filler.fill_single_measurement_operation_space_time(51, 0, filler.measurement_climatology_command, filler.measurement_climatology_name)271 self.assertEqual(result['name'], 'climatology_input_51')272 273 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)274 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'H_50')275 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], 'J_50')276 self.assertDictEqual(result['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})277 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')278 self.assertEqual(result['runmodule']['component_index'], 0)279 280 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)281 self.assertEqual(result['runmodule']['method'], 'EXACT')282 283 self.assertEqual(result['runmodule']['compute_sample'], 0)284 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])285 286 self.assertDictEqual(result['runmodule']['storage_climatology']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_climatology_51'})287 self.assertEqual(result['newdatasets'][0]['name'], 'measurement_climatology_51')288 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_climatology_51/%Y/', 'measurement_climatology_51_%Y%m%d.pickle'])289 filler = FullstaceJsonFiller(3, 290 current_dir, '', current_dir,291 template_operation, template_grid,292 start_date, end_date,293 1, 1,294 'A', 'C', 'C', 'D', 295 'large_scale_input', 'measurement_large_scale', 'G', 'H',296 'I', 'J', 297 'K', 'L',298 'M', 'N', 'O')299 300 filler.load_templates()301 result = filler.fill_single_measurement_operation_space_time(0, 1, filler.measurement_large_scale_command, filler.measurement_large_scale_name)302 self.assertEqual(result['name'], 'large_scale_input_0')303 304 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'D_0')305 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)306 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], None)307 self.assertDictEqual(result['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})308 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')309 310 self.assertEqual(result['runmodule']['insitu_biases'], 1)311 self.assertEqual(result['runmodule']['global_biases'], 1)312 313 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)314 self.assertEqual(result['runmodule']['method'], 'EXACT')315 316 self.assertEqual(result['runmodule']['compute_sample'], 0)317 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])318 self.assertEqual(result['runmodule']['component_index'], 1)319 self.assertDictEqual(result['runmodule']['storage_large_scale']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_large_scale_0'})320 self.assertDictEqual(result['runmodule']['storage_large_scale']['measurement_time_index_write'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })321 self.assertEqual(result['step']['start'], start_date+'000000')322 self.assertEqual(result['step']['end'], end_date+'000000')323 self.assertEqual(result['newdatasets'][0]['name'], 'measurement_large_scale_0')324 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_large_scale_0/%Y/', 'measurement_large_scale_0_%Y%m%d.pickle'])325 result = filler.fill_single_measurement_operation_space_time(14, 1, filler.measurement_large_scale_command, filler.measurement_large_scale_name)326 self.assertEqual(result['name'], 'large_scale_input_14')327 328 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'D_14')329 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)330 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], 'J_13')331 self.assertDictEqual(result['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})332 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')333 self.assertEqual(result['runmodule']['component_index'], 1)334 335 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)336 self.assertEqual(result['runmodule']['method'], 'EXACT')337 338 self.assertEqual(result['runmodule']['compute_sample'], 0)339 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])340 self.assertDictEqual(result['runmodule']['storage_large_scale']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_large_scale_14'})341 self.assertEqual(result['newdatasets'][0]['name'], 'measurement_large_scale_14')342 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_large_scale_14/%Y/', 'measurement_large_scale_14_%Y%m%d.pickle'])343 def test_fill_single_solution_operation_space_time(self):344 current_dir=''345 template_operation = self.test_template_file346 template_grid = self.test_template_filenames[0]347 start_date = '19870405'348 end_date = '19880405'349 bias = 1350 filler = FullstaceJsonFiller(52, 351 current_dir, '', current_dir,352 template_operation, template_grid,353 start_date, end_date,354 1, 0,355 'A', 'measurement_climatology', 'climatology_solve', 'solution_climatology', 356 'E', 'F', 'G', 'H',357 'I', 'J', 358 'K', 'L',359 'M', 'N', 'O')360 361 filler.load_templates()362 result = filler.fill_single_solution_operation_space_time(0, 0, filler.solution_climatology_command, filler.solution_climatology_name, filler.measurement_climatology_name)363 self.assertEqual(result['name'], 'climatology_solve_0')364 365 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)366 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)367 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], None)368 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')369 370 self.assertEqual(result['runmodule']['insitu_biases'], 1)371 self.assertEqual(result['runmodule']['global_biases'], 0)372 373 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)374 self.assertEqual(result['runmodule']['method'], 'EXACT')375 self.assertEqual(result['runmodule']['compute_sample'], 0)376 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])377 self.assertEqual(result['runmodule']['component_index'], 0)378 self.assertDictEqual(result['runmodule']['storage_climatology']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'solution_climatology_0'})379 self.assertDictEqual(result['runmodule']['storage_climatology']['measurementfilelist_read'], { 'python_class' : 'eumopps.catalogue.placeholder.InputFileList','datasetname' : 'measurement_climatology_0'})380 self.assertDictEqual(result['step'], { 'python_class' : 'eumopps.catalogue.step.StepOnce'})381 self.assertEqual(len(result['newdatasets']), 1)382 self.assertEqual(result['newdatasets'][0]['name'], 'solution_climatology_0')383 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_climatology_0/', 'solution_climatology_0.pickle'])384 result = filler.fill_single_solution_operation_space_time(51, 0, filler.solution_climatology_command, filler.solution_climatology_name, filler.measurement_climatology_name)385 self.assertEqual(result['name'], 'climatology_solve_51')386 387 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)388 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)389 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], None)390 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')391 self.assertEqual(result['runmodule']['component_index'], 0)392 393 self.assertEqual(result['runmodule']['compute_uncertainties'], 1)394 self.assertEqual(result['runmodule']['method'], 'APPROXIMATED')395 self.assertEqual(result['runmodule']['compute_sample'], 1)396 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])397 self.assertDictEqual(result['runmodule']['storage_climatology']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'solution_climatology_51'})398 self.assertDictEqual(result['runmodule']['storage_climatology']['marginal_std_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'uncertainties_climatology'})399 self.assertDictEqual(result['runmodule']['storage_climatology']['sample_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'sample_climatology'})400 self.assertDictEqual(result['runmodule']['storage_climatology']['measurementfilelist_read'], { 'python_class' : 'eumopps.catalogue.placeholder.InputFileList','datasetname' : 'measurement_climatology_51'})401 self.assertEqual(len(result['newdatasets']), 3)402 self.assertEqual(result['newdatasets'][0]['name'], 'solution_climatology_51')403 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_climatology_51/', 'solution_climatology_51.pickle'])404 self.assertEqual(result['newdatasets'][1]['name'], 'uncertainties_climatology')405 self.assertListEqual(result['newdatasets'][1]['subsets'][0]['layout']['patterns'], ['uncertainties_climatology/', 'uncertainties_climatology.pickle'])406 self.assertEqual(result['newdatasets'][2]['name'], 'sample_climatology')407 self.assertListEqual(result['newdatasets'][2]['subsets'][0]['layout']['patterns'], ['sample_climatology/', 'sample_climatology.pickle'])408 filler = FullstaceJsonFiller(15, 409 current_dir, '', current_dir,410 template_operation, template_grid,411 start_date, end_date,412 0, 1,413 'A', 'C', 'C', 'D', 414 'E', 'measurement_large_scale', 'large_scale_solve', 'solution_large_scale',415 'I', 'J', 416 'K', 'L',417 'M', 'N', 'O')418 419 filler.load_templates()420 result = filler.fill_single_solution_operation_space_time(0, 1, filler.solution_large_scale_command, filler.solution_large_scale_name,filler.measurement_large_scale_name)421 self.assertEqual(result['name'], 'large_scale_solve_0')422 423 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)424 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)425 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], None)426 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')427 428 self.assertEqual(result['runmodule']['insitu_biases'], 0)429 self.assertEqual(result['runmodule']['global_biases'], 1)430 431 self.assertEqual(result['runmodule']['compute_uncertainties'], 0)432 self.assertEqual(result['runmodule']['method'], 'EXACT')433 434 self.assertEqual(result['runmodule']['compute_sample'], 0)435 self.assertEqual(result['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])436 self.assertEqual(result['runmodule']['component_index'], 1)437 self.assertDictEqual(result['runmodule']['storage_large_scale']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'solution_large_scale_0'})438 self.assertDictEqual(result['runmodule']['storage_large_scale']['measurementfilelist_read'], { 'python_class' : 'eumopps.catalogue.placeholder.InputFileList','datasetname' : 'measurement_large_scale_0'})439 self.assertDictEqual(result['step'], { 'python_class' : 'eumopps.catalogue.step.StepOnce'})440 self.assertEqual(len(result['newdatasets']), 1)441 self.assertEqual(result['newdatasets'][0]['name'], 'solution_large_scale_0')442 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_large_scale_0/', 'solution_large_scale_0.pickle'])443 result = filler.fill_single_solution_operation_space_time(14, 1, filler.solution_large_scale_command, filler.solution_large_scale_name,filler.measurement_large_scale_name)444 self.assertEqual(result['name'], 'large_scale_solve_14')445 446 self.assertEqual(result['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)447 self.assertEqual(result['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)448 self.assertEqual(result['runmodule']['storage_local']['statefilename_read']['datasetname'], None)449 self.assertEqual(result['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')450 self.assertEqual(result['runmodule']['component_index'], 1)451 452 self.assertEqual(result['runmodule']['compute_uncertainties'], 1)453 self.assertEqual(result['runmodule']['method'], 'APPROXIMATED')454 self.assertDictEqual(result['runmodule']['storage_large_scale']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'solution_large_scale_14'})455 self.assertDictEqual(result['runmodule']['storage_large_scale']['marginal_std_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'uncertainties_large_scale'})456 self.assertDictEqual(result['runmodule']['storage_large_scale']['sample_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile','datasetname' : 'sample_large_scale'})457 self.assertDictEqual(result['runmodule']['storage_large_scale']['measurementfilelist_read'], { 'python_class' : 'eumopps.catalogue.placeholder.InputFileList','datasetname' : 'measurement_large_scale_14'})458 self.assertEqual(len(result['newdatasets']), 3)459 self.assertEqual(result['newdatasets'][0]['name'], 'solution_large_scale_14')460 self.assertListEqual(result['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_large_scale_14/', 'solution_large_scale_14.pickle'])461 self.assertEqual(result['newdatasets'][1]['name'], 'uncertainties_large_scale')462 self.assertListEqual(result['newdatasets'][1]['subsets'][0]['layout']['patterns'], ['uncertainties_large_scale/', 'uncertainties_large_scale.pickle'])463 self.assertEqual(result['newdatasets'][2]['name'], 'sample_large_scale')464 self.assertListEqual(result['newdatasets'][2]['subsets'][0]['layout']['patterns'], ['sample_large_scale/', 'sample_large_scale.pickle'])465 def test_fill_descriptor(self):466 current_dir=''467 template_operation = self.test_template_file468 template_grid = self.test_template_file469 start_date = '19870405'470 end_date = '19880405'471 bias = 1472 filler = FullstaceJsonFiller(3, 473 current_dir, '', current_dir,474 template_operation, template_grid,475 start_date, end_date,476 1, 1,477 'climatology_input', 'measurement_climatology', 'climatology_solve', 'solution_climatology', 478 'large_scale_input', 'measurement_large_scale', 'large_scale_solve', 'solution_large_scale',479 'local_input_and_solve', 'solution_local', 480 'output_grid', 'eustace_infilled',481 'output_climatology_name', 'output_large_scale_name', 'output_local_name')482 483 result = filler.fill_descriptor()484 485 self.assertEqual(result['python_class'], 'eumopps.catalogue.catalogue.Catalogue')486 self.assertTrue(isinstance(result['operations'], list))487 self.assertEqual(len(result['operations']), 16)488 489 # Analyzing more in detail490 # Climatology491 climatology_input_0 = result['operations'][0]492 self.assertEqual(climatology_input_0['name'], 'climatology_input_0')493 494 self.assertEqual(climatology_input_0['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)495 self.assertEqual(climatology_input_0['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)496 self.assertEqual(climatology_input_0['runmodule']['storage_local']['statefilename_read']['datasetname'], None)497 self.assertDictEqual(climatology_input_0['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})498 self.assertEqual(climatology_input_0['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')499 self.assertEqual(climatology_input_0['runmodule']['insitu_biases'], 1)500 self.assertEqual(climatology_input_0['runmodule']['global_biases'], 1)501 self.assertEqual(climatology_input_0['runmodule']['compute_uncertainties'], 0)502 self.assertEqual(climatology_input_0['runmodule']['method'], 'EXACT')503 self.assertEqual(climatology_input_0['runmodule']['compute_sample'], 0)504 self.assertEqual(climatology_input_0['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])505 self.assertEqual(climatology_input_0['runmodule']['component_index'], 0)506 self.assertDictEqual(climatology_input_0['runmodule']['storage_climatology']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_climatology_0'})507 self.assertDictEqual(climatology_input_0['runmodule']['storage_climatology']['measurement_time_index_write'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })508 self.assertEqual(climatology_input_0['step']['start'], start_date+'000000')509 self.assertEqual(climatology_input_0['step']['end'], end_date+'000000')510 self.assertEqual(len(climatology_input_0['newdatasets']), 1)511 self.assertEqual(climatology_input_0['newdatasets'][0]['name'], 'measurement_climatology_0')512 self.assertListEqual(climatology_input_0['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_climatology_0/%Y/', 'measurement_climatology_0_%Y%m%d.pickle'])513 climatology_solve_0 = result['operations'][1]514 self.assertEqual(climatology_solve_0['name'], 'climatology_solve_0')515 516 self.assertEqual(climatology_solve_0['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)517 self.assertEqual(climatology_solve_0['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)518 self.assertEqual(climatology_solve_0['runmodule']['storage_local']['statefilename_read']['datasetname'], None)519 self.assertEqual(climatology_solve_0['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')520 self.assertEqual(climatology_solve_0['runmodule']['insitu_biases'], 1)521 self.assertEqual(climatology_solve_0['runmodule']['global_biases'], 1)522 self.assertEqual(climatology_solve_0['runmodule']['compute_uncertainties'], 0)523 self.assertEqual(climatology_solve_0['runmodule']['method'], 'EXACT')524 self.assertEqual(climatology_solve_0['runmodule']['compute_sample'], 0)525 self.assertEqual(climatology_solve_0['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])526 self.assertEqual(climatology_solve_0['runmodule']['component_index'], 0)527 self.assertDictEqual(climatology_solve_0['runmodule']['storage_climatology']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_climatology_0'})528 self.assertDictEqual(climatology_solve_0['step'], { 'python_class' : 'eumopps.catalogue.step.StepOnce'})529 self.assertEqual(climatology_solve_0['newdatasets'][0]['name'], 'solution_climatology_0')530 self.assertListEqual(climatology_solve_0['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_climatology_0/', 'solution_climatology_0.pickle'])531 climatology_input_2 = result['operations'][10]532 self.assertEqual(climatology_input_2['name'], 'climatology_input_2')533 534 self.assertEqual(climatology_input_2['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)535 self.assertEqual(climatology_input_2['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'solution_large_scale_1')536 self.assertEqual(climatology_input_2['runmodule']['storage_local']['statefilename_read']['datasetname'], 'solution_local_1')537 self.assertDictEqual(climatology_input_2['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})538 self.assertEqual(climatology_input_2['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')539 self.assertEqual(climatology_input_2['runmodule']['insitu_biases'], 1)540 self.assertEqual(climatology_input_2['runmodule']['global_biases'], 1)541 self.assertEqual(climatology_input_2['runmodule']['compute_uncertainties'], 0)542 self.assertEqual(climatology_input_2['runmodule']['method'], 'EXACT')543 self.assertEqual(climatology_input_2['runmodule']['compute_sample'], 0)544 self.assertEqual(climatology_input_2['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])545 self.assertEqual(climatology_input_2['runmodule']['component_index'], 0)546 self.assertDictEqual(climatology_input_2['runmodule']['storage_climatology']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_climatology_2'})547 self.assertDictEqual(climatology_input_2['runmodule']['storage_climatology']['measurement_time_index_write'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })548 self.assertEqual(climatology_input_2['step']['start'], start_date+'000000')549 self.assertEqual(climatology_input_2['step']['end'], end_date+'000000')550 self.assertEqual(climatology_input_2['newdatasets'][0]['name'], 'measurement_climatology_2')551 self.assertListEqual(climatology_input_2['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_climatology_2/%Y/', 'measurement_climatology_2_%Y%m%d.pickle'])552 climatology_solve_2 = result['operations'][11]553 self.assertEqual(climatology_solve_2['name'], 'climatology_solve_2')554 555 self.assertEqual(climatology_solve_2['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)556 self.assertEqual(climatology_solve_2['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)557 self.assertEqual(climatology_solve_2['runmodule']['storage_local']['statefilename_read']['datasetname'], None)558 self.assertEqual(climatology_solve_2['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')559 self.assertEqual(climatology_solve_2['runmodule']['insitu_biases'], 1)560 self.assertEqual(climatology_solve_2['runmodule']['global_biases'], 1)561 self.assertEqual(climatology_solve_2['runmodule']['compute_uncertainties'], 1)562 self.assertEqual(climatology_solve_2['runmodule']['method'], 'APPROXIMATED')563 self.assertEqual(climatology_solve_2['runmodule']['compute_sample'], 1)564 self.assertEqual(climatology_solve_2['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])565 self.assertEqual(climatology_solve_2['runmodule']['component_index'], 0)566 self.assertDictEqual(climatology_solve_2['runmodule']['storage_climatology']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_climatology_2'})567 self.assertDictEqual(climatology_solve_2['runmodule']['storage_climatology']['marginal_std_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'uncertainties_climatology'})568 self.assertDictEqual(climatology_solve_2['runmodule']['storage_climatology']['sample_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'sample_climatology'})569 self.assertDictEqual(climatology_solve_2['step'], { 'python_class' : 'eumopps.catalogue.step.StepOnce'})570 self.assertEqual(climatology_solve_2['newdatasets'][0]['name'], 'solution_climatology_2')571 self.assertListEqual(climatology_solve_2['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_climatology_2/', 'solution_climatology_2.pickle'])572 self.assertEqual(climatology_solve_2['newdatasets'][1]['name'], 'uncertainties_climatology')573 self.assertListEqual(climatology_solve_2['newdatasets'][1]['subsets'][0]['layout']['patterns'], ['uncertainties_climatology/', 'uncertainties_climatology.pickle'])574 self.assertEqual(climatology_solve_2['newdatasets'][2]['name'], 'sample_climatology')575 self.assertListEqual(climatology_solve_2['newdatasets'][2]['subsets'][0]['layout']['patterns'], ['sample_climatology/', 'sample_climatology.pickle'])576 # Large scale577 large_scale_input_0 = result['operations'][2]578 self.assertEqual(large_scale_input_0['name'], 'large_scale_input_0')579 580 self.assertEqual(large_scale_input_0['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'solution_climatology_0')581 self.assertEqual(large_scale_input_0['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)582 self.assertEqual(large_scale_input_0['runmodule']['storage_local']['statefilename_read']['datasetname'], None)583 self.assertDictEqual(large_scale_input_0['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})584 self.assertEqual(large_scale_input_0['runmodule']['insitu_biases'], 1)585 self.assertEqual(large_scale_input_0['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')586 self.assertEqual(large_scale_input_0['runmodule']['global_biases'], 1)587 self.assertEqual(large_scale_input_0['runmodule']['component_index'], 1)588 self.assertEqual(large_scale_input_0['runmodule']['compute_uncertainties'], 0)589 self.assertEqual(large_scale_input_0['runmodule']['method'], 'EXACT')590 self.assertEqual(large_scale_input_0['runmodule']['compute_sample'], 0)591 self.assertEqual(large_scale_input_0['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])592 self.assertDictEqual(large_scale_input_0['runmodule']['storage_large_scale']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_large_scale_0'})593 self.assertDictEqual(large_scale_input_0['runmodule']['storage_large_scale']['measurement_time_index_write'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })594 self.assertEqual(large_scale_input_0['step']['start'], start_date+'000000')595 self.assertEqual(large_scale_input_0['step']['end'], end_date+'000000')596 self.assertEqual(len(large_scale_input_0['newdatasets']), 1)597 self.assertEqual(large_scale_input_0['newdatasets'][0]['name'], 'measurement_large_scale_0')598 self.assertListEqual(large_scale_input_0['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_large_scale_0/%Y/', 'measurement_large_scale_0_%Y%m%d.pickle'])599 large_scale_solve_0 = result['operations'][3]600 self.assertEqual(large_scale_solve_0['name'], 'large_scale_solve_0')601 602 self.assertEqual(large_scale_solve_0['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)603 self.assertEqual(large_scale_solve_0['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)604 self.assertEqual(large_scale_solve_0['runmodule']['storage_local']['statefilename_read']['datasetname'], None)605 self.assertEqual(large_scale_solve_0['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')606 self.assertEqual(large_scale_solve_0['runmodule']['insitu_biases'], 1)607 self.assertEqual(large_scale_solve_0['runmodule']['global_biases'], 1)608 self.assertEqual(large_scale_solve_0['runmodule']['compute_uncertainties'], 0)609 self.assertEqual(large_scale_solve_0['runmodule']['method'], 'EXACT')610 self.assertEqual(large_scale_solve_0['runmodule']['compute_sample'], 0)611 self.assertEqual(large_scale_solve_0['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])612 self.assertEqual(large_scale_solve_0['runmodule']['component_index'], 1)613 self.assertDictEqual(large_scale_solve_0['runmodule']['storage_large_scale']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_large_scale_0'})614 self.assertDictEqual(large_scale_solve_0['step'], { 'python_class' : 'eumopps.catalogue.step.StepOnce'})615 self.assertEqual(len(large_scale_solve_0['newdatasets']), 1)616 self.assertEqual(large_scale_solve_0['newdatasets'][0]['name'], 'solution_large_scale_0')617 self.assertListEqual(large_scale_solve_0['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_large_scale_0/', 'solution_large_scale_0.pickle'])618 large_scale_input_2 = result['operations'][12]619 self.assertEqual(large_scale_input_2['name'], 'large_scale_input_2')620 621 self.assertEqual(large_scale_input_2['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'solution_climatology_2')622 self.assertEqual(large_scale_input_2['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)623 self.assertEqual(large_scale_input_2['runmodule']['storage_local']['statefilename_read']['datasetname'], 'solution_local_1')624 self.assertDictEqual(large_scale_input_2['runmodule']['storage_local']['time_index'], {'python_class': 'eumopps.catalogue.placeholder.StepIndex'})625 self.assertEqual(large_scale_input_2['runmodule']['insitu_biases'], 1)626 self.assertEqual(large_scale_input_2['runmodule']['global_biases'], 1)627 self.assertEqual(large_scale_input_2['runmodule']['compute_uncertainties'], 0)628 self.assertEqual(large_scale_input_2['runmodule']['method'], 'EXACT')629 self.assertEqual(large_scale_input_2['runmodule']['compute_sample'], 0)630 self.assertEqual(large_scale_input_2['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])631 self.assertEqual(large_scale_input_2['runmodule']['component_index'], 1)632 self.assertDictEqual(large_scale_input_2['runmodule']['storage_large_scale']['measurementfilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'measurement_large_scale_2'})633 self.assertDictEqual(large_scale_input_2['runmodule']['storage_large_scale']['measurement_time_index_write'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })634 self.assertEqual(large_scale_input_2['step']['start'], start_date+'000000')635 self.assertEqual(large_scale_input_2['step']['end'], end_date+'000000')636 self.assertEqual(len(large_scale_input_2['newdatasets']), 1)637 self.assertEqual(large_scale_input_2['newdatasets'][0]['name'], 'measurement_large_scale_2')638 self.assertListEqual(large_scale_input_2['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['measurement_large_scale_2/%Y/', 'measurement_large_scale_2_%Y%m%d.pickle'])639 large_scale_solve_2 = result['operations'][13]640 self.assertEqual(large_scale_solve_2['name'], 'large_scale_solve_2')641 642 self.assertEqual(large_scale_solve_2['runmodule']['storage_climatology']['statefilename_read']['datasetname'], None)643 self.assertEqual(large_scale_solve_2['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], None)644 self.assertEqual(large_scale_solve_2['runmodule']['storage_local']['statefilename_read']['datasetname'], None)645 self.assertEqual(large_scale_solve_2['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.solve')646 self.assertEqual(large_scale_solve_2['runmodule']['insitu_biases'], 1)647 self.assertEqual(large_scale_solve_2['runmodule']['global_biases'], 1)648 self.assertEqual(large_scale_solve_2['runmodule']['compute_uncertainties'], 1)649 self.assertEqual(large_scale_solve_2['runmodule']['method'], 'APPROXIMATED')650 self.assertEqual(large_scale_solve_2['runmodule']['component_index'], 1)651 self.assertEqual(large_scale_solve_2['runmodule']['compute_sample'], 1)652 self.assertEqual(large_scale_solve_2['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])653 self.assertDictEqual(large_scale_solve_2['runmodule']['storage_large_scale']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_large_scale_2'})654 self.assertDictEqual(large_scale_solve_2['runmodule']['storage_large_scale']['marginal_std_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'uncertainties_large_scale'})655 self.assertDictEqual(large_scale_solve_2['runmodule']['storage_large_scale']['sample_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'sample_large_scale'})656 self.assertEqual(large_scale_solve_2['step'], { 'python_class' : 'eumopps.catalogue.step.StepOnce'})657 self.assertEqual(large_scale_solve_2['newdatasets'][0]['name'], 'solution_large_scale_2')658 self.assertEqual(len(large_scale_solve_2['newdatasets']), 3)659 self.assertListEqual(large_scale_solve_2['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_large_scale_2/', 'solution_large_scale_2.pickle'])660 self.assertEqual(large_scale_solve_2['newdatasets'][1]['name'], 'uncertainties_large_scale')661 self.assertListEqual(large_scale_solve_2['newdatasets'][1]['subsets'][0]['layout']['patterns'], ['uncertainties_large_scale/', 'uncertainties_large_scale.pickle'])662 self.assertEqual(large_scale_solve_2['newdatasets'][2]['name'], 'sample_large_scale')663 self.assertListEqual(large_scale_solve_2['newdatasets'][2]['subsets'][0]['layout']['patterns'], ['sample_large_scale/', 'sample_large_scale.pickle'])664 # Local scale665 local_input_and_solve_2 = result['operations'][14]666 self.assertEqual(local_input_and_solve_2['name'], 'local_input_and_solve_2')667 668 self.assertEqual(local_input_and_solve_2['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'solution_climatology_2')669 self.assertEqual(local_input_and_solve_2['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'solution_large_scale_2')670 self.assertEqual(local_input_and_solve_2['runmodule']['storage_local']['statefilename_read']['datasetname'], None)671 self.assertEqual(local_input_and_solve_2['runmodule']['python_function'], 'eustace.analysis.advanced_standard.examples.example_eustace.process_inputs')672 self.assertEqual(local_input_and_solve_2['runmodule']['insitu_biases'], 1)673 self.assertEqual(local_input_and_solve_2['runmodule']['global_biases'], 1)674 self.assertEqual(local_input_and_solve_2['runmodule']['compute_uncertainties'], 1)675 self.assertEqual(local_input_and_solve_2['runmodule']['method'], 'APPROXIMATED')676 self.assertEqual(local_input_and_solve_2['runmodule']['compute_sample'], 1)677 self.assertEqual(local_input_and_solve_2['runmodule']['sample_size'], definitions.GLOBAL_SAMPLE_SHAPE[3])678 self.assertEqual(local_input_and_solve_2['runmodule']['component_index'], 2)679 self.assertDictEqual(local_input_and_solve_2['runmodule']['storage_local']['statefilename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'solution_local_2'})680 self.assertDictEqual(local_input_and_solve_2['runmodule']['storage_local']['marginal_std_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'uncertainties_local'})681 self.assertDictEqual(local_input_and_solve_2['runmodule']['storage_local']['sample_filename_write'], { 'python_class' : 'eumopps.catalogue.placeholder.OutputFile', 'datasetname' : 'sample_local'})682 self.assertDictEqual(local_input_and_solve_2['runmodule']['storage_local']['time_index'], { "python_class" : "eumopps.catalogue.placeholder.StepIndex" })683 self.assertEqual(local_input_and_solve_2['step']['start'], start_date+'000000')684 self.assertEqual(local_input_and_solve_2['step']['end'], end_date+'000000')685 self.assertEqual(len(local_input_and_solve_2['newdatasets']), 3)686 self.assertEqual(local_input_and_solve_2['newdatasets'][0]['name'], 'solution_local_2')687 self.assertListEqual(local_input_and_solve_2['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['solution_local_2/%Y/', 'solution_local_2_%Y%m%d.pickle'])688 self.assertEqual(local_input_and_solve_2['newdatasets'][1]['name'], 'uncertainties_local')689 self.assertListEqual(local_input_and_solve_2['newdatasets'][1]['subsets'][0]['layout']['patterns'], ['uncertainties_local/%Y/', 'uncertainties_local_%Y%m%d.pickle'])690 self.assertEqual(local_input_and_solve_2['newdatasets'][2]['name'], 'sample_local')691 self.assertListEqual(local_input_and_solve_2['newdatasets'][2]['subsets'][0]['layout']['patterns'], ['sample_local/%Y/', 'sample_local_%Y%m%d.pickle'])692 # Output gridding693 output_grid = result['operations'][15]694 self.assertEqual(output_grid['name'], 'output_grid')695 696 self.assertEqual(output_grid['runmodule']['storage_climatology']['statefilename_read']['datasetname'], 'solution_climatology_2')697 self.assertEqual(output_grid['runmodule']['storage_climatology']['marginal_std_filename_read']['datasetname'], 'uncertainties_climatology')698 self.assertEqual(output_grid['runmodule']['storage_climatology']['sample_filename_read']['datasetname'], 'sample_climatology')699 self.assertEqual(output_grid['runmodule']['storage_large_scale']['statefilename_read']['datasetname'], 'solution_large_scale_2')700 self.assertEqual(output_grid['runmodule']['storage_large_scale']['marginal_std_filename_read']['datasetname'], 'uncertainties_large_scale')701 self.assertEqual(output_grid['runmodule']['storage_large_scale']['sample_filename_read']['datasetname'], 'sample_large_scale')702 self.assertEqual(output_grid['runmodule']['storage_local']['statefilename_read']['datasetname'], 'solution_local_2')703 self.assertEqual(output_grid['runmodule']['storage_local']['marginal_std_filename_read']['datasetname'], 'uncertainties_local')704 self.assertEqual(output_grid['runmodule']['storage_local']['sample_filename_read']['datasetname'], 'sample_local')705 self.assertEqual(output_grid['runmodule']['outputfile']['datasetname'], 'eustace_infilled')706 self.assertEqual(output_grid['runmodule']['insitu_biases'], 1)707 self.assertEqual(output_grid['runmodule']['global_biases'], 1)708 self.assertEqual(output_grid['step']['start'], start_date+'000000')709 self.assertEqual(output_grid['step']['end'], end_date+'000000')710 self.assertEqual(output_grid['runmodule']['compute_uncertainties'], 0)711 self.assertEqual(output_grid['runmodule']['method'], 'EXACT')712 self.assertEqual(output_grid['runmodule']['compute_sample'], 0)713 self.assertEqual(output_grid['newdatasets'][0]['name'], 'eustace_infilled')714 self.assertListEqual(output_grid['newdatasets'][0]['subsets'][0]['layout']['patterns'], ['eustace_infilled/%Y/', 'eustace_infilled_%Y%m%d.nc'])715 def test_create_descriptor(self):716 current_dir=''717 template_operation = self.test_template_file718 template_grid = self.test_template_file719 start_date = '19870405'720 end_date = '19880405'721 bias = 1722 filler = FullstaceJsonFiller(3, 723 current_dir, './',724 template_operation, '', template_grid,725 start_date, end_date,726 1, 1,727 'climatology_input', 'measurement_climatology', 'climatology_solve', 'solution_climatology', 728 'large_scale_input', 'measurement_large_scale', 'large_scale_solve', 'solution_large_scale',729 'local_input_and_solve', 'solution_local', 730 'output_grid', 'eustace_infilled',731 'output_climatology_name', 'output_large_scale_name', 'output_local_name')732 733 filler.create_descriptor('baba.json')734 self.assertTrue(os.path.exists('./baba.json'))735 os.remove('./baba.json')736 737 def test_return_output_patterns(self):738 739 for input_name, output_list in zip(['A', 'abgs'], [['A/%Y/', 'A_%Y%m%d.nc'], ['abgs/%Y/', 'abgs_%Y%m%d.nc']]):740 self.assertListEqual(FullstaceJsonFiller.return_output_patterns(input_name, 'nc', 'measurement'), output_list)741 for input_name, output_list in zip(['A', 'abgs'], [['A/%Y/', 'A_%Y%m%d.nc'], ['abgs/%Y/', 'abgs_%Y%m%d.nc']]):742 self.assertListEqual(FullstaceJsonFiller.return_output_patterns(input_name, 'nc', 'space_solution'), output_list)743 for input_name, output_list in zip(['A', 'abgs'], [['A/', 'A.nc'], ['abgs/', 'abgs.nc']]):744 self.assertListEqual(FullstaceJsonFiller.return_output_patterns(input_name, 'nc', 'spacetime_solution'), output_list)745 for input_name, output_list in zip(['A', 'abgs'], [['A/', 'A.nc'], ['abgs/', 'abgs.nc']]):746 self.assertRaises(ValueError, FullstaceJsonFiller.return_output_patterns, input_name, 'nc', 'spjkbchw_time_solution')747 def test_check_none(self):748 749 for test_dictionary in self.dictionaries_with_None:750 self.assertRaises(ValueError, FullstaceJsonFiller.check_none, test_dictionary)751# To uncomment when more detailed tests on descriptor generation are required 752"""753 def test_against_original_descriptor(self):754 755 current_dir='test/'756 template_operation = 'test_advstd_operation_template.json'757 template_grid = 'test_advstd_outputgrid_template.json'758 start_date = '20060101'759 end_date = '20101231'760 bias = 1761 filler = FullstaceJsonFiller(1, 762 current_dir, './',763 template_operation, template_grid,764 start_date, end_date,765 1, 1,766 'climatology_input', 'measurement_climatology', 'climatology_solve', 'solution_climatology', 767 'large_scale_input', 'measurement_large_scale', 'large_scale_solve', 'solution_large_scale',768 'local_input_and_solve', 'solution_local', 769 'output_grid', 'eustace_example_infilled')770 771 result = filler.fill_descriptor()['operations']772 with open(self.original_descriptor_file) as fp:773 comparison = json.load(fp)774 comparison = comparison['operations']775 self.assertEqual(len(result), len(comparison))776 777 self.check_all_keys(result, comparison)778 self.check_all_items(result, comparison)779 780 def check_all_keys(self, descriptor, comparison):781 if isinstance(descriptor, dict) and isinstance(comparison, dict):782 if len(descriptor) != len(comparison):783 message = 'Sub dictionaries differ!\nlen(descriptor) = {}, keys = {}\nlen(comparison)={}, keys={}'.format(len(descriptor), descriptor.keys(), len(comparison), comparison.keys())784 raise ValueError(message)785 else:786 left = descriptor.keys()787 left.sort()788 right = comparison.keys()789 right.sort()790 self.assertListEqual(left, right)791 for key in descriptor.keys():792 return self.check_all_keys(descriptor[key], comparison[key])793 elif isinstance(descriptor, list) and isinstance(comparison, list):794 return [ self.check_all_keys(item_1, item_2) for item_1, item_2 in zip(descriptor, comparison) ]795 796 def check_all_items(self, descriptor, comparison):797 if isinstance(descriptor, dict) and isinstance(comparison, dict):798 for key in descriptor.keys():799 return self.check_all_items(descriptor[key], comparison[key])800 elif isinstance(descriptor, list) and isinstance(comparison, list):801 return [ self.check_all_items(item_1, item_2) for item_1, item_2 in zip(descriptor, comparison) ]802 else:803 self.assertEqual(descriptor, comparison)...

Full Screen

Full Screen

test_strds_to_rast3.py

Source:test_strds_to_rast3.py Github

copy

Full Screen

1"""Test t.rast.to.rast32(C) 2014 by the GRASS Development Team3This program is free software under the GNU General Public4License (>=v2). Read the file COPYING that comes with GRASS5for details.6@author Soeren Gebbert7"""8import grass.pygrass.modules as pymod9import subprocess10from grass.gunittest.case import TestCase11from grass.gunittest.gmodules import SimpleModule12class TestSTRDSToRast3(TestCase):13 def setUp(self):14 """Create input data15 """16 self.use_temp_region()17 self.runModule("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")18 self.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)19 self.runModule("r.mapcalc", expression="prec_1i = 100")20 self.runModule("r.mapcalc", expression="prec_2i = 200")21 self.runModule("r.mapcalc", expression="prec_3i = 300")22 self.runModule("r.mapcalc", expression="prec_4i = 400")23 self.runModule("r.mapcalc", expression="prec_5i = 500")24 self.runModule("r.mapcalc", expression="prec_6i = 600")25 26 self.runModule("r.mapcalc", expression="prec_1d = 100.0")27 self.runModule("r.mapcalc", expression="prec_2d = 200.0")28 self.runModule("r.mapcalc", expression="prec_3d = 300.0")29 self.runModule("r.mapcalc", expression="prec_4d = 400.0")30 self.runModule("r.mapcalc", expression="prec_5d = 500.0")31 self.runModule("r.mapcalc", expression="prec_6d = 600.0")32 33 self.runModule("r.mapcalc", expression="prec_1f = float(100.0)")34 self.runModule("r.mapcalc", expression="prec_2f = float(200.0)")35 self.runModule("r.mapcalc", expression="prec_3f = float(300.0)")36 self.runModule("r.mapcalc", expression="prec_4f = float(400.0)")37 self.runModule("r.mapcalc", expression="prec_5f = float(500.0)")38 self.runModule("r.mapcalc", expression="prec_6f = float(600.0)")39 40 self.runModule("t.create", type="strds", temporaltype="absolute", 41 output="precip_i", title="A test integer", 42 description="A test integer values")43 self.runModule("t.register", flags="i", type="raster", input="precip_i", 44 maps="prec_1i,prec_2i,prec_3i,prec_4i,prec_5i,prec_6i", 45 start="2001-01-01", increment="3 months")46 self.runModule("t.create", type="strds", temporaltype="absolute", 47 output="precip_f", title="A test float", 48 description="A test float values")49 self.runModule("t.register", flags="i", type="raster", input="precip_f",50 maps="prec_1f,prec_2f,prec_3f,prec_4f,prec_5f,prec_6f", 51 start="2001-01-01", increment="3 months")52 self.runModule("t.create", type="strds", temporaltype="absolute", 53 output="precip_d", title="A test float", 54 description="A test float values")55 self.runModule("t.register", flags="i", type="raster", input="precip_d", 56 maps="prec_1d,prec_2d,prec_3d,prec_4d,prec_5d,prec_6d", 57 start="2001-01-01", increment="3 months")58 def tearDown(self):59 """Remove generated data"""60 #self.runModule("t.remove", flags="rf", type="strds", 61 # inputs="precip_i,precip_f,precip_d")62 #self.runModule('g.remove', type='raster', pattern='prec_*', flags='f')63 self.del_temp_region()64 def otest_3m(self):65 """Convert STRDS into 3d raster map, granularity 3 months"""66 self.assertModule("t.rast.to.rast3", input="precip_i", output="precip_i")67 self.assertModule("t.rast.to.rast3", input="precip_f", output="precip_f")68 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")69 univar_string="""n=57670 null_cells=071 cells=57672 min=10073 max=60074 range=50075 mean=35076 mean_of_abs=35077 stddev=170.78251276599378 variance=29166.666666666779 coeff_var=48.795003647426780 sum=201600"""81 self.assertRaster3dFitsUnivar(raster="precip_i", reference=univar_string, precision=2)82 self.assertRaster3dFitsUnivar(raster="precip_f", reference=univar_string, precision=2)83 self.assertRaster3dFitsUnivar(raster="precip_d", reference=univar_string, precision=2)84 tinfo_string="""north=8085 south=086 east=12087 west=088 bottom=121389 top=123190 nsres=1091 ewres=1092 tbres=393 rows=894 cols=1295 depths=696 datatype="DCELL"97 timestamp="1 Jan 2001 00:00:00 / 1 Jul 2002 00:00:00"98 units="none"99 vertical_units="months" """100 self.assertRaster3dFitsInfo(raster="precip_i", reference=tinfo_string, precision=2)101 tinfo_string="""north=80102 south=0103 east=120104 west=0105 bottom=1213106 top=1231107 nsres=10108 ewres=10109 tbres=3110 rows=8111 cols=12112 depths=6113 datatype="FCELL"114 timestamp="1 Jan 2001 00:00:00 / 1 Jul 2002 00:00:00"115 units="none"116 vertical_units="months" """117 self.assertRaster3dFitsInfo(raster="precip_f", reference=tinfo_string, precision=2)118 tinfo_string="""north=80119 south=0120 east=120121 west=0122 bottom=1213123 top=1231124 nsres=10125 ewres=10126 tbres=3127 rows=8128 cols=12129 depths=6130 datatype="DCELL"131 timestamp="1 Jan 2001 00:00:00 / 1 Jul 2002 00:00:00"132 units="none"133 vertical_units="months" """134 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)135 def test_3m_gap(self):136 """Convert STRDS with gaps into 3d raster map, granularity 3 months"""137 138 self.runModule("t.unregister", maps="prec_3d,prec_3f,prec_3i")139 self.assertModule("t.rast.to.rast3", input="precip_i", output="precip_i")140 self.assertModule("t.rast.to.rast3", input="precip_f", output="precip_f")141 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")142 univar_string="""n=480143 null_cells=96144 cells=576145 min=100146 max=600147 range=500148 mean=360149 mean_of_abs=360150 stddev=185.472369909914151 variance=34400152 coeff_var=51.5201027527539153 sum=172800"""154 univar = SimpleModule("r3.univar", flags="g", map="precip_i")155 self.assertModuleKeyValue(module=univar, reference=univar_string, precision=2, sep="=")156 tinfo_string="""north=80157 south=0158 east=120159 west=0160 bottom=1213161 top=1231162 nsres=10163 ewres=10164 tbres=3165 rows=8166 cols=12167 depths=6168 datatype="DCELL"169 timestamp="1 Jan 2001 00:00:00 / 1 Jul 2002 00:00:00"170 units="none"171 vertical_units="months" """172 self.assertRaster3dFitsInfo(raster="precip_i", reference=tinfo_string, precision=2)173 tinfo_string="""north=80174 south=0175 east=120176 west=0177 bottom=1213178 top=1231179 nsres=10180 ewres=10181 tbres=3182 rows=8183 cols=12184 depths=6185 datatype="FCELL"186 timestamp="1 Jan 2001 00:00:00 / 1 Jul 2002 00:00:00"187 units="none"188 vertical_units="months" """189 self.assertRaster3dFitsInfo(raster="precip_f", reference=tinfo_string, precision=2)190 tinfo_string="""north=80191 south=0192 east=120193 west=0194 bottom=1213195 top=1231196 nsres=10197 ewres=10198 tbres=3199 rows=8200 cols=12201 depths=6202 datatype="DCELL"203 timestamp="1 Jan 2001 00:00:00 / 1 Jul 2002 00:00:00"204 units="none"205 vertical_units="months" """206 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)207class TestSTRDSToRast3MultiGran(TestCase):208 def setUp(self):209 """Create input data210 """211 self.use_temp_region()212 self.runModule("g.gisenv", set="TGIS_USE_CURRENT_MAPSET=1")213 self.runModule("g.region", s=0, n=80, w=0, e=120, b=0, t=50, res=10, res3=10)214 215 self.runModule("r.mapcalc", expression="prec_1d = 100.0")216 self.runModule("r.mapcalc", expression="prec_2d = 200.0")217 self.runModule("r.mapcalc", expression="prec_3d = 300.0")218 self.runModule("r.mapcalc", expression="prec_4d = 400.0")219 self.runModule("r.mapcalc", expression="prec_5d = 500.0")220 self.runModule("r.mapcalc", expression="prec_6d = 600.0")221 self.runModule("t.create", type="strds", temporaltype="absolute", 222 output="precip_d", title="A test float", 223 description="A test float values")224 def tearDown(self):225 """Remove generated data"""226 #self.runModule("t.remove", flags="rf", type="strds", inputs="precip_d")227 #self.runModule('g.remove', type='raster', pattern='prec_*', flags='f')228 self.del_temp_region()229 def otest_years(self):230 """Convert STRDS into 3d raster map, granularity5 years"""231 self.runModule("t.register", flags="i", type="raster", input="precip_d", 232 maps="prec_1d,prec_2d,prec_3d,prec_4d,prec_5d,prec_6d", 233 start="2000-01-01", increment="5 years")234 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")235 tinfo_string="""north=80236 south=0237 east=120238 west=0239 bottom=100240 top=130241 nsres=10242 ewres=10243 tbres=3244 rows=8245 cols=12246 depths=6247 datatype="DCELL"248 timestamp="1 Jan 2000 00:00:00 / 1 Jan 2030 00:00:00"249 units="none"250 vertical_units="years" """251 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)252 def otest_months(self):253 """Convert STRDS into 3d raster map, granularity 6 months"""254 self.runModule("t.register", flags="i", type="raster", input="precip_d", 255 maps="prec_1d,prec_2d,prec_3d,prec_4d,prec_5d,prec_6d", 256 start="2000-01-01", increment="6 months")257 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")258 tinfo_string="""north=80259 south=0260 east=120261 west=0262 bottom=1201263 top=1237264 nsres=10265 ewres=10266 tbres=6267 rows=8268 cols=12269 depths=6270 datatype="DCELL"271 timestamp="1 Jan 2000 00:00:00 / 1 Jan 2003 00:00:00"272 units="none"273 vertical_units="months" """274 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)275 def otest_days(self):276 """Convert STRDS into 3d raster map, granularity 7 days"""277 self.runModule("t.register", flags="i", type="raster", input="precip_d", 278 maps="prec_1d,prec_2d,prec_3d,prec_4d,prec_5d,prec_6d", 279 start="2000-01-01", increment="7 days")280 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")281 self.runModule("r3.info", map="precip_d")282 tinfo_string="""north=80283 south=0284 east=120285 west=0286 bottom=36524287 top=36566288 nsres=10289 ewres=10290 tbres=7291 rows=8292 cols=12293 depths=6294 datatype="DCELL"295 timestamp="1 Jan 2000 00:00:00 / 12 Feb 2000 00:00:00"296 units="none"297 vertical_units="days" """298 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)299 def otest_hours(self):300 """Convert STRDS into 3d raster map, granularity 7 days"""301 self.runModule("t.register", flags="i", type="raster", input="precip_d", 302 maps="prec_1d,prec_2d,prec_3d,prec_4d,prec_5d,prec_6d", 303 start="2000-01-01", increment="3 hours")304 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")305 self.runModule("r3.info", map="precip_d")306 tinfo_string="""north=80307 south=0308 east=120309 west=0310 bottom=36524311 top=36524.8312 nsres=10313 ewres=10314 tbres=0.125315 rows=8316 cols=12317 depths=6318 datatype="DCELL"319 timestamp="1 Jan 2000 00:00:00 / 1 Jan 2000 18:00:00"320 units="none"321 vertical_units="hours" """322 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)323 def otest_minutes(self):324 """Convert STRDS into 3d raster map, granularity 7 days"""325 self.runModule("t.register", flags="i", type="raster", input="precip_d", 326 maps="prec_1d,prec_2d,prec_3d,prec_4d,prec_5d,prec_6d", 327 start="2000-01-01", increment="17 minutes")328 self.assertModule("t.rast.to.rast3", input="precip_d", output="precip_d")329 self.runModule("r3.info", map="precip_d")330 tinfo_string="""north=80331 south=0332 east=120333 west=0334 bottom=36524335 top=36524.1336 nsres=10337 ewres=10338 tbres=0.0118056339 rows=8340 cols=12341 depths=6342 datatype="DCELL"343 timestamp="1 Jan 2000 00:00:00 / 1 Jan 2000 01:42:00"344 units="none"345 vertical_units="minutes" """346 self.assertRaster3dFitsInfo(raster="precip_d", reference=tinfo_string, precision=2)347if __name__ == '__main__':348 from grass.gunittest.main import test...

Full Screen

Full Screen

test_r_futures_potential.py

Source:test_r_futures_potential.py Github

copy

Full Screen

1#!/usr/bin/env python32import os3from grass.gunittest.case import TestCase4from grass.gunittest.main import test5class TestPotential(TestCase):6 output = "potential.csv"7 dredge_out = "dredge_out.csv"8 @classmethod9 def setUpClass(cls):10 cls.use_temp_region()11 cls.runModule("g.region", raster="lsat7_2002_30@PERMANENT")12 cls.runModule(13 "r.mapcalc",14 expression="ndvi_2002 = double(lsat7_2002_40@PERMANENT - lsat7_2002_30@PERMANENT) / double(lsat7_2002_40@PERMANENT + lsat7_2002_30@PERMANENT)",15 )16 cls.runModule(17 "r.mapcalc",18 expression="ndvi_1987 = double(lsat5_1987_40@landsat - lsat5_1987_30@landsat) / double(lsat5_1987_40@landsat + lsat5_1987_30@landsat)",19 )20 cls.runModule(21 "r.mapcalc",22 expression="urban_2002 = if(ndvi_2002 <= 0.1 && isnull(lakes), 1, if(isnull(lakes), 0, null()))",23 )24 cls.runModule(25 "r.mapcalc",26 expression="urban_1987 = if(ndvi_1987 <= 0.1 && isnull(lakes), 1, if(isnull(lakes), 0, null()))",27 )28 cls.runModule("r.slope.aspect", elevation="elevation", slope="slope")29 cls.runModule("r.grow.distance", input="lakes", distance="lakes_dist")30 cls.runModule("r.mapcalc", expression="lakes_dist_km = lakes_dist/1000.")31 cls.runModule("v.to.rast", input="streets_wake", output="streets", use="val")32 cls.runModule("r.grow.distance", input="streets", distance="streets_dist")33 cls.runModule("r.mapcalc", expression="streets_dist_km = streets_dist/1000.")34 cls.runModule(35 "r.futures.devpressure",36 input="urban_2002",37 output="devpressure",38 method="gravity",39 size=15,40 flags="n",41 )42 cls.runModule(43 "r.mapcalc",44 expression="urban_change = if(urban_2002 == 1, if(urban_1987 == 0, 1, null()), 0)",45 )46 cls.runModule("r.mapcalc", expression="single_level = 1")47 cls.runModule(48 "r.sample.category",49 input="urban_change",50 output="sampling",51 sampled=[52 "zipcodes",53 "single_level",54 "devpressure",55 "slope",56 "lakes_dist_km",57 "streets_dist_km",58 ],59 npoints=[500, 100],60 random_seed=1,61 )62 @classmethod63 def tearDownClass(cls):64 cls.runModule('g.remove', flags='f', type='raster',65 name=['slope', 'lakes_dist', 'lakes_dist_km', 'streets',66 'streets_dist', 'streets_dist_km', 'devpressure',67 'ndvi_2002', 'ndvi_1987', 'urban_1987', 'urban_2002',68 'urban_change', 'single_level'])69 cls.runModule('g.remove', flags='f', type='vector', name=['sampling'])70 cls.del_temp_region()71 def tearDown(self):72 try:73 os.remove(self.output)74 os.remove(self.dredge_out)75 except OSError:76 pass77 def test_potential_run(self):78 """Test if results is in expected limits"""79 self.assertModule(80 "r.futures.potential",81 input="sampling",82 columns=["devpressure", "lakes_dist_km", "slope", "streets_dist_km"],83 developed_column="urban_change",84 subregions_column="zipcodes",85 output=self.output,86 )87 with open(self.output, "r") as f:88 i = 089 for line in f.readlines():90 line = line.strip().split(",")91 self.assertEqual(len(line), 6)92 if i == 0:93 self.assertEqual(94 line,95 [96 "ID",97 "Intercept",98 "devpressure",99 "lakes_dist_km",100 "slope",101 "streets_dist_km",102 ],103 )104 i += 1105 self.assertEqual(i, 14)106 def test_potential_run_dredge(self):107 """Test if results is in expected limits"""108 self.assertModule(109 "r.futures.potential",110 flags="d",111 input="sampling",112 columns=["devpressure", "lakes_dist_km", "slope", "streets_dist_km"],113 developed_column="urban_change",114 subregions_column="zipcodes",115 min_variables=4,116 max_variables=4,117 output=self.output,118 )119 with open(self.output, "r") as f:120 i = 0121 for line in f.readlines():122 line = line.strip().split(",")123 self.assertEqual(len(line), 6)124 if i == 0:125 self.assertEqual(126 sorted(line),127 [128 "ID",129 "Intercept",130 "devpressure",131 "lakes_dist_km",132 "slope",133 "streets_dist_km",134 ],135 )136 i += 1137 self.assertEqual(i, 14)138 def test_potential_run_dredge_export(self):139 """Test if results is in expected limits"""140 self.assertModule(141 "r.futures.potential",142 flags="d",143 input="sampling",144 columns=["devpressure", "lakes_dist_km", "slope", "streets_dist_km"],145 developed_column="urban_change",146 subregions_column="zipcodes",147 min_variables=3,148 max_variables=4,149 nprocs=2,150 fixed_columns=["slope"],151 dredge_output=self.dredge_out,152 output=self.output,153 )154 with open(self.output, "r") as f:155 i = 0156 for line in f.readlines():157 line = line.strip().split(",")158 self.assertEqual(len(line), 5)159 if i == 0:160 self.assertEqual(161 line,162 ["ID", "Intercept", "devpressure", "streets_dist_km", "slope"],163 )164 i += 1165 self.assertEqual(i, 14)166 with open(self.dredge_out, "r") as f:167 i = 0168 for line in f.readlines():169 line = line.strip().split(",")170 self.assertEqual(len(line), 11)171 if i == 0:172 self.assertEqual(173 line,174 [175 "ID",176 "Intercept",177 "devpressure",178 "lakes_dist_km",179 "slope",180 "streets_dist_km",181 "df",182 "logLik",183 "AIC",184 "delta",185 "weight",186 ],187 )188 i += 1189 self.assertEqual(i, 5)190 def test_potential_run_single_level(self):191 """Test if results is in expected limits"""192 self.assertModule(193 "r.futures.potential",194 input="sampling",195 columns=["devpressure", "lakes_dist_km", "slope", "streets_dist_km"],196 developed_column="urban_change",197 subregions_column="single_level",198 output=self.output,199 )200 with open(self.output, "r") as f:201 i = 0202 for line in f.readlines():203 line = line.strip().split(",")204 self.assertEqual(len(line), 6)205 if i == 0:206 self.assertEqual(207 line,208 [209 "ID",210 "Intercept",211 "devpressure",212 "lakes_dist_km",213 "slope",214 "streets_dist_km",215 ],216 )217 i += 1218 self.assertEqual(i, 2)219if __name__ == "__main__":...

Full Screen

Full Screen

test_r_futures_calib.py

Source:test_r_futures_calib.py Github

copy

Full Screen

1#!/usr/bin/env python32import os3import filecmp4from grass.gunittest.case import TestCase5from grass.gunittest.main import test6class TestPGACalib(TestCase):7 pga_params = dict(development_pressure='devpressure',8 predictors=['slope', 'lakes_dist_km', 'streets_dist_km'],9 n_dev_neighbourhood=15, devpot_params='data/potential.csv',10 num_neighbors=4, seed_search='random', development_pressure_approach='gravity',11 gamma=1.5, scaling_factor=1, subregions='zipcodes',12 demand='data/demand.csv')13 @classmethod14 def setUpClass(cls):15 cls.use_temp_region()16 cls.runModule('g.region', raster="lsat7_2002_30@PERMANENT")17 cls.runModule('r.mapcalc',18 expression="ndvi_2002 = double(lsat7_2002_40@PERMANENT - lsat7_2002_30@PERMANENT) / double(lsat7_2002_40@PERMANENT + lsat7_2002_30@PERMANENT)")19 cls.runModule('r.mapcalc',20 expression="ndvi_1987 = double(lsat5_1987_40@landsat - lsat5_1987_30@landsat) / double(lsat5_1987_40@landsat + lsat5_1987_30@landsat)")21 cls.runModule('r.mapcalc', expression="urban_1987 = if(ndvi_1987 <= 0.1 && isnull(lakes), 1, if(isnull(lakes), 0, null()))")22 cls.runModule('r.mapcalc', expression="urban_2002 = if(ndvi_2002 <= 0.1 && isnull(lakes), 1, if(isnull(lakes), 0, null()))")23 cls.runModule('r.slope.aspect', elevation='elevation', slope='slope')24 cls.runModule('r.grow.distance', input='lakes', distance='lakes_dist')25 cls.runModule('r.mapcalc', expression="lakes_dist_km = lakes_dist/1000.")26 cls.runModule('v.to.rast', input='streets_wake', output='streets', use='val')27 cls.runModule('r.grow.distance', input='streets', distance='streets_dist')28 cls.runModule('r.mapcalc', expression="streets_dist_km = streets_dist/1000.")29 cls.runModule('r.futures.devpressure', input='urban_2002', output='devpressure', method='gravity', size=15, flags='n')30 @classmethod31 def tearDownClass(cls):32 cls.runModule('g.remove', flags='f', type='raster',33 name=['slope', 'lakes_dist', 'lakes_dist_km', 'streets',34 'streets_dist', 'streets_dist_km', 'devpressure',35 'ndvi_2002', 'ndvi_1987', 'urban_1987', 'urban_2002'])36 cls.del_temp_region()37 def tearDown(self):38 for each in ('data/out_library.txt',39 'data/out_library_subregion.csv',40 'data/out_calib.csv',41 'data/out_calib_subregion.csv'):42 try:43 os.remove(each)44 except OSError:45 pass46 def test_pga_calib_library(self):47 """Test if generated patch library matches the reference"""48 self.assertModule('r.futures.calib', flags='l',49 development_start='urban_1987',50 development_end='urban_2002',51 patch_threshold=0,52 subregions='zipcodes',53 patch_sizes='data/out_library.txt')54 self.assertTrue(filecmp.cmp('data/out_library.txt', 'data/ref_library.txt', shallow=False),55 "Patch libraries differ")56 def test_pga_calib_library_subregions(self):57 """Test if generated patch library matches the reference"""58 self.assertModule('r.futures.calib', flags='ls',59 development_start='urban_1987',60 development_end='urban_2002',61 patch_threshold=0,62 subregions='zipcodes',63 patch_sizes='data/out_library_subregion.csv')64 self.assertTrue(filecmp.cmp('data/out_library_subregion.csv', 'data/ref_library_subregion.csv', shallow=False),65 "Patch libraries differ")66 def test_pga_calib_compactness(self):67 """Test if compactness calib file matches the reference"""68 self.assertModule('r.futures.calib',69 development_start='urban_1987',70 development_end='urban_2002',71 patch_threshold=0,72 patch_sizes='data/out_library.txt',73 compactness_mean=[0.1, 0.8],74 compactness_range=[0.1],75 discount_factor=[0.1],76 calibration_results='data/out_calib.csv',77 nprocs=1,78 repeat=2,79 random_seed=1,80 **self.pga_params)81 self.assertTrue(filecmp.cmp('data/out_calib.csv', 'data/ref_calib.csv', shallow=False),82 "Calibration results differ")83 def test_pga_calib_compactness_subregions(self):84 """Test if compactness calib file matches the reference"""85 self.assertModule('r.futures.calib', flags='s',86 development_start='urban_1987',87 development_end='urban_2002',88 patch_threshold=0,89 patch_sizes='data/out_library_subregion.csv',90 compactness_mean=[0.1, 0.8],91 compactness_range=[0.1],92 discount_factor=[0.1],93 calibration_results='data/out_calib_subregion.csv',94 nprocs=1,95 repeat=2,96 random_seed=1,97 **self.pga_params)98 self.assertTrue(filecmp.cmp('data/out_library_subregion.csv', 'data/ref_library_subregion.csv', shallow=False),99 "Patch libraries differ")100 self.assertTrue(filecmp.cmp('data/out_calib_subregion.csv', 'data/ref_calib_subregion.csv', shallow=False),101 "Calibration results differ")102if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Nose automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful