Skip to content

Commit

Permalink
Per #1020, update the VarInfo class to parse and store the set_attrs …
Browse files Browse the repository at this point in the history
…dictionary members.
  • Loading branch information
JohnHalleyGotway committed Jun 5, 2020
1 parent 0b0fab9 commit d8c943a
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 29 deletions.
22 changes: 22 additions & 0 deletions met/src/basic/vx_config/config_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,28 @@ static const char conf_key_trunc_factor[] = "gaussian_trunc_factor";
static const char conf_key_eclv_points[] = "eclv_points";
static const char conf_key_var_name_map[] = "var_name_map";

//
// Entries for set_attrs dictionary
//
static const char conf_key_set_attrs[] = "set_attrs";
static const char conf_key_set_name[] = "set_name";
static const char conf_key_set_units[] = "set_units";
static const char conf_key_set_level[] = "set_level";
static const char conf_key_set_long_name[] = "set_long_name";
static const char conf_key_set_ensemble[] = "set_ensemble";
static const char conf_key_set_grid[] = "set_grid";
static const char conf_key_set_init[] = "set_init";
static const char conf_key_set_valid[] = "set_valid";
static const char conf_key_set_lead[] = "set_lead";
static const char conf_key_is_precipitation[] = "is_precipitation";
static const char conf_key_is_specific_humidity[] = "is_specific_humidity";
static const char conf_key_is_u_wind[] = "is_u_wind";
static const char conf_key_is_v_wind[] = "is_v_wind";
static const char conf_key_is_grid_relative[] = "is_grid_relative";
static const char conf_key_is_wind_speed[] = "is_wind_speed";
static const char conf_key_is_wind_direction[] = "is_wind_direction";
static const char conf_key_is_prob[] = "is_prob";

//
// Climatology parameter key names
//
Expand Down
155 changes: 127 additions & 28 deletions met/src/libcode/vx_data2d/var_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ using namespace std;
#include "vx_math.h"
#include "vx_log.h"

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

int parse_set_attrs_flag(Dictionary *dict, const char *key);

///////////////////////////////////////////////////////////////////////////////
//
// Code for class VarInfo
Expand Down Expand Up @@ -81,36 +85,56 @@ void VarInfo::init_from_scratch() {
void VarInfo::assign(const VarInfo &v) {

// Copy
MagicStr = v.magic_str();
ReqName = v.req_name();
Name = v.name();
LongName = v.long_name();
Units = v.units();
Level = v.level();

PFlag = v.p_flag();
PName = v.p_name();
PUnits = v.p_units();
PThreshLo = v.p_thresh_lo();
PThreshHi = v.p_thresh_hi();
PAsScalar = v.p_as_scalar();

UVIndex = v.uv_index();

Init = v.init();
Valid = v.valid();
Lead = v.lead();
Ensemble = v.ens ();
MagicStr = v.MagicStr;
ReqName = v.ReqName;
Name = v.Name;
Units = v.Units;
Level = v.Level;
LongName = v.LongName;
Ensemble = v.Ensemble;

PFlag = v.PFlag;
PName = v.PName;
PUnits = v.PUnits;
PThreshLo = v.PThreshLo;
PThreshHi = v.PThreshHi;
PAsScalar = v.PAsScalar;

UVIndex = v.UVIndex;

Init = v.Init;
Valid = v.Valid;
Lead = v.Lead;

ConvertFx = v.ConvertFx;

CensorThresh = v.censor_thresh();
CensorVal = v.censor_val();
CensorThresh = v.CensorThresh;
CensorVal = v.CensorVal;

nBins = v.nBins;
Range = v.Range;

nBins = v.n_bins();
Range = v.range();
Regrid = v.Regrid;

Regrid = v.Regrid;
SetAttrsName = v.SetAttrsName;
SetAttrsUnits = v.SetAttrsUnits;
SetAttrsLevel = v.SetAttrsLevel;
SetAttrsLongName = v.SetAttrsLongName;
SetAttrsEnsemble = v.SetAttrsEnsemble;
SetAttrsGrid = v.SetAttrsGrid;

SetAttrsInit = v.SetAttrsInit;
SetAttrsValid = v.SetAttrsValid;
SetAttrsLead = v.SetAttrsLead;

SetAttrsIsPrecipitation = v.SetAttrsIsPrecipitation;
SetAttrsIsSpecificHumidity = v.SetAttrsIsSpecificHumidity;
SetAttrsIsUWind = v.SetAttrsIsUWind;
SetAttrsIsVWind = v.SetAttrsIsVWind;
SetAttrsIsGridRelative = v.SetAttrsIsGridRelative;
SetAttrsIsWindSpeed = v.SetAttrsIsWindSpeed;
SetAttrsIsWindDirection = v.SetAttrsIsWindDirection;
SetAttrsIsProb = v.SetAttrsIsProb;

return;
}
Expand Down Expand Up @@ -151,6 +175,26 @@ void VarInfo::clear() {

Regrid.clear();

SetAttrsName.clear();
SetAttrsUnits.clear();
SetAttrsLevel.clear();
SetAttrsLongName.clear();
SetAttrsEnsemble.clear();
SetAttrsGrid.clear();

SetAttrsInit = (unixtime) 0;
SetAttrsValid = (unixtime) 0;
SetAttrsLead = bad_data_int;

SetAttrsIsPrecipitation = bad_data_int;
SetAttrsIsSpecificHumidity = bad_data_int;
SetAttrsIsUWind = bad_data_int;
SetAttrsIsVWind = bad_data_int;
SetAttrsIsGridRelative = bad_data_int;
SetAttrsIsWindSpeed = bad_data_int;
SetAttrsIsWindDirection = bad_data_int;
SetAttrsIsProb = bad_data_int;

return;
}

Expand Down Expand Up @@ -380,10 +424,11 @@ void VarInfo::set_magic(const ConcatString &nstr, const ConcatString &lstr) {
///////////////////////////////////////////////////////////////////////////////

void VarInfo::set_dict(Dictionary &dict) {
Dictionary * attrs_dict = (Dictionary *) 0;
ThreshArray ta;
NumArray na;
ConcatString s;
bool f;
bool b;
int n;

// Set init time, if present
Expand All @@ -405,8 +450,8 @@ void VarInfo::set_dict(Dictionary &dict) {
}

// Parse prob_as_scalar, if present
f = dict.lookup_bool(conf_key_prob_as_scalar, false);
if(dict.last_lookup_status()) set_p_as_scalar(f);
b = dict.lookup_bool(conf_key_prob_as_scalar, false);
if(dict.last_lookup_status()) set_p_as_scalar(b);

// Lookup conversion function, if present
ConvertFx.set(dict.lookup(conf_key_convert));
Expand Down Expand Up @@ -440,6 +485,52 @@ void VarInfo::set_dict(Dictionary &dict) {
// Parse regrid, if present
Regrid = parse_conf_regrid(&dict, false);

// Parse set_attrs dictionary, if present
attrs_dict = dict.lookup_dictionary(conf_key_set_attrs, false);

if(attrs_dict) {

// Parse strings
SetAttrsName =
attrs_dict->lookup_string(conf_key_set_name, false);
SetAttrsUnits =
attrs_dict->lookup_string(conf_key_set_units, false);
SetAttrsLevel =
attrs_dict->lookup_string(conf_key_set_level, false);
SetAttrsLongName =
attrs_dict->lookup_string(conf_key_set_long_name, false);
SetAttrsEnsemble =
attrs_dict->lookup_string(conf_key_set_ensemble, false);
SetAttrsGrid =
attrs_dict->lookup_string(conf_key_set_grid, false);

// Parse times
s = attrs_dict->lookup_string(conf_key_set_init, false);
if(attrs_dict->last_lookup_status()) SetAttrsInit = timestring_to_unix(s.c_str());
s = attrs_dict->lookup_string(conf_key_set_valid, false);
if(attrs_dict->last_lookup_status()) SetAttrsValid = timestring_to_unix(s.c_str());
s = attrs_dict->lookup_string(conf_key_set_lead, false);
if(attrs_dict->last_lookup_status()) SetAttrsLead = timestring_to_sec(s.c_str());

// Parse flags
SetAttrsIsPrecipitation =
parse_set_attrs_flag(attrs_dict, conf_key_is_precipitation);
SetAttrsIsSpecificHumidity =
parse_set_attrs_flag(attrs_dict, conf_key_is_specific_humidity);
SetAttrsIsUWind =
parse_set_attrs_flag(attrs_dict, conf_key_is_u_wind);
SetAttrsIsVWind =
parse_set_attrs_flag(attrs_dict, conf_key_is_v_wind);
SetAttrsIsGridRelative =
parse_set_attrs_flag(attrs_dict, conf_key_is_grid_relative);
SetAttrsIsWindSpeed =
parse_set_attrs_flag(attrs_dict, conf_key_is_wind_speed);
SetAttrsIsWindDirection =
parse_set_attrs_flag(attrs_dict, conf_key_is_wind_direction);
SetAttrsIsProb =
parse_set_attrs_flag(attrs_dict, conf_key_is_prob);
}

return;
}

Expand Down Expand Up @@ -627,3 +718,11 @@ bool VarInfo::is_prob() {
}

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

int parse_set_attrs_flag(Dictionary *dict, const char *key) {
if(!dict) return(bad_data_int);
bool b = dict->lookup_bool(key, false);
return(dict->last_lookup_status() ? (int) b : bad_data_int);
}

///////////////////////////////////////////////////////////////////////////////
5 changes: 4 additions & 1 deletion met/src/libcode/vx_data2d/var_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,18 @@ class VarInfo
ConcatString SetAttrsLevel;
ConcatString SetAttrsLongName;
ConcatString SetAttrsEnsemble;

ConcatString SetAttrsGrid;

unixtime SetAttrsInit;
unixtime SetAttrsValid;
int SetAttrsLead;
ConcatString SetAttrsGrid;

int SetAttrsIsPrecipitation;
int SetAttrsIsSpecificHumidity;
int SetAttrsIsUWind;
int SetAttrsIsVWind;
int SetAttrsIsGridRelative;
int SetAttrsIsWindSpeed;
int SetAttrsIsWindDirection;
int SetAttrsIsProb;
Expand Down

0 comments on commit d8c943a

Please sign in to comment.