pylawr.functions.grid#
- pylawr.functions.grid.get_cartesian(grid, use_altitude=False)[source]#
This method calculates cartesian coordinates based on the given grid. The cartesian coordinates are calculated based on simplifications and uses trigonometric functions. The latitude (lat), longitude (lon) and height values (h) are extracted from the given grid, while the earth_radius (R) is set for the remapping.
..math:
x = R * cos(lat) * cos(lon) y = R * cos(lat) * sin(lon) z = h + R * sin(lat)
- Parameters
grid (child of
pylawr.grid.BaseGrid) – The cartesian coordinates are calculated based on this grid. The grid needs the methods:get_altitude()andget_lat_lon()and should be a child ofBaseGrid.use_altitude (bool) – Use the altitude for cartesian coordinates. Default is False. Note, using the correct altitude for the cartesian coordinates for remapping may not preferred.
- Returns
cartesian – The calculated coordinates based on the given grid. The last dimension is x, y and z, while the other dimension sizes are defined by the shape of the input grid.
- Return type
- pylawr.functions.grid.get_latlon_grid(orig_grid)[source]#
This function can be used to get a rectangular
LatLonGrid. The edges of the rectangular grid are determined by the boundary values of the original grid. The median step-wide of the original grid is used as resolution.- Parameters
orig_grid (child of
pylawr.grid.BaseGrid) – This original grid is used to determine edges and step wide of the latitude and longitude grid.- Returns
latlon_grid – This grid is created based on given original grid with edges and step wide determined by the original grid.
- Return type
- pylawr.functions.grid.get_masked_grid(origin_grid, mask_array)[source]#
Mask value within a given origin grid.
- Parameters
mask_array (
numpy.ndarray(bool)) – This mask is applied on givenorigin_grid. Should have the same shape asorigin_grid. All values set to True are used, while values set to False are dismissed.origin_grid (child of
pylawr.grid.base.BaseGrid) – This grid is used to infer the latitude, longitude and altitude values for the unstructured grid.
- Returns
masked_grid – The unstructured grid with all non-masked values. This unstructured grid gets its latitude, longitude and altitude values from given
origin_grid. All values set to True withinmask_arrayare used.- Return type
- pylawr.functions.grid.prepare_grid(grid)[source]#
This method is used to prepare the grid for the remapping, the grid is transformed into cartesian coordinates with :py:meth:
_get_cartesianand then stacked and transposed.- Parameters
grid (child of
pylawr.grid.BaseGrid) – The cartesian coordinates are calculated based on this grid. The grid needs the methods:get_altitude()andget_lat_lon()and should be a child ofBaseGrid.- Returns
cartesian – The calculated coordinates based on the given grid. The last dimension is x, y and z, while the first dimension is a stacked dimension based on the original grid dimensions.
- Return type
- pylawr.functions.grid.remap_data(data, orig_grid, new_grid, remapper=None)[source]#
This function remaps data based on given grids with given remap instance. If the remap instance was not fitted yet, it will be fitted.
- Parameters
data (
xarray.DataArray) – This data is remapped by given remapper. The last coordinate(s) should be the grid coordinates.orig_grid (child of
pylawr.grid.BaseGrid) – This grid is used as basis grid for the remapping. The last data coordinates should have the same shape as this grid.new_grid (child of
pylawr.grid.BaseGrid) – The data is remapped to this grid.remapper (child of
pylawr.remap.BaseRemapor None, optional) – This remapper is used to remap given data to new grid. If the remapper is already fitted, it is assumed that the remapper was fitted to given grids. Default value (None) is an unfittedNearestNeighborinstance with a single nearest neighbor.
- Returns
remapped_data (
xarray.DataArray) – This data was remapped tonew_gridwith given remapper.remapper (child of
pylawr.remap.BaseRemap) – This remapper was used to remap given data. This remapper is fitted to given grids.
Warning
For a fitted
remapper, we assume that theremapperwas fitted to given grids!Notes
Most of processing time is spend on fitting given
remapper. It is recommended to give a fitted remapper to increase the speed of this function.