Skip to content

Commit

Permalink
Per #1918, add nxy(), anomaly(), and standard_anomaly() functions to …
Browse files Browse the repository at this point in the history
…DataPlane.
  • Loading branch information
JohnHalleyGotway committed Feb 18, 2022
1 parent 6b2134d commit e72368f
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 10 deletions.
62 changes: 55 additions & 7 deletions met/src/basic/vx_util/data_plane.cc
Original file line number Diff line number Diff line change
Expand Up @@ -406,23 +406,71 @@ void DataPlane::censor(const ThreshArray &censor_thresh,

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

void DataPlane::anomaly(const DataPlane &mn) {

// Check dimensions
if(Nxy != mn.Nxy) {
mlog << Error << "\nDataPlane::anomaly() -> "
<< "the data dimensions do not match: ("
<< Nx << ", " << Ny << ") != ("
<< mn.Nx << ", " << mn.Ny << ")!\n\n";
exit(1);
}

void DataPlane::replace_bad_data(const double value)
// Subtract the mean
for(int i=0; i<Nxy; i++) {
if(is_bad_data(Data[i]) || is_bad_data(mn.Data[i])) {
Data[i] = bad_data_double;
}
else {
Data[i] -= mn.Data[i];
}
}

{
return;
}

int j;
///////////////////////////////////////////////////////////////////////////////

for (j=0; j<Nxy; ++j) {
void DataPlane::standard_anomaly(const DataPlane &mn,
const DataPlane &sd) {

// Check dimensions
if(Nxy != mn.Nxy || Nxy != sd.Nxy) {
mlog << Error << "\nDataPlane::standard_anomaly() -> "
<< "the data dimensions do not match: ("
<< Nx << ", " << Ny << ") != ("
<< mn.Nx << ", " << mn.Ny << ") != ("
<< sd.Nx << ", " << sd.Ny << ")!\n\n";
exit(1);
}

if ( is_bad_data(Data[j]) ) Data[j] = value;
// Subtract the mean and divide by the standard deviation
for(int i=0; i<Nxy; i++) {
if(is_bad_data(Data[i]) ||
is_bad_data(mn.Data[i]) ||
is_bad_data(sd.Data[i]) ||
is_eq(sd.Data[i], 0.0)) {
Data[i] = bad_data_double;
}
else {
Data[i] = (Data[i] - mn.Data[i])/sd.Data[i];
}
}

return;
}

return;
///////////////////////////////////////////////////////////////////////////////

}
void DataPlane::replace_bad_data(const double value) {

for(int i=0; i<Nxy; i++) {
if(is_bad_data(Data[i])) Data[i] = value;
}

return;
}

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

Expand Down
11 changes: 8 additions & 3 deletions met/src/basic/vx_util/data_plane.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class DataPlane {

int Nx;
int Ny;

int Nxy; // Nx*Ny

unixtime InitTime; // Initialization time in unixtime
Expand Down Expand Up @@ -86,6 +85,8 @@ class DataPlane {

int nx() const;
int ny() const;
int nxy() const;

bool is_empty() const;
bool is_all_bad_data() const;
int n_good_data() const;
Expand All @@ -108,6 +109,9 @@ class DataPlane {
void convert (const UserFunc_1Arg &);
void censor (const ThreshArray &, const NumArray &);

void anomaly (const DataPlane &);
void standard_anomaly(const DataPlane &, const DataPlane &);

void replace_bad_data(const double value);

int two_to_one(int x, int y, bool to_north=true) const;
Expand All @@ -131,8 +135,9 @@ class DataPlane {

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

inline int DataPlane::nx() const { return (Nx); }
inline int DataPlane::ny() const { return (Ny); }
inline int DataPlane::nx() const { return (Nx); }
inline int DataPlane::ny() const { return (Ny); }
inline int DataPlane::nxy() const { return (Nxy); }

inline bool DataPlane::is_empty() const { return (Nxy == 0); }

Expand Down

0 comments on commit e72368f

Please sign in to comment.