WSL/SLF GitLab Repository

Commit c893b9cb authored by Mathias Bavay's avatar Mathias Bavay
Browse files

The Nakamura and Huwald algorithms in Unventilated_T were not properly...

The Nakamura and Huwald algorithms in Unventilated_T were not properly implemented... This has been fixed and they should now really follow their respective papers. The DBO plugin has been a little bit cleaned up, waiting for new developments of the REST API.
parent cd79721b
......@@ -36,11 +36,6 @@ ProcUnventilatedT::ProcUnventilatedT(const std::vector<std::string>& vec_args, c
void ProcUnventilatedT::process(const unsigned int& param, const std::vector<MeteoData>& ivec,
std::vector<MeteoData>& ovec)
{
if (param!=MeteoData::TA) {
ostringstream ss;
ss << "Can not use " << getName() << " processing on " << MeteoData::getParameterName(param);
throw InvalidArgumentException(ss.str(), AT);
}
ovec = ivec;
if (usr_vw_thresh!=IOUtils::nodata)
......@@ -62,18 +57,17 @@ void ProcUnventilatedT::filterTA(const unsigned int& param, std::vector<MeteoDat
void ProcUnventilatedT::correctTA(const unsigned int& param, std::vector<MeteoData>& ovec) const
{
for (size_t ii=0; ii<ovec.size(); ii++) {
double& tmp = ovec[ii](param);
if (tmp == IOUtils::nodata) continue; //preserve nodata values
double& ta = ovec[ii](param);
if (ta == IOUtils::nodata) continue; //preserve nodata values
double albedo = usr_albedo;
double iswr = ovec[ii](MeteoData::ISWR);
const double rswr = ovec[ii](MeteoData::RSWR);
const double ta = ovec[ii](MeteoData::TA);
double vw = ovec[ii](MeteoData::VW);
double hs = ovec[ii](MeteoData::HS);
if (iswr!=IOUtils::nodata && rswr!=IOUtils::nodata && rswr>5. && iswr>5.) {
albedo = iswr / rswr;
albedo = rswr / iswr;
hs = IOUtils::nodata; //to make sure we would not try to recompute a pseudo albedo later
}
......@@ -82,7 +76,7 @@ void ProcUnventilatedT::correctTA(const unsigned int& param, std::vector<MeteoDa
else iswr = soil_albedo*rswr;
}
if (iswr==IOUtils::nodata || ta==IOUtils::nodata || vw==IOUtils::nodata)
if (iswr==IOUtils::nodata || vw==IOUtils::nodata)
continue;
if (hs!=IOUtils::nodata) { //try to get snow height in order to adjust the albedo
......@@ -97,12 +91,12 @@ void ProcUnventilatedT::correctTA(const unsigned int& param, std::vector<MeteoDa
if (X<1e-4) continue; //the correction does not work well for small X values
if (nakamura) {
const double C0 = 0.13;
const double C1 = 373.40 * albedo / dflt_albedo; //in order to introduce the albedo as a scaling factor
const double C1 = 373.40; /* albedo / dflt_albedo; //in order to introduce the albedo as a scaling factor*/
const double RE = C0 + C1*X;
tmp -= RE; //substracting the radiative error
ta -= RE; //substracting the radiative error
} else {
const double RE = 3.1 * sqrt(X);
tmp -= RE; //substracting the radiative error
const double RE = 3.1 * sqrt(albedo*X*1e3);
ta -= RE; //substracting the radiative error
}
}
}
......
......@@ -104,7 +104,7 @@ void JSONQuery(const std::string& path, picojson::value& v, std::vector<picojson
if (v.is<picojson::object>()) {
picojson::value::object& obj = v.get<picojson::object>();
for (map<string,picojson::value>::iterator it = obj.begin(); it != obj.end(); ++it) {
for (std::map<std::string,picojson::value>::iterator it = obj.begin(); it != obj.end(); ++it) {
if (it->first==local_path) {
if (!remaining_path.empty())
JSONQuery(remaining_path, it->second, results);
......@@ -207,13 +207,14 @@ std::vector<double> getDoubles(const std::string& path, picojson::value& v)
/*************************************************************************************************/
const int DBO::http_timeout_dflt = 60; // seconds until connect time out for libcurl
const std::string DBO::sensors_endpoint = "/osper-api/osper/stations/";
const std::string DBO::metadata_endpoint = "/osper-api/osper/stations/";
const std::string DBO::data_endpoint = "/osper-api/osper/timeseries/";
const std::string DBO::null_string = "null";
DBO::DBO(const std::string& configfile)
: cfg(configfile), vecStationName(), vecMeta(),
coordin(), coordinparam(), coordout(), coordoutparam(),
endpoint(), userid(), passwd(), default_timezone(1.),
endpoint(), default_timezone(1.),
http_timeout(http_timeout_dflt), dbo_debug(false)
{
initDBOConnection();
......@@ -224,7 +225,7 @@ DBO::DBO(const std::string& configfile)
DBO::DBO(const Config& cfgreader)
: cfg(cfgreader), vecStationName(), vecMeta(),
coordin(), coordinparam(), coordout(), coordoutparam(),
endpoint(), userid(), passwd(), default_timezone(1.),
endpoint(), default_timezone(1.),
http_timeout(http_timeout_dflt), dbo_debug(false)
{
initDBOConnection();
......@@ -242,8 +243,6 @@ void DBO::initDBOConnection() {
if (*endpoint.rbegin() != '/') endpoint += "/";
cerr << "[i] Using DBO URL: " << endpoint << endl;
cfg.getValue("DBO_USER", "Input", userid, IOUtils::nothrow);
cfg.getValue("DBO_PASS", "Input", passwd, IOUtils::nothrow);
cfg.getValue("DBO_DEBUG", "INPUT", dbo_debug, IOUtils::nothrow);
}
......@@ -268,10 +267,8 @@ void DBO::fillStationMeta()
vecMeta.clear();
for(size_t ii=0; ii<vecStationName.size(); ii++) {
const std::string station_id = vecStationName[ii];
const string anon_request = sensors_endpoint + IOUtils::strToLower( station_id );
const string auth = "&username=" + userid + "&password=" + passwd;
const string request = (!userid.empty())? anon_request+auth : anon_request;
const std::string station_id( vecStationName[ii] );
const std::string request( metadata_endpoint + IOUtils::strToLower( station_id ) );
stringstream ss;
if (curl_read(request, ss)) {
......@@ -301,12 +298,14 @@ void DBO::fillStationMeta()
}
}
void DBO::readData(const Date& /*dateStart*/, const Date& /*dateEnd*/, std::vector<MeteoData>& /*vecMeteo*/, const size_t& stationindex)
void DBO::readData(const Date& dateStart, const Date& dateEnd, std::vector<MeteoData>& /*vecMeteo*/, const size_t& /*stationindex*/)
{
const std::string station_id = vecStationName[stationindex];
const string anon_request = sensors_endpoint + IOUtils::strToLower( station_id );
const string auth = "&username=" + userid + "&password=" + passwd;
const string request = (!userid.empty())? anon_request+auth : anon_request;
const unsigned int tsID = 4;
std::ostringstream ss_ID;
ss_ID << tsID;
const std::string base_url( data_endpoint + ss_ID.str() );
const std::string period( "?from=" + dateStart.toString(Date::ISO_TZ) + "&until=" + dateEnd.toString(Date::ISO_TZ) );
const std::string request( base_url + period + "&limit=10" );
std::cerr << "Request: " << request << "\n";
stringstream ss;
......@@ -317,11 +316,12 @@ void DBO::readData(const Date& /*dateStart*/, const Date& /*dateEnd*/, std::vect
if (!err.empty())
throw IOException("Error while parsing JSON: "+err, AT);
//printJSON(v, 1);
printJSON(v, 1);
//http://developwis.wsl.ch:8730/osper-api/osper/timeseries/1?from=2016-11-17T13%3A00Z&until=2017-01-05T13%3A00Z&limit=3
} else {
if (dbo_debug)
std::cout << "****\nRequest: " << request << "\n****\n";
throw IOException("Could not retrieve data for station " + station_id, AT);
throw IOException("Could not retrieve data for timeseries " + ss_ID.str(), AT);
}
}
......
......@@ -60,13 +60,13 @@ class DBO : public IOInterface {
std::vector<std::string> vecStationName;
std::vector<StationData> vecMeta;
std::string coordin, coordinparam, coordout, coordoutparam; ///< projection parameters
std::string endpoint, userid, passwd; ///< Variables for endpoint configuration
std::string endpoint; ///< Variables for endpoint configuration
double default_timezone;
int http_timeout; //time out for http connections
bool dbo_debug;
static const int http_timeout_dflt;
static const std::string sensors_endpoint, null_string;
static const std::string metadata_endpoint, data_endpoint, null_string;
};
} //end namespace mio
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment