예제 #1
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_id`.
    :param grid_id: Same.
    :return: pathless_file_name_prefixes: 1-D list with possible starts of
        pathless file names.
    """

    nwp_model_utils.check_grid_id(model_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)]
예제 #2
0
def _get_prefixes_for_pathless_file_name(model_name, grid_id=None):
    """Returns possible prefixes for pathless file name.

    :param model_name: Name of model.
    :param grid_id: String ID for grid.
    :return: pathless_file_name_prefixes: 1-D list of possible prefixes for
        pathless file name.
    """

    nwp_model_utils.check_grid_id(model_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)]
예제 #3
0
    def test_check_grid_id_ruc252(self):
        """Ensures correct output from check_grid_id for RUC on 252 grid."""

        nwp_model_utils.check_grid_id(nwp_model_utils.RUC_MODEL_NAME,
                                      nwp_model_utils.ID_FOR_252GRID)
예제 #4
0
    def test_check_grid_id_rap130(self):
        """Ensures correct output from check_grid_id for RAP on 130 grid."""

        nwp_model_utils.check_grid_id(nwp_model_utils.RAP_MODEL_NAME,
                                      nwp_model_utils.ID_FOR_130GRID)
예제 #5
0
    def test_check_grid_id_narr(self):
        """Ensures correct output from check_grid_id when model is NARR."""

        nwp_model_utils.check_grid_id(nwp_model_utils.NARR_MODEL_NAME)
    def test_check_grid_id_rap236(self):
        """Ensures correct output from check_grid_id for RAP on 236 grid."""

        with self.assertRaises(ValueError):
            nwp_model_utils.check_grid_id(nwp_model_utils.RAP_MODEL_NAME,
                                          nwp_model_utils.ID_FOR_236GRID)
예제 #7
0
def init_map_with_nwp_projection(
        model_name=None,
        grid_id=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 NWP (numerical weather prediction)-model projection.

    If min_latitude_deg = max_latitude_deg = min_longitude_deg =
    max_longitude_deg = None, corners of the map will be corners of the model
    grid.

    :param model_name: Name of NWP model.
    :param grid_id: String ID for model grid.
    :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) of map.
    :param max_latitude_deg: Latitude at upper-right corner (deg N) of map.
    :param min_longitude_deg: Longitude at bottom-left corner (deg E) of map.
    :param max_longitude_deg: Longitude at upper-right corner (deg E) of map.
    :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`.
    """

    nwp_model_utils.check_grid_id(model_name, grid_id)
    map_corners_deg = [
        min_latitude_deg, max_latitude_deg, min_longitude_deg,
        max_longitude_deg
    ]

    if any([c is None for c in map_corners_deg]):
        grid_cell_edge_x_metres, grid_cell_edge_y_metres = (
            nwp_model_utils.get_xy_grid_cell_edges(model_name, grid_id))
        min_latitude_deg_as_array, min_longitude_deg_as_array = (
            nwp_model_utils.project_xy_to_latlng(
                numpy.array([grid_cell_edge_x_metres[0]]),
                numpy.array([grid_cell_edge_y_metres[0]]),
                projection_object=None,
                model_name=model_name,
                grid_id=grid_id))
        max_latitude_deg_as_array, max_longitude_deg_as_array = (
            nwp_model_utils.project_xy_to_latlng(
                numpy.array([grid_cell_edge_x_metres[-1]]),
                numpy.array([grid_cell_edge_y_metres[-1]]),
                projection_object=None,
                model_name=model_name,
                grid_id=grid_id))

        min_latitude_deg = min_latitude_deg_as_array[0]
        max_latitude_deg = max_latitude_deg_as_array[0]
        min_longitude_deg = min_longitude_deg_as_array[0]
        max_longitude_deg = max_longitude_deg_as_array[0]

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

    return init_lambert_conformal_map(
        standard_latitudes_deg=standard_latitudes_deg,
        central_longitude_deg=central_longitude_deg,
        fig_width_inches=fig_width_inches,
        fig_height_inches=fig_height_inches,
        resolution_string=resolution_string,
        min_latitude_deg=min_latitude_deg,
        max_latitude_deg=max_latitude_deg,
        min_longitude_deg=min_longitude_deg,
        max_longitude_deg=max_longitude_deg)