Ejemplo n.º 1
0
def init_lambert_conformal_projection(standard_latitudes_deg,
                                      central_longitude_deg):
    """Initializes Lambert conformal projection.

    :param standard_latitudes_deg: length-2 numpy array with standard parallels
        (deg N).  standard_latitudes_deg[0] is the first standard parallel;
        standard_latitudes_deg[1] is the second standard parallel.
    :param central_longitude_deg: central meridian (deg E).
    :return: projection_object: object created by `pyproj.Proj`, specifying the
        Lambert conformal projection.
    """

    error_checking.assert_is_valid_lat_numpy_array(standard_latitudes_deg)
    error_checking.assert_is_numpy_array(standard_latitudes_deg,
                                         exact_dimensions=numpy.array([2]))

    error_checking.assert_is_non_array(central_longitude_deg)
    central_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        central_longitude_deg, allow_nan=False)

    return Proj(proj='lcc',
                lat_1=standard_latitudes_deg[0],
                lat_2=standard_latitudes_deg[1],
                lon_0=central_longitude_deg,
                rsphere=EARTH_RADIUS_METRES,
                ellps='sphere')
Ejemplo n.º 2
0
def init_equidistant_cylindrical_map(
        fig_width_inches=DEFAULT_FIG_WIDTH_INCHES,
        fig_height_inches=DEFAULT_FIG_HEIGHT_INCHES,
        resolution_string=DEFAULT_BOUNDARY_RESOLUTION_STRING,
        min_latitude_deg=None,
        max_latitude_deg=None,
        min_longitude_deg=None,
        max_longitude_deg=None):
    """Initializes map with equidistant cylindrical projection.

    :param fig_width_inches: Figure width.
    :param fig_height_inches: Figure height.
    :param resolution_string: See documentation for init_lambert_conformal_map.
    :param min_latitude_deg: Latitude at bottom-left corner (deg N).
    :param max_latitude_deg: Latitude at upper-right corner (deg N).
    :param min_longitude_deg: Longitude at bottom-left corner (deg E).
    :param max_longitude_deg: Longitude at upper-right corner (deg E).
    :return: figure_object: Instance of `matplotlib.figure.Figure`.
    :return: axes_object: Instance of `matplotlib.axes._subplots.AxesSubplot`.
    :return: basemap_object: Instance of `mpl_toolkits.basemap.Basemap`.
    """

    error_checking.assert_is_greater(fig_width_inches, 0)
    error_checking.assert_is_greater(fig_height_inches, 0)
    error_checking.assert_is_string(resolution_string)
    error_checking.assert_is_valid_latitude(min_latitude_deg)
    error_checking.assert_is_valid_latitude(max_latitude_deg)

    error_checking.assert_is_non_array(max_longitude_deg)
    error_checking.assert_is_non_array(min_longitude_deg)
    min_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        min_longitude_deg)
    max_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        max_longitude_deg)

    figure_object, axes_object = pyplot.subplots(1,
                                                 1,
                                                 figsize=(fig_width_inches,
                                                          fig_height_inches))

    basemap_object = Basemap(projection='cyl',
                             resolution=resolution_string,
                             llcrnrlat=min_latitude_deg,
                             llcrnrlon=min_longitude_deg,
                             urcrnrlat=max_latitude_deg,
                             urcrnrlon=max_longitude_deg)

    return figure_object, axes_object, basemap_object
Ejemplo n.º 3
0
def init_azimuthal_equidistant_projection(central_latitude_deg,
                                          central_longitude_deg):
    """Initializes azimuthal equidistant projection.

    :param central_latitude_deg: Central latitude (deg N).
    :param central_longitude_deg: Central longitude (deg E).
    :return: projection_object: object created by `pyproj.Proj`, specifying the
        Lambert conformal projection.
    """

    error_checking.assert_is_valid_latitude(central_latitude_deg)
    error_checking.assert_is_non_array(central_longitude_deg)
    central_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        central_longitude_deg, allow_nan=False)

    return Proj(proj='aeqd',
                lat_0=central_latitude_deg,
                lon_0=central_longitude_deg)
