Skip to content

Commit

Permalink
Feature 1971 mtd error to warning (#2221)
Browse files Browse the repository at this point in the history
Co-authored-by: Dave Albo <dave@seneca.rap.ucar.edu>
Co-authored-by: John Halley Gotway <johnhg@ucar.edu>
  • Loading branch information
3 people authored Aug 5, 2022
1 parent aa24dce commit 86ab23f
Show file tree
Hide file tree
Showing 6 changed files with 185 additions and 54 deletions.
85 changes: 66 additions & 19 deletions src/tools/other/mode_time_domain/mtd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
// ---- ---- ---- -----------
// 000 10-15-15 Bullock New
// 001 05-15-17 Prestopnik P. Added regrid shape
// 002 04-18-19 Halley Gotway Add FCST and OBS units.
// 003 04-25-19 Halley Gotway Add percentiles to 2D output.
// 004 07-06-22 Howard Soh METplus-Internal #19 Rename main to met_ain
// 002 04-18-19 Halley Gotway Add FCST and OBS units
// 003 04-25-19 Halley Gotway Add percentiles to 2D output
// 004 07-06-22 Howard Soh METplus-Internal #19 Rename main to met_main
// 005 08-01-22 Albo MET #1971 Differing time steps
//
////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -205,13 +206,20 @@ MtdIntFile fcst_obj, obs_obj;
MM_Engine engine;


//
// storage for valid times
//

vector<unixtime> valid_times_fcst;
vector<unixtime> valid_times_obs;

//
// read the data files
//

mtd_read_data(config, *(config.fcst_info), fcst_filenames, fcst_raw);
valid_times_fcst = mtd_read_data(config, *(config.fcst_info), fcst_filenames, fcst_raw);

mtd_read_data(config, *(config.obs_info), obs_filenames, obs_raw);
valid_times_obs = mtd_read_data(config, *(config.obs_info), obs_filenames, obs_raw);

if ( fcst_raw.nt() != obs_raw.nt() ) {

Expand Down Expand Up @@ -436,13 +444,21 @@ for (j=0; j<(fcst_obj.n_objects()); ++j) {

mask_2d = fcst_obj.const_t_mask(t, j + 1); // 1-based

if (t < 0 || t >= (int)valid_times_fcst.size()) {
mlog << Error
<< "\n " << program_name
<< ": index " << t << " out of forecast valid times range 0 to "
<< valid_times_fcst.size()-1 << "\n\n";
exit ( 1 );
}

fcst_raw.get_data_plane(t, raw_2d);

att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value);

att_2.set_fcst();

att_2.set_valid_time(fcst_obj.start_valid_time() + t*(fcst_obj.delta_t()));
att_2.set_valid_time(valid_times_fcst[t]);

att_2.set_lead_time(fcst_obj.lead_time(t));

Expand Down Expand Up @@ -470,13 +486,21 @@ for (j=0; j<(obs_obj.n_objects()); ++j) {

mask_2d = obs_obj.const_t_mask(t, j + 1); // 1-based

if (t < 0 || t >= (int)valid_times_obs.size()) {
mlog << Error
<< "\n " << program_name << ": index " << t
<< " out of obs valid times range 0 to "
<< valid_times_obs.size()-1 << "\n\n";
exit ( 1 );
}

obs_raw.get_data_plane(t, raw_2d);

att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value);

att_2.set_obs();

att_2.set_valid_time(obs_obj.start_valid_time() + t*(obs_obj.delta_t()));
att_2.set_valid_time(valid_times_obs[t]);

att_2.set_lead_time(obs_obj.lead_time(t));

Expand Down Expand Up @@ -680,18 +704,23 @@ if ( have_pairs ) {

for (t=(att_3.tmin()); t<=(att_3.tmax()); ++t) {

// mask_2d = mask.const_t_mask(t, j + 1); // 1-based
mask_2d = mask.const_t_mask(t, 1); // 1-based

// cout << "j = " << j << ", vol = " << mask_2d.object_volume(0) << '\n';
if (t < 0 || t >= (int)valid_times_fcst.size()) {
mlog << Error
<< "\n " << program_name << ": index " << t
<< " out of forecast valid times range 0 to "
<< valid_times_fcst.size()-1 << "\n\n";
exit ( 1 );
}

fcst_raw.get_data_plane(t, raw_2d);

att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value);

att_2.set_fcst();

att_2.set_valid_time(fcst_obj.start_valid_time() + t*(fcst_obj.delta_t()));
att_2.set_valid_time(valid_times_fcst[t]);

att_2.set_lead_time(fcst_obj.lead_time(t));

Expand Down Expand Up @@ -723,16 +752,23 @@ if ( have_pairs ) {

for (t=(att_3.tmin()); t<=(att_3.tmax()); ++t) {

// mask_2d = mask.const_t_mask(t, j + 1); // 1-based
mask_2d = mask.const_t_mask(t, 1); // 1-based

if (t < 0 || t >= (int)valid_times_obs.size()) {
mlog << Error
<< "\n " << program_name << ": index " << t
<< " out of obs valid times range 0 to "
<< valid_times_obs.size()-1 << "\n\n";
exit ( 1 );
}

obs_raw.get_data_plane(t, raw_2d);

att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value);

att_2.set_obs();

att_2.set_valid_time(obs_obj.start_valid_time() + t*(obs_obj.delta_t()));
att_2.set_valid_time(valid_times_obs[t]);

att_2.set_lead_time(obs_obj.lead_time(t));

Expand Down Expand Up @@ -785,9 +821,8 @@ mlog << Debug(2)
<< "Creating 2D constant-time slice attributes file: \""
<< path << "\"\n";

do_2d_txt_output(fcst_raw, obs_raw,
fcst_simple_att_2d, obs_simple_att_2d,
fcst_cluster_att_2d, obs_cluster_att_2d, config, path.c_str());
do_2d_txt_output(fcst_raw, obs_raw, fcst_simple_att_2d, obs_simple_att_2d,
fcst_cluster_att_2d, obs_cluster_att_2d, config, path.c_str());

//
// write simple single attributes
Expand Down Expand Up @@ -872,7 +907,6 @@ mlog << Debug(2)

do_mtd_nc_output(config.nc_info, engine, fcst_raw, obs_raw, fcst_obj, obs_obj, config, path.c_str());


//
// done
//
Expand Down Expand Up @@ -1058,11 +1092,17 @@ ConcatString prefix;
ConcatString path;


//
// storage for valid times
//

vector<unixtime> valid_times;

//
// read the data files
//

mtd_read_data(config, *(config.fcst_info), single_filenames, raw);
valid_times = mtd_read_data(config, *(config.fcst_info), single_filenames, raw);

//
// copy forecast name/units/level to observation
Expand Down Expand Up @@ -1166,13 +1206,21 @@ for (j=0; j<(obj.n_objects()); ++j) {

mask_2d = obj.const_t_mask(t, j + 1); // 1-based

if (t < 0 || t >= (int)valid_times.size()) {
mlog << Error
<< "\n " << program_name << ": index " << t
<< " out of valid times range 0 to "
<< valid_times.size()-1 << "\n\n";
exit ( 1 );
}

raw.get_data_plane(t, raw_2d);

att_2 = calc_2d_single_atts(mask_2d, raw_2d, j + 1, config.inten_perc_value);

att_2.set_fcst();

att_2.set_valid_time(obj.start_valid_time() + t*(obj.delta_t()));
att_2.set_valid_time(valid_times[t]);

att_2.set_lead_time(obj.lead_time(t));

Expand Down Expand Up @@ -1232,7 +1280,6 @@ mlog << Debug(2)
do_mtd_nc_output(config.nc_info, raw, obj, config, path.c_str());



//
// done
//
Expand Down
35 changes: 34 additions & 1 deletion src/tools/other/mode_time_domain/mtd_file_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ Nx = Ny = Nt = 0;

StartValidTime = (unixtime) 0;

ActualValidTimes.clear();

DeltaT = 0;

Filename.clear();
Expand Down Expand Up @@ -292,7 +294,6 @@ return;

}


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


Expand All @@ -306,6 +307,19 @@ return;

}

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


void MtdFileBase::init_actual_valid_times(const vector<unixtime> &validTimes)

{

ActualValidTimes = validTimes;

return;

}


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

Expand Down Expand Up @@ -349,6 +363,25 @@ return ( StartValidTime + t*DeltaT );

}

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


unixtime MtdFileBase::actual_valid_time(int t) const

{

if ( (t < 0) || ( t >= (int)ActualValidTimes.size()) ) {

mlog << Error << "\n\n MtdFileBase::valid_time(int t) -> range check error\n\n";

exit ( 1 );

}

return ( ActualValidTimes[t] );

}


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

Expand Down
11 changes: 9 additions & 2 deletions src/tools/other/mode_time_domain/mtd_file_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ class MtdFileBase {

int Nx, Ny, Nt;

unixtime StartValidTime;
unixtime StartValidTime; // useful for constant time increments

int DeltaT; // seconds
int DeltaT; // seconds, useful for constant time increments

vector<unixtime> ActualValidTimes; // useful for uneven time increments

IntArray Lead_Times;

Expand All @@ -113,8 +115,11 @@ class MtdFileBase {
void set_grid(const Grid &);

void set_start_valid_time (unixtime);

void set_delta_t (int); // seconds

void init_actual_valid_times(const vector<unixtime> &validTimes);

void set_lead_time(int index, int value);

void set_filetype(MtdFileType);
Expand Down Expand Up @@ -143,6 +148,8 @@ class MtdFileBase {

unixtime valid_time (int) const;

unixtime actual_valid_time (int) const;

int lead_time (int index) const;

//
Expand Down
Loading

0 comments on commit 86ab23f

Please sign in to comment.