layer#
Sounding and Hodograph Analysis and Research Program Library (SHARPlib) :: Atmospheric Layer Routines
Layer Definitions#
Atmospheric layers can be defined in pressure or height coordinate space. These named structs are used to determine over which layer and in what coordinate space various calculations are performed in. There is an additional named struct that is used to store the index range the layer occupies.
- class nwsspc.sharp.calc.layer.PressureLayer(self)#
- class nwsspc.sharp.calc.layer.PressureLayer(self, bottom: float, top: float, delta: float = -1000.0)
- property bottom#
The bottom of the PressureLayer (Pa)
- property top#
The top of the PressureLayer (Pa)
- property delta#
The PressureLayer delta (increment) to use if iterating (Pa)
- class nwsspc.sharp.calc.layer.HeightLayer(self)#
- class nwsspc.sharp.calc.layer.HeightLayer(self, bottom: float, top: float, delta: float = 100.0)
- property bottom#
The bottom of the HeightLayer (meters)
- property top#
The top of the HeightLayer (meters)
- property delta#
The HeightLayer delta (increment) to use if iterating (meters).
Layer Conversions#
Layers can be converted from one coordinate system to another using interpolation, or have their index values calculated for looping over arrays.
- nwsspc.sharp.calc.layer.height_layer_to_pressure(layer: nwsspc.sharp.calc.layer.HeightLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], isAGL: bool = False) nwsspc.sharp.calc.layer.PressureLayer #
Converts a HeightLayer to a PressureLayer via interpolation, with the optional argument to convert the HeightLayer from meters AGL to MSL by adding the station height to the HeightLayer. If for some strange reason you provide a HeightLayer that is out of the bounds of height[], then the bottom and top of the output layer will be set to MISSING.
- Parameters:
pressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressureheight (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of heightsisAGL (
bool
) – Whether or not the station height needs to be added for interpolation (default: False)
- Return type:
- nwsspc.sharp.calc.layer.pressure_layer_to_height(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], toAGL: bool = False) nwsspc.sharp.calc.layer.HeightLayer #
Converts a PressureLayer to a HeightLayer via interpolation, with the optional argument to convert the HeightLayer to meters AGL by subtracting off the station height from the returned HeightLayer. If for some strange reason you provide a PressureLayer that is out of the bounds of pressure[], then the bottom and top of the output layer will be set to MISSING.
- Parameters:
pressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressureheight (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of heightstoAGL (
bool
) – Whether or not to subtract the station height from the HeightLayer (default: False)
- Return type:
- nwsspc.sharp.calc.layer.get_layer_index(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) nwsspc.sharp.calc.layer.LayerIndex #
- nwsspc.sharp.calc.layer.get_layer_index(layer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) nwsspc.sharp.calc.layer.LayerIndex
Overloaded function.
get_layer_index(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> nwsspc.sharp.calc.layer.LayerIndex
Finds the interior array indices encapsulated by the given PressureLayer. More specifically, the returned LayerIndex excludes the exact top and bottom values (in mathematical notation, [bottom, top]). This behavior is due to the fact many algorithms use interpolation to get the exact values of arbitrary top/bottom locations within a profile.
If layer.bottom or layer.top are out of bounds, this function will truncate the layer to the coordinate range of data provided by coord[] in an attempt to gracefully continue and produce a result. This will modify the value of the given PressureLayer.
- Parameters:
pressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressures
- Returns:
A LayerIndex with {kbot, ktop}.
- Return type:
get_layer_index(layer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> nwsspc.sharp.calc.layer.LayerIndex
Finds the interior array indices encapsulated by the given HeightLayer. More specifically, the returned LayerIndex excludes the exact top and bottom values (in mathematical notation, [bottom, top]). This behavior is due to the fact many algorithms use interpolation to get the exact values of arbitrary top/bottom locations within a profile.
If layer.bottom or layer.top are out of bounds, this function will truncate the layer to the coordinate range of data provided by coord[] in an attempt to gracefully continue and produce a result. This will modify the value of the given HeightLayer.
- Parameters:
height (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of heights
- Returns:
A LayerIndex with {kbot, ktop}.
- Return type:
Layer Calculations#
Perform a search or calculation over a given layer type.
- nwsspc.sharp.calc.layer.layer_min(layer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) tuple[float, float] #
- nwsspc.sharp.calc.layer.layer_min(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) tuple[float, float]
Overloaded function.
layer_min(layer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> tuple[float, float]
Returns the minimum value of the data array within the given HeightLayer. The function bounds checks the layer by calling get_layer_index.
- Parameters:
height (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of heightsdata (
numpy.ndarray[dtype=float32]
) – 1D array of data
- Returns:
(min_value, level_of_min)
- Return type:
tuple[float
,float]
layer_min(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> tuple[float, float]
Returns the minimum value of the data array within the given PressureLayer. The function bounds checks the layer by calling get_layer_index.
- Parameters:
pressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressuredata (
numpy.ndarray[dtype=float32]
) – 1D array of data
- Returns:
(min_value, level_of_min)
- Return type:
tuple[float
,float]
- nwsspc.sharp.calc.layer.layer_max(layer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) tuple[float, float] #
- nwsspc.sharp.calc.layer.layer_max(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) tuple[float, float]
Overloaded function.
layer_max(layer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> tuple[float, float]
Returns the maximum value observed within the given data array over the given HeightLayer. The function bounds checks the layer by calling get_layer_index.
- Parameters:
height (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of height valuesdata (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of data values
- Returns:
(max_value, level_of_max)
- Return type:
tuple[float
,float]
layer_max(layer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> tuple[float, float]
Returns the maximum value observed within the given data array over the given PressureLayer. The function bounds checks the layer by calling get_layer_index.
- Parameters:
pressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressure valuesdata (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of data values
- Returns:
(max_value, level_of_max)
- Return type:
tuple[float
,float]
- nwsspc.sharp.calc.layer.layer_mean(PressureLayer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) float #
- nwsspc.sharp.calc.layer.layer_mean(HeightLayer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], isAGL: bool = False) float
Overloaded function.
layer_mean(PressureLayer: nwsspc.sharp.calc.layer.PressureLayer, pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False]) -> float
Computes the pressure-weighted mean value of a field over a given PressureLayer.
- Parameters:
pressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressure valuesdata (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of data values
- Return type:
float
layer_mean(HeightLayer: nwsspc.sharp.calc.layer.HeightLayer, height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], isAGL: bool = False) -> float
Computes the pressure-weighted mean value of a field over a given HeightLayer.
- Parameters:
height (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of height valuespressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressure valuesdata (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of data valuesisAGL (
bool
) – Whether or not the surface station height should be added to the HeightLayer (default: False)
- Return type:
float
- nwsspc.sharp.calc.layer.integrate_layer_trapz(layer: nwsspc.sharp.calc.layer.HeightLayer, data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], integ_sign: int = 0, weighted: bool = False) float #
- nwsspc.sharp.calc.layer.integrate_layer_trapz(layer: nwsspc.sharp.calc.layer.PressureLayer, data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], integ_sign: int = 0, weighted: bool = False) float
Overloaded function.
integrate_layer_trapz(layer: nwsspc.sharp.calc.layer.HeightLayer, data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], height: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], integ_sign: int = 0, weighted: bool = False) -> float
Returns a trapezoidal integration of the given data array over the given HeightLayer. There is an additional argument that determines whether this is a weighted average or not. The sign of the integration may be passed as well, i.e. integrating only positive or negative area, by passing a 1, 0, or -1 to integ_sign.
- Parameters:
data (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of data valuesheight (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of height valuesinteg_sign (
int
) – The sign of the area to integrate (-1: negative; 1: positive; 0: both; default: 0)weighted (
bool
) – Boolean determining whether or not the integration is weighted by the coordinate array
- Return type:
float
integrate_layer_trapz(layer: nwsspc.sharp.calc.layer.PressureLayer, data: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], pressure: ndarray[dtype=float32, shape=(*), order='C', device='cpu', writable=False], integ_sign: int = 0, weighted: bool = False) -> float
Returns the trapezoidal integration of the given data array over the given PressureLayer. There is an additional argument that determines whether this is a weighted average or not. The sign of the integration may be passed as well, i.e. integrating only positive or negative area, by passing a 1, 0, or -1 to integ_sign.
- Parameters:
data (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of data valuespressure (
numpy.ndarray[dtype=float32]
) – 1D NumPy array of pressure valuesinteg_sign (
int
) – The sign of the area to integrate (-1: negative; 1: positive; 0: both; default: 0)weighted (
bool
) – Boolean determining whether or not the integration is weighted by the coordinate array
- Return type:
float