Ejemplo n.º 4
0
def init_lcc_projection(standard_latitudes_deg,
                        central_longitude_deg,
                        ellipsoid_name=SPHERE_NAME,
                        earth_radius_metres=DEFAULT_EARTH_RADIUS_METRES):
    """Initializes LCC (Lambert conformal conic) projection.

    :param standard_latitudes_deg: length-2 numpy array of standard parallels
        (deg N).
    :param central_longitude_deg: Central meridian (deg E).
    :param ellipsoid_name: Ellipsoid (examples are "sphere" and "WGS84").
    :param earth_radius_metres: [used only if ellipsoid_name = "sphere"]
        Earth radius.
    :return: projection_object: Instance of `pyproj.Proj`, specifying the LCC
        projection.
    """

    error_checking.assert_is_valid_lat_numpy_array(standard_latitudes_deg)
    these_expected_dim = numpy.array([2], dtype=int)
    error_checking.assert_is_numpy_array(standard_latitudes_deg,
                                         exact_dimensions=these_expected_dim)

    error_checking.assert_is_non_array(central_longitude_deg)
    central_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        central_longitude_deg, allow_nan=False)

    _check_ellipsoid(ellipsoid_name)

    if ellipsoid_name == SPHERE_NAME:
        error_checking.assert_is_greater(earth_radius_metres, 0.)

        return Proj(proj='lcc',
                    lat_1=standard_latitudes_deg[0],
                    lat_2=standard_latitudes_deg[1],
                    lon_0=central_longitude_deg,
                    rsphere=earth_radius_metres,
                    ellps=ellipsoid_name)

    return Proj(proj='lcc',
                lat_1=standard_latitudes_deg[0],
                lat_2=standard_latitudes_deg[1],
                lon_0=central_longitude_deg,
                ellps=ellipsoid_name)
Ejemplo n.º 5
0
def init_cylindrical_equidistant_projection(central_latitude_deg,
                                            central_longitude_deg,
                                            true_scale_latitude_deg):
    """Initializes cylindrical equidistant projection.

    :param central_latitude_deg: Central latitude (deg N).
    :param central_longitude_deg: Central longitude (deg E).
    :param true_scale_latitude_deg: Latitude of true scale (deg N).
    :return: projection_object: Instance of `pyproj.Proj`.
    """

    error_checking.assert_is_valid_latitude(central_latitude_deg)
    error_checking.assert_is_valid_latitude(true_scale_latitude_deg)
    error_checking.assert_is_non_array(central_longitude_deg)
    central_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        central_longitude_deg, allow_nan=False)

    return Proj(proj='eqc',
                lat_0=central_latitude_deg,
                lon_0=central_longitude_deg,
                lat_ts=true_scale_latitude_deg,
                rsphere=EARTH_RADIUS_METRES,
                ellps='sphere')
Ejemplo n.º 6
0
def create_lambert_conformal_map(
        min_latitude_deg,
        max_latitude_deg,
        min_longitude_deg,
        max_longitude_deg,
        standard_latitudes_deg=numpy.full(2, 25.),
        central_longitude_deg=265.,
        figure_width_inches=DEFAULT_FIGURE_WIDTH_INCHES,
        figure_height_inches=DEFAULT_FIGURE_HEIGHT_INCHES,
        resolution_string=DEFAULT_RESOLUTION_STRING):
    """Creates Lambert conformal map.

    This method only initializes a map with the Lambert conformal projection.
    It does not plot anything.

    Latitudes must be in deg N, and longitudes must be in deg E.

    :param min_latitude_deg: See doc for `_check_basemap_args`.
    :param max_latitude_deg: Same.
    :param min_longitude_deg: Same.
    :param max_longitude_deg: Same.
    :param standard_latitudes_deg: length-2 numpy array of standard latitudes
        for projection.
    :param central_longitude_deg: Central longitude for projection.
    :param figure_width_inches: Figure width.
    :param figure_height_inches: Figure height.
    :param resolution_string: See doc for `_check_basemap_args`.
    :return: figure_object: Figure handle (instance of
        `matplotlib.figure.Figure`).
    :return: axes_object: Axes handle (instance of
        `matplotlib.axes._subplots.AxesSubplot`).
    :return: basemap_object: Basemap handle (instance of
        `mpl_toolkits.basemap.Basemap`).
    """

    min_longitude_deg, max_longitude_deg = _check_basemap_args(
        min_latitude_deg=min_latitude_deg,
        max_latitude_deg=max_latitude_deg,
        min_longitude_deg=min_longitude_deg,
        max_longitude_deg=max_longitude_deg,
        resolution_string=resolution_string)

    error_checking.assert_is_valid_lat_numpy_array(standard_latitudes_deg)
    error_checking.assert_is_numpy_array(standard_latitudes_deg,
                                         exact_dimensions=numpy.array(
                                             [2], dtype=int))

    error_checking.assert_is_non_array(central_longitude_deg)
    central_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        central_longitude_deg)

    figure_object, axes_object = pyplot.subplots(
        1, 1, figsize=(figure_width_inches, figure_height_inches))

    basemap_object = Basemap(projection='lcc',
                             lat_1=standard_latitudes_deg[0],
                             lat_2=standard_latitudes_deg[1],
                             lon_0=central_longitude_deg,
                             rsphere=EARTH_RADIUS_METRES,
                             ellps=ELLIPSOID_NAME,
                             resolution=resolution_string,
                             llcrnrlat=min_latitude_deg,
                             llcrnrlon=min_longitude_deg,
                             urcrnrlat=max_latitude_deg,
                             urcrnrlon=max_longitude_deg)

    return figure_object, axes_object, basemap_object
