def test_read_ppfile_var_grid(self, fname=None): if fname is None: fname = testdata_filepath("ukv_eg_variable_sample.pp") pp = fields_from_pp_file(fname) self.assertEqual(len(pp), 1) field = pp[0] self.assertIsNotNone(field.pp_extra_data) self.assertEqual(field.lbrel, 3) self.assertEqual(field.lbvc, 65) data = field.get_data() self.assertEqual(data.shape[0], field.lbrow) self.assertEqual(data.shape[1], field.lbnpt) expected_extra = [1, 2, 12, 13, 14, 15] self.assertEqual(len(field.pp_extra_data), 6) self.assertArrayEqual(list(field.pp_extra_data.keys()), expected_extra) self.assertEqual(len(field.pp_extra_data[1]), field.lbnpt) self.assertEqual(len(field.pp_extra_data[12]), field.lbnpt) self.assertEqual(len(field.pp_extra_data[13]), field.lbnpt) self.assertEqual(len(field.pp_extra_data[2]), field.lbrow) self.assertEqual(len(field.pp_extra_data[14]), field.lbrow) self.assertEqual(len(field.pp_extra_data[15]), field.lbrow)
def test_pp_file_format_check(self): pp_file = testdata_filepath("n48_multi_field.pp") self.assertTrue(mule.pp.file_is_pp_file(pp_file)) um_file = testdata_filepath("n48_multi_field.ff") self.assertFalse(mule.pp.file_is_pp_file(um_file)) um_file = testdata_filepath("soil_params.anc") self.assertFalse(mule.pp.file_is_pp_file(um_file)) um_file = testdata_filepath("eg_boundary_sample.lbc") self.assertFalse(mule.pp.file_is_pp_file(um_file)) um_file = testdata_filepath("n48_eg_dump_special.dump") self.assertFalse(mule.pp.file_is_pp_file(um_file))
def test_ff_to_pp_var_grid(self): ff = mule.FieldsFile.from_file( testdata_filepath("ukv_eg_variable_sample.ff")) with self.temp_filename() as temp_path: fields_to_pp_file(temp_path, ff.fields, ff) # Re-read self.test_read_ppfile_var_grid(temp_path)
def test_ff_to_pp_fix_grid(self): ff = mule.FieldsFile.from_file( testdata_filepath("n48_multi_field.ff")) with self.temp_filename() as temp_path: fields_to_pp_file(temp_path, ff.fields) # Re-read self.test_read_ppfile_fix_grid(temp_path)
def test_read_lbcfile(self): lbc = LBCFile.from_file( tests.testdata_filepath("eg_boundary_sample.lbc")) self.assertEqual(type(lbc), LBCFile) self.assertIsNotNone(lbc.integer_constants) self.assertEqual(lbc.integer_constants.shape, (46, )) self.assertIsNotNone(lbc.real_constants) self.assertEqual(lbc.real_constants.shape, (38, )) self.assertIsNotNone(lbc.level_dependent_constants) self.assertEqual(lbc.level_dependent_constants.shape, (39, 4)) self.assertIsNone(lbc.row_dependent_constants) self.assertIsNone(lbc.column_dependent_constants) self.assertEqual(len(lbc.fields), 10) self.assertEqual([fld.lbrel for fld in lbc.fields[:-1]], [3] * 9) self.assertEqual([fld.lbvc for fld in lbc.fields[:-1]], [0] * 9)
def test_read_fieldsfile(self): dump = DumpFile.from_file( tests.testdata_filepath("n48_eg_dump_special.dump")) self.assertEqual(type(dump), DumpFile) self.assertIsNotNone(dump.integer_constants) self.assertEqual(dump.integer_constants.shape, (46, )) self.assertIsNotNone(dump.real_constants) self.assertEqual(dump.real_constants.shape, (38, )) self.assertIsNotNone(dump.level_dependent_constants) self.assertEqual(dump.level_dependent_constants.shape, (71, 8)) self.assertIsNone(dump.row_dependent_constants) self.assertIsNone(dump.column_dependent_constants) self.assertEqual(len(dump.fields), 2) self.assertEqual([fld.lbrel for fld in dump.fields], [3, -32768]) self.assertEqual([fld.lbvc for fld in dump.fields[:-1]], [0])
def test_read_ancilfile(self): with warnings.catch_warnings(): msg_exp = r".*Ancillary files do not define.*" warnings.filterwarnings("ignore", msg_exp) anc = AncilFile.from_file( tests.testdata_filepath("soil_params.anc")) self.assertEqual(type(anc), AncilFile) self.assertIsNotNone(anc.integer_constants) self.assertEqual(anc.integer_constants.shape, (15, )) self.assertIsNotNone(anc.real_constants) self.assertEqual(anc.real_constants.shape, (6, )) self.assertIsNone(anc.level_dependent_constants) self.assertIsNone(anc.row_dependent_constants) self.assertIsNone(anc.column_dependent_constants) self.assertEqual(len(anc.fields), 11) self.assertEqual([fld.lbrel for fld in anc.fields[:-1]], [2] * 10) self.assertEqual([fld.lbvc for fld in anc.fields[:-1]], [129] * 10)
def test_read_ppfile_fix_grid(self, fname=None): if fname is None: fname = testdata_filepath("n48_multi_field.pp") pp = fields_from_pp_file(fname) self.assertEqual(len(pp), 4) expected_rel = (3, 3, 3, 3) expected_vc = (1, 1, 6, 129) for field, rel, vc in zip(pp, expected_rel, expected_vc): self.assertIsNone(field.pp_extra_data) self.assertEqual(field.lbrel, rel) self.assertEqual(field.lbvc, vc) data = field.get_data() self.assertEqual(data.shape[0], field.lbrow) self.assertEqual(data.shape[1], field.lbnpt)