1 #include <det/Detector.h>
3 #include <utl/ErrorLogger.h>
5 #include <utl/ReferenceEllipsoid.h>
6 #include <utl/AugerException.h>
8 #include <atm/Atmosphere.h>
9 #include <atm/GOESDB.h>
21 const int gNumEasting = 30;
22 const int gNumNorthing = 12;
23 const int gNumCloudProbabilityLevels = 5;
24 const double gStartEasting = (440000 + 553.2)*
m;
25 const double gStartNorthing = (6060000 + 9736.34)*
m;
26 const double gDeltaEasting = 2394.9*
m;
27 const double gDeltaNorthing = 5493.03*
m;
32 GOESDB::GetPixelWidthEasting()
40 GOESDB::GetPixelWidthNorthing()
43 return gDeltaNorthing;
48 GOESDB::GetNumberOfPixels()
51 return gNumEasting * gNumNorthing;
56 GOESDB::GetPixelId(
const double easting,
const double northing)
59 const int northPixel = GetNorthPixel(northing);
60 const int eastPixel = GetEastPixel(easting, northPixel);
61 return gNumEasting * northPixel + eastPixel;
66 GOESDB::GetNorthPixel(
const double northing)
69 const double deltaNorthing = GetPixelWidthNorthing();
70 return (northing - gStartNorthing) / deltaNorthing;
75 GOESDB::GetEastPixel(
const double easting,
const int northPixel)
78 const double deltaEasting = GetPixelWidthEasting();
79 return (easting - (gStartEasting - (northPixel%6) *
80 deltaEasting / 6)) / deltaEasting;
85 GOESDB::GetPixelCenter(
const unsigned int pixelId)
88 if (pixelId >= GetNumberOfPixels()) {
90 errMsg <<
" pixel id " << pixelId <<
" out of bound ";
94 if (fPixelCenters.empty()) {
96 const double deltaEasting = GetPixelWidthEasting();
97 const double deltaNorthing = GetPixelWidthNorthing();
100 for (
unsigned int i = 0; i < GetNumberOfPixels(); ++i) {
101 const unsigned int eastPixel = i % gNumEasting;
102 const unsigned int northPixel = i / gNumEasting;
103 const double easting = gStartEasting + eastPixel * deltaEasting
104 - (northPixel%6) * deltaEasting / 6 + deltaEasting / 2;
105 const double northing = gStartNorthing + northPixel * deltaNorthing
107 const UTMPoint thisPoint(northing, easting, 1400*
m, 19,
'H', wgs84);
108 fPixelCenters.push_back(thisPoint);
113 return fPixelCenters[pixelId];
118 GOESDB::GetCloudProbability(
const unsigned int pId)
121 return IndexToProbability(GetCloudProbabilityIndex(pId));
126 GOESDB::IndexToProbability(
const unsigned int cpIndex)
129 return cpIndex / double(gNumCloudProbabilityLevels);
134 GOESDB::GetCloudProbabilityIndex(
const unsigned int pId)
139 im[
"pixel_id"] = boost::lexical_cast<
string>(pId);
141 boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
143 return fPixelMap[pId];
148 GOESDB::HasData(
const unsigned int pId)
151 if (fPixelMap.find(pId) != fPixelMap.end())
154 const VManager& manager = Detector::GetInstance().GetAManagerRegister().GetManager(
"AGOESSQLManager");
161 if (cloudProb < 0 || cloudProb > gNumCloudProbabilityLevels - 1) {
162 ostringstream errMsg;
163 errMsg <<
" cloud index from DB out of range! Index = " << cloudProb
164 <<
", expected range is [" << 0 <<
", "
165 << gNumCloudProbabilityLevels - 1 <<
"]"
166 <<
" (maybe gNumCloudProbabilityLevels needs to be changed?)";
169 fPixelMap[pId] = cloudProb;
175 GOESDB::GetAllCloudProbabilities()
178 if (fPixelMap.size() < GetNumberOfPixels()) {
181 Detector::GetInstance().GetAManagerRegister().GetManager(
"AGOESSQLManager");
188 auto maxCloudProb = max_element(fPixelMap.begin(), fPixelMap.end());
189 if (maxCloudProb->second < 0 || maxCloudProb->second > gNumCloudProbabilityLevels - 1) {
190 ostringstream errMsg;
191 errMsg <<
" cloud index from DB out of range! Index = " << maxCloudProb->first
192 <<
", expected range is [" << 0 <<
", "
193 << gNumCloudProbabilityLevels - 1 <<
"]"
194 <<
" (maybe gNumCloudProbabilityLevels needs to be changed?)";
199 msg <<
"request for data not found in the database for time "
200 << Detector::GetInstance().GetTime() << endl;
204 boost::lexical_cast<string>(Detector::GetInstance().GetTime()));
210 for (
const auto&
p : fPixelMap)
211 retval[
p.first] = IndexToProbability(
p.second);
218 GOESDB::GetCloudProbability(
const Point&
p)
222 return GetCloudProbability(utmPoint);
232 return GetCloudProbability(x, y);
237 GOESDB::GetCloudProbability(
const double easting,
const double northing)
240 const int pId = GetPixelId(easting, northing);
241 if (pId < 0 || pId >=
int(GetNumberOfPixels()))
244 return GetCloudProbability(pId);
252 double p2X,
double p2Y,
double p3X,
double p3Y)
254 const double s1X = p1X - p0X;
255 const double s1Y = p1Y - p0Y;
256 const double s2X = p3X - p2X;
257 const double s2Y = p3Y - p2Y;
259 if (s1X * s2Y == s2X * s1Y)
262 const double d = s1X * s2Y - s2X * s1Y;
264 const double s = (-s1Y * (p0X - p2X) + s1X * (p0Y - p2Y)) / d;
265 const double t = ( s2X * (p0Y - p2Y) - s2Y * (p0X - p2X)) / d;
267 return (s >= 0 && s <= 1 && t >= 0 && t <= 1);
276 const double dX = GetPixelWidthEasting() / 2;
277 const double dY = GetPixelWidthNorthing() / 2;
287 const int pixelId1 = GetPixelId(x1, y1);
288 const int pixelId2 = GetPixelId(x2, y2);
290 int maxCloudProbabilityIndex = -1;
292 for (
int i = 0; i < int(GetNumberOfPixels()); ++i) {
293 bool isCloudPixel =
false;
294 if (i == pixelId1 || i == pixelId2)
308 const int thisIndex = GetCloudProbabilityIndex(i);
309 if (thisIndex > maxCloudProbabilityIndex)
310 maxCloudProbabilityIndex = thisIndex;
314 return IndexToProbability(maxCloudProbabilityIndex);
bool SegmentIntersection(double p0X, double p0Y, double p1X, double p1Y, double p2X, double p2Y, double p3X, double p3Y)
Class to hold and convert a point in geodetic coordinates.
Base class for exceptions trying to access non-existing components.
Interface for detector managers.
double GetNorthing() const
Get the northing.
Exception for reporting variable out of valid range.
virtual Status GetData(double &returnData, const std::string &componentProperty, const std::string &componentName, const IndexMap &componentIndex) const =0
Exception to use in case requested data not found in the database with detailed printout.
Reference ellipsoids for UTM transformations.
double GetEasting() const
Get the easting.
std::map< unsigned int, double > ProbabilityMap
std::map< std::string, std::string > IndexMap
utl::CoordinateSystemPtr Get(const std::string &id)
Get a well-known Coordinate System.