Beispiel #1
0
 def test_unicode_proj4_string(self):
     """Test that unicode is accepted for area creation.
     """
     from pyresample import utils
     utils.get_area_def(u"eurol", u"eurol", u"bla",
                        u'+proj=stere +a=6378273 +b=6356889.44891 +lat_0=90 +lat_ts=70 +lon_0=-45',
                        1000, 1000, (-1000, -1000, 1000, 1000))
Beispiel #2
0
 def test_unicode_proj4_string(self):
     """Test that unicode is accepted for area creation.
     """
     from pyresample import utils
     utils.get_area_def(u"eurol", u"eurol", u"bla",
                        u'+proj=stere +a=6378273 +b=6356889.44891 +lat_0=90 +lat_ts=70 +lon_0=-45',
                        1000, 1000, (-1000, -1000, 1000, 1000))
Beispiel #3
0
    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
Beispiel #4
0
    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'] + ' +units=km'
        except TypeError:
            proj_str = self.nc.attrs['gdal_projection'].decode() + ' +units=km'

        nlines, ncols = self.nc[dsid.name].shape

        area_extent = (float(self.nc.attrs['gdal_xgeo_up_left']) / 1000.,
                       float(self.nc.attrs['gdal_ygeo_low_right']) / 1000.,
                       float(self.nc.attrs['gdal_xgeo_low_right']) / 1000.,
                       float(self.nc.attrs['gdal_ygeo_up_left']) / 1000.)

        area = get_area_def('some_area_name',
                            "On-the-fly area",
                            'geosmsg',
                            proj_str,
                            ncols,
                            nlines,
                            area_extent)

        return area
    def get_area_def(self, dsid):
        a = self.mda['projection_parameters']['a']
        b = self.mda['projection_parameters']['b']
        h = self.mda['projection_parameters']['h']
        lon_0 = self.mda['projection_parameters']['ssp_longitude']

        proj_dict = {'a': float(a),
                     'b': float(b),
                     'lon_0': float(lon_0),
                     'h': float(h),
                     'proj': 'geos',
                     'units': 'm'}

        nlines = self.mda['number_of_lines']
        ncols = self.mda['number_of_columns']

        area_extent = (-5570248.477339745,
                       -5567248.074173927,
                       5567248.074173927,
                       5570248.477339745)

        area = get_area_def('some_area_name',
                            "On-the-fly area",
                            'geosmsg',
                            proj_dict,
                            ncols,
                            nlines,
                            area_extent)

        return area
Beispiel #6
0
    def get_area_def(self, dsid):
        """Get the area definition of the datasets in the file.

        Only applicable for MSG products!
        """
        if self.pps:
            # PPS:
            raise NotImplementedError

        if dsid.name.endswith('_pal'):
            raise NotImplementedError

        try:
            proj_str = self.nc.attrs['gdal_projection'] + ' +units=km'
        except TypeError:
            proj_str = self.nc.attrs['gdal_projection'].decode() + ' +units=km'

        nlines, ncols = self.nc[dsid.name].shape

        area_extent = (float(self.nc.attrs['gdal_xgeo_up_left']) / 1000,
                       float(self.nc.attrs['gdal_ygeo_low_right']) / 1000,
                       float(self.nc.attrs['gdal_xgeo_low_right']) / 1000,
                       float(self.nc.attrs['gdal_ygeo_up_left']) / 1000)

        area = get_area_def('some_area_name',
                            "On-the-fly area",
                            'geosmsg',
                            proj_str,
                            ncols,
                            nlines,
                            area_extent)

        return area
