Ejemplo n.º 1
0
def ll2cr(swath_def, area_def, fill=np.nan, copy=True):
    """Map input swath pixels to output grid column and rows.

    Parameters
    ----------

    swath_def : SwathDefinition
        Navigation definition for swath data to remap
    area_def : AreaDefinition
        Grid definition to be mapped to
    fill : float, optional
        Fill value used in longitude and latitude arrays
    copy : bool, optional
        Create a copy of the longitude and latitude arrays (default: True)

    Returns
    -------

    (swath_points_in_grid, cols, rows) : tuple of integer, numpy array, numpy array
        Number of points from the input swath overlapping the destination
        area and the column and row arrays to pass to `fornav`.


    .. note::

        ll2cr uses the pyproj library which is limited to 64-bit float
        navigation arrays in order to not do additional copying or casting
        of data types.

    """
    lons, lats = swath_def.get_lonlats()
    # ll2cr requires 64-bit floats due to pyproj limitations
    # also need a copy of lons, lats since they are written to in-place
    try:
        lons = lons.astype(np.float64, copy=copy)
        lats = lats.astype(np.float64, copy=copy)
    except TypeError:
        lons = lons.astype(np.float64)
        lats = lats.astype(np.float64)

    # Break the input area up in to the expected parameters for ll2cr
    p = area_def.proj_str
    cw = area_def.pixel_size_x
    # cell height must be negative for this to work as expected
    ch = -abs(area_def.pixel_size_y)
    w = area_def.x_size
    h = area_def.y_size
    ox = area_def.area_extent[0] + cw / 2.
    oy = area_def.area_extent[3] + ch / 2.
    swath_points_in_grid = _ll2cr.ll2cr_static(lons, lats, fill,
                                               p, cw, ch, w, h, ox, oy)
    return swath_points_in_grid, lons, lats
Ejemplo n.º 2
0
def ll2cr(swath_def, area_def, fill=np.nan, copy=True):
    """Map input swath pixels to output grid column and rows.

    Parameters
    ----------

    swath_def : SwathDefinition
        Navigation definition for swath data to remap
    area_def : AreaDefinition
        Grid definition to be mapped to
    fill : float, optional
        Fill value used in longitude and latitude arrays
    copy : bool, optional
        Create a copy of the longitude and latitude arrays (default: True)

    Returns
    -------

    (swath_points_in_grid, cols, rows) : tuple of integer, numpy array, numpy array
        Number of points from the input swath overlapping the destination
        area and the column and row arrays to pass to `fornav`.


    .. note::

        ll2cr uses the pyproj library which is limited to 64-bit float
        navigation arrays in order to not do additional copying or casting
        of data types.

    """
    lons, lats = swath_def.get_lonlats()
    # ll2cr requires 64-bit floats due to pyproj limitations
    # also need a copy of lons, lats since they are written to in-place
    try:
        lons = lons.astype(np.float64, copy=copy)
        lats = lats.astype(np.float64, copy=copy)
    except TypeError:
        lons = lons.astype(np.float64)
        lats = lats.astype(np.float64)

    # Break the input area up in to the expected parameters for ll2cr
    p = area_def.proj_str
    cw = area_def.pixel_size_x
    # cell height must be negative for this to work as expected
    ch = -abs(area_def.pixel_size_y)
    w = area_def.width
    h = area_def.height
    ox = area_def.area_extent[0] + cw / 2.
    oy = area_def.area_extent[3] + ch / 2.
    swath_points_in_grid = _ll2cr.ll2cr_static(lons, lats, fill,
                                               p, cw, ch, w, h, ox, oy)
    return swath_points_in_grid, lons, lats
Ejemplo n.º 3
0
 def test_lcc_fail1(self):
     from pyresample.ewa import _ll2cr
     lon_arr = create_test_longitude(-15.0, 15.0, (50, 100), dtype=np.float64)
     lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64)
     grid_info = static_lcc.copy()
     fill_in = np.nan
     proj_str = grid_info["proj4_definition"]
     cw = grid_info["cell_width"]
     ch = grid_info["cell_height"]
     ox = grid_info["origin_x"]
     oy = grid_info["origin_y"]
     w = grid_info["width"]
     h = grid_info["height"]
     points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str,
                                          cw, ch, w, h, ox, oy)
     self.assertEqual(points_in_grid, 0, "none of these test points should fall in this grid")
Ejemplo n.º 4
0
 def test_lcc_basic1(self):
     from pyresample.ewa import _ll2cr
     lon_arr = create_test_longitude(-95.0, -75.0, (50, 100), dtype=np.float64)
     lat_arr = create_test_latitude(18.0, 40.0, (50, 100), dtype=np.float64)
     grid_info = static_lcc.copy()
     fill_in = np.nan
     proj_str = grid_info["proj4_definition"]
     cw = grid_info["cell_width"]
     ch = grid_info["cell_height"]
     ox = grid_info["origin_x"]
     oy = grid_info["origin_y"]
     w = grid_info["width"]
     h = grid_info["height"]
     points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str,
                                          cw, ch, w, h, ox, oy)
     self.assertEqual(points_in_grid, lon_arr.size, "all these test points should fall in this grid")
Ejemplo n.º 5
0
    def test_geo_antimeridian(self):
        """Ensure output for anti-meridian crossing input includes all points."""
        from pyresample.ewa import _ll2cr
        lon_arr = create_test_longitude(160.0, 200.0, (50, 100), dtype=np.float64)
        lat_arr = create_test_latitude(40.0, 60.0, (50, 100), dtype=np.float64)

        # wrap values in lon_arr so -180 ≤ longitude (degrees east) ≤ 180
        lon_arr[lon_arr > 180] -= 360.0

        grid_info = static_geo_whole_earth.copy()
        fill_in = np.nan
        proj_str = grid_info['proj4_definition']
        cw = grid_info['cell_width']
        ch = grid_info['cell_height']
        ox = grid_info['origin_x']
        oy = grid_info['origin_y']
        w = grid_info['width']
        h = grid_info['height']
        points_in_grid = _ll2cr.ll2cr_static(lon_arr, lat_arr, fill_in, proj_str,
                                             cw, ch, w, h, ox, oy)
        self.assertEqual(points_in_grid, lon_arr.size,
                         'all these test points should fall in this grid')