Skip to content

Commit

Permalink
Per #2924, move fcst_info/obs_info into the VxPairBase pointer.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway committed Jul 16, 2024
1 parent d2f6800 commit f1f27b1
Show file tree
Hide file tree
Showing 9 changed files with 162 additions and 186 deletions.
2 changes: 1 addition & 1 deletion src/libcode/vx_data2d/var_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ class EnsVarInfo {

private:
std::vector<InputInfo> inputs; // Vector of InputInfo
VarInfo * ctrl_info; // Field info for control member
VarInfo * ctrl_info; // Field info for control member

public:
EnsVarInfo();
Expand Down
160 changes: 90 additions & 70 deletions src/libcode/vx_statistics/pair_base.cc

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/libcode/vx_statistics/pair_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ class VxPairBase {
//
//////////////////////////////////////////////////////////////////

VarInfo *finfo_ptr; // Not Allocated
VarInfoGrib *oinfo_ptr; // Not Allocated
VarInfo *fcst_info; // Forecast field, allocated by VarInfoFactory
VarInfo *obs_info; // Observation field, allocated by VarInfoFactory

VarInfo *fclm_info; // Forecast climatology field, allocated by VarInfoFactory
VarInfo *oclm_info; // Observation climatology field, allocated by VarInfoFactory
Expand Down Expand Up @@ -315,6 +315,9 @@ class VxPairBase {

int three_to_one(int, int, int);

void set_fcst_info(VarInfo *);
void set_obs_info(VarInfo *);

void set_fcst_climo_info(VarInfo *);
void set_obs_climo_info(VarInfo *);

Expand Down
42 changes: 18 additions & 24 deletions src/libcode/vx_statistics/pair_data_ensemble.cc
Original file line number Diff line number Diff line change
Expand Up @@ -993,8 +993,8 @@ void VxPairDataEnsemble::init_from_scratch() {

VxPairBase::init_from_scratch();

fcst_info = (EnsVarInfo *) nullptr;
obs_info = (VarInfo *) nullptr;
ens_info = (EnsVarInfo *) nullptr;
obs_info = (VarInfo *) nullptr;

clear();

Expand All @@ -1007,8 +1007,8 @@ void VxPairDataEnsemble::clear() {

VxPairBase::clear();

if(fcst_info) { delete fcst_info; fcst_info = (EnsVarInfo *) nullptr; }
if(obs_info) { delete obs_info; obs_info = (VarInfo *) nullptr; }
if(ens_info) { delete ens_info; ens_info = (EnsVarInfo *) nullptr; }
if(obs_info) { delete obs_info; obs_info = (VarInfo *) nullptr; }

obs_error_info = (ObsErrorInfo *) nullptr;

Expand All @@ -1025,7 +1025,7 @@ void VxPairDataEnsemble::assign(const VxPairDataEnsemble &vx_pd) {

VxPairBase::assign(vx_pd);

set_fcst_info(vx_pd.fcst_info);
set_ens_info(vx_pd.ens_info);
set_obs_info(vx_pd.obs_info);

obs_error_info = vx_pd.obs_error_info;
Expand All @@ -1039,23 +1039,17 @@ void VxPairDataEnsemble::assign(const VxPairDataEnsemble &vx_pd) {

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

void VxPairDataEnsemble::set_fcst_info(EnsVarInfo *info) {
void VxPairDataEnsemble::set_ens_info(EnsVarInfo *info) {
VarInfoFactory f;

// Deallocate, if necessary
if(fcst_info) { delete fcst_info; fcst_info = (EnsVarInfo *) nullptr; }
if(ens_info) { delete ens_info; ens_info = (EnsVarInfo *) nullptr; }

// Perform a deep copy
fcst_info = new EnsVarInfo(*info);
ens_info = new EnsVarInfo(*info);

return;
}

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

void VxPairDataEnsemble::set_obs_info(VarInfo *info) {

copy_var_info(info, obs_info);
// Set the base pointer
if(!fcst_info) set_fcst_info(info->get_var_info());

return;
}
Expand Down Expand Up @@ -1246,8 +1240,8 @@ void VxPairDataEnsemble::add_point_obs(float *hdr_arr, int *hdr_typ_arr,
}

// Set flags
bool spfh_flag = fcst_info->get_var_info()->is_specific_humidity() &&
obs_info->is_specific_humidity();
bool spfh_flag = fcst_info->is_specific_humidity() &&
obs_info->is_specific_humidity();

// Store pointer to ObsErrorEntry
ObsErrorEntry *oerr_ptr = (ObsErrorEntry *) nullptr;
Expand Down Expand Up @@ -1328,7 +1322,7 @@ void VxPairDataEnsemble::add_point_obs(float *hdr_arr, int *hdr_typ_arr,

if(mlog.verbosity_level() >= REJECT_DEBUG_LEVEL) {
mlog << Debug(REJECT_DEBUG_LEVEL)
<< "For " << fcst_info->get_var_info()->magic_str()
<< "For " << fcst_info->magic_str()
<< " versus " << obs_info->magic_str()
<< ", skipping observation since it is a duplicate:\n"
<< pnt_obs_str << "\n";
Expand All @@ -1353,8 +1347,8 @@ void VxPairDataEnsemble::add_point_obs(float *hdr_arr, int *hdr_typ_arr,
void VxPairDataEnsemble::add_ens(int member, bool mn, Grid &gr) {

// Set flag for specific humidity
bool spfh_flag = fcst_info->get_var_info()->is_specific_humidity() &&
obs_info->is_specific_humidity();
bool spfh_flag = fcst_info->is_specific_humidity() &&
obs_info->is_specific_humidity();

// Loop through all the PairDataEnsemble objects and interpolate
for(vector<PairDataEnsemble>::iterator it = pd.begin();
Expand All @@ -1380,7 +1374,7 @@ void VxPairDataEnsemble::add_ens(int member, bool mn, Grid &gr) {
fcst_na.erase();

// Interpolate using the observation pressure level or height
double to_lvl = (fcst_info->get_var_info()->level().type() == LevelType_Pres ?
double to_lvl = (fcst_info->level().type() == LevelType_Pres ?
it->lvl_na[i_obs] : it->elv_na[i_obs]);
int lvl_blw, lvl_abv;

Expand Down Expand Up @@ -1410,7 +1404,7 @@ void VxPairDataEnsemble::add_ens(int member, bool mn, Grid &gr) {
it->x_na[i_obs], it->y_na[i_obs],
it->interp_mthd, it->interp_wdth, it->interp_shape,
gr.wrap_lon(), 0, spfh_flag,
fcst_info->get_var_info()->level().type(),
fcst_info->level().type(),
to_lvl, lvl_blw, lvl_abv,
fcst_na);
}
Expand All @@ -1422,7 +1416,7 @@ void VxPairDataEnsemble::add_ens(int member, bool mn, Grid &gr) {
it->cmn_na[i_obs], it->csd_na[i_obs],
it->interp_mthd, it->interp_wdth, it->interp_shape,
gr.wrap_lon(), interp_thresh, spfh_flag,
fcst_info->get_var_info()->level().type(),
fcst_info->level().type(),
to_lvl, lvl_blw, lvl_abv));
}

Expand Down
6 changes: 2 additions & 4 deletions src/libcode/vx_statistics/pair_data_ensemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,7 @@ class VxPairDataEnsemble : public VxPairBase {
//
//////////////////////////////////////////////////////////////////

EnsVarInfo *fcst_info; // Forecast field, allocated by EnsVarInfo
VarInfo *obs_info; // Observation field, allocated by VarInfoFactory
EnsVarInfo *ens_info; // Ensemble data, allocated by EnsVarInfo

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

Expand All @@ -205,8 +204,7 @@ class VxPairDataEnsemble : public VxPairBase {

void clear();

void set_fcst_info(EnsVarInfo *);
void set_obs_info(VarInfo *);
void set_ens_info(EnsVarInfo *);
void set_size(int, int, int);

// Call set_ens_size before add_ens
Expand Down
40 changes: 4 additions & 36 deletions src/libcode/vx_statistics/pair_data_point.cc
Original file line number Diff line number Diff line change
Expand Up @@ -420,8 +420,8 @@ void VxPairDataPoint::init_from_scratch() {

VxPairBase::init_from_scratch();

fcst_info = (VarInfo *) nullptr;
obs_info = (VarInfoGrib *) nullptr;
fcst_info = (VarInfo *) nullptr;
obs_info = (VarInfo *) nullptr;

clear();

Expand All @@ -434,8 +434,8 @@ void VxPairDataPoint::clear() {

VxPairBase::clear();

if(fcst_info) { delete fcst_info; fcst_info = (VarInfo *) nullptr; }
if(obs_info) { delete obs_info; obs_info = (VarInfoGrib *) nullptr; }
if(fcst_info) { delete fcst_info; fcst_info = (VarInfo *) nullptr; }
if(obs_info) { delete obs_info; obs_info = (VarInfo *) nullptr; }

pd.clear();

Expand All @@ -450,9 +450,6 @@ void VxPairDataPoint::assign(const VxPairDataPoint &vx_pd) {

VxPairBase::assign(vx_pd);

set_fcst_info(vx_pd.fcst_info);
set_obs_info(vx_pd.obs_info);

set_size(vx_pd.n_msg_typ, vx_pd.n_mask, vx_pd.n_interp);

pd = vx_pd.pd;
Expand All @@ -462,35 +459,6 @@ void VxPairDataPoint::assign(const VxPairDataPoint &vx_pd) {

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

void VxPairDataPoint::set_fcst_info(VarInfo *info) {

copy_var_info(info, fcst_info);

// Set the base pointer
finfo_ptr = fcst_info;

return;
}

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

void VxPairDataPoint::set_obs_info(VarInfoGrib *info) {

// Deallocate, if necessary
if(obs_info) { delete obs_info; obs_info = (VarInfoGrib *) nullptr; }

// Perform a deep copy
obs_info = new VarInfoGrib;
*obs_info = *info;

// Set the base pointer
oinfo_ptr = obs_info;

return;
}

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

void VxPairDataPoint::set_size(int types, int masks, int interps) {

VxPairBase::set_size(types, masks, interps);
Expand Down
7 changes: 0 additions & 7 deletions src/libcode/vx_statistics/pair_data_point.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,13 @@ class VxPairDataPoint : public VxPairBase {
//
//////////////////////////////////////////////////////////////////

VarInfo *fcst_info; // Forecast field, allocated by VarInfoFactory
VarInfoGrib *obs_info; // Observation field, allocated by VarInfoFactory

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

// 3-Dim vector of PairDataPoint objects [n_msg_typ][n_mask][n_interp]
std::vector<PairDataPoint> pd;

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

void clear();

void set_fcst_info(VarInfo *);
void set_obs_info(VarInfoGrib *);
void set_size(int, int, int);

void load_seeps_climo(const ConcatString &seeps_climo_name);
Expand Down
Loading

0 comments on commit f1f27b1

Please sign in to comment.