Beispiel #7
0
    def test_lonlat2colrow(self):
        from pyresample import utils
        area_id = 'meteosat_0deg'
        area_name = 'Meteosat 0 degree Service'
        proj_id = 'geos0'
        x_size = 3712
        y_size = 3712
        area_extent = [-5570248.477339261, -5567248.074173444, 5567248.074173444, 5570248.477339261]
        proj_dict = {'a': '6378169.00',
                     'b': '6356583.80',
                     'h': '35785831.0',
                     'lon_0': '0.0',
                     'proj': 'geos'}
        area = utils.get_area_def(area_id,
                                  area_name,
                                  proj_id,
                                  proj_dict,
                                  x_size, y_size,
                                  area_extent)

        # Imatra, Wiesbaden
        longitudes = np.array([28.75242, 8.24932])
        latitudes = np.array([61.17185, 50.08258])
        cols__, rows__ = area.lonlat2colrow(longitudes, latitudes)

        # test arrays
        cols_expects = np.array([2304, 2040])
        rows_expects = np.array([186, 341])
        self.assertTrue((cols__ == cols_expects).all())
        self.assertTrue((rows__ == rows_expects).all())

        # test scalars
        lon, lat = (-8.125547604568746, -14.345524111874646)
        self.assertTrue(area.lonlat2colrow(lon,lat) == (1567, 2375))
Beispiel #8
0
def get_smops_area_def(nx=1440, ny=720):
    """Short summary.

    Parameters
    ----------
    nx : type
        Description of parameter `nx` (the default is 1440).
    ny : type
        Description of parameter `ny` (the default is 720).

    Returns
    -------
    type
        Description of returned object.

    """
    p = Proj(proj='eqc',
             lat_ts=0.,
             lat_0=0.,
             lon_0=0.,
             x_0=0.,
             y_0=0.,
             a=6378137,
             b=6378137,
             units='m')
    proj4_args = p.srs
    area_name = 'Global .25 degree SMOPS Grid'
    area_id = 'smops'
    proj_id = area_id
    aa = p([-180, 180], [-90, 90])
    area_extent = (aa[0][0], aa[1][0], aa[0][1], aa[1][1])
    area_def = utils.get_area_def(area_id, area_name, proj_id, proj4_args, nx,
                                  ny, area_extent)
    return area_def
Beispiel #9
0
def get_gfs_area_def(nx=1440, ny=721):
    """Short summary.

    Parameters
    ----------
    nx : type
        Description of parameter `nx` (the default is 1440).
    ny : type
        Description of parameter `ny` (the default is 721).

    Returns
    -------
    type
        Description of returned object.

    """
    # proj4_args = '+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m'
    p = Proj(proj='eqc',
             lat_ts=0.,
             lat_0=0.,
             lon_0=0.,
             x_0=0.,
             y_0=0.,
             a=6378137,
             b=6378137,
             units='m')
    proj4_args = p.srs
    area_name = 'Global .25 degree SMOPS Grid'
    area_id = 'smops'
    proj_id = area_id
    aa = p([0, 360 - .25], [-90, 90.])
    area_extent = (aa[0][0], aa[1][0], aa[0][1], aa[1][1])
    area_def = utils.get_area_def(area_id, area_name, proj_id, proj4_args, nx,
                                  ny, area_extent)
    return area_def
Beispiel #10
0
    def get_area_def(self, dsid):
        """Get the area definition of the datasets in the file.

        Only applicable for MSG products!
        """
        if self.pps:
            # PPS:
            raise NotImplementedError

        if dsid.name.endswith('_pal'):
            raise NotImplementedError

        proj_str, area_extent = self._get_projection()

        nlines, ncols = self.nc[dsid.name].shape

        area = get_area_def('some_area_name',
                            "On-the-fly area",
                            'geosmsg',
                            proj_str,
                            ncols,
                            nlines,
                            area_extent)

        return area
Beispiel #11
0
def get_sinu_area_def(dset):
    from pyresample import utils
    from pyproj import Proj
    p = Proj(dset.attrs['proj4_srs'])
    proj4_args = p.srs
    area_name = 'MODIS Grid Def'
    area_id = 'modis'
    proj_id = area_id
    area_extent = dset.attrs['area_extent']
    nx, ny = dset.longitude.shape
    return utils.get_area_def(area_id, area_name, proj_id, proj4_args, nx, ny,
                              area_extent)
