Skip to content

Commit

Permalink
apps/ingest/src/Era5Nc2Mdv - testing
Browse files Browse the repository at this point in the history
  • Loading branch information
mike-dixon committed Nov 19, 2023
1 parent fe7518f commit 5d8da0d
Show file tree
Hide file tree
Showing 18 changed files with 325 additions and 2,057 deletions.
1 change: 1 addition & 0 deletions codebase/apps/ingest/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ add_subdirectory (CwbObs2Spdb)
add_subdirectory (CwbSfc2Mdv)
add_subdirectory (EolMobileKml2Spdb)
add_subdirectory (EraGrib2Mdv)
add_subdirectory (Era5Nc2Mdv)
add_subdirectory (GemVolXml2Dsr)
add_subdirectory (Gini2Mdv)
add_subdirectory (GoesRGLM2Spdb)
Expand Down
20 changes: 10 additions & 10 deletions codebase/apps/ingest/src/Era5Nc2Mdv/CIDD.era5
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ field_list = {
# ERA5
#

Div Div mdvp:://localhost::$(HOME)/data/ERA5/mdv&D div.colors 1/s -5 80 5 dcont 1 0
Q Q mdvp:://localhost::$(HOME)/data/ERA5/mdv&Q mixr_kgpkg.colors kg/kg -5 80 5 dcont 1 0
RH RH mdvp:://localhost::$(HOME)/data/ERA5/mdv&R rh.colors % -5 80 5 dcont 1 0
T T mdvp:://localhost::$(HOME)/data/ERA5/mdv&T tempK.colors K -5 80 5 dcont 1 0
U U mdvp:://localhost::$(HOME)/data/ERA5/mdv&U vel_45.colors m/s -5 80 5 dcont 1 0
V V mdvp:://localhost::$(HOME)/data/ERA5/mdv&V vel_45.colors m/s -5 80 5 dcont 1 0
W W mdvp:://localhost::$(HOME)/data/ERA5/mdv&W vert_wspd.colors Pa/s -5 80 5 dcont 1 0
Z Z mdvp:://localhost::$(HOME)/data/ERA5/mdv&Z geoht_m.colors m2/s2 -5 80 5 dcont 1 0
ht ht mdvp:://localhost::$(HOME)/data/ERA5/mdv&height heightkm.colors m -5 80 5 dcont 1 0
pres pres mdvp:://localhost::$(HOME)/data/ERA5/mdv&pressure pressure_mb.colors hPa -5 80 5 dcont 1 0
Div Div mdvp:://localhost::$(HOME)/data/ERA5/mdv&div div.colors 1/s -5 80 5 dcont 1 0
Q Q mdvp:://localhost::$(HOME)/data/ERA5/mdv&spec_hum mixr_kgpkg.colors kg/kg -5 80 5 dcont 1 0
RH RH mdvp:://localhost::$(HOME)/data/ERA5/mdv&RH rh.colors % -5 80 5 dcont 1 0
T T mdvp:://localhost::$(HOME)/data/ERA5/mdv&temp tempK.colors K -5 80 5 dcont 1 0
U U mdvp:://localhost::$(HOME)/data/ERA5/mdv&u vel_45.colors m/s -5 80 5 dcont 1 0
V V mdvp:://localhost::$(HOME)/data/ERA5/mdv&v vel_45.colors m/s -5 80 5 dcont 1 0
W W mdvp:://localhost::$(HOME)/data/ERA5/mdv&w vert_wspd.colors Pa/s -5 80 5 dcont 1 0
Z Z mdvp:://localhost::$(HOME)/data/ERA5/mdv&Z geoht_m.colors m2/s2 -5 80 5 dcont 1 0
ht ht mdvp:://localhost::$(HOME)/data/ERA5/mdv&height heightkm.colors m -5 80 5 dcont 1 0
pres pres mdvp:://localhost::$(HOME)/data/ERA5/mdv&pressure pressure_mb.colors hPa -5 80 5 dcont 1 0

</GRIDS>

Expand Down
7 changes: 3 additions & 4 deletions codebase/apps/ingest/src/Era5Nc2Mdv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ project (Era5Nc2Mdv)
set (SRCS
Params.cc
Args.cc
ReadFile.cc
HtInterp.cc
OutputFile.cc
Era5File.cc
Era5Nc2Mdv.cc
main.cc
HtInterp.cc
Main.cc
)

# include directories
Expand Down
71 changes: 71 additions & 0 deletions codebase/apps/ingest/src/Era5Nc2Mdv/Era5Nc2Mdv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,12 @@ int Era5Nc2Mdv::_createVol(const vector<string> &pathsAtTime,

} // ipath

// convert temp field units to C

if (_params.convert_temperature_to_celcius) {
_convertTempToC(mdvx);
}

// create height field from geopotential, for interpolation onto height levels

_addHeightField(mdvx);
Expand All @@ -479,6 +485,12 @@ int Era5Nc2Mdv::_createVol(const vector<string> &pathsAtTime,
interp.interpVlevelsToHeight(mdvx);
}

// rename fields if requested

if (_params.rename_output_fields) {
_renameFields(mdvx);
}

// write output file

if (_params.debug) {
Expand Down Expand Up @@ -749,3 +761,62 @@ int Era5Nc2Mdv::_addHeightField(DsMdvx &mdvx)

}

////////////////////////////////////////////////////////
// convert temperature field units to C
//
// Returns 0 on success, -1 on failure

int Era5Nc2Mdv::_convertTempToC(DsMdvx &mdvx)

{

MdvxField *tField = mdvx.getField(_params.temperature_field_name);
if (tField == NULL) {
cerr << "WARNING - Era5Nc2Mdv::_convertTempToC" << endl;
cerr << " Cannot find temperature field: "
<< _params.temperature_field_name <<endl;
return -1;
}

float *tData = (float*) tField->getVol();
int64_t nPoints = tField->getVolNumValues();
for (int64_t ii = 0; ii < nPoints; ii++) {
double kelvin = tData[ii];
double celcius = kelvin - 273.16;
tData[ii] = celcius;
}
tField->setUnits("C");

return 0;

}

////////////////////////////////////////////////////////
// rename fields before write
// Returns 0 on success, -1 on failure

void Era5Nc2Mdv::_renameFields(DsMdvx &mdvx)

{

for (int ifield = 0; ifield < _params.output_fields_n; ifield++) {

const Params::output_field_t &ofld = _params._output_fields[ifield];

MdvxField *field = mdvx.getField(ofld.input_field_name);
if (field == NULL) {
cerr << "WARNING - Era5Nc2Mdv::_renameFields" << endl;
cerr << " Cannot find field: "
<< ofld.input_field_name <<endl;
cerr << " Renaming will be ignored" << endl;
continue;
}

field->setFieldName(ofld.output_field_name);
field->setFieldNameLong(ofld.output_long_name);
field->setUnits(ofld.output_units);

}

}

4 changes: 3 additions & 1 deletion codebase/apps/ingest/src/Era5Nc2Mdv/Era5Nc2Mdv.hh
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ private:
int _getLevelIndex(double level);
int _addHeightField(DsMdvx &mdvx);
int _addPressureField(DsMdvx &mdvx);

int _convertTempToC(DsMdvx &mdvx);
void _renameFields(DsMdvx &mdvx);

};

#endif
Expand Down
Loading

0 comments on commit 5d8da0d

Please sign in to comment.