def test_image_given_empty_state(self): name = None pattern = None locator = None state = db.State() loader = data.DBLoader(name, pattern, locator) result = loader.image(state) expect = self.empty_image self.assert_dict_equal(expect, result)
def test_image_given_non_existent_entry_in_database(self): name = None pattern = None database = db.Database.connect(":memory:") locator = db.Locator(database.connection) state = db.State(variable="variable", initial_time="2019-01-01 00:00:00", valid_time="2019-01-01 00:00:00", pressure=1000.) loader = data.DBLoader(name, pattern, locator) result = loader.image(state) expect = self.empty_image self.assert_dict_equal(expect, result)
def file_loader(file_type, pattern, label=None, locator=None): file_type = file_type.lower().replace("_", "") if file_type == 'rdt': return rdt.Loader(pattern) elif file_type == 'gpm': return data.GPM(pattern) elif file_type == 'earthnetworks': return earth_networks.Loader.pattern(pattern) elif file_type == 'eida50': return satellite.EIDA50(pattern) elif file_type == 'unifiedmodel': return data.DBLoader(label, pattern, locator) else: raise Exception("unrecognised file_type: {}".format(file_type))
def test_image_given_inconsistent_pressures(self): path = "file.nc" variable = "variable" initial_time = "2019-01-01 00:00:00" valid_time = "2019-01-01 00:00:00" pressure = 1000. database = db.Database.connect(":memory:") database.insert_file_name(path, initial_time) database.insert_pressure(path, variable, pressure, i=0) database.insert_time(path, variable, valid_time, i=0) locator = db.Locator(database.connection) state = db.State(variable=variable, initial_time=initial_time, valid_time=valid_time, pressure=pressure, pressures=[925.]) loader = data.DBLoader(None, "*.nc", locator) result = loader.image(state) expect = self.empty_image self.assert_dict_equal(expect, result)
def file_loader(file_type, pattern, label=None, locator=None): file_type = file_type.lower().replace("_", "") print(file_type) if file_type == 'rdt': return rdt.Loader(pattern) elif file_type == 'gpm': return data.GPM(pattern) elif file_type == 'earthnetworks': return earth_networks.Loader.pattern(pattern) elif file_type == 'eida50': return satellite.EIDA50(pattern) elif file_type == 'griddedforecast': return gridded_forecast.ImageLoader(label, pattern) elif file_type == 'ghrsstl4': return ghrsstl4.ImageLoader(label, pattern) elif file_type == 'unifiedmodel': return data.DBLoader(label, pattern, locator) elif file_type == 'intake': return intake_loader.IntakeLoader(pattern) elif file_type == 'saf': return saf.saf(pattern, label, locator) else: raise Exception("unrecognised file_type: {}".format(file_type))