Beispiel #12
0
def get_sinu_area_def(dset):
    from pyproj import Proj
    from pyresample import utils

    p = Proj(dset.attrs["proj4_srs"])
    proj4_args = p.srs
    area_name = "MODIS Grid Def"
    area_id = "modis"
    proj_id = area_id
    area_extent = dset.attrs["area_extent"]
    nx, ny = dset.longitude.shape
    return utils.get_area_def(area_id, area_name, proj_id, proj4_args, nx, ny, area_extent)
Beispiel #13
0
def open_s2_tile(fname):
    data = read_jp2_data(fname)
    size = data.shape
    params = parse_tile(fname)
    areadef = utils.get_area_def(
        params[0],
        "Sentinel 2 tile " + params[0],
        "PROJ EPSG:" + params[1][0],
        "init=epsg:" + params[1][0],
        size[0],
        size[1],
        params[1][1],
    )
    return [data, areadef]
Beispiel #14
0
    def test_reduce_north_pole(self):
        """Test reducing around the poles."""

        from pyresample import utils
        area_id = 'ease_sh'
        description = 'Antarctic EASE grid'
        proj_id = 'ease_sh'
        projection = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m'
        x_size = 425
        y_size = 425
        area_extent = (-5326849.0625, -5326849.0625, 5326849.0625,
                       5326849.0625)
        area_def = utils.get_area_def(area_id, description, proj_id,
                                      projection, x_size, y_size, area_extent)

        grid_lons, grid_lats = area_def.get_lonlats()

        area_id = 'ease_sh'
        description = 'Antarctic EASE grid'
        proj_id = 'ease_sh'
        projection = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m'
        x_size = 1000
        y_size = 1000
        area_extent = (-532684.0625, -532684.0625, 532684.0625, 532684.0625)
        smaller_area_def = utils.get_area_def(area_id, description, proj_id,
                                              projection, x_size, y_size,
                                              area_extent)

        data = np.fromfunction(lambda y, x: (y + x), (1000, 1000))
        lons, lats = smaller_area_def.get_lonlats()

        lons, lats, data = swath_from_lonlat_grid(grid_lons, grid_lats, lons,
                                                  lats, data, 7000)

        cross_sum = data.sum()
        expected = 999000000.0
        self.assertAlmostEqual(cross_sum, expected)
Beispiel #15
0
    def test_reduce_north_pole(self):
        """Test reducing around the poles."""

        from pyresample import utils
        area_id = 'ease_sh'
        description = 'Antarctic EASE grid'
        proj_id = 'ease_sh'
        projection = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m'
        x_size = 425
        y_size = 425
        area_extent = (-5326849.0625, -5326849.0625,
                       5326849.0625, 5326849.0625)
        area_def = utils.get_area_def(area_id, description, proj_id,
                                      projection, x_size, y_size, area_extent)

        grid_lons, grid_lats = area_def.get_lonlats()

        area_id = 'ease_sh'
        description = 'Antarctic EASE grid'
        proj_id = 'ease_sh'
        projection = '+proj=laea +lat_0=-90 +lon_0=0 +a=6371228.0 +units=m'
        x_size = 1000
        y_size = 1000
        area_extent = (-532684.0625, -532684.0625, 532684.0625, 532684.0625)
        smaller_area_def = utils.get_area_def(area_id, description, proj_id,
                                              projection, x_size, y_size,
                                              area_extent)

        data = np.fromfunction(lambda y, x: (y + x), (1000, 1000))
        lons, lats = smaller_area_def.get_lonlats()

        lons, lats, data = swath_from_lonlat_grid(grid_lons, grid_lats,
                                                  lons, lats, data, 7000)

        cross_sum = data.sum()
        expected = 999000000.0
        self.assertAlmostEqual(cross_sum, expected)
