pylawr.grid#
|
The BaseGrid is a base class for all radar grids. |
|
The CartesianGrid can be used for easier composite calculations of radar fields. |
|
The LatLonGrid can be used to translate RadarGrids into NWP weather model grids. |
|
The PolarGrid is the natural grid of a radar. |
|
The RectangularGrid can be used for easier composite calculations of radar fields. |
|
An unstructured grid is a grid, where for every grid point latitude and longitude values are given, but they don't need to be in their own structured grid. |
pylawr.grid.base.BaseGrid#
- class pylawr.grid.base.BaseGrid(center=(53.56796, 9.97451, 95), beam_ele=3)[source]#
Bases:
objectThe BaseGrid is a base class for all radar grids.
- Parameters
center (tuple(float), optional) – The center of the grid. The centre should have two or three entries within the tuple. The first entry is the latitude position of the grid center in degree. The second entry is the longitude position of the grid centre in degree. The optional third entry is the height of the center above mean sea level in meters. If no third entry is given the center height is set to zero. The centre is used to transform the polar coordinates into latitude and longitude coordinates. It is also used to calculate the altitude map together with the beam elevation. Default is the position on the top of the “Geomatikum”: (53.56796, 9.97451, 95).
beam_ele (float, optional) – The beam elevation in degrees. The beam elevation is used to calculate the altitude map. The beam elevation is set constant if it is a float. The value of the beam elevation are normalized for angle between -90 and 90 degrees such that the sign is preserved. This beam elevation is used to calculate the elevation for a grid point. The calculated elevation is valid for the whole grid box.
- static _calc_altitude(radar_distance, beam_elevation=3.0, radar_height=0.0, earth_radius=6364335, ke=1.3333333333333333)[source]#
Calculate the altitude map for this grid based on the distance to the radar site, the centre position height and the beam elevation. Calculates the radar beam height taking refraction into account based on [Doviak et al., 2006] using
\[h = [r^2 + (k_{\mathrm{e}}\,a)^2 + 2\,r\,k_{\mathrm{e}}\,a\, \sin\,\Theta_{\mathrm{e}}]^{1/2} - k_{\mathrm{e}}\,a\]with \(h\) is the radar beam height, \(r\) is the distance to the radar, \(k_{\mathrm{e}}\) is an adjustment factor, \(a\) is the earth radius, and \(\Theta_{\mathrm{e}}\) is the radar elevation angle.
- Parameters
radar_distance (numpy.ndarray, int or float) – Distance to the radar site in metres.
beam_elevation (float) – The beam elevation in degrees.
radar_height (float) – Height of the radar at center position in metres.
earth_radius (int) – Radius of earth in metres.
ke (float) – Adjustment factor dependent on the refractive index gradient.
- Returns
altitude – The calculated altitude.
- Return type
- abstract _calc_coordinates()[source]#
Calculate the coordinates for this grid.
- Returns
coordinates – The calculated coordinates for this grid.
- Return type
- _check_data(data)[source]#
Method to check if the type and shape of the given data is right.
- Parameters
data (python obj) – Data to check.
- Raises
TypeError – TypeError is raised if the given data is not a numpy.ndarray.
ValueError – ValueError is raised if the given data has not the right shape.
- abstract _coords2latlon(*args)[source]#
Calculate the latitude and longitude coordinates for this grid based on given coordinates.
- Returns
latitude (numpy.ndarray) – The calculated latitude coordinate as numpy.ndarray with the shape of the coordinates.
longitude (numpy.ndarray) – The calculated longitude coordinate as numpy.ndarray with the shape of the coordinates.
- property altitude#
The altitude map for this grid. Similar characteristics to a lazy property but the altitude is only calculated based on the beam elevation if the altitude was not set. Therefore, a user customized altitude map is possible.
- property beam_elevation#
- property beam_elevation_field#
Get the beam elevation as repeated numpy.ndarray with the same shape as the data.
- property center#
The center position for this grid as tuple (latitude, longitude, height).
- abstract property center_distance#
Get the distance to the center in meters.
- Returns
distance – The distance to the center in meters.
- Return type
- property coord_fields#
Get the coordinates as meshgrid fields.
- property coord_names#
Get the coordinate names as tuple.
- property coords#
- property earth_radius#
- get_altitude()[source]#
Get the altitude map for this grid as xarray.DataArray.
- Returns
altitude – The altitude map for this grid as xarray.DataArray in meters above mean sea level. The coordinates of the DataArray are the grid coordinates.
- Return type
- get_beam_elevation()[source]#
Get the beam elevation for this grid as xarray.DataArray.
- Returns
elevation – The elevation for this grid as xarray.DataArray in degrees.
- Return type
xarray.DataArray
- get_center()[source]#
Get the center lat, lon, height for this grid as xarray.Dataset.
- Returns
center – The center for this grid as xarray.Dataset including latitude in degrees_north, longitude in degrees_east, and altitude in meters.
- Return type
xarray.Dataset
- get_coordinates()[source]#
Get the coordinates for this grid in a xarray-conform structure.
- Returns
coords – The coordinates for this grid in a xarray-conform structure. The key is the coordinate name. The coordinates have as value a tuple with their own name, indicating that the they are self-describing, and the coordinate values as numpy array.
- Return type
dict(str, (str, numpy.ndarray))
- get_lat_lon()[source]#
Get the latitude and longitude for this grid as xarray.Dataset.
- Returns
lat_lon – The latitude and longitude coordinates as xarray.Dataset. The latitudes and longitudes are variables within this dataset. The coordinates of the dataset are the grid coordinates.
- Return type
- get_multiindex()[source]#
Get the coordinates for this grid as :py:class:
pandas.Multiindex.- Returns
multiindex – The coordinates as Multiindex with the coordinate names as level name. The values are the cross-product of the coordinate values.
- Return type
:py:class:
pandas.Multiindex
- property grid_shape#
Return the shape of the grid.
- property lat_lon#
- property lat_lon_bounds#
- property size#
pylawr.grid.CartesianGrid#
- class pylawr.grid.CartesianGrid(resolution=100, start=-20000, nr_points=401, center=(53.56796, 9.97451, 95), beam_ele=3.0)[source]#
Bases:
RectangularGridThe CartesianGrid can be used for easier composite calculations of radar fields. The calculated coordinates are relative to the given center and valid for the centroids of the grid points.
- Parameters
resolution (tuple(float or int), float or int, optional) – The resolution of the CartesianGrid in meters. The first value is valid for y, while the second one is valid for x. If the parameter is float or int, then the resolution will be set to equal values for y and x. Only the first two entries of a tuple will be used. Default is 100.
start (tuple(float or int), float or int, optional) – The start position of the lower left grid point centroid within the CartesianGrid in meters. This position is relative to the center. The first value is valid for y, while the second one is valid for x. If the parameter is float or int, then the resolution will be set to equal values for y and x. Only the first two entries of a tuple will be used. Default is -20000.
nr_points (tuple(int) or int, optional) – The number of points for both directions. The first value is valid for y, while the second one is valid for x. If the tuple is int, then the resolution will be set to equal values for y and x. Only the first two entries of a tuple will be used. Default is 401.
center (tuple(float), optional) – The center of the grid. The center should have two or three entries within the tuple. The first entry is the latitude position of the grid center in degree. The second entry is the longitude position of the grid center in degree. The optional third entry is the height of the center above mean sea level in meters. If no third entry is given the center height is set to zero. The center is used to transform the polar coordinates into latitude and longitude coordinates. It is also used to calculate the altitude map together with the beam elevation. Default is the position on the top of the “Geomatikum”: (53.56796, 9.97451, 95). The center is also the center of the equator. Thus, the north pole for the rotated pole coordinates will be calculated based on this parameter. The altitude will be set to constant, based on the defined third value.
beam_ele (float, optional) – The beam elevation in degrees. The beam elevation is used to calculate the altitude map. The beam elevation is set constant if it is a float. The value of the beam elevation are normalized for angle between -90 and 90 degrees such that the sign is preserved. This beam elevation is used to calculate the elevation for a grid point. The calculated elevation is valid for the whole grid box.
- _coords2latlon(*coords)[source]#
Calculate the latitude and longitude coordinates for this grid based on given coordinates.
- Returns
latitude (numpy.ndarray) – The calculated latitude coordinate as numpy.ndarray with the shape of the coordinates.
longitude (numpy.ndarray) – The calculated longitude coordinate as numpy.ndarray with the shape of the coordinates.
- property center_distance#
Get the distance to the center in meters.
- Returns
distance – The distance to the center in meters.
- Return type
- property meters2deg#
- property north_pole#
Get the north pole for given center. At the moment, only center coordinates in the first quadrant (latitude and longitude are positive) are used to calculate the north pole.
- Returns
lat (float) – The latitude of the north pole.
lon (float) – The longitude of the north pole.
- Raises
ValueError – A ValueError is raised if the center coordinates are not within the first quadrant.
pylawr.grid.LatLonGrid#
- class pylawr.grid.LatLonGrid(resolution=(0.0009, 0.001515), start=(53.387, 9.673), nr_points=401, center=(53.56796, 9.97451, 95), beam_ele=3.0)[source]#
Bases:
RectangularGridThe LatLonGrid can be used to translate RadarGrids into NWP weather model grids. The calculated coordinates are absolute values and valid for the centroids of the grid points.
- Parameters
resolution (tuple(float or int), float or int, optional) – The resolution of the LatLonGrid in degrees. The first value is valid for lat, while the second one is valid for lon. If the parameter is float or int, then the resolution will be set to equal values for lat and lon. Only the first two entries of a tuple will be used. Default is (0.0009, 0.001515).
start (tuple(float or int), float or int, optional) – The start position of the lower left grid point centroid within the LatLonGrid in degrees. This position is relative to the center. The first value is valid for lat, while the second one is valid for lon. If the parameter is float or int, then the resolution will be set to equal values for lat and lon. Only the first two entries of a tuple will be used. Default is (53.387, 9.673).
nr_points (tuple(int) or int, optional) – The number of points for both directions. The first value is valid for lat, while the second one is valid for lon. If the tuple is int, then the resolution will be set to equal values for lat and lon. Only the first two entries of a tuple will be used. Default is 401.
center (tuple(float), optional) – The center of the grid. The center should have two or three entries within the tuple. The first entry is the latitude position of the grid center in degree. The second entry is the longitude position of the grid center in degree. The optional third entry is the height of the center above mean sea level in degrees. If no third entry is given the center height is set to zero. The center is used to transform the polar coordinates into latitude and longitude coordinates. It is also used to calculate the altitude map together with the beam elevation. Default is the position on the top of the “Geomatikum”: (53.56796, 9.97451, 95). The center is also the center of the equator. Thus, the north pole for the rotated pole coordinates will be calculated based on this parameter. The altitude will be set to constant, based on the defined third value.
beam_ele (float, optional) – The beam elevation in degrees. The beam elevation is used to calculate the altitude map. The beam elevation is set constant if it is a float. The value of the beam elevation are normalized for angle between -90 and 90 degrees such that the sign is preserved. This beam elevation is used to calculate the elevation for a grid point. The calculated elevation is valid for the whole grid box.
- _coords2latlon(*coords)[source]#
Returns the given coordinates because they are already latitude and longitude.
- Returns
latitude (numpy.ndarray) – The calculated latitude coordinate as numpy.ndarray with the shape of the coordinates.
longitude (numpy.ndarray) – The calculated longitude coordinate as numpy.ndarray with the shape of the coordinates.
- static _get_distance(p1, p2)[source]#
Calculate the distance between two points.
- Parameters
- Returns
dlat (array_like) – The difference in the latitude coordinates between second point and first point in radians.
dlon (array_like) – The difference in the longitude coordinates between second point and first point in radians.
- _haversine_distance(p1, p2)[source]#
Calculate the great circle distance between two points on the earth. The formula is based on the haversine formula [deMendozayRios, 1795].
- Parameters
- Returns
distance – The calculated haversine distance in meters.
- Return type
array_like
- _haversine_formula(p1, p2, dlat, dlon)[source]#
Calculate the great circle distance between two points on the earth. The formula is based on the haversine formula [deMendozayRios, 1795].
- Parameters
p1 (tuple (array_like, array_like)) – The coordinates (latitude, longitude) of the first point in radians.
p2 (tuple (array_like, array_like)) – The coordinates (latitude, longitude) of the second point in radians.
dlat (array_like) – The distance between the first and the second latitude in radians.
dlon (array_like) – The distance between the first and the second longitude in radians.
- Returns
distance – The calculated haversine distance in meters.
- Return type
array_like
Notes
The haversine distance is calculated based on the earth radius, given within the initialization.
- static _latlon2rad(latitude, longitude)[source]#
Convert given latitude and longitude pair into radians.
- Parameters
latitude (array_like) – The latitude in degrees which should be converted into radians.
longitude (array_like) – The longitude in degrees which should be converted into radians.
- Returns
rad_lat (array_like) – The converted latitude in radians.
rad_lon (array_like) – The converted longitude in radians.
- property center_distance#
Get the distance to the center in meters.
- Returns
distance – The distance to the center in meters.
- Return type
pylawr.grid.PolarGrid#
- class pylawr.grid.PolarGrid(center=(53.56796, 9.97451, 95), beam_ele=3, nr_ranges=333, range_res=59.95849, range_offset=0, nr_azi=360, azi_offset=0)[source]#
Bases:
BaseGridThe PolarGrid is the natural grid of a radar. The polar grid is defined such that the radar is the north pole of the grid. Within the initialization, the ranges and azimuth are valid for the lower left grid boundary. Later, the methods are valid for the centroid.
- Parameters
center (tuple(float), optional) – The center of the grid. The center should have two or three entries within the tuple. The first entry is the latitude position of the grid center in degree. The second entry is the longitude position of the grid center in degree. The optional third entry is the height of the center above mean sea level in meters. If no third entry is given the center height is set to zero. The center is used to transform the polar coordinates into latitude and longitude coordinates. It is also used to calculate the altitude map together with the beam elevation. Default is the position on the top of the “Geomatikum”: (53.56796, 9.97451, 95).
beam_ele (float, optional) – The beam elevation in degrees. The beam elevation is used to calculate the altitude map. The beam elevation is set constant if it is a float. The value of the beam elevation are normalized for angle between -90 and 90 degrees such that the sign is preserved. This beam elevation is used to calculate the elevation for a grid point. The calculated elevation is valid for the whole grid box.
nr_ranges (int, optional) – The number of ranges with every beam. Default is 333.
range_res (float, optional) – The step width of every range in meters. Default is 59.95849.
range_offset (float, optional) – The offset of the ranges in meters. This value is used as start value for the creation of the offsets. Default is 0.
nr_azi (int, optional) – The number of azimuth angles. This is used to calculate the azimuth angles. Default is 360.
azi_offset (float, optional) – The azimuth offset in degrees. This value is used as offset for the creation of the azimuth linspace. This could be used to rotate the radar grid. Default is 0.
- _calc_coordinates()[source]#
Calculate the coordinates for this grid.
- Returns
coordinates – The calculated coordinates for this grid.
- Return type
- _coords2latlon(azimuth, range)[source]#
Method to convert the polar coordinate field of a radar to latitude and longitude coordinates. The formulas are taken from Wikipedia-Nautisches-Dreieck.
- Parameters
range_field (Field containing the range values) –
azimuth_field (Field containing the angle information in degree.) –
- Returns
latitude (numpy.ndarray) – The calculated latitude coordinate as numpy.ndarray with the shape of the coordinates.
longitude (numpy.ndarray) – The calculated longitude coordinate as numpy.ndarray with the shape of the coordinates.
- property azimuth#
- property beam_elevation_field#
Get the beam elevation as repeated numpy.ndarray with the same shape as the data.
- property center_distance#
Get the distance to the center in meters.
- Returns
distance – The distance to the center in meters.
- Return type
- get_azimuth_offset()[source]#
Get the azimuth offset for this grid as xarray.DataArray.
- Returns
elevation – The azimuth offset for this grid as xarray.DataArray in degrees.
- Return type
xarray.DataArray
- property ranges#
pylawr.grid.RectangularGrid#
- class pylawr.grid.RectangularGrid(resolution=100, start=-5000, nr_points=500, center=(53.56796, 9.97451, 95), beam_ele=3)[source]#
Bases:
BaseGridThe RectangularGrid can be used for easier composite calculations of radar fields. The calculated coordinates are valid for the centroids of the grid points.
- Parameters
resolution (tuple(float or int), float or int, optional) – The resolution of the RectangularGrid. If the parameter is float or int, then the resolution will be set to equal values for both coordinates. Only the first two entries of a tuple will be used. Default is 100.
start (tuple(float or int), float or int, optional) – The start position of the lower left grid point centroid within the RectangularGrid.If the parameter is float or int, then the resolution will be set to equal values for booth coordinates. Only the first two entries of a tuple will be used. Default is -5000.
nr_points (tuple(int) or int, optional) – The number of points for both directions. If the tuple is int, then the resolution will be set to equal values for both coordinates. Only the first two entries of a tuple will be used. Default is 500.
center (tuple(float), optional) – The center of the grid. The center should have two or three entries within the tuple. The first entry is the latitude position of the grid center in degree. The second entry is the longitude position of the grid center in degree. The optional third entry is the height of the center above mean sea level in meters. If no third entry is given the center height is set to zero. The center is used to transform the coordinates into latitude and longitude coordinates. Default is the position on the top of the “Geomatikum”: (53.56796, 9.97451, 95).
beam_ele (float, optional) – The beam elevation in degrees. The beam elevation is used to calculate the altitude map. The beam elevation is set constant if it is a float. The value of the beam elevation are normalized for angle between -90 and 90 degrees such that the sign is preserved. This beam elevation is used to calculate the elevation for a grid point. The calculated elevation is valid for the whole grid box.
- _calc_coordinates()[source]#
Calculate the coordinates for this grid.
- Returns
coordinates – The calculated coordinates for this grid.
- Return type
- abstract _coords2latlon(*args)[source]#
Calculate the latitude and longitude coordinates for this grid based on given coordinates.
- Returns
latitude (numpy.ndarray) – The calculated latitude coordinate as numpy.ndarray with the shape of the coordinates.
longitude (numpy.ndarray) – The calculated longitude coordinate as numpy.ndarray with the shape of the coordinates.
- property _data_shape#
- abstract property center_distance#
Get the distance to the center in meters.
- Returns
distance – The distance to the center in meters.
- Return type
- property nr_points#
- property resolution#
- property start#
pylawr.grid.UnstructuredGrid#
- class pylawr.grid.UnstructuredGrid(in_coords, center=(53.56796, 9.97451, 95), beam_ele=3.0)[source]#
Bases:
BaseGridAn unstructured grid is a grid, where for every grid point latitude and longitude values are given, but they don’t need to be in their own structured grid. This grid can be used to read in icosahedral model data. Further it is used for hole interpolation within this pylawr package. Compared to other grids this grid is only an one-dimensional grid with a coordinate called
grid_cell.- Parameters
in_coords (:py:class:
numpy.ndarray) – The input coordinates in degrees. These input coordinates are used as coordinates. The array need to have two axes. The first dimension is also used as grid dimension. The second dimension indicates if only latitude and longitude (2) is given or if an additional altitude in metre (3) is passed. If no altitude is given, the altitude is calculated based on the distance to the center.center (tuple(float), optional) – The center of the grid. The centre should have two or three entries within the tuple. The first entry is the latitude position of the grid center in degree. The second entry is the longitude position of the grid centre in degree. The optional third entry is the height of the center above mean sea level in meters. If no third entry is given the center height is set to zero. The centre is used to transform the polar coordinates into latitude and longitude coordinates. It is also used to calculate the altitude map together with the beam elevation. Default is the position on the top of the “Geomatikum”: (53.56796, 9.97451, 95).
beam_ele (float, optional) – The beam elevation in degrees. The beam elevation is used to calculate the altitude map. The beam elevation is set constant if it is a float. The value of the beam elevation are normalized for angle between -90 and 90 degrees such that the sign is preserved. This beam elevation is used to calculate the elevation for a grid point. The calculated elevation is valid for the whole grid box.
- _calc_altitude(*args)[source]#
Calculate the altitude map for this grid based on the given altitude of the in_coords or, if no altitude is given, on the distance to the radar site, the centre position height and the beam elevation. For the altitude calculation refer to the super class
pylawr.grid.BaseGrid.- Parameters
args – Optional parameters, need to be provided if the altitude calculation of
pylawr.grid.BaseGridis applied.- Returns
altitude – The altitude.
- Return type
- _calc_coordinates()[source]#
Calculate the coordinates for this grid.
- Returns
coordinates – The calculated coordinates for this grid.
- Return type
- _coords2latlon(*args)[source]#
Calculate the latitude and longitude coordinates for this grid based on given coordinates.
- Returns
latitude (numpy.ndarray) – The calculated latitude coordinate as numpy.ndarray with the shape of the coordinates.
longitude (numpy.ndarray) – The calculated longitude coordinate as numpy.ndarray with the shape of the coordinates.
- property _data_shape#
- _haversine_distance(p1, p2)[source]#
Calculate the great circle distance between two points on the earth. The formula is based on the haversine formula [deMendozayRios, 1795].
- Parameters
- Returns
distance – The calculated haversine distance in meters.
- Return type
array_like
- _haversine_formula(p1, p2, dlat, dlon)[source]#
Calculate the great circle distance between two points on the earth. The formula is based on the haversine formula [deMendozayRios, 1795].
- Parameters
p1 (tuple (array_like, array_like)) – The coordinates (latitude, longitude) of the first point in radians.
p2 (tuple (array_like, array_like)) – The coordinates (latitude, longitude) of the second point in radians.
dlat (array_like) – The distance between the first and the second latitude in radians.
dlon (array_like) – The distance between the first and the second longitude in radians.
- Returns
distance – The calculated haversine distance in meters.
- Return type
array_like
Notes
The haversine distance is calculated based on the earth radius, given within the initialization.
- property center_distance#
Get the distance to the center in meters.
- Returns
distance – The distance to the center in meters.
- Return type
- get_coordinates()[source]#
Get the coordinates for this grid in a xarray-conform structure.
- Returns
coords – The coordinates for this grid in a xarray-conform structure. The key is the coordinate name. The coordinates have as value a tuple with their own name, indicating that the they are self-describing, and the coordinate values as numpy array.
- Return type
dict(str, (str, numpy.ndarray))