-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBackupSnowModel.h
67 lines (55 loc) · 2.37 KB
/
BackupSnowModel.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#ifndef BACKUP_SNOW_MODEL
#define BACKUP_SNOW_MODEL
#include <datastr/PartialConfidenceTemporalGeographicMap.h>
#include <datastr/TemporalGeographicMap.h>
#include <time.h>
using namespace std;
namespace openworld {
class BackupSnowModel : public SnowModel {
protected:
TemporalGeographicMap<double>& data; // saves pointer
TemporalGeographicMap<double>& backup; // saves pointer
double backupConfidence;
Measure backupStartTime;
public:
BackupSnowModel(TemporalGeographicMap<double>* data, TemporalGeographicMap<double>* backup,
DividedRange time, double backupConfidence, Measure backupStartTime)
: SnowModel(time), data(*data), backup(*backup), backupStartTime(backupStartTime) {
this->backupConfidence = backupConfidence;
confs = new double[time.count()];
for (unsigned ii = 0; ii < time.count(); ii++)
confs[ii] = 0;
}
virtual SnowModel* clone() {
return new BackupSnowModel(data.clone(), backup.clone(), this->time, backupConfidence, backupStartTime);
}
virtual GeographicMap<double>& operator[](Measure tt) {
time_t timet = tt.getValue();
struct tm tmstr = *gmtime(&timet);
GeographicMap<double>& backupMap = backup[backupStartTime + DividedRange::toTimespan(tmstr.tm_yday)];
if (tt >= data.getTimes().getMin() && tt < data.getTimes().getMax()) {
GeographicMap<double>& dataMap = data[tt];
GeographicMap<double>* result = tew_(MatrixGeographicMap<double>(dataMap.getLatitudes(), dataMap.getLongitudes()));
unsigned valids = 0;
for (unsigned rr = 0; rr < dataMap.getLatitudes().count(); rr++)
for (unsigned cc = 0; cc < dataMap.getLongitudes().count(); cc++) {
double val = dataMap.getCellConst(rr, cc);
if (val >= 0) {
valids++;
result->getCell(rr, cc) = val;
} else
result->getCell(rr, cc) = backupMap.getCellConst(rr, cc);
}
confs[time.inRange(tt)] = backupConfidence + ((1 - backupConfidence) * valids) / (dataMap.getLatitudes().count() * dataMap.getLongitudes().count());
return *result;
} else {
confs[time.inRange(tt)] = backupConfidence;
return backupMap;
}
}
virtual void inform(GeographicMap<double>& newMeltVolume, GeographicMap<double>& newSnowVolume) {
// do nothing
}
};
}
#endif