def getarea(area_id):
    areas = pd.read_csv(
        "/media/leonidas/Hitachi/daily_viirs/2017_packed/batchHDF2Geotiff/areas.csv",
        sep=';')
    myarea = areas.loc[areas['area_id'] == area_id]

    area_id = myarea.iloc[0]['area_id']
    x_size = myarea.iloc[0]['x_size']
    y_size = myarea.iloc[0]['y_size']
    proj_id = myarea.iloc[0]['proj_id']

    area_extent = (myarea.iloc[0]['xmin'], myarea.iloc[0]['ymin'],
                   myarea.iloc[0]['xmax'], myarea.iloc[0]['ymax'])

    ##Grid area
    proj_id, description, projection = getproj(proj_id)

    area_def = utils.get_area_def(area_id, description, proj_id, projection,
                                  x_size, y_size, area_extent)
    return area_def
Beispiel #17
0
    def test_colrow2lonlat(self):

        from pyresample import utils
        area_id = 'meteosat_0deg'
        area_name = 'Meteosat 0 degree Service'
        proj_id = 'geos0'
        x_size = 3712
        y_size = 3712
        area_extent = [
            -5570248.477339261, -5567248.074173444, 5567248.074173444,
            5570248.477339261
        ]
        proj_dict = {
            'a': '6378169.00',
            'b': '6356583.80',
            'h': '35785831.0',
            'lon_0': '0.0',
            'proj': 'geos'
        }
        area = utils.get_area_def(area_id, area_name, proj_id, proj_dict,
                                  x_size, y_size, area_extent)

        # Imatra, Wiesbaden
        cols = np.array([2304, 2040])
        rows = np.array([186, 341])
        lons__, lats__ = area.colrow2lonlat(cols, rows)

        # test arrays
        lon_expects = np.array([28.77763033, 8.23765962])
        lat_expects = np.array([61.20120556, 50.05836402])
        self.assertTrue(np.allclose(lons__, lon_expects, rtol=0, atol=1e-7))
        self.assertTrue(np.allclose(lats__, lat_expects, rtol=0, atol=1e-7))

        # test scalars
        lon__, lat__ = area.colrow2lonlat(1567, 2375)
        lon_expect = -8.125547604568746
        lat_expect = -14.345524111874646
        self.assertTrue(np.allclose(lon__, lon_expect, rtol=0, atol=1e-7))
        self.assertTrue(np.allclose(lat__, lat_expect, rtol=0, atol=1e-7))
Beispiel #18
0
def grid_lonlat(dx=17000, dy=17000, lon0=0, x0=0, y0=0):
    import pyproj
    from pyresample import utils

    proj_dict = '+proj=sinu +lon_0=' + str(lon0) + '+x_0=' + str(
        x0) + 'y_0=' + str(y0)
    prj = pyproj.Proj(proj_dict)

    x_len, tmp = prj(180, 0)
    x_len -= dx / 2
    tmp, y_len = prj(0, 90)
    y_len -= dy / 2

    area_id = 'ease_sh'
    name = area_id
    proj_id = area_id
    x_size = np.floor((2 * x_len) / dx)
    y_size = np.floor((2 * y_len) / dy)
    area_extent = (-x_len, -y_len, -x_len + x_size * dx, -y_len + y_size * dy)
    area_def = utils.get_area_def(area_id, name, proj_id, proj_dict, x_size,
                                  y_size, area_extent)
    lonp, latp = area_def.get_lonlats()
    lonp = lonp.astype('float32')
    latp = latp.astype('float32')
    for i in range(lonp.shape[0]):
        icenter = int(np.ceil(lonp.shape[1] / 2))
        tmp = lonp[i, :icenter]
        ixb = icenter - np.argmax(tmp[::-1] > 10)
        if ixb >= icenter: ixb = 0
        lonp[i, :ixb] = np.nan
        latp[i, :ixb] = np.nan
        icenter = int(np.floor(lonp.shape[1] / 2))
        tmp = lonp[i, icenter:]
        ixb = icenter + np.argmax(tmp < -10)
        if ixb <= icenter: ixb = lonp.shape[1]
        lonp[i, ixb:] = np.nan
        latp[i, ixb:] = np.nan

    return lonp, latp, area_def
Beispiel #19
0
    def test_colrow2lonlat(self):

        from pyresample import utils
        area_id = 'meteosat_0deg'
        area_name = 'Meteosat 0 degree Service'
        proj_id = 'geos0'
        x_size = 3712
        y_size = 3712
        area_extent = [-5570248.477339261, -5567248.074173444, 5567248.074173444, 5570248.477339261]
        proj_dict = {'a': '6378169.00',
                     'b': '6356583.80',
                     'h': '35785831.0',
                     'lon_0': '0.0',
                     'proj': 'geos'}
        area = utils.get_area_def(area_id,
                                  area_name,
                                  proj_id,
                                  proj_dict,
                                  x_size, y_size,
                                  area_extent)

        # Imatra, Wiesbaden
        cols = np.array([2304, 2040])
        rows = np.array([186, 341])
        lons__, lats__ = area.colrow2lonlat(cols, rows)

        # test arrays
        lon_expects = np.array([28.77763033, 8.23765962])
        lat_expects = np.array([61.20120556, 50.05836402])
        self.assertTrue(np.allclose(lons__, lon_expects, rtol = 0, atol = 1e-7))
        self.assertTrue(np.allclose(lats__, lat_expects, rtol = 0, atol = 1e-7))

        # test scalars
        lon__, lat__ = area.colrow2lonlat(1567, 2375)
        lon_expect = -8.125547604568746
        lat_expect = -14.345524111874646
        self.assertTrue(np.allclose(lon__, lon_expect, rtol = 0, atol = 1e-7))
        self.assertTrue(np.allclose(lat__, lat_expect, rtol = 0, atol = 1e-7))
Beispiel #20
0
    def test_get_xy_from_lonlat(self):
        """Test the function get_xy_from_lonlat"""
        from pyresample import utils
        area_id = 'test'
        area_name = 'Test area with 2x2 pixels'
        proj_id = 'test'
        x_size = 2
        y_size = 2
        area_extent = [1000000, 0, 1050000, 50000]
        proj_dict = {
            "proj": 'laea',
            'lat_0': '60',
            'lon_0': '0',
            'a': '6371228.0',
            'units': 'm'
        }
        area_def = utils.get_area_def(area_id, area_name, proj_id, proj_dict,
                                      x_size, y_size, area_extent)
        import pyproj
        p__ = pyproj.Proj(proj_dict)
        lon_ul, lat_ul = p__(1000000, 50000, inverse=True)
        lon_ur, lat_ur = p__(1050000, 50000, inverse=True)
        lon_ll, lat_ll = p__(1000000, 0, inverse=True)
        lon_lr, lat_lr = p__(1050000, 0, inverse=True)

        eps_lonlat = 0.01
        eps_meters = 100
        x__, y__ = area_def.get_xy_from_lonlat(lon_ul + eps_lonlat,
                                               lat_ul - eps_lonlat)
        x_expect, y_expect = 0, 0
        self.assertEqual(x__, x_expect)
        self.assertEqual(y__, y_expect)
        x__, y__ = area_def.get_xy_from_lonlat(lon_ur - eps_lonlat,
                                               lat_ur - eps_lonlat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 0)
        x__, y__ = area_def.get_xy_from_lonlat(lon_ll + eps_lonlat,
                                               lat_ll + eps_lonlat)
        self.assertEqual(x__, 0)
        self.assertEqual(y__, 1)
        x__, y__ = area_def.get_xy_from_lonlat(lon_lr - eps_lonlat,
                                               lat_lr + eps_lonlat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 1)

        lon, lat = p__(1025000 - eps_meters, 25000 - eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 0)
        self.assertEqual(y__, 1)

        lon, lat = p__(1025000 + eps_meters, 25000 - eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 1)

        lon, lat = p__(1025000 - eps_meters, 25000 + eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 0)
        self.assertEqual(y__, 0)

        lon, lat = p__(1025000 + eps_meters, 25000 + eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 0)

        lon, lat = p__(999000, -10, inverse=True)
        self.assert_raises(ValueError, area_def.get_xy_from_lonlat, lon, lat)
        self.assert_raises(ValueError, area_def.get_xy_from_lonlat, 0., 0.)

        # Test getting arrays back:
        lons = [lon_ll + eps_lonlat, lon_ur - eps_lonlat]
        lats = [lat_ll + eps_lonlat, lat_ur - eps_lonlat]
        x__, y__ = area_def.get_xy_from_lonlat(lons, lats)

        x_expects = np.array([0, 1])
        y_expects = np.array([1, 0])
        self.assertTrue((x__.data == x_expects).all())
        self.assertTrue((y__.data == y_expects).all())
    def test_get_xy_from_lonlat(self):
        """Test the function get_xy_from_lonlat"""
        from pyresample import utils
        area_id = 'test'
        area_name = 'Test area with 2x2 pixels'
        proj_id = 'test'
        x_size = 2
        y_size = 2
        area_extent = [1000000, 0, 1050000, 50000] 
        proj_dict = {"proj": 'laea', 
                     'lat_0': '60', 
                     'lon_0': '0', 
                     'a': '6371228.0', 'units': 'm'}
        area_def = utils.get_area_def(area_id, 
                                      area_name, 
                                      proj_id, 
                                      proj_dict, 
                                      x_size, y_size, 
                                      area_extent)
        import pyproj
        p__ = pyproj.Proj(proj_dict)
        lon_ul, lat_ul = p__(1000000, 50000, inverse=True)
        lon_ur, lat_ur = p__(1050000, 50000, inverse=True)
        lon_ll, lat_ll = p__(1000000, 0, inverse=True)
        lon_lr, lat_lr = p__(1050000, 0, inverse=True)
        
        eps_lonlat = 0.01
        eps_meters = 100
        x__, y__ = area_def.get_xy_from_lonlat(lon_ul + eps_lonlat, 
                                               lat_ul - eps_lonlat)
        x_expect, y_expect = 0, 0
        self.assertEqual(x__, x_expect)
        self.assertEqual(y__, y_expect)
        x__, y__ = area_def.get_xy_from_lonlat(lon_ur - eps_lonlat, 
                                               lat_ur - eps_lonlat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 0)
        x__, y__ = area_def.get_xy_from_lonlat(lon_ll + eps_lonlat, 
                                               lat_ll + eps_lonlat)
        self.assertEqual(x__, 0)
        self.assertEqual(y__, 1)
        x__, y__ = area_def.get_xy_from_lonlat(lon_lr - eps_lonlat, 
                                               lat_lr + eps_lonlat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 1)

        lon, lat = p__(1025000 - eps_meters, 25000 - eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 0)
        self.assertEqual(y__, 1)

        lon, lat = p__(1025000 + eps_meters, 25000 - eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 1)

        lon, lat = p__(1025000 - eps_meters, 25000 + eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 0)
        self.assertEqual(y__, 0)

        lon, lat = p__(1025000 + eps_meters, 25000 + eps_meters, inverse=True)
        x__, y__ = area_def.get_xy_from_lonlat(lon, lat)
        self.assertEqual(x__, 1)
        self.assertEqual(y__, 0)

        lon, lat = p__(999000, -10, inverse=True)
        self.assert_raises(ValueError, area_def.get_xy_from_lonlat, lon, lat)
        self.assert_raises(ValueError, area_def.get_xy_from_lonlat, 0., 0.)

        # Test getting arrays back:
        lons = [lon_ll + eps_lonlat, lon_ur - eps_lonlat]
        lats = [lat_ll + eps_lonlat, lat_ur - eps_lonlat]
        x__, y__ = area_def.get_xy_from_lonlat(lons, lats)

        x_expects = np.array([0, 1])
        y_expects = np.array([1, 0])
        self.assertTrue((x__.data == x_expects).all())
        self.assertTrue((y__.data == y_expects).all())