Ejemplo n.º 7
0
    def test_assert_is_non_array_numpy_array(self):
        """Checks assert_is_non_array when input is numpy array."""

        with self.assertRaises(TypeError):
            error_checking.assert_is_non_array(REAL_NUMPY_ARRAY)
Ejemplo n.º 8
0
    def test_assert_is_non_array_tuple(self):
        """Checks assert_is_non_array when input is tuple."""

        with self.assertRaises(TypeError):
            error_checking.assert_is_non_array(REAL_NUMBER_TUPLE)
Ejemplo n.º 9
0
    def test_assert_is_non_array_list(self):
        """Checks assert_is_non_array when input is list."""

        with self.assertRaises(TypeError):
            error_checking.assert_is_non_array(REAL_NUMBER_LIST)
Ejemplo n.º 10
0
    def test_assert_is_non_array_true(self):
        """Checks assert_is_non_array when input is scalar."""

        error_checking.assert_is_non_array(SINGLE_INTEGER)
Ejemplo n.º 11
0
def init_lambert_conformal_map(
        standard_latitudes_deg=None,
        central_longitude_deg=None,
        fig_width_inches=DEFAULT_FIG_WIDTH_INCHES,
        fig_height_inches=DEFAULT_FIG_HEIGHT_INCHES,
        resolution_string=DEFAULT_BOUNDARY_RESOLUTION_STRING,
        min_latitude_deg=None,
        max_latitude_deg=None,
        min_longitude_deg=None,
        max_longitude_deg=None):
    """Initializes map with LCC (Lambert conformal conic) projection.

    :param standard_latitudes_deg: length-2 numpy array of standard parallels
        (deg N).  standard_latitudes_deg[i] is the (i + 1)th standard parallel.
    :param central_longitude_deg: Central meridian (deg E).
    :param fig_width_inches: Figure width.
    :param fig_height_inches: Figure height.
    :param resolution_string: Resolution for boundaries (e.g., coastlines and
        political borders).  Options are "c" for crude, "l" for low, "i" for
        intermediate, "h" for high, and "f" for full.  Keep in mind that higher-
        resolution boundaries take much longer to draw.
    :param min_latitude_deg: Latitude at bottom-left corner (deg N).
    :param max_latitude_deg: Latitude at upper-right corner (deg N).
    :param min_longitude_deg: Longitude at bottom-left corner (deg E).
    :param max_longitude_deg: Longitude at upper-right corner (deg E).
    :return: figure_object: Instance of `matplotlib.figure.Figure`.
    :return: axes_object: Instance of `matplotlib.axes._subplots.AxesSubplot`.
    :return: basemap_object: Instance of `mpl_toolkits.basemap.Basemap`.
    """

    error_checking.assert_is_valid_lat_numpy_array(standard_latitudes_deg)
    error_checking.assert_is_numpy_array(standard_latitudes_deg,
                                         exact_dimensions=numpy.array([2]))

    error_checking.assert_is_non_array(central_longitude_deg)
    central_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        central_longitude_deg)

    error_checking.assert_is_greater(fig_width_inches, 0)
    error_checking.assert_is_greater(fig_height_inches, 0)
    error_checking.assert_is_string(resolution_string)
    error_checking.assert_is_valid_latitude(min_latitude_deg)
    error_checking.assert_is_valid_latitude(max_latitude_deg)

    error_checking.assert_is_non_array(max_longitude_deg)
    error_checking.assert_is_non_array(min_longitude_deg)
    min_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        min_longitude_deg)
    max_longitude_deg = lng_conversion.convert_lng_positive_in_west(
        max_longitude_deg)

    figure_object, axes_object = pyplot.subplots(1,
                                                 1,
                                                 figsize=(fig_width_inches,
                                                          fig_height_inches))

    basemap_object = Basemap(projection='lcc',
                             lat_1=standard_latitudes_deg[0],
                             lat_2=standard_latitudes_deg[1],
                             lon_0=central_longitude_deg,
                             rsphere=EARTH_RADIUS_METRES,
                             ellps=ELLIPSOID,
                             resolution=resolution_string,
                             llcrnrlat=min_latitude_deg,
                             llcrnrlon=min_longitude_deg,
                             urcrnrlat=max_latitude_deg,
                             urcrnrlon=max_longitude_deg)

    return figure_object, axes_object, basemap_object