layer#
Layer Definitions#
-
struct PressureLayer#
A simple structure of two named floats that represent a pressure layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Public Functions
-
inline PressureLayer()#
Construct an empty sharp::PressureLayer.
Sets the top and bottom to sharp::MISSING
-
PressureLayer(float bot, float top, float delta = -1000.0)#
Constructs a sharp::PressureLayer.
- Parameters:
bot – (bottom of layer, Pa)
top – (top of layer, Pa)
delta – (pressure increment, Pa)
Public Members
-
float bottom#
The bottom of the pressure layer (Pa)
-
float top#
The top of the pressure layer (Pa)
-
float delta#
The pressure interval with which to iterate over the layer (Pa)
Public Static Attributes
-
static constexpr LayerCoordinate coord = LayerCoordinate::pressure#
The coordinate system of the layer.
-
struct HeightLayer#
A simple structure of named floats that represent a height layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Public Functions
-
inline HeightLayer()#
Construct an empty sharp::HeightLayer.
Sets the top and bottom to sharp::MISSING
-
HeightLayer(float bot, float top, float delta = 100.0)#
Constructs a sharp::HeightLayer.
- Parameters:
bot – (bottom of layer, meters)
top – (top of layer, meters)
delta – (height increment, meters)
Public Members
-
float bottom#
The bottom of the height layer (meters)
-
float top#
The top of the height layer (meters)
-
float delta#
The height interval with which to iterate over the layer (meters)
Public Static Attributes
-
static constexpr LayerCoordinate coord = LayerCoordinate::height#
The coordinate system of the layer.
-
struct LayerIndex#
A simple structure of two named integer indices for the top and bottom of a layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Layer Conversions#
-
HeightLayer sharp::pressure_layer_to_height(PressureLayer layer, const float pressure[], const float height[], const std::ptrdiff_t N, const bool toAGL = false)#
Converts a sharp::PressureLayer to a sharp::HeightLayer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Converts a sharp::PressureLayer to a sharp::HeightLayer via interpolation, with the option of returning the layer in meters AGL or MSL. 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 sharp::MISSING.
- Parameters:
layer – (Pa)
pressure – (Pa)
height – (meters)
N – (Length of arrays)
toAGL – Flag whether to return meters AGL or MSL (default: false)
- Returns:
{bottom, top}
-
PressureLayer sharp::height_layer_to_pressure(HeightLayer layer, const float pressure[], const float height[], const std::ptrdiff_t N, const bool isAGL = false)#
Converts a sharp::HeightLayer to a sharp::PressureLayer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Converts a sharp::HeightLayer to a sharp::PressureLayer via interpolation, with a flag to signal whether the input layer is in meters AGL or meters MSL. 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 sharp::MISSING.
- Parameters:
layer – (meters)
pressure – (Pa)
height – (meters)
N – (Length of arrays)
isAGL – Whether the input layer is AGL / MSL (default: false)
- Returns:
{bottom, top}
-
LayerIndex sharp::get_layer_index(PressureLayer &layer, const float pressure[], const std::ptrdiff_t N)#
Finds the array indices corresponding to the given sharp::PressureLayer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Returns the array indices corresponding to the given sharp::PressureLayer, and performs bounds checking on the layer. As part of the bounds checking, the sharp::PressureLayer is modified if the bottom or top of the layer is out of bounds, which is why it gets passed as a reference.
If the exact values of the top and bottom of the layer are present, their indices are ignored. The default behavior is that the bottom and top of a layer is computed by interpolation by default, since it may or may not be present in the native data.
- Parameters:
layer – {bottom, top}
pressure – (Pa)
N – (length of array)
- Returns:
{kbot, ktop}
-
LayerIndex sharp::get_layer_index(HeightLayer &layer, const float height[], const std::ptrdiff_t N)#
Finds the array indices corresponding to the given sharp::HeightLayer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Returns the array indices corresponding to the given sharp::HeightLayer, and performs bounds checking on the layer. As part of the bounds checking, the sharp::HeightLayer is modified if the bottom or top of the layer is out of bounds, which is why it gets passed as a reference.
If the exact values of the top and bottom of the layer are present, their indices are ignored. The default behavior is that the bottom and top of a layer is computed by interpolation by default, since it may or may not be present in the native data.
- Parameters:
layer – {bottom, top}
height – (meters)
N – (length of array)
- Returns:
{kbot, ktop}
Layer Calculations#
-
template<typename L>
constexpr float sharp::layer_min(L layer, const float coord_arr[], const float data_arr[], const std::ptrdiff_t N, float *lvl_of_min = nullptr)# Returns the minimum value in the given layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Returns the minimum value observed within the given data array over the given sharp::PressureLayer or sharp::HeightLayer. The function bounds checks the layer by calling sharp::get_layer_index.
If lvl_of_min is not a nullptr, then the pointer will be dereferenced and filled with the coordinate of the minimum value.
- Parameters:
layer – (sharp::PressureLayer or sharp::HeightLayer)
coord_arr – (coordinate units; Pa or meters)
data_arr – (data array to find min on)
N – (length of arrays)
lvl_of_min – (level of min val)
- Returns:
layer_min
-
template<typename L>
constexpr float sharp::layer_max(L layer, const float coord_arr[], const float data_arr[], const std::ptrdiff_t N, float *lvl_of_max = nullptr)# Returns the maximim value in the given layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Returns the maximum value observed within the given data array over the given sharp::PressureLayer or sharp::HeightLayer. The function bounds checks the layer by calling sharp::get_layer_index.
If lvl_of_max is not a nullptr, then the pointer will be dereferenced and filled with the coordinate of the maximum value.
- Parameters:
layer – (sharp::PressureLayer or sharp::HeightLayer)
coord_arr – (coordinate units; Pa or meters)
data_arr – (data array to find max on)
N – (length of arrays)
lvl_of_max – (level of max val)
- Returns:
layer_max
-
float sharp::layer_mean(PressureLayer layer, const float pressure[], const float data_arr[], const std::ptrdiff_t N)#
Computes the mass-weighted mean value of a field over a given pressure layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Computes the mass-weighted mean value of given arrays of data and corresponding pressure coordinates over the given sharp::PressureLayer.
- Parameters:
layer – (sharp::PressureLayer)
pressure – (vertical pressure array; Pa)
data_arr – (The data for which to compute a mean)
N – (length of pressure and data arrays)
- Returns:
layer_mean
-
float sharp::layer_mean(HeightLayer layer, const float height[], const float pressure[], const float data_arr[], const std::ptrdiff_t N, const bool isAGL = false)#
Computes the mass-weighted mean value of a field over a given height layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Computes the mass-weighted mean value of given arrays of data and corresponding height coordinates over the given sharp::HeightLayer. This is really just a fancy wrapper around the implementation that uses sharp::PressureLayer.
- Parameters:
layer – (sharp::HeightLayer)
height – (vertical height array; meters)
pressure – (vertical pressure array; Pa)
data_arr – (The data for which to compute a mean)
N – (length of pressure and data arrays)
isAGL – (whether or not intput is in AGL or MSL)
- Returns:
layer_mean
-
template<typename L>
float sharp::integrate_layer_trapz(L layer, const float var_array[], const float coord_array[], const std::ptrdiff_t N, const int integ_sign = 0, const bool weighted = false)# Returns a trapezoidal integration of the given layer.
- Author
Kelton Halbert - NWS Storm Prediction Center
Returns a trapezoidal integration of the given data array over the given sharp::PressureLayer or sharp::HeightLayer. There is an additional default 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 values, by passing a 1 or -1 to integ_sign.
- Parameters:
layer – (sharp::PressureLayer or sharp::HeightLayer)
var_array – (data array to integrate)
coord_array – (coordinate array to integrate over)
N – (length of arrays)
weighted – (bool; default=false)
integ_sign – (int; default=0)
- Returns:
integrated_value