def test_check_grid_name_rap130(self):
        """Ensures correct output from check_grid_name.

        In this case, model is RAP and grid is NCEP 130.
        """

        nwp_model_utils.check_grid_name(
            model_name=nwp_model_utils.RAP_MODEL_NAME,
            grid_name=nwp_model_utils.NAME_OF_130GRID)
    def test_check_grid_name_narr_extended221(self):
        """Ensures correct output from check_grid_name.

        In this case, model is NARR and grid is extended NCEP 221.
        """

        nwp_model_utils.check_grid_name(
            model_name=nwp_model_utils.NARR_MODEL_NAME,
            grid_name=nwp_model_utils.NAME_OF_EXTENDED_221GRID)
    def test_check_grid_name_rap_extended221(self):
        """Ensures correct output from check_grid_name.

        In this case, model is RAP and grid is extended NCEP 221.
        """

        with self.assertRaises(ValueError):
            nwp_model_utils.check_grid_name(
                model_name=nwp_model_utils.RAP_MODEL_NAME,
                grid_name=nwp_model_utils.NAME_OF_EXTENDED_221GRID)
    def test_check_grid_name_narr130(self):
        """Ensures correct output from check_grid_name.

        In this case, model is NARR and grid is NCEP 130.
        """

        with self.assertRaises(ValueError):
            nwp_model_utils.check_grid_name(
                model_name=nwp_model_utils.NARR_MODEL_NAME,
                grid_name=nwp_model_utils.NAME_OF_130GRID)
Example #5
0
def _get_pathless_file_name_prefixes(model_name, grid_id=None):
    """Returns possible starts of pathless file names for the given model/grid.

    :param model_name: See doc for `nwp_model_utils.check_grid_name`.
    :param grid_id: Same.
    :return: pathless_file_name_prefixes: 1-D list with possible starts of
        pathless file names.
    """

    grid_id = nwp_model_utils.check_grid_name(
        model_name=model_name, grid_name=grid_id)

    if model_name == nwp_model_utils.NARR_MODEL_NAME:
        return [NARR_ID_FOR_FILE_NAMES]

    if model_name == nwp_model_utils.RAP_MODEL_NAME:
        return ['{0:s}_{1:s}'.format(model_name, grid_id)]

    return ['ruc2_{0:s}'.format(grid_id), 'ruc2anl_{0:s}'.format(grid_id)]
Example #6
0
def create_map_with_nwp_proj(model_name,
                             grid_name=None,
                             latlng_limit_dict=None,
                             xy_limit_dict=None,
                             figure_width_inches=DEFAULT_FIGURE_WIDTH_INCHES,
                             figure_height_inches=DEFAULT_FIGURE_HEIGHT_INCHES,
                             resolution_string=DEFAULT_RESOLUTION_STRING):
    """Initializes map with same projection as NWP model.

    However, this map will have false easting = false northing = 0 metres.

    If `latlng_limit_dict is not None`, corners of the map will be determined by
    lat-long coords.

    If `xy_limit_dict is not None`, corners of the map will be determined by
    x-y coords.

    If both are None, corners of the map will be x-y corners of model grid.

    :param model_name: See doc for `nwp_model_utils.check_grid_name`.
    :param grid_name: See doc for `nwp_model_utils.check_grid_name`.
    :param latlng_limit_dict: Dictionary with the following keys:
    latlng_limit_dict['min_latitude_deg']: Minimum latitude (deg N) in map.
    latlng_limit_dict['max_latitude_deg']: Max latitude (deg N) in map.
    latlng_limit_dict['min_longitude_deg']: Minimum longitude (deg E) in map.
    latlng_limit_dict['max_longitude_deg']: Max longitude (deg E) in map.

    :param xy_limit_dict: Dictionary with the following keys:
    xy_limit_dict['x_min_metres']: Minimum x-coord in map.
    xy_limit_dict['x_max_metres']: Max x-coord in map.
    xy_limit_dict['y_min_metres']: Minimum y-coord in map.
    xy_limit_dict['y_max_metres']: Max y-coord in map.

    :param figure_width_inches: Figure width.
    :param figure_height_inches: Figure height.
    :param resolution_string: See doc for `create_lambert_conformal_map`.
    :return: figure_object: Same.
    :return: axes_object: Same.
    :return: basemap_object: Same.
    """

    nwp_model_utils.check_grid_name(model_name=model_name, grid_name=grid_name)

    standard_latitudes_deg, central_longitude_deg = (
        nwp_model_utils.get_projection_params(model_name))

    if latlng_limit_dict is None and xy_limit_dict is None:
        all_x_coords_metres, all_y_coords_metres = (
            nwp_model_utils.get_xy_grid_cell_edges(model_name=model_name,
                                                   grid_name=grid_name))

        false_easting_metres, false_northing_metres = (
            nwp_model_utils.get_false_easting_and_northing(
                model_name=model_name, grid_name=grid_name))

        all_x_coords_metres -= false_easting_metres
        all_y_coords_metres -= false_northing_metres

        xy_limit_dict = {
            X_MIN_KEY: numpy.min(all_x_coords_metres),
            X_MAX_KEY: numpy.max(all_x_coords_metres),
            Y_MIN_KEY: numpy.min(all_y_coords_metres),
            Y_MAX_KEY: numpy.max(all_y_coords_metres)
        }

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

    if latlng_limit_dict is not None:
        min_latitude_deg = latlng_limit_dict[MIN_LATITUDE_KEY]
        max_latitude_deg = latlng_limit_dict[MAX_LATITUDE_KEY]

        error_checking.assert_is_valid_lat_numpy_array(
            numpy.array([min_latitude_deg, max_latitude_deg]))

        min_longitude_deg = lng_conversion.convert_lng_positive_in_west(
            latlng_limit_dict[MIN_LONGITUDE_KEY])

        max_longitude_deg = lng_conversion.convert_lng_positive_in_west(
            latlng_limit_dict[MAX_LONGITUDE_KEY])

        error_checking.assert_is_greater(max_latitude_deg, min_latitude_deg)
        error_checking.assert_is_greater(max_longitude_deg, min_longitude_deg)

        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)
    else:
        x_min_metres = xy_limit_dict[X_MIN_KEY]
        x_max_metres = xy_limit_dict[X_MAX_KEY]
        y_min_metres = xy_limit_dict[Y_MIN_KEY]
        y_max_metres = xy_limit_dict[Y_MAX_KEY]

        error_checking.assert_is_greater(x_max_metres, x_min_metres)
        error_checking.assert_is_greater(y_max_metres, y_min_metres)

        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,
                                 llcrnrx=x_min_metres,
                                 urcrnrx=x_max_metres,
                                 llcrnry=y_min_metres,
                                 urcrnry=y_max_metres)

    return figure_object, axes_object, basemap_object