Skip to content

Commit

Permalink
Per #2279, add point_weight_flag to the Point-Stat and Ensemble-Stat …
Browse files Browse the repository at this point in the history
…config class. Also remove sue unneeded wgt_dp argument for the add_point_obs() functions. Plan to add logic to set the point weights only AFTER all the observations have been collected for each verification task.
  • Loading branch information
JohnHalleyGotway committed Oct 10, 2024
1 parent f5f4d99 commit d520fef
Show file tree
Hide file tree
Showing 16 changed files with 51 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/basic/vx_util/util_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ static const int tmp_buf_size = 512;
static const double grib_earth_radius_km = 6371.20;
static const int default_nc_compression = 0;
static const int default_precision = 5;
static const double default_grid_weight = 1.0;
static const double default_weight = 1.0;
static const char default_tmp_dir[] = "/tmp";

////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_statistics/apply_mask.cc
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void parse_grid_weight(const Grid &grid, const GridWeightType t,
w = grid.calc_area(x, y);
}
else {
w = default_grid_weight;
w = default_weight;
}

// Store the current weight
Expand Down
10 changes: 6 additions & 4 deletions src/libcode/vx_statistics/pair_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,14 @@ class PairBase {
const ClimoPntInfo &, double);

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

void add_grid_obs(double, const ClimoPntInfo &, double);
void add_grid_obs(double,
const ClimoPntInfo &, double);

void add_grid_obs(double, double, double, const ClimoPntInfo &, double);
void add_grid_obs(double, double, double,
const ClimoPntInfo &, double);

void add_climo(double, const ClimoPntInfo &);

Expand Down
10 changes: 2 additions & 8 deletions src/libcode/vx_statistics/pair_data_ensemble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1170,8 +1170,7 @@ void VxPairDataEnsemble::add_point_obs(float *hdr_arr, int *hdr_typ_arr,
const char *hdr_sid_str,
unixtime hdr_ut,
const char *obs_qty, float *obs_arr,
Grid &gr, const char *var_name,
const DataPlane *wgt_dp) {
Grid &gr, const char *var_name) {

// Check the observation VarInfo file type
if(obs_info->file_type() != FileType_Gb1) {
Expand Down Expand Up @@ -1303,17 +1302,12 @@ void VxPairDataEnsemble::add_point_obs(float *hdr_arr, int *hdr_typ_arr,
gr, obs_x, obs_y, obs_v, obs_lvl, obs_hgt,
cpi)) continue;

// Compute weight for current point
double wgt_v = (wgt_dp == nullptr ?
default_grid_weight :
wgt_dp->get(x, y));

// 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,
obs_v, obs_qty, cpi, wgt_v)) {
obs_v, obs_qty, cpi, default_weight)) {

if(mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) {
mlog << Debug(REJECT_DEBUG_LEVEL)
Expand Down
2 changes: 1 addition & 1 deletion src/libcode/vx_statistics/pair_data_ensemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class VxPairDataEnsemble : public VxPairBase {

void add_point_obs(float *, int *, const char *, const char *,
unixtime, const char *, float *, Grid &,
const char * = 0, const DataPlane * = 0);
const char *);
void add_ens(int, bool mn, Grid &);
};

Expand Down
18 changes: 4 additions & 14 deletions src/libcode/vx_statistics/pair_data_point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -503,8 +503,7 @@ void VxPairDataPoint::set_size(int types, int masks, int interps) {
void VxPairDataPoint::add_point_obs(float *hdr_arr, const char *hdr_typ_str,
const char *hdr_sid_str, unixtime hdr_ut,
const char *obs_qty, float *obs_arr,
Grid &gr, const char *var_name,
const DataPlane *wgt_dp) {
Grid &gr, const char *var_name) {

// Increment the number of tries count
n_try++;
Expand Down Expand Up @@ -553,11 +552,7 @@ void VxPairDataPoint::add_point_obs(float *hdr_arr, const char *hdr_typ_str,
obs_info->is_specific_humidity();
bool precip_flag = fcst_info->is_precipitation() &&
obs_info->is_precipitation();
int precip_interval = bad_data_int;
if(precip_flag) {
if(wgt_dp) precip_interval = wgt_dp->accum();
else precip_interval = fcst_dpa[0].accum();
}
int precip_interval = fcst_dpa[0].accum();

bool has_seeps = false;
SeepsScore *seeps = nullptr;
Expand Down Expand Up @@ -623,17 +618,12 @@ void VxPairDataPoint::add_point_obs(float *hdr_arr, const char *hdr_typ_str,
continue;
}

// Compute weight for current point
double wgt_v = (wgt_dp == nullptr ?
default_grid_weight :
wgt_dp->get(x, y));

// 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,
hdr_lat, hdr_lon, obs_x, obs_y, hdr_ut, obs_lvl,
obs_hgt, fcst_v, obs_v, obs_qty, cpi, wgt_v)) {
obs_hgt, fcst_v, obs_v, obs_qty, cpi, default_weight)) {

if(mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) {
mlog << Debug(REJECT_DEBUG_LEVEL)
Expand Down Expand Up @@ -954,7 +944,7 @@ void subset_wind_pairs(const PairDataPoint &pd_u, const PairDataPoint &pd_v,
// Loop over the pairs
for(i=0; i<pd_u.n_obs; i++) {

wgt = (wgt_flag ? pd_u.wgt_na[i] : default_grid_weight);
wgt = (wgt_flag ? pd_u.wgt_na[i] : default_weight);

// Compute wind speeds
fcst_wind = convert_u_v_to_wind(pd_u.f_na[i], pd_v.f_na[i]);
Expand Down
16 changes: 8 additions & 8 deletions src/libcode/vx_statistics/pair_data_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,19 @@ class PairDataPoint : public PairBase {
void extend(int);

bool add_point_pair(const char *, double, double, double, double,
unixtime, double, double, double, double,
const char *, const ClimoPntInfo &, 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,
unixtime, double, double, double, double,
const char *, const ClimoPntInfo &,
double, const SeepsScore *);
unixtime, double, double, double, double, const char *,
const ClimoPntInfo &, double,
const SeepsScore *);

bool add_grid_pair(double, double, const ClimoPntInfo &, double);
bool add_grid_pair(double, double,
const ClimoPntInfo &, double);

bool add_grid_pair(const NumArray &f_in, const NumArray &o_in,
const NumArray &fcmn_in, const NumArray &fcsd_in,
Expand Down Expand Up @@ -121,8 +122,7 @@ class VxPairDataPoint : public VxPairBase {
void set_seeps_thresh(const SingleThresh &p1_thresh);

void add_point_obs(float *, const char *, const char *, unixtime,
const char *, float *, Grid &, const char * = 0,
const DataPlane * = 0);
const char *, float *, Grid &, const char *);
};


Expand Down
5 changes: 4 additions & 1 deletion src/tools/core/ensemble_stat/ensemble_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void EnsembleStatConfInfo::clear() {
mask_area_map.clear();
mask_sid_map.clear();
grid_weight_flag = GridWeightType::None;
tmp_dir.clear();
point_weight_flag = PointWeightType::None;
output_prefix.clear();
version.clear();

Expand Down Expand Up @@ -158,6 +158,9 @@ void EnsembleStatConfInfo::process_config(GrdFileType etype,
// Conf: grid_weight_flag
grid_weight_flag = parse_conf_grid_weight_flag(&conf);

// Conf: point_weight_flag
point_weight_flag = parse_conf_point_weight_flag(&conf);

// Conf: output_prefix
output_prefix = conf.lookup_string(conf_key_output_prefix);

Expand Down
5 changes: 3 additions & 2 deletions src/tools/core/ensemble_stat/ensemble_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ class EnsembleStatConfInfo {

gsl_rng *rng_ptr; // GSL random number generator (allocated)

GridWeightType grid_weight_flag; // Grid weighting flag
ConcatString tmp_dir; // Directory for temporary files
GridWeightType grid_weight_flag; // Grid weighting flag
PointWeightType point_weight_flag; // Point weighting flag

ConcatString output_prefix; // String to customize output file name
ConcatString version; // Config file version

Expand Down
2 changes: 1 addition & 1 deletion src/tools/core/grid_stat/grid_stat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2088,7 +2088,7 @@ void get_mask_points(const GridStatVxOpt &vx_opt,
if(ocsd_ptr) apply_mask(*ocsd_ptr, mask_mp, pd.ocsd_na);
else pd.ocsd_na.add_const(bad_data_double, pd.n_obs);
if(wgt_ptr) apply_mask(*wgt_ptr, mask_mp, pd.wgt_na);
else pd.wgt_na.add_const(default_grid_weight, pd.n_obs);
else pd.wgt_na.add_const(default_weight, pd.n_obs);

if(ocmn_ptr && ocsd_ptr) pd.compute_climo_cdf();

Expand Down
4 changes: 4 additions & 0 deletions src/tools/core/point_stat/point_stat_conf_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void PointStatConfInfo::clear() {
msg_typ_group_map.clear();
mask_area_map.clear();
mask_sid_map.clear();
point_weight_flag = PointWeightType::None;
tmp_dir.clear();
output_prefix.clear();
version.clear();
Expand Down Expand Up @@ -151,6 +152,9 @@ void PointStatConfInfo::process_config(GrdFileType ftype) {
// Conf: model
model = parse_conf_string(&conf, conf_key_model);

// Conf: point_weight_flag
point_weight_flag = parse_conf_point_weight_flag(&conf);

// Conf: tmp_dir
tmp_dir = parse_conf_tmp_dir(&conf);

Expand Down
2 changes: 2 additions & 0 deletions src/tools/core/point_stat/point_stat_conf_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ class PointStatConfInfo {
// Mapping of mask names to Station ID lists
std::map<ConcatString,MaskSID> mask_sid_map;

PointWeightType point_weight_flag; // Point weighting flag

ConcatString tmp_dir; // Directory for temporary files
ConcatString output_prefix; // String to customize output file name
ConcatString version; // Config file version
Expand Down
2 changes: 1 addition & 1 deletion src/tools/core/series_analysis/series_analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ void process_scores() {
(ocsd_flag ? ocsd_dp(x, y) : bad_data_double));

pd_block[i].add_grid_pair(fcst_dp(x, y), obs_dp(x, y),
cpi, default_grid_weight);
cpi, default_weight);

} // end for i
} // end for i_series
Expand Down
22 changes: 11 additions & 11 deletions src/tools/core/stat_analysis/aggr_stat_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1727,8 +1727,8 @@ void aggr_wind_lines(LineDataFile &f, STATAnalysisJob &job,
// Append the unit vectors with no climatological values
//
ClimoPntInfo cpi;
m[key].pd_u.add_grid_pair(uf, uo, cpi, default_grid_weight);
m[key].pd_v.add_grid_pair(vf, vo, cpi, default_grid_weight);
m[key].pd_u.add_grid_pair(uf, uo, cpi, default_weight);
m[key].pd_v.add_grid_pair(vf, vo, cpi, default_weight);

//
// Keep track of the unique header column entries
Expand Down Expand Up @@ -1843,8 +1843,8 @@ void aggr_mpr_wind_lines(LineDataFile &f, STATAnalysisJob &job,
aggr.hdr_sa.add(hdr);
ClimoPntInfo u_cpi(ufcmn, ufcsd, uocmn, uocsd);
ClimoPntInfo v_cpi(vfcmn, vfcsd, vocmn, vocsd);
aggr.pd_u.add_grid_pair(uf, uo, u_cpi, default_grid_weight);
aggr.pd_v.add_grid_pair(vf, vo, v_cpi, default_grid_weight);
aggr.pd_u.add_grid_pair(uf, uo, u_cpi, default_weight);
aggr.pd_v.add_grid_pair(vf, vo, v_cpi, default_weight);

//
// Add the new map entry
Expand Down Expand Up @@ -1908,8 +1908,8 @@ void aggr_mpr_wind_lines(LineDataFile &f, STATAnalysisJob &job,
m[key].hdr_sa.add(hdr);
ClimoPntInfo u_cpi(ufcmn, ufcsd, uocmn, uocsd);
ClimoPntInfo v_cpi(vfcmn, vfcsd, vocmn, vocsd);
m[key].pd_u.add_grid_pair(uf, uo, u_cpi, default_grid_weight);
m[key].pd_v.add_grid_pair(vf, vo, v_cpi, default_grid_weight);
m[key].pd_u.add_grid_pair(uf, uo, u_cpi, default_weight);
m[key].pd_v.add_grid_pair(vf, vo, v_cpi, default_weight);
}
}

Expand Down Expand Up @@ -2054,8 +2054,8 @@ void aggr_mpr_wind_lines(LineDataFile &f, STATAnalysisJob &job,
it->second.pd_v.f_na[i], uf, vf);
convert_u_v_to_unit(it->second.pd_u.o_na[i],
it->second.pd_v.o_na[i], uo, vo);
aggr.pd_u.add_grid_pair(uf, uo, cpi, default_grid_weight);
aggr.pd_v.add_grid_pair(vf, vo, cpi, default_grid_weight);
aggr.pd_u.add_grid_pair(uf, uo, cpi, default_weight);
aggr.pd_v.add_grid_pair(vf, vo, cpi, default_weight);
}

//
Expand Down Expand Up @@ -2137,7 +2137,7 @@ void aggr_mpr_lines(LineDataFile &f, STATAnalysisJob &job,
aggr.pd.ocmn_na.add(cur.obs_climo_mean);
aggr.pd.ocsd_na.add(cur.obs_climo_stdev);
aggr.pd.ocdf_na.add(cur.obs_climo_cdf);
aggr.pd.wgt_na.add(default_grid_weight);
aggr.pd.wgt_na.add(default_weight);

aggr.fcst_var = cur.fcst_var;
aggr.obs_var = cur.obs_var;
Expand Down Expand Up @@ -2168,7 +2168,7 @@ void aggr_mpr_lines(LineDataFile &f, STATAnalysisJob &job,
m[key].pd.ocmn_na.add(cur.obs_climo_mean);
m[key].pd.ocsd_na.add(cur.obs_climo_stdev);
m[key].pd.ocdf_na.add(cur.obs_climo_cdf);
m[key].pd.wgt_na.add(default_grid_weight);
m[key].pd.wgt_na.add(default_weight);

//
// Only aggregate consistent variable names
Expand Down Expand Up @@ -3065,7 +3065,7 @@ void aggr_orank_lines(LineDataFile &f, STATAnalysisJob &job,
//
ClimoPntInfo cpi(cur.fcst_climo_mean, cur.fcst_climo_stdev,
cur.obs_climo_mean, cur.obs_climo_stdev);
m[key].ens_pd.add_grid_obs(cur.obs, cpi, default_grid_weight);
m[key].ens_pd.add_grid_obs(cur.obs, cpi, default_weight);
m[key].ens_pd.skip_ba.add(false);
m[key].ens_pd.n_pair++;
m[key].ens_pd.r_na.add(cur.rank);
Expand Down
1 change: 0 additions & 1 deletion src/tools/core/stat_analysis/parse_stat_line.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void parse_fho_ctable(STATLine &l, TTContingencyTable &ct) {
double h_rate = atof(l.get_item("H_RATE"));
double o_rate = atof(l.get_item("O_RATE"));

// MET #2887: JHG multiple by the sum of the weights here instead?
double fy = n_pairs * f_rate;
double fy_oy = n_pairs * h_rate;
double oy = n_pairs * o_rate;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/other/gsi_tools/gsidens2orank.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ void process_conv_data(ConvData &d, int i_mem) {
bad_data_double, bad_data_double);
ens_pd.add_point_obs(d.sid.c_str(), d.lat, d.lon,
bad_data_double, bad_data_double, d.obs_ut, d.prs,
d.elv, d.obs, na_str, cpi, default_grid_weight);
d.elv, d.obs, na_str, cpi, default_weight);

// Initialize ensemble members and mean to bad data
for(i=0; i<n_ens; i++) ens_pd.add_ens(i, bad_data_double);
Expand Down Expand Up @@ -432,7 +432,7 @@ void process_rad_data(RadData &d, int i_mem) {
ens_pd.add_point_obs(na_str, d.lat, d.lon,
bad_data_double, bad_data_double, d.obs_ut,
bad_data_double, d.elv, d.obs, na_str,
cpi, default_grid_weight);
cpi, default_weight);

// Initialize ensemble members and mean to bad data
for(i=0; i<n_ens; i++) ens_pd.add_ens(i, bad_data_double);
Expand Down

0 comments on commit d520fef

Please sign in to comment.