Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature 1971 mtd error to warning #2221

Merged
merged 9 commits into from
Aug 5, 2022
37 changes: 28 additions & 9 deletions src/tools/other/mode_time_domain/mtd.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,13 +206,22 @@ MtdIntFile fcst_obj, obs_obj;
MM_Engine engine;


//
// storage for valid times
//

unixtime * valid_times_fcst = 0;
valid_times_fcst = new unixtime [fcst_filenames.n()];
unixtime * valid_times_obs = 0;
valid_times_obs = new unixtime [obs_filenames.n()];

//
// read the data files
//

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

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

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

Expand Down Expand Up @@ -443,7 +452,7 @@ for (j=0; j<(fcst_obj.n_objects()); ++j) {

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 @@ -477,7 +486,7 @@ for (j=0; j<(obs_obj.n_objects()); ++j) {

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 @@ -692,7 +701,7 @@ if ( have_pairs ) {

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 @@ -733,7 +742,7 @@ if ( have_pairs ) {

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 @@ -786,7 +795,7 @@ mlog << Debug(2)
<< "Creating 2D constant-time slice attributes file: \""
<< path << "\"\n";

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

Expand Down Expand Up @@ -873,6 +882,8 @@ mlog << Debug(2)

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

if ( valid_times_fcst ) { delete [] valid_times_fcst; valid_times_fcst = 0; }
if ( valid_times_obs ) { delete [] valid_times_obs; valid_times_obs = 0; }

//
// done
Expand Down Expand Up @@ -1051,11 +1062,18 @@ ConcatString prefix;
ConcatString path;


//
// storage for valid times
//

unixtime * valid_times = 0;
valid_times = new unixtime [single_filenames.n()];

//
// read the data files
//

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

//
// copy forecast name/units/level to observation
Expand Down Expand Up @@ -1165,7 +1183,7 @@ for (j=0; j<(obj.n_objects()); ++j) {

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 @@ -1225,6 +1243,7 @@ mlog << Debug(2)
do_mtd_nc_output(config.nc_info, raw, obj, config, path.c_str());


if ( valid_times ) { delete [] valid_times; valid_times = 0; }

//
// done
Expand Down
80 changes: 59 additions & 21 deletions src/tools/other/mode_time_domain/mtd_read_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ using namespace std;

#include "mtd_read_data.h"

#include "num_array.h"

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


void mtd_read_data(MtdConfigInfo & config, VarInfo & varinfo,
const StringArray & filenames, MtdFloatFile & raw)
const StringArray & filenames, MtdFloatFile & raw,
unixtime valid_times[])

{

Expand All @@ -39,15 +41,10 @@ if ( filenames.n() < 2 ) {

}

int j;
int j, k;
Met2dDataFile * data_2d_file = 0;
Met2dDataFileFactory factory;
DataPlane plane;
unixtime * valid_times = 0;



valid_times = new unixtime [filenames.n()];

//
// read the files
Expand Down Expand Up @@ -96,30 +93,73 @@ for (j=0; j<(filenames.n()); ++j) {

} // for j

varinfo.set_valid(valid_times[0]);
varinfo.set_valid(valid_times[0]);

//
// check the time intervals
// check the time intervals for consistency
// Store the time differences between succesive valid times in an array
// See if differences are constant or not, and if not see if all diffs are months
//

unixtime dt_start, dt;
unixtime dt_start, dt, *dtArray;
int numDt = filenames.n() - 1;
dtArray = new unixtime [numDt];

dt_start = valid_times[1] - valid_times[0];
dtArray[0] = dt_start;

for (j=2; j<(filenames.n()); ++j) {
dtArray[j - 1] = dt = valid_times[j] - valid_times[j - 1];
}

dt = valid_times[j] - valid_times[j - 1];

if ( dt != dt_start ) {

mlog << Error << "\n\n mtd_read_data() -> file time increments are not constant!\n\n";

exit ( 1 );

bool variableTimeIncs = false;
for (j=0; j<numDt; ++j) {
if (variableTimeIncs) {
break;
}
for (k=j+1; k<numDt; ++k) {
if ( dtArray[j] != dtArray[k]) {
variableTimeIncs = true;
break;
}
}

}
if (variableTimeIncs) {
// compute the mode and use it as the actual delta, by storing it to dt_start
NumArray na;
for (j=0; j<numDt; ++j) {
na.add((double)dtArray[j]);
}
dt_start = (unixtime)na.mode();

// test if the differences are all months (in seconds)
bool isMonths = true;
int secondsPerDay = 24*3600;
for (j=0; j<numDt; ++j) {
int days = dtArray[j]/secondsPerDay;
if (days != 28 && days != 29 && days != 30 && days != 31) {
isMonths = false;
break;
}
}

if (isMonths) {
mlog << Debug(2) << "\n\n mtd_read_data() -> file time increments are months (not constant), use MODE of the increments, mode=" << dt_start << " seconds = " << dt_start/(24*3600) << " days\n\n";
} else {
// compute some measures that might be used to exit with an error, for now just show them to the user and go on
double mean, var, svar;
na.compute_mean_variance(mean, var);
svar = sqrt(var);
unixtime umean = (unixtime)mean;
unixtime uvar = (unixtime)var;
unixtime suvar = (unixtime)svar;
mlog << Warning << "\n\n mtd_read_data() -> file time increments are not constant, could be problematic\n";
mlog << Warning << " mtd_read_data() -> use MODE of the increments, mode=" << dt_start << "\n";
mlog << Warning << " mtd_read_data() -> time increment properties: mean=" << umean << " variance=" << uvar << " sqrt(var)=" << suvar << "\n\n";
}
}
delete [] dtArray;

//
// load up the rest of the MtdFloatFile class members
//
Expand All @@ -138,8 +178,6 @@ raw.calc_data_minmax();
// done
//

if ( valid_times ) { delete [] valid_times; valid_times = 0; }

return;

}
Expand Down
3 changes: 2 additions & 1 deletion src/tools/other/mode_time_domain/mtd_read_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@


extern void mtd_read_data(MtdConfigInfo &, VarInfo &,
const StringArray & filenames, MtdFloatFile &);
const StringArray & filenames, MtdFloatFile &,
unixtime valid_times[]);


////////////////////////////////////////////////////////////////////////
Expand Down
20 changes: 14 additions & 6 deletions src/tools/other/mode_time_domain/mtd_txt_output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,8 @@ return;

void do_2d_txt_output(const MtdFloatFile & fcst_raw,
const MtdFloatFile & obs_raw,
const unixtime valid_times_fcst[],
const unixtime valid_times_obs[],
const SingleAtt2DArray & fcst_simple_att,
const SingleAtt2DArray & obs_simple_att,
const SingleAtt2DArray & fcst_cluster_att,
Expand Down Expand Up @@ -494,9 +496,11 @@ for (j=0; j<(fcst_simple_att.n()); ++j) {

table.set_entry(r, fcst_lead_column, sec_to_hhmmss(fcst_simple_att.lead_time(j)));

table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_simple_att.valid_time(j)));
//table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_simple_att.valid_time(j)));
table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_fcst[j]));

table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.valid_time(t)));
//table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.valid_time(t)));
table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_obs[t]));

