pysiral.grid ============ .. py:module:: pysiral.grid .. autoapi-nested-parse:: Created on Sun Jun 11 19:24:04 2017 @author: Stefan Classes ------- .. autoapisummary:: pysiral.grid.GridDefinition pysiral.grid.GridTrajectoryExtract Module Contents --------------- .. py:class:: GridDefinition(preset=None) Bases: :py:obj:`pysiral.core.legacy_classes.DefaultLoggingClass` A container class for geospatial grids. The main components are a) the projection (based on pyproj) and b) the extent and grid size. The class is currently designed for stereographic/equal area projection types. .. py:attribute:: _preset :value: None .. py:attribute:: _metadata .. py:attribute:: _griddef_filename :value: None .. py:attribute:: _proj :value: None .. py:attribute:: _proj_dict .. py:attribute:: _extent_dict .. py:method:: set_from_griddef_file(filename) Initialize the object with a grid definition (.yaml) file. Examples can be found in pysiral/settings/griddef .. py:method:: set_projection(**kwargs) .. py:method:: proj(longitude, latitude, **kwargs) .. py:method:: grid_indices(longitude, latitude) Computes the grid indices the given lon/lat pairs would be sorted into (no clipping) .. py:method:: get_grid_coordinates(mode='center') Returns longitude/latitude points for each grid cell Note: mode keyword only for future use. center coordinates are returned by default .. py:method:: set_extent(**kwargs) .. py:method:: _set_proj() .. py:property:: hemisphere .. py:property:: grid_id .. py:property:: grid_tag .. py:property:: grid_name .. py:property:: resolution_tag .. py:property:: proj_dict .. py:property:: extent .. py:property:: area_extent .. py:property:: resolution .. py:property:: pyresample_area_def Returns a pyresample.geometry.AreaDefinition instance .. py:property:: xc .. py:property:: yc .. py:property:: xc_km .. py:property:: yc_km .. py:property:: netcdf_vardef .. py:class:: GridTrajectoryExtract(trajectory_longitude: numpy.typing.NDArray, trajectory_latitude: numpy.typing.NDArray, griddef: Union[dict, pysiral.core.legacy_classes.AttrDict]) Bases: :py:obj:`object` Implements fast extraction of gridded data along a track using Image Interpolation. This class computes the track coordinates in image coordinates upon initialization and then allows to extract the multiple variables. Requirements are the longitude, latitude values of the trajectory and the projection and extent of the grid. Usage ----- .. code-block:: python grid2track = GridTrajectoryExtract(track_longitude, track_latitude, grid_def) track_var_01 = grid2track.get_from_grid_variable(grid_var_01, outside_value=outside_value_01) track_var_02 = grid2track.get_from_grid_variable(grid_var_02, outside_value=outside_value_02) ... .. py:attribute:: trajectory_longitude .. py:attribute:: trajectory_latitude .. py:attribute:: griddef .. py:attribute:: p .. py:method:: _get_track_image_coordinates() -> Tuple[numpy.typing.NDArray, numpy.typing.NDArray] Computes and returns the image coordinates, by converting the trajectory lon/lat values to projection coordinates and scaling them tho the grid extent :raises: None :return: image x coordindate, image y coordinate .. py:method:: get_from_grid_variable(grid_var: numpy.typing.NDArray, order: int = 0, flipud: bool = False, outside_value: Any = np.nan) -> numpy.typing.NDArray Returns the grid variable along the trajectory using interpolation with the specified order. If required the grid var can be flipped upside down before extraction (flipud = True). :param grid_var: The gridded variable :param order: Order of the image interpolation (see scipy.ndimage.map_coordinates) :param flipud: Flag if the grid variable should be flipped before extraction. :param outside_value: Value to be used for part of the trajectory outside the grid :raises: None :return: The grid variable extracted and interpolation for the trajectory location