Skip to content

Commit

Permalink
Per #2893, add obtype_as_obs_message_type_flag option for Point-Stat …
Browse files Browse the repository at this point in the history
…and Ensemble-Stat that applies when writing MPR, SEEPS_MPR, and ORANK line types. If true, write the input observation message type to the OBTYPE output column rather than the name of the group.
  • Loading branch information
JohnHalleyGotway committed Oct 15, 2024
1 parent c5cd28d commit 399e609
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 34 deletions.
1 change: 1 addition & 0 deletions src/basic/vx_config/config_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,7 @@ static const char conf_key_model[] = "model";
static const char conf_key_desc[] = "desc";
static const char conf_key_obtype[] = "obtype";
static const char conf_key_output_flag[] = "output_flag";
static const char conf_key_obtype_as_obs_message_type_flag[] = "obtype_as_obs_message_type_flag";
static const char conf_key_obs_window[] = "obs_window";
static const char conf_key_beg[] = "beg";
static const char conf_key_end[] = "end";
Expand Down
14 changes: 13 additions & 1 deletion src/libcode/vx_stat_out/stat_columns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,7 @@ void write_mpr_row(StatHdrColumns &shc, const PairDataPoint *pd_ptr,
STATOutputType out_type,
AsciiTable &stat_at, int &stat_row,
AsciiTable &txt_at, int &txt_row,
bool update_obtype,
bool update_thresh) {

// MPR line type
Expand All @@ -1567,6 +1568,9 @@ void write_mpr_row(StatHdrColumns &shc, const PairDataPoint *pd_ptr,
// Write a line for each matched pair
for(int i=0; i<pd_ptr->n_obs; i++) {

// MET #2893 write individual obs message type
if(update_obtype) shc.set_obtype(pd_ptr->typ_sa[i].c_str());

// Set the observation valid time
shc.set_obs_valid_beg(pd_ptr->vld_ta[i]);
shc.set_obs_valid_end(pd_ptr->vld_ta[i]);
Expand Down Expand Up @@ -1645,6 +1649,7 @@ void write_seeps_mpr_row(StatHdrColumns &shc, const PairDataPoint *pd_ptr,
STATOutputType out_type,
AsciiTable &stat_at, int &stat_row,
AsciiTable &txt_at, int &txt_row,
bool update_obtype,
bool update_thresh) {

// SEEPS line type
Expand All @@ -1668,6 +1673,9 @@ void write_seeps_mpr_row(StatHdrColumns &shc, const PairDataPoint *pd_ptr,
if(!pd_ptr->seeps_mpr[i] ||
is_bad_data(pd_ptr->seeps_mpr[i]->score)) continue;

// MET #2893 write individual obs message type
if(update_obtype) shc.set_obtype(pd_ptr->typ_sa[i].c_str());

// Set the observation valid time
shc.set_obs_valid_beg(pd_ptr->vld_ta[i]);
shc.set_obs_valid_end(pd_ptr->vld_ta[i]);
Expand Down Expand Up @@ -1899,7 +1907,8 @@ void write_phist_row(StatHdrColumns &shc, const PairDataEnsemble *pd_ptr,
void write_orank_row(StatHdrColumns &shc, const PairDataEnsemble *pd_ptr,
STATOutputType out_type,
AsciiTable &stat_at, int &stat_row,
AsciiTable &txt_at, int &txt_row) {
AsciiTable &txt_at, int &txt_row,
bool update_obtype) {

// Observation Rank line type
shc.set_line_type(stat_orank_str);
Expand All @@ -1913,6 +1922,9 @@ void write_orank_row(StatHdrColumns &shc, const PairDataEnsemble *pd_ptr,
// Write a line for each ensemble pair
for(int i=0; i<pd_ptr->n_obs; i++) {

// MET #2893 write individual obs message type
if(update_obtype) shc.set_obtype(pd_ptr->typ_sa[i].c_str());

// Set the observation valid time
shc.set_obs_valid_beg(pd_ptr->vld_ta[i]);
shc.set_obs_valid_end(pd_ptr->vld_ta[i]);
Expand Down
9 changes: 5 additions & 4 deletions src/libcode/vx_stat_out/stat_columns.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ extern void write_dmap_row (StatHdrColumns &, const DMAPInfo &, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &);
extern void write_mpr_row (StatHdrColumns &, const PairDataPoint *, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &,
bool update_thresh = true);
bool update_obtype, bool update_thresh = true);
extern void write_seeps_row (StatHdrColumns &, const SeepsAggScore *, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &,
bool update_thresh = true);
bool update_obtype, bool update_thresh = true);
extern void write_seeps_mpr_row (StatHdrColumns &, const PairDataPoint *, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &,
bool update_thresh = true);
bool update_obtype, bool update_thresh = true);
extern void write_isc_row (StatHdrColumns &, const ISCInfo &, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &);
extern void write_ecnt_row (StatHdrColumns &, const ECNTInfo &, STATOutputType,
Expand All @@ -124,7 +124,8 @@ extern void write_rhist_row (StatHdrColumns &, const PairDataEnsemble *, STATOut
extern void write_phist_row (StatHdrColumns &, const PairDataEnsemble *, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &);
extern void write_orank_row (StatHdrColumns &, const PairDataEnsemble *, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &);
AsciiTable &, int &, AsciiTable &, int &,
bool update_obtype = false);
extern void write_ssvar_row (StatHdrColumns &, const PairDataEnsemble *, double, STATOutputType,
AsciiTable &, int &, AsciiTable &, int &);
extern void write_relp_row (StatHdrColumns &, const PairDataEnsemble *, STATOutputType,
Expand Down
10 changes: 8 additions & 2 deletions src/libcode/vx_statistics/pair_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void PairBase::clear() {
ocsd_na.clear();
ocdf_na.clear();

typ_sa.clear();
sid_sa.clear();
lat_na.clear();
lon_na.clear();
Expand Down Expand Up @@ -155,6 +156,7 @@ void PairBase::erase() {
ocsd_na.erase();
ocdf_na.erase();

typ_sa.clear(); // no erase option
sid_sa.clear(); // no erase option
lat_na.erase();
lon_na.erase();
Expand Down Expand Up @@ -427,7 +429,7 @@ void PairBase::compute_climo_cdf() {

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

bool PairBase::add_point_obs(const char *sid,
bool PairBase::add_point_obs(const char *typ, const char *sid,
double lat, double lon, double x, double y,
unixtime ut, double lvl, double elv,
double o, const char *qc,
Expand Down Expand Up @@ -476,6 +478,7 @@ bool PairBase::add_point_obs(const char *sid,
}
else {
station_values_t val;
val.typ = string(typ);
val.sid = string(sid);
val.lat = lat;
val.lon = lon;
Expand All @@ -497,6 +500,7 @@ bool PairBase::add_point_obs(const char *sid,
}

if(obs_summary == ObsSummary::None) {
typ_sa.add(typ);
sid_sa.add(sid);
lat_na.add(lat);
lon_na.add(lon);
Expand All @@ -520,7 +524,7 @@ bool PairBase::add_point_obs(const char *sid,

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

void PairBase::set_point_obs(int i_obs, const char *sid,
void PairBase::set_point_obs(int i_obs, const char *typ, const char *sid,
double lat, double lon, double x, double y,
unixtime ut, double lvl, double elv,
double o, const char *qc,
Expand All @@ -534,6 +538,7 @@ void PairBase::set_point_obs(int i_obs, const char *sid,
exit(1);
}

typ_sa.set(i_obs, typ);
sid_sa.set(i_obs, sid);
lat_na.set(i_obs, lat);
lon_na.set(i_obs, lon);
Expand Down Expand Up @@ -751,6 +756,7 @@ void PairBase::calc_obs_summary(){
// Store summarized value in the map
svt.summary_val = ob.val;

typ_sa.add (svt.typ.c_str());
sid_sa.add (svt.sid.c_str());
lat_na.add (svt.lat);
lon_na.add (svt.lon);
Expand Down
8 changes: 6 additions & 2 deletions src/libcode/vx_statistics/pair_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ struct station_values_t {

void clear();

std::string typ;
std::string sid;
double lat;
double lon;
Expand Down Expand Up @@ -110,6 +111,7 @@ class PairBase {
NumArray ocdf_na; // Observation climatology cumulative distribution function [n_obs]

// Point Observation Information
StringArray typ_sa; // Message type [n_obs]
StringArray sid_sa; // Station ID [n_obs]
NumArray lat_na; // Latitude [n_obs]
NumArray lon_na; // Longitude [n_obs]
Expand Down Expand Up @@ -168,11 +170,13 @@ class PairBase {
ob_val_t compute_median(std::string sng_key);
ob_val_t compute_percentile(std::string sng_key, int perc);

bool add_point_obs(const char *, double, double, double, double,
bool add_point_obs(const char *, const char *,
double, double, double, double,
unixtime, double, double, double, const char *,
const ClimoPntInfo &, double);

void set_point_obs(int, const char *, double, double, double, double,
void set_point_obs(int, const char *, const char *,
double, double, double, double,
unixtime, double, double, double,
const char *, const ClimoPntInfo &, double);

Expand Down
5 changes: 3 additions & 2 deletions src/libcode/vx_statistics/pair_data_ensemble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1311,8 +1311,9 @@ void VxPairDataEnsemble::add_point_obs(float *hdr_arr, int *hdr_typ_arr,
// Add the observation value
// Weight is from the nearest grid point
int n = three_to_one(i_msg_typ, i_mask, i_interp);
if(!pd[n].add_point_obs(hdr_sid_str, hdr_lat, hdr_lon,
obs_x, obs_y, hdr_ut, obs_lvl, obs_hgt,
if(!pd[n].add_point_obs(hdr_typ_str, hdr_sid_str,
hdr_lat, hdr_lon, obs_x, obs_y,
hdr_ut, obs_lvl, obs_hgt,
obs_v, obs_qty, cpi, wgt_v)) {

if(mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) {
Expand Down
27 changes: 15 additions & 12 deletions src/libcode/vx_statistics/pair_data_point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ void PairDataPoint::assign(const PairDataPoint &pd) {
ClimoPntInfo cpi(pd.fcmn_na[i], pd.fcsd_na[i],
pd.ocmn_na[i], pd.ocsd_na[i]);

if(add_point_pair(pd.sid_sa[i].c_str(), pd.lat_na[i], pd.lon_na[i],
if(add_point_pair(pd.typ_sa[i].c_str(), pd.sid_sa[i].c_str(),
pd.lat_na[i], pd.lon_na[i],
pd.x_na[i], pd.y_na[i], pd.vld_ta[i],
pd.lvl_na[i], pd.elv_na[i],
pd.f_na[i], pd.o_na[i], pd.o_qc_sa[i].c_str(),
Expand All @@ -176,13 +177,14 @@ void PairDataPoint::assign(const PairDataPoint &pd) {

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

bool PairDataPoint::add_point_pair(const char *sid, double lat, double lon,
bool PairDataPoint::add_point_pair(const char *typ, const char *sid,
double lat, double lon,
double x, double y, unixtime ut,
double lvl, double elv,
double f, double o, const char *qc,
const ClimoPntInfo &cpi, double wgt) {

if(!add_point_obs(sid, lat, lon, x, y, ut, lvl, elv, o, qc,
if(!add_point_obs(typ, sid, lat, lon, x, y, ut, lvl, elv, o, qc,
cpi, wgt)) return false;

f_na.add(f);
Expand Down Expand Up @@ -233,7 +235,8 @@ void PairDataPoint::set_seeps_score(SeepsScore *seeps, int index) {

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

void PairDataPoint::set_point_pair(int i_obs, const char *sid,
void PairDataPoint::set_point_pair(int i_obs,
const char *typ, const char *sid,
double lat, double lon,
double x, double y, unixtime ut,
double lvl, double elv,
Expand All @@ -248,7 +251,7 @@ void PairDataPoint::set_point_pair(int i_obs, const char *sid,
exit(1);
}

set_point_obs(i_obs, sid, lat, lon, x, y, ut, lvl, elv,
set_point_obs(i_obs, typ, sid, lat, lon, x, y, ut, lvl, elv,
o, qc, cpi, wgt);

f_na.set(i_obs, f);
Expand Down Expand Up @@ -380,8 +383,8 @@ PairDataPoint PairDataPoint::subset_pairs_cnt_thresh(

// Handle point data
if(is_point_vx()) {
if(out_pd.add_point_pair(sid_sa[i].c_str(), lat_na[i],
lon_na[i], x_na[i], y_na[i],
if(out_pd.add_point_pair(typ_sa[i].c_str(), sid_sa[i].c_str(),
lat_na[i], lon_na[i], x_na[i], y_na[i],
vld_ta[i], lvl_na[i], elv_na[i],
f_na[i], o_na[i], o_qc_sa[i].c_str(),
cpi, wgt_na[i])) {
Expand Down Expand Up @@ -631,7 +634,7 @@ void VxPairDataPoint::add_point_obs(float *hdr_arr, const char *hdr_typ_str,
// Add the forecast, climatological, and observation data
// Weight is from the nearest grid point
int n = three_to_one(i_msg_typ, i_mask, i_interp);
if(!pd[n].add_point_pair(hdr_sid_str,
if(!pd[n].add_point_pair(hdr_typ_str, hdr_sid_str,
hdr_lat, hdr_lon, obs_x, obs_y, hdr_ut, obs_lvl,
obs_hgt, fcst_v, obs_v, obs_qty, cpi, wgt_v)) {

Expand Down Expand Up @@ -996,14 +999,14 @@ void subset_wind_pairs(const PairDataPoint &pd_u, const PairDataPoint &pd_v,
// Handle point data
if(pd_u.is_point_vx()) {

out_pd_u.add_point_pair(pd_u.sid_sa[i].c_str(),
out_pd_u.add_point_pair(pd_u.typ_sa[i].c_str(), pd_u.sid_sa[i].c_str(),
pd_u.lat_na[i], pd_u.lon_na[i],
pd_u.x_na[i], pd_u.y_na[i], pd_u.vld_ta[i],
pd_u.lvl_na[i], pd_u.elv_na[i],
pd_u.f_na[i], pd_u.o_na[i],
pd_u.o_qc_sa[i].c_str(),
u_cpi, pd_u.wgt_na[i]);
out_pd_v.add_point_pair(pd_v.sid_sa[i].c_str(),
out_pd_v.add_point_pair(pd_v.typ_sa[i].c_str(), pd_v.sid_sa[i].c_str(),
pd_v.lat_na[i], pd_v.lon_na[i],
pd_v.x_na[i], pd_v.y_na[i], pd_v.vld_ta[i],
pd_v.lvl_na[i], pd_v.elv_na[i],
Expand Down Expand Up @@ -1074,8 +1077,8 @@ PairDataPoint subset_climo_cdf_bin(const PairDataPoint &pd,

// Handle point data
if(pd.is_point_vx()) {
out_pd.add_point_pair(pd.sid_sa[i].c_str(), pd.lat_na[i],
pd.lon_na[i], pd.x_na[i], pd.y_na[i],
out_pd.add_point_pair(pd.typ_sa[i].c_str(), pd.sid_sa[i].c_str(),
pd.lat_na[i], pd.lon_na[i], pd.x_na[i], pd.y_na[i],
pd.vld_ta[i], pd.lvl_na[i], pd.elv_na[i],
pd.f_na[i], pd.o_na[i], pd.o_qc_sa[i].c_str(),
cpi, pd.wgt_na[i]);
Expand Down
6 changes: 4 additions & 2 deletions src/libcode/vx_statistics/pair_data_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,16 @@ class PairDataPoint : public PairBase {

void extend(int);

bool add_point_pair(const char *, double, double, double, double,
bool add_point_pair(const char *, const char *,
double, double, double, double,
unixtime, double, double, double, double,
const char *, const ClimoPntInfo &, double);
void load_seeps_climo(const ConcatString &seeps_climo_name);
void set_seeps_thresh(const SingleThresh &p1_thresh);
void set_seeps_score(SeepsScore *, int index=-1);

void set_point_pair(int, const char *, double, double, double, double,
void set_point_pair(int, const char *, const char *,
double, double, double, double,
unixtime, double, double, double, double,
const char *, const ClimoPntInfo &,
double, const SeepsScore *);
Expand Down
9 changes: 8 additions & 1 deletion src/tools/core/ensemble_stat/ensemble_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2236,10 +2236,17 @@ void write_txt_files(const EnsembleStatVxOpt &vx_opt,
// Set the header column
shc.set_obs_thresh(na_str);

// Store current obtype value
string cur_obtype = shc.get_obtype();

write_orank_row(shc, &pd_all,
vx_opt.output_flag[i_orank],
stat_at, i_stat_row,
txt_at[i_orank], i_txt_row[i_orank]);
txt_at[i_orank], i_txt_row[i_orank],
conf_info.obtype_as_obs_message_type_flag);

// Reset the obtype column
shc.set_obtype(cur_obtype.c_str());

// Reset the observation valid time
shc.set_obs_valid_beg(vx_opt.vx_pd.beg_ut);
Expand Down
5 changes: 5 additions & 0 deletions src/tools/core/ensemble_stat/ensemble_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ void EnsembleStatConfInfo::clear() {
vld_ens_thresh = bad_data_double;
vld_data_thresh = bad_data_double;
msg_typ_group_map.clear();
obtype_as_obs_message_type = false;
msg_typ_sfc.clear();
mask_area_map.clear();
mask_sid_map.clear();
Expand Down Expand Up @@ -173,6 +174,10 @@ void EnsembleStatConfInfo::process_config(GrdFileType etype,
msg_typ_sfc.parse_css(default_msg_typ_group_surface);
}

// Conf: obtype_as_obs_message_type_flag
obtype_as_obs_message_type_flag =
conf.lookup_bool(conf_key_obtype_as_obs_message_type_flag);

// Conf: ens_member_ids
ens_member_ids = parse_conf_ens_member_ids(&conf);

Expand Down
1 change: 1 addition & 0 deletions src/tools/core/ensemble_stat/ensemble_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ class EnsembleStatConfInfo {
// Message type groups that should be processed together
std::map<ConcatString,StringArray> msg_typ_group_map;
StringArray msg_typ_sfc;
bool obtype_as_obs_message_type;

// Mapping of mask names to MaskPlanes
std::map<ConcatString,MaskPlane> mask_area_map;
Expand Down
Loading

0 comments on commit 399e609

Please sign in to comment.