def test__shape_of_earth(self): grid_definition_template_12(self.test_cube, self.mock_grib) self._check_key('shapeOfTheEarth', 7) self._check_key('scaleFactorOfEarthMajorAxis', 0) self._check_key('scaledValueOfEarthMajorAxis', 6377563.396) self._check_key('scaleFactorOfEarthMinorAxis', 0) self._check_key('scaledValueOfEarthMinorAxis', 6356256.909)
def test__negative_grid_points_gribapi_fixed(self): test_cube = self._make_test_cube(x_points=[-1, 1, 3, 5, 7], y_points=[-4, 9]) grid_definition_template_12(test_cube, self.mock_grib) self._check_key("X1", -100) self._check_key("X2", 700) self._check_key("Y1", -400) self._check_key("Y2", 900)
def test__scale_factor_gribapi_fixed(self): def get_native_type(grib, key): assert key == "scaleFactorAtReferencePoint" return float self.mock_gribapi.grib_get_native_type = get_native_type grid_definition_template_12(self.test_cube, self.mock_grib) self._check_key("scaleFactorAtReferencePoint", 0.9996012717)
def test__grid_points_approx(self): test_cube = self._make_test_cube(x_points=[1.001, 3.003, 5.005, 7.007], y_points=[4, 9]) grid_definition_template_12(test_cube, self.mock_grib) self._check_key("X1", 100) self._check_key("X2", 701) self._check_key("Y1", 400) self._check_key("Y2", 900) self._check_key("Di", 200) self._check_key("Dj", 500)
def test__grid_points_exact(self): test_cube = self._make_test_cube(x_points=[1, 3, 5, 7], y_points=[4, 9]) grid_definition_template_12(test_cube, self.mock_grib) self._check_key("X1", 100) self._check_key("X2", 700) self._check_key("Y1", 400) self._check_key("Y2", 900) self._check_key("Di", 200) self._check_key("Dj", 500)
def test__scale_factor_gribapi_broken(self): # GRIBAPI expects a signed int for scaleFactorAtReferencePoint # but it should accept a float, so work around this. # See https://software.ecmwf.int/issues/browse/SUP-1100 def get_native_type(grib, key): assert key == "scaleFactorAtReferencePoint" return int self.mock_gribapi.grib_get_native_type = get_native_type grid_definition_template_12(self.test_cube, self.mock_grib) self._check_key("scaleFactorAtReferencePoint", 1065346526)
def test__negative_grid_points_gribapi_broken(self): self.mock_gribapi.GribInternalError = FakeGribError # Force the test to run the signed int --> unsigned int workaround. def set(grib, key, value): if key in ["X1", "X2", "Y1", "Y2"] and value < 0: raise self.mock_gribapi.GribInternalError() grib.keys[key] = value self.mock_gribapi.grib_set = set test_cube = self._make_test_cube(x_points=[-1, 1, 3, 5, 7], y_points=[-4, 9]) grid_definition_template_12(test_cube, self.mock_grib) self._check_key("X1", 0x80000064) self._check_key("X2", 700) self._check_key("Y1", 0x80000190) self._check_key("Y2", 900)
def test__grid_shape(self): test_cube = self._make_test_cube(x_points=np.arange(13), y_points=np.arange(6)) grid_definition_template_12(test_cube, self.mock_grib) self._check_key('Ni', 13) self._check_key('Nj', 6)
def test__template_specifics(self): grid_definition_template_12(self.test_cube, self.mock_grib) self._check_key("latitudeOfReferencePoint", 49000000.0) self._check_key("longitudeOfReferencePoint", -2000000.0) self._check_key("XR", 40000000.0) self._check_key("YR", -10000000.0)
def test__template_number(self): grid_definition_template_12(self.test_cube, self.mock_grib) self._check_key('gridDefinitionTemplateNumber', 12)
def test__scanmode_reverse(self): test_cube = self._make_test_cube(x_points=np.arange(7, 0, -1)) grid_definition_template_12(test_cube, self.mock_grib) self._check_key('iScansPositively', 0) self._check_key('jScansPositively', 1)
def test__scanmode(self): grid_definition_template_12(self.test_cube, self.mock_grib) self._check_key('iScansPositively', 1) self._check_key('jScansPositively', 1)