def get_area_def(self, dsid): """Get the area definition of the datasets in the file.""" if dsid.name.endswith('_pal'): raise NotImplementedError try: proj_str = self.nc.attrs['gdal_projection'] except TypeError: proj_str = self.nc.attrs['gdal_projection'].decode() # Convert proj_str from km to m proj_str = proj_units_to_meters(proj_str) nlines, ncols = self.nc[dsid.name].shape area_extent = (float(self.nc.attrs['gdal_xgeo_up_left']), float(self.nc.attrs['gdal_ygeo_low_right']), float(self.nc.attrs['gdal_xgeo_low_right']), float(self.nc.attrs['gdal_ygeo_up_left'])) area = get_area_def('some_area_name', "On-the-fly area", 'geosmsg', proj_str, ncols, nlines, area_extent) return area
def test_proj_units_to_meters(self): prj = '+asd=123123123123' res = proj_units_to_meters(prj) self.assertEqual(res, prj) prj = '+a=6378.137' res = proj_units_to_meters(prj) self.assertEqual(res, '+a=6378137.000') prj = '+a=6378.137 +units=km' res = proj_units_to_meters(prj) self.assertEqual(res, '+a=6378137.000') prj = '+a=6378.137 +b=6378.137' res = proj_units_to_meters(prj) self.assertEqual(res, '+a=6378137.000 +b=6378137.000') prj = '+a=6378.137 +b=6378.137 +h=35785.863' res = proj_units_to_meters(prj) self.assertEqual(res, '+a=6378137.000 +b=6378137.000 +h=35785863.000')