Beispiel #22
0
    def insert_line(self, msg):
        """Insert the line corresponding to *msg* in the database.
        """
        if msg.type == "dataset":

            new_msg = Message(rawstr=str(msg))
            new_msg.type = "file"
            del new_msg.data["dataset"]

            if 'uid' not in new_msg.data:
                for item in msg.data["dataset"]:
                    new_msg.data.update(item)
                    self.insert_line(new_msg)
            else:
                self.insert_line(new_msg)

        elif msg.type == "file":

            if (("start_time" not in msg.data.keys()
                 or "end_time" not in msg.data.keys())
                    and "area" not in msg.data.keys()):
                logger.warning("Missing field, not creating record from " +
                               str(msg))
                return
            #required_fields = ["start_time", "end_time"]
            # for field in required_fields:
            #     if field not in msg.data.keys():
            #         logger.warning("Missing required " + field
            #                     + ", not creating record from "
            #                     + str(msg))
            #         return

            try:
                import ipdb
                ipdb.set_trace()
                file_obj = File(msg.data["uid"],
                                self.dbm,
                                filetype=msg.data.get("type", None),
                                fileformat=msg.data.get("format", None))
            except NoResultFound:
                logger.warning("Cannot process: " + str(msg))
                return

            logger.debug("adding :" + str(msg))

            for key, val in msg.data.items():
                if key in ["uid", "type", "area"]:
                    continue
                if key == "uri":
                    file_obj["URIs"] += [val]
                    continue
                try:
                    file_obj[key] = val
                except NoResultFound:
                    logger.warning("Cannot add: " + str((key, val)))

            if ("start_time" in msg.data.keys()
                    and "end_time" in msg.data.keys()):
                # compute sub_satellite_track
                satname = msg.data["platform_name"]
                sat = Orbital(sat_lookup.get(satname, satname))
                dt_ = timedelta(seconds=10)
                current_time = msg.data["start_time"]
                lonlat_list = []
                while current_time < msg.data["end_time"]:
                    pos = sat.get_lonlatalt(current_time)
                    lonlat_list.append(pos[:2])
                    current_time += dt_
                pos = sat.get_lonlatalt(msg.data["end_time"])
                lonlat_list.append(pos[:2])

                logger.debug("Computed sub-satellite track")

                if len(lonlat_list) < 2:
                    logger.info("Sub satellite track to short, skipping it.")
                else:
                    file_obj["sub_satellite_track"] = lonlat_list
                    logger.debug("Added sub-satellite track")

            if "area" in msg.data.keys():
                logger.debug("Add area definition to the data")
                area_def = get_area_def(str(msg.data["area"]["id"]),
                                        str(msg.data["area"]["name"]),
                                        str(msg.data["area"]["proj_id"]),
                                        str(msg.data["area"]["proj4"]),
                                        msg.data["area"]["shape"][0],
                                        msg.data["area"]["shape"][1],
                                        msg.data["area"]["area_extent"])
                logger.debug("Adding boundary...")
                file_obj["area"] = area_def
                logger.debug("Boundary added.")
Beispiel #23
0
    'y_0': 3210000,
    'ellps': 'GRS80'
}

### Greek_Grid area definition
area_id = 'greek_grid'
description = 'Greek Grid'
proj_id = 'greekgrid_2100'
x_size = 100
y_size = 100
area_extent = (31600, 4218500, 106600, 4293500)
projection = '+proj=tmerc +lat_0=0 +lon_0=24 +x_0=500000 +y_0=0 +ellps=GRS80 +units=m'

#area_def = geometry.AreaDefinition(area_id, description, proj_id, proj_dict, x_size, y_size, area_extent) #area_extent: (x_ll, y_ll, x_ur, y_ur)

area_def = utils.get_area_def(area_id, description, proj_id, projection,
                              x_size, y_size, area_extent)
#print(area_def)

BASEDIR = '/media/leonidas/Hitachi/daily_viirs/2017/3332700175/001'
OUTPUT_DIR = os.path.join(BASEDIR, "geotiffs")

os.chdir(BASEDIR)
swath_files = glob.glob('SVDNB_npp_d*.h5')

txt = open(os.path.join(BASEDIR, "errors.txt"), "a")

if not os.path.exists(OUTPUT_DIR):
    os.makedirs(OUTPUT_DIR)

for file in swath_files:
    try:
Beispiel #24
0
        if args.verbose:
            print "Area not defined! REALLY!"
        sys.exit()
    area_id = args.area.lower()
    area_name = args.area.lower()
    proj_id = args.area.lower()
    proj4_args = (
        '+proj=eqc +lat_ts=0 +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +a=6378137 +b=6378137 +units=m'
    )
    prj = pyproj.Proj(proj4_args)
    # X_bound_deg is bound in degree, X_bound_m is meter on map
    [w_bound_m, e_bound_m], [s_bound_m,
                             n_bound_m] = prj([w_bound_deg, e_bound_deg],
                                              [s_bound_deg, n_bound_deg])
    area_extent = (w_bound_m, s_bound_m, e_bound_m, n_bound_m)
    xsize = ysize = 1000  # whatever numbers
    area = utils.get_area_def(area_id, area_name, proj_id, proj4_args, xsize,
                              ysize, area_extent)
    #test if swath and area overlap
    if swath.overlaps(area):
        overlap_fraction = swath.overlap_rate(area)
        print 'Granule overlaps with', args.area, 'area'
        print '### overlap fraction is', overlap_fraction
    else:
        print 'Granule DOES NOT overlap with', args.area, 'area'

p.dispose()

if (istar or iszip) and args.delete:
    rmtree(product)
Beispiel #25
0
    cpp_filedir = os.path.join(cpp_dir, cpp_file)
    cpp = nc_import(cpp_filedir)
    # Get microphysic paramteers and geo metadata
    proj4 = cpp.getncattr("CMSAF_proj4_params")
    extent = cpp.getncattr("CMSAF_area_extent")
    cot = cpp.variables["cot"][:][0]
    reff = cpp.variables["reff"][:][0]
    cwp = cpp.variables["cwp"][:][0]
    # Geolocate and resample microphysic parameters
    from pyresample import utils
    area_id = 'CPP_cmsaf'
    area_name = 'Gridded cloud physical properties from CMSAF'
    proj_id = 'CPP_cmsaf'
    x_size = cot.shape[0]
    y_size = cot.shape[1]
    cpp_area = utils.get_area_def(area_id, area_name, proj_id, proj4, x_size,
                                  y_size, extent)
    cot_fd = image.ImageContainerQuick(cot, cpp_area)
    reff_fd = image.ImageContainerQuick(reff, cpp_area)
    cwp_fd = image.ImageContainerQuick(cwp, cpp_area)

    # Fog example
    germ_scene = GeostationaryFactory.create_scene(satname="meteosat",
                                                   satnumber='10',
                                                   instrument="seviri",
                                                   time_slot=time)
    germ_scene.load(germ_scene.image.fls_day.prerequisites.add('HRV'),
                    area_extent=ger_extent)

    #germ_scene.project('euro4', mode="nearest")
    #germ_scene.image[0.6].show()