Commit 696914cf authored by Marc R.'s avatar Marc R.

derived variables: added computation of 3D wind speed

parent fdb69a7c
......@@ -64,6 +64,7 @@ MDerivedMetVarsDataSource::MDerivedMetVarsDataSource()
//! and be done outside of the class as a configuration/plug-in mechanism.
registerDerivedDataFieldProcessor(new MHorizontalWindSpeedProcessor());
registerDerivedDataFieldProcessor(new MMagnitudeOfAirVelocityProcessor());
registerDerivedDataFieldProcessor(new MPotentialTemperatureProcessor());
registerDerivedDataFieldProcessor(new MEquivalentPotentialTemperatureProcessor());
registerDerivedDataFieldProcessor(new MGeopotentialHeightProcessor());
......@@ -615,17 +616,57 @@ void MHorizontalWindSpeedProcessor::compute(
}
MPotentialTemperatureProcessor::MPotentialTemperatureProcessor()
// Magnitude of air velocity (3D wind speed; "wind" is defined as 2D only in
// CF).
// =========================================================================
MMagnitudeOfAirVelocityProcessor::MMagnitudeOfAirVelocityProcessor()
: MDerivedDataFieldProcessor(
"air_potential_temperature",
QStringList() << "air_temperature")
"magnitude_of_air_velocity",
QStringList() << "eastward_wind" << "northward_wind"
<< "upward_air_velocity")
{}
void MMagnitudeOfAirVelocityProcessor::compute(
QList<MStructuredGrid *> &inputGrids, MStructuredGrid *derivedGrid)
{
// input 0 = "eastward_wind"
// input 1 = "northward_wind"
// input 2 = "upward_air_velocity"
for (unsigned int n = 0; n < derivedGrid->getNumValues(); n++)
{
float u_ms = inputGrids.at(0)->getValue(n);
float v_ms = inputGrids.at(1)->getValue(n);
float w_ms = inputGrids.at(2)->getValue(n);
if (u_ms == M_MISSING_VALUE || v_ms == M_MISSING_VALUE
|| w_ms == M_MISSING_VALUE)
{
derivedGrid->setValue(n, M_MISSING_VALUE);
}
else
{
float windspeed3D = windSpeed3D_ms(u_ms, v_ms, w_ms);
derivedGrid->setValue(n, windspeed3D);
}
}
}
// Potential temperature
// =====================
MPotentialTemperatureProcessor::MPotentialTemperatureProcessor()
: MDerivedDataFieldProcessor(
"air_potential_temperature",
QStringList() << "air_temperature")
{
}
void MPotentialTemperatureProcessor::compute(
QList<MStructuredGrid *> &inputGrids, MStructuredGrid *derivedGrid)
{
......
......@@ -196,6 +196,17 @@ public:
};
class MMagnitudeOfAirVelocityProcessor
: public MDerivedDataFieldProcessor
{
public:
MMagnitudeOfAirVelocityProcessor();
void compute(QList<MStructuredGrid*>& inputGrids,
MStructuredGrid *derivedGrid);
};
class MPotentialTemperatureProcessor
: public MDerivedDataFieldProcessor
{
......
......@@ -442,6 +442,12 @@ double windSpeed_ms(double u_ms, double v_ms)
}
double windSpeed3D_ms(double u_ms, double v_ms, double w_ms)
{
return sqrt(pow(u_ms, 2) + pow(v_ms, 2) + pow(w_ms, 2));
}
double potentialTemperature_K(double T_K, double p_Pa)
{
return T_K * pow( 100000. / p_Pa,
......
......@@ -260,6 +260,14 @@ double boxVolume_dry(double northWestLon, double northWestLat,
double windSpeed_ms(double u_ms, double v_ms);
/**
Computes 3D wind speed (aka magnitude of air velocity in CF naming) in
[m.s-1] from eastward wind (@p u_ms), northward wind (@p v_ms) and
upward_air_velocity (@p w_ms).
*/
double windSpeed3D_ms(double u_ms, double v_ms, double w_ms);
/**
Computes potential temperature in [K] from temperature @p T_K in [K] and
pressure @p p_Pa in [Pa].
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment