Skip to content

Commit

Permalink
Per #1528, update plot_point_obs config file options and plot_point_o…
Browse files Browse the repository at this point in the history
…bs_conf_info.h/.cc to process them.
  • Loading branch information
JohnHalleyGotway committed Nov 10, 2020
1 parent c24890a commit 5580650
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 76 deletions.
77 changes: 38 additions & 39 deletions met/data/config/PlotPointObsConfig_default
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@
//
////////////////////////////////////////////////////////////////////////////////

plot_data_plane = {
flag = FALSE;
field = { name = ""; level = ""; };
data_color_table = :q
{
flag = TRUE;
// Gridded data plotting options

grid_data = {

field = [];

grid_plot_info = {
color_table = "MET_BASE/colortables/met_default.ctable";
plot_min = 0.0;
plot_max = 0.0;
Expand All @@ -22,35 +23,38 @@ plot_data_plane = {

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

// Define named colors in RGB format
black = { 0, 0, 0 }
red = { 255, 0, 0 }
// Point data filtering options
// May be set separately in each "point_data" entry

message_type = [];
sid_inc = [];
sid_exc = [];
obs_var = [];
obs_quality = [];
valid_beg = "";
valid_end = "";
lat_thresh = NA;
lon_thresh = NA;
elv_thresh = NA;
hgt_thresh = NA;
prs_thresh = NA;
obs_thresh = NA;

// Filtering options
// May be set separately in each "plot_point_obs" entry
// Point data pre-processing options
// May be set separately in each "point_data" entry

message_type = [];
sid_inc = [];
sid_exc = [];
obs_var = [];
obs_quality = [];
valid_beg = "";
valid_end = "";
lat_thresh = NA;
lon_thresh = NA;
elv_thresh = NA;
height_thresh = NA;
pressure_thresh = NA;
obs_thresh = NA;
convert(x) = x;
censor_thresh = [];
censor_val = [];

// Plotting options
// May be set separately in each "plot_point_obs" entry
// Point data plotting options
// May be set separately in each "point_data" entry

dotsize(x) = 10; // Function of the obs value
line_color = red;
line_width = 1;
fill_color = red;
fill_color_table = { // Takes precedence over fill_color
dotsize(x) = 10; // Function of the obs value
line_color = [ 255, 0, 0 ];
line_width = 1;
fill_color = [ 255, 0, 0 ];
fill_plot_info = { // Overrides fill_color
flag = FALSE;
color_table = "MET_BASE/colortables/met_default.ctable";
plot_min = 0.0;
Expand All @@ -59,14 +63,9 @@ fill_color_table = { // Takes precedence over fill_color
colorbar_spacing = 1;
}

// Array of dictionaries to define plotting options
plot_point_obs = [
{
fill_color = red;
convert(x) = x;
censor_thresh = [];
censor_val = [];
}
// Array of point data filtering, pre-processing, and plotting options
point_data = [
{ fill_color = [ 255, 0, 0 ]; }
];

////////////////////////////////////////////////////////////////////////////////
Expand Down
163 changes: 142 additions & 21 deletions met/src/tools/other/plot_point_obs/plot_point_obs_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@

using namespace std;

#include "plot_point_obs_conf_info.h"
#include "vx_log.h"
#include "vx_util.h"
#include "vx_config.h"
#include "vx_data2d.h"
#include "vx_data2d_factory.h"

#include "plot_point_obs_conf_info.h"

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

Expand Down Expand Up @@ -80,12 +85,11 @@ void PlotPointObsOpt::clear() {
line_color.clear();
line_width = 0.0;
fill_color.clear();
fill_ctable.clear();
fill_ctable_flag = false;
fill_colorbar_flag = false;
fill_plot_info.clear();

// Initialize point location data
n_obs = 0;
obs_value_flag = false;
locations.clear();

return;
Expand All @@ -95,7 +99,82 @@ void PlotPointObsOpt::clear() {

void PlotPointObsOpt::process_config(Dictionary &dict) {

// Conf: JHG work here
// Initialize
clear();

// Conf: message_type
msg_typ = parse_conf_message_type(&dict);

// Conf: sid_inc and sid_exc
sid_inc = parse_conf_sid_list(&dict, conf_key_sid_inc);
sid_exc = parse_conf_sid_list(&dict, conf_key_sid_exc);

// Conf: obs_var
obs_var = dict.lookup_string_array(conf_key_obs_var);

// Conf: obs_quality
obs_qty = dict.lookup_string_array(conf_key_obs_qty);

// Conf: valid_beg and valid_end
valid_beg = dict.lookup_unixtime(conf_key_valid_beg);
valid_end = dict.lookup_unixtime(conf_key_valid_end);

// Conf: lat_thresh and lon_thresh
lat_thresh = dict.lookup_thresh(conf_key_lat_thresh);
lon_thresh = dict.lookup_thresh(conf_key_lon_thresh);

// Conf: elv_thresh and hgt_thresh
elv_thresh = dict.lookup_thresh(conf_key_elv_thresh);
hgt_thresh = dict.lookup_thresh(conf_key_hgt_thresh);

// Conf: prs_thresh and obs_thresh
prs_thresh = dict.lookup_thresh(conf_key_prs_thresh);
obs_thresh = dict.lookup_thresh(conf_key_obs_thresh);

// Conf: convert function
convert_fx.set(dict.lookup(conf_key_convert));

// Conf: censor_thresh and censor_val
censor_thresh = dict.lookup_thresh_array(conf_key_censor_thresh, false);
censor_val = dict.lookup_num_array(conf_key_censor_val, false);

// Check for equal number of censor thresholds and values
if(censor_thresh.n() != censor_val.n()) {
mlog << Error << "\nPlotPointObsOpt::process_config() -> "
<< "The number of censor thresholds in \""
<< conf_key_censor_thresh << "\" (" << censor_thresh.n()
<< ") must match the number of replacement values in \""
<< conf_key_censor_val << "\" (" << censor_val.n() << ").\n\n";
exit(1);
}

// Conf: dotsize function
dotsize_fx.set(dict.lookup(conf_key_dotsize));

// Conf: line_color
line_color = dict.lookup_num_array(conf_key_line_color);

// Conf: line_width
line_width = dict.lookup_double(conf_key_line_width);

// Conf: fill_color
fill_color = dict.lookup_num_array(conf_key_fill_color);

// Check for correctly formatted colors
if(line_color.n() != 3 || fill_color.n() != 3) {
mlog << Error << "\nPlotPointObsOpt::process_config() -> "
<< "The \"" << conf_key_line_color << "\" and \"" << conf_key_fill_color
<< "\" entries must be specified as three RGB values.\n\n";
exit(1);
}

// Conf: fill_plot_info
fill_plot_info = parse_conf_plot_info(
dict.lookup_dictionary(conf_key_fill_plot_info));

// Set obs_value_flag if a fill color table is enabled
// or the dotsize function is not constant
obs_value_flag = (fill_plot_info.flag || dotsize_fx(1) != dotsize_fx(2));

return;
}
Expand Down Expand Up @@ -139,8 +218,8 @@ bool PlotPointObsOpt::add(const Observation &obs) {
loc.lat = obs.getLatitude();
loc.lon = obs.getLongitude();

// Only store the value if a colortable is defined
loc.val = (fill_ctable_flag ? obs.getValue() : bad_data_double);
// Only store the value if the flag is set
loc.val = (obs_value_flag ? obs.getValue() : bad_data_double);

// Update the set of locations
n_obs++;
Expand Down Expand Up @@ -172,7 +251,7 @@ PlotPointObsConfInfo::~PlotPointObsConfInfo() {
void PlotPointObsConfInfo::init_from_scratch() {

// Initialize pointers
data_plane_info = (VarInfo *) 0;
grid_data_info = (VarInfo *) 0;

clear();

Expand All @@ -184,12 +263,9 @@ void PlotPointObsConfInfo::init_from_scratch() {
void PlotPointObsConfInfo::clear() {

// Initialize values
data_plane_flag = false;
data_ctable.clear();
data_ctable_flag = false;
data_colorbar_flag = false;
conf.clear();
plot_opts.clear();
grid_data_flag = false;
grid_plot_info.clear();
point_opts.clear();

return;
}
Expand All @@ -211,28 +287,73 @@ void PlotPointObsConfInfo::read_config(const char *user_file_name) {

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

void PlotPointObsConfInfo::process_config() {
ConcatString s;
StringArray sa;
Dictionary *dict = (Dictionary *) 0;
void PlotPointObsConfInfo::process_config(GrdFileType ftype) {
VarInfoFactory info_factory;
Dictionary *dict = (Dictionary *) 0;
Dictionary *fdict = (Dictionary *) 0;
PlotPointObsOpt opt;
int i, n;

// Dump the contents of the config file
if(mlog.verbosity_level() >= 5) conf.dump(cout);

// Initialize
clear();

// Conf: JHG work here
// Conf: grid_data
dict = conf.lookup_dictionary(conf_key_grid_data);

// Conf: field
fdict = dict->lookup_array(conf_key_field);

// Check length
if((n = parse_conf_n_vx(fdict)) > 1) {
mlog << Error << "\nPlotPointObsConfInfo::process_config() -> "
<< "the \"" << conf_key_grid_data << "." << conf_key_field
<< "\" array can only have length 0 or 1.\n\n";
exit(1);
}

// Process gridded data
if(n > 0) {

grid_data_flag = true;

// Allocate new VarInfo object
grid_data_info = info_factory.new_var_info(ftype);
grid_data_info->set_dict(*(fdict));

// Conf: grid_plot_info
grid_plot_info = parse_conf_plot_info(
dict->lookup_dictionary(conf_key_grid_plot_info));
}

// Conf: point_data
dict = conf.lookup_array(conf_key_point_data);

// Check length
if((n = dict->n_entries()) == 0) {
mlog << Error << "\nPlotPointObsConfInfo::process_config() -> "
<< "the \"" << conf_key_point_data
<< "\" array is empty!\n\n";
exit(1);
}

// Parse each array entry
for(i=0; i<n; i++) {
opt.process_config(*((*dict)[i]->dict_value()));
point_opts.push_back(opt);
}

return;
}
////////////////////////////////////////////////////////////////////////

bool PlotPointObsConfInfo::add(const Observation &obs) {
bool match = false;

for(vector<PlotPointObsOpt>::iterator it = plot_opts.begin();
it != plot_opts.end(); it++) {
for(vector<PlotPointObsOpt>::iterator it = point_opts.begin();
it != point_opts.end(); it++) {
if((match = it->add(obs))) break;
}

Expand Down
29 changes: 13 additions & 16 deletions met/src/tools/other/plot_point_obs/plot_point_obs_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,13 @@ class PlotPointObsOpt {
NumArray line_color;
double line_width;
NumArray fill_color;
PlotInfo fill_ctable;
bool fill_ctable_flag;
bool fill_colorbar_flag;
PlotInfo fill_plot_info;

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

// Unique collection of locations
int n_obs;
bool obs_value_flag;
set<LocationInfo> locations;

//////////////////////////////////////////////////////////////////
Expand All @@ -122,31 +121,29 @@ class PlotPointObsConfInfo {

PlotPointObsConfInfo();
~PlotPointObsConfInfo();

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

// Options to plot a field of gridded data
bool data_plane_flag;
VarInfo *data_plane_info;
PlotInfo data_ctable;
bool data_ctable_flag;
bool data_colorbar_flag;


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

// PlotPointObs configuration object
MetConfig conf;

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

// Options to plot a field of gridded data
bool grid_data_flag;
VarInfo *grid_data_info;
PlotInfo grid_plot_info;

// Array of plotting options
vector<PlotPointObsOpt> plot_opts;
// Options for plotting point data
vector<PlotPointObsOpt> point_opts;

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

void clear();

void read_config(const char *);

void process_config();
void process_config(GrdFileType);

bool add(const Observation &);
};
Expand Down

0 comments on commit 5580650

Please sign in to comment.