Esempio n. 1
0
def test_parse_lon_lat():
    grid_shape = (1, 1, 1)
    grid_limits = ((0, 1), (0, 1), (0, 1))
    grid = pyart.testing.make_empty_grid(grid_shape, grid_limits)

    lon, lat = common.parse_lon_lat(grid, None, None)
    assert_almost_equal(lon, -98.1, 2)
    assert_almost_equal(lat, 36.74, 2)

    lon, lat = common.parse_lon_lat(grid, -12.34, 56.78)
    assert_almost_equal(lon, -12.34, 2)
    assert_almost_equal(lat, 56.78, 2)
Esempio n. 2
0
def test_parse_lon_lat():
    grid_shape = (1, 1, 1)
    grid_limits = ((0, 1), (0, 1), (0, 1))
    grid = pyart.testing.make_empty_grid(grid_shape, grid_limits)

    lon, lat = common.parse_lon_lat(grid, None, None)
    assert_almost_equal(lon, -98.1, 2)
    assert_almost_equal(lat, 36.74, 2)

    lon, lat = common.parse_lon_lat(grid, -12.34, 56.78)
    assert_almost_equal(lon, -12.34, 2)
    assert_almost_equal(lat, 56.78, 2)
Esempio n. 3
0
    def plot_crosshairs(self,
                        lon=None,
                        lat=None,
                        linestyle='--',
                        color='r',
                        linewidth=2,
                        ax=None):
        """
        Plot crosshairs at a given longitude and latitude.

        Parameters
        ----------
        lon, lat : float
            Longitude and latitude (in degrees) where the crosshairs should
            be placed. If None the center of the grid is used.
        linestyle : str
            Matplotlib string describing the line style.
        color : str
            Matplotlib string for color of the line.
        linewidth : float
            Width of markers in points.
        ax : axes or None
            Axis to add the crosshairs to, if None the current axis is used.

        """
        # parse the parameters
        ax = common.parse_ax(ax)
        lon, lat = common.parse_lon_lat(self.grid, lon, lat)

        # add crosshairs
        ax.axhline(lat, color=color, linestyle=linestyle, linewidth=linewidth)
        ax.axvline(lon, color=color, linestyle=linestyle, linewidth=linewidth)
Esempio n. 4
0
    def _find_nearest_grid_indices(self, lon, lat):
        """ Find the nearest x, y grid indices for a given latitude and longitude. """

        # A similar method would make a good addition to the Grid class itself
        lon, lat = common.parse_lon_lat(self.grid, lon, lat)
        grid_lons, grid_lats = self.grid.get_point_longitude_latitude()
        diff = (grid_lats - lat)**2 + (grid_lons - lon)**2
        y_index, x_index = np.unravel_index(diff.argmin(), diff.shape)
        return x_index, y_index