table.set_entry(r, obs_lead_column, sec_to_hhmmss(obs_raw.lead_time(t)));

Expand All @@ -508,11 +512,13 @@ for (j=0; j<(obs_simple_att.n()); ++j) {

t = obs_simple_att.time_index(j);

table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.valid_time(t)));
//table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.valid_time(t)));
table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_fcst[t]));

table.set_entry(r, fcst_lead_column, sec_to_hhmmss(fcst_raw.lead_time(t)));

table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_simple_att.valid_time(j)));
//table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_simple_att.valid_time(j)));
table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_obs[j]));

table.set_entry(r, obs_lead_column, sec_to_hhmmss(obs_simple_att.lead_time(j)));

Expand All @@ -528,7 +534,8 @@ for (j=0; j<(fcst_cluster_att.n()); ++j) {

table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_cluster_att.valid_time(j)));

table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.valid_time(t)));
//table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(obs_raw.valid_time(t)));
table.set_entry(r, obs_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_obs[t]));

table.set_entry(r, obs_lead_column, sec_to_hhmmss(obs_raw.lead_time(t)));

Expand All @@ -540,7 +547,8 @@ for (j=0; j<(obs_cluster_att.n()); ++j) {

t = obs_cluster_att.time_index(j);

table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.valid_time(t)));
//table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(fcst_raw.valid_time(t)));
table.set_entry(r, fcst_valid_column, unix_to_yyyymmdd_hhmmss(valid_times_fcst[t]));

table.set_entry(r, fcst_lead_column, sec_to_hhmmss(fcst_raw.lead_time(t)));

Expand Down
2 changes: 2 additions & 0 deletions src/tools/other/mode_time_domain/mtd_txt_output.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ extern void do_3d_pair_txt_output(const PairAtt3DArray &,

extern void do_2d_txt_output(const MtdFloatFile & fcst_raw,
const MtdFloatFile & obs_raw,
const unixtime valid_times_fcst[],
const unixtime valid_times_obs[],
const SingleAtt2DArray & fcst_single_att,
const SingleAtt2DArray & obs_single_att,
const SingleAtt2DArray & fcst_cluster_att,
Expand Down