Skip to content

Commit

Permalink
Merge pull request #2203 from dtcenter/feature_1815_level_value
Browse files Browse the repository at this point in the history
Feature 1815 level value
  • Loading branch information
hsoh-u authored Jul 18, 2022
2 parents e8af847 + b6029c3 commit 3d13abc
Show file tree
Hide file tree
Showing 28 changed files with 1,070 additions and 763 deletions.
12 changes: 9 additions & 3 deletions docs/Users_Guide/appendixA.rst
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,10 @@ Q. How do I choose a time slice in a NetCDF file?

A.
When processing NetCDF files, the level information needs to be
specified to tell MET which 2D slice of data to use. There is
currently no way to explicitly define which time slice to use
other than selecting the time index.
specified to tell MET which 2D slice of data to use. The index is selected from
a value when it starts with "@" for vertical level (pressure or height)
and time. The actual time, @YYYYMMDD_HHMM, is allowed instead of selecting
the time index.

Let's use plot_data_plane as an example:

Expand All @@ -160,6 +161,11 @@ Let's use plot_data_plane as an example:
obs.ps \
'name="APCP"; level="(5,*,*)";'
plot_data_plane \
gtg_obs_forecast.20130730.i00.f00.nc \
altitude_20000.ps \
'name = "edr"; level = "(@20130730_0000,@20000,*,*)";'
Assuming that the first array is the time, this will select the 6-th
time slice of the APCP data and plot it since these indices are 0-based.

Expand Down
14 changes: 13 additions & 1 deletion docs/Users_Guide/config_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -991,7 +991,8 @@ File-format specific settings for the "field" entry:

* (i,...,j,*,*) for a single field, where i,...,j specifies fixed
dimension values and *,* specifies the two dimensions for the
gridded field. For example:
gridded field. @ specifies the vertical level value or time value
instead of offset, (i,...,@NNN,*,*). For example:

.. code-block:: none
Expand All @@ -1006,6 +1007,17 @@ File-format specific settings for the "field" entry:
}
];
field = [
{
name = "QVAPOR";
level = "(@20220601_1200,@850,*,*)";
},
{
name = "TMP_P850_ENS_MEAN";
level = [ "(*,*)" ];
}
];
* Python (using PYTHON_NUMPY or PYTHON_XARRAY):

* The Python interface for MET is described in Appendix F of the MET
Expand Down
16 changes: 15 additions & 1 deletion internal/test_unit/xml/unit_plot_data_plane.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,20 @@
</output>
</test>

<test name="plot_data_plane_NCCF_latlon_by_value">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
&DATA_DIR_MODEL;/nccf/gtg/latlon/gtg_obs_forecast.20130730.i00.f00.nc \
&OUTPUT_DIR;/plot_data_plane/gtg_obs_forecast.20130730.i00.f00.NCCF_latlon_20000.ps \
'name = "edr"; level = "(0,@20000,*,*)";' \
-title "NCCF Latitude/Longitude Level 0" \
-v 1
</param>
<output>
<ps>&OUTPUT_DIR;/plot_data_plane/gtg_obs_forecast.20130730.i00.f00.NCCF_latlon_20000.ps</ps>
</output>
</test>

<test name="plot_data_plane_NCCF_north_to_south">
<exec>&MET_BIN;/plot_data_plane</exec>
<param> \
Expand Down Expand Up @@ -403,7 +417,7 @@
<param> \
&DATA_DIR_MODEL;/easm/pr_day_MPI-ESM-MR_rcp85_r1i1p1_20060101-20091231.nc \
&OUTPUT_DIR;/plot_data_plane/EaSM_CMIP5_pr_day_MPI-ESM-MR_rcp85_r1i1p1_20060101_12_time.ps \
'name="pr"; level="(20060102_000000,*,*)";' \
'name="pr"; level="(@20060102_000000,*,*)";' \
-v 4
</param>
<output>
Expand Down
1 change: 1 addition & 0 deletions src/basic/vx_util/util_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ static const double const_gop = 9.80616; // from The Ceaseless Wind
static const double const_rd = 287.0; // kg/k dry gas constant

static const int vx_data2d_star = -12345;
static const int vx_data2d_dim_by_value = -123456; // apply the value instead of offset for slicing

////////////////////////////////////////////////////////////////////////

Expand Down
22 changes: 4 additions & 18 deletions src/libcode/vx_data2d/level_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ void LevelInfo::init_from_scratch() {

clear();

return;
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -88,9 +87,8 @@ void LevelInfo::assign(const LevelInfo &l) {
Upper = l.upper();
Lower = l.lower();
Increment = l.increment();
time_as_offset = l.is_time_as_offset();
Is_offset = l.is_offset();

return;
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -106,9 +104,8 @@ void LevelInfo::clear() {
Upper = 0.0;
Lower = 0.0;
Increment = 0.0;
time_as_offset = true;
Is_offset = true;

return;
}

///////////////////////////////////////////////////////////////////////////////
Expand All @@ -125,78 +122,67 @@ void LevelInfo::dump(ostream &out) const {
<< " Upper = " << Upper << "\n"
<< " Increment = " << Increment << "\n";

return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_type(LevelType lt) {
Type = lt;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_type_num(int i) {
TypeNum = i;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_req_name(const char *str) {
ReqName = str;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_name(const char *str) {
Name = str;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_units(const char *str) {
Units = str;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_upper(double u) {
Upper = u;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_lower(double l) {
Lower = l;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_range(double l, double u) {
Lower = l;
Upper = u;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_increment(double i) {
Increment = i;
return;
}

///////////////////////////////////////////////////////////////////////////////

void LevelInfo::set_time_as_offset(bool b) {
time_as_offset = b;
return;
void LevelInfo::set_is_offset(bool b) {
Is_offset = b;
}

///////////////////////////////////////////////////////////////////////////////
8 changes: 4 additions & 4 deletions src/libcode/vx_data2d/level_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class LevelInfo
double Upper; // Upper level limit
double Lower; // Lower level limit
double Increment; // Increment (time: seconds, 0 for no increment)
bool time_as_offset;// default: true, false: the (time) value instead
bool Is_offset; // default: true, false: the value instead
// of the offset at Lower and Upper

void init_from_scratch();
Expand Down Expand Up @@ -77,7 +77,7 @@ class LevelInfo
double upper() const;
double lower() const;
double increment() const;
bool is_time_as_offset()const;
bool is_offset() const;

//
// set stuff
Expand All @@ -92,7 +92,7 @@ class LevelInfo
void set_lower(double l);
void set_range(double l, double u);
void set_increment(double i);
void set_time_as_offset(bool b);
void set_is_offset(bool b);

};

Expand All @@ -106,7 +106,7 @@ inline ConcatString LevelInfo::units() const { return(Units); }
inline double LevelInfo::upper() const { return(Upper); }
inline double LevelInfo::lower() const { return(Lower); }
inline double LevelInfo::increment()const { return(Increment);}
inline bool LevelInfo::is_time_as_offset()const { return(time_as_offset);}
inline bool LevelInfo::is_offset()const { return(Is_offset);}

///////////////////////////////////////////////////////////////////////////////

Expand Down
16 changes: 5 additions & 11 deletions src/libcode/vx_data2d_nc_met/met_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,6 @@ using namespace std;
static const char x_dim_name [] = "lon";
static const char y_dim_name [] = "lat";

static const string valid_time_att_name = "valid_time";
static const string init_time_att_name = "init_time";
static const string valid_time_ut_att_name = "valid_time_ut";
static const string init_time_ut_att_name = "init_time_ut";
static const string accum_time_att_name = "accum_time_sec";

static const int max_met_args = 30;

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -254,11 +248,11 @@ for (j=0; j<Ndims; ++j) {
//
// parse the variable attributes
//
get_att_str( Var[j], name_att_name, Var[j].name_att );
get_att_str( Var[j], long_name_att_name, Var[j].long_name_att );
get_att_str( Var[j], level_att_name, Var[j].level_att );
get_att_str( Var[j], units_att_name, Var[j].units_att );
get_att_int( Var[j], accum_time_att_name, Var[j].AccumTime );
get_att_name ( Var[j], Var[j].name_att );
get_var_long_name( Var[j].var, Var[j].long_name_att );
get_att_level ( Var[j], Var[j].level_att );
get_var_units ( Var[j].var, Var[j].units_att );
get_att_accum_time( Var[j], Var[j].AccumTime );

get_att_unixtime( Var[j], init_time_ut_att_name, ill);
get_att_unixtime( Var[j], valid_time_ut_att_name, vll);
Expand Down
20 changes: 18 additions & 2 deletions src/libcode/vx_data2d_nc_pinterp/data2d_nc_pinterp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,25 @@ bool MetNcPinterpDataFile::data_plane(VarInfo &vinfo, DataPlane &plane) {
plane.clear();

// Read the data
PinterpNc->get_nc_var_info(vinfo_nc->req_name().c_str(), info);
LongArray dimension = vinfo_nc->dimension();
int dim_count = dimension.n_elements();
for (int k=0; k<dim_count; k++) {
if (dimension[k] == vx_data2d_dim_by_value) {
string dim_name = GET_NC_NAME(get_nc_dim(info->var, k));
NcVarInfo *var_info = find_var_info_by_dim_name(PinterpNc->Var, dim_name,
PinterpNc->Nvars);
if (var_info) {
long new_offset = get_index_at_nc_data(var_info->var,
vinfo_nc->dim_value(k),
dim_name, (k == info->t_slot));
if (new_offset != bad_data_int) dimension[k] = new_offset;
}
}
}

status = PinterpNc->data(vinfo_nc->req_name().c_str(),
vinfo_nc->dimension(),
plane, pressure, info);
dimension, plane, pressure, info);

// Check that the times match those requested
if(status) {
Expand Down
Loading

0 comments on commit 3d13abc

Please sign in to comment.