WSL/SLF GitLab Repository

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

The PotentialSW filter can now handle RSWR, most of the (useful) constants...

The PotentialSW filter can now handle RSWR, most of the (useful) constants defined in the Shade and UnventillatedT filters are now in ProcessingBlock (for easy reuse), the Shade filter now has an easier structure (the Sun object can now do internal caching making the external caching such as performed in the filter not needed anymore).
parent e68543bb
......@@ -44,6 +44,15 @@ void FilterPotentialSW::process(const unsigned int& param, const std::vector<Met
Sun.setLatLon(position.getLat(), position.getLon(), position.getAltitude()); //if they are constant, nothing will be recomputed
Sun.setDate(ovec[ii].date.getJulian(true), 0.); //quicker: we stick to gmt
double albedo = 1.; //needed if we are dealing with RSWR
if (param==MeteoData::RSWR) {
const double HS = ovec[ii](MeteoData::HS);
if (HS!=IOUtils::nodata) //no big deal if we can not adapt the albedo
albedo = (HS>=snow_thresh)? snow_albedo : soil_albedo;
else
albedo = 0.5;
}
//if we don't have TA and RH, set them so the reduced precipitable water will get an average value
double TA = ovec[ii](MeteoData::TA);
double RH = ovec[ii](MeteoData::RH);
......@@ -56,7 +65,7 @@ void FilterPotentialSW::process(const unsigned int& param, const std::vector<Met
double toa_h, direct_h, diffuse_h;
Sun.getHorizontalRadiation(toa_h, direct_h, diffuse_h);
if (value<min_coeff*toa_h || value>max_coeff*(direct_h+diffuse_h))
if (value/albedo<min_coeff*toa_h || value/albedo>max_coeff*(direct_h+diffuse_h)) //for ISWR, albedo==1
value = IOUtils::nodata;
}
}
......
......@@ -22,6 +22,7 @@
#include <algorithm>
#include <meteoio/meteoFilters/ProcShade.h>
#include <meteoio/meteoLaws/Sun.h>
#include <meteoio/IOHandler.h>
#include <meteoio/FileUtils.h>
......@@ -37,12 +38,9 @@ struct sort_pred {
};
const double ProcShade::diffuse_thresh = 15.; //below this threshold, not correction is performed since it will only be diffuse
const double ProcShade::soil_albedo = .23; //grass
const double ProcShade::snow_albedo = .85; //snow
const double ProcShade::snow_thresh = .1; //if snow height greater than this threshold -> snow albedo
ProcShade::ProcShade(const std::vector<std::string>& vec_args, const std::string& name, const Config &i_cfg)
: ProcessingBlock(name), cfg(i_cfg), dem(), Suns(), masks()
: ProcessingBlock(name), cfg(i_cfg), dem(), masks()
{
parse_args(vec_args);
properties.stage = ProcessingProperties::first; //for the rest: default values
......@@ -54,16 +52,8 @@ void ProcShade::process(const unsigned int& param, const std::vector<MeteoData>&
ovec = ivec;
if (ovec.empty()) return;
const string stationHash( ovec[0].meta.getHash() );
//check if the station already has an associated SunObject
std::map< std::string, SunObject >::iterator it = Suns.find( stationHash );
if (it==Suns.end()) {
const Coords position( ovec[0].meta.position );
const SunObject tmp(position.getLat(), position.getLon(), position.getAltitude());
Suns[ stationHash ] = tmp;
it = Suns.find( stationHash );
}
const std::string stationHash( ovec[0].meta.getHash() );
SunObject Sun;
//check if the station already has an associated mask, first as wildcard then by station hash
std::map< std::string , std::vector< std::pair<double,double> > >::iterator mask = masks.find( "*" );
......@@ -84,10 +74,12 @@ void ProcShade::process(const unsigned int& param, const std::vector<MeteoData>&
double& tmp = ovec[ii](param);
if (tmp == IOUtils::nodata) continue; //preserve nodata values
if (tmp<diffuse_thresh) continue; //only diffuse radiation, there is nothing to correct
it->second.setDate(ovec[ii].date.getJulian(true), 0.); //quicker: we stick to gmt
const Coords position( ovec[ii].meta.position );
Sun.setLatLon(position.getLat(), position.getLon(), position.getAltitude()); //if they are constant, nothing will be recomputed
Sun.setDate(ovec[ii].date.getJulian(true), 0.); //quicker: we stick to gmt
double sun_azi, sun_elev;
it->second.position.getHorizontalCoordinates(sun_azi, sun_elev);
Sun.position.getHorizontalCoordinates(sun_azi, sun_elev);
const double mask_elev = getMaskElevation(mask->second, sun_azi);
if (mask_elev>0 && mask_elev>sun_elev) { //the point is in the shade
......@@ -109,11 +101,11 @@ void ProcShade::process(const unsigned int& param, const std::vector<MeteoData>&
const bool has_potRad = (ISWR!=IOUtils::nodata && TA!=IOUtils::nodata && RH!=IOUtils::nodata);
if (has_potRad)
it->second.calculateRadiation(TA, RH, albedo);
Sun.calculateRadiation(TA, RH, albedo);
else
if (ovec[ii].date.getJulian(true) - julian_prev > 1.) continue; //no way to get ISWR and/or potential radiation, previous Md is too old
const double Md = (has_potRad)? it->second.getSplitting(ISWR) : Md_prev; //fallback: use previous valid value
const double Md = (has_potRad)? Sun.getSplitting(ISWR) : Md_prev; //fallback: use previous valid value
tmp *= Md; //only keep the diffuse radiation, either on RSWR or ISWR
if (has_potRad) {
Md_prev = Md;
......
......@@ -19,7 +19,6 @@
#define PROCSHADE_H
#include <meteoio/meteoFilters/FilterBlock.h>
#include <meteoio/meteoLaws/Sun.h>
#include <meteoio/Config.h>
#include <meteoio/dataClasses/DEMObject.h>
#include <vector>
......@@ -72,10 +71,9 @@ class ProcShade : public ProcessingBlock {
const Config &cfg;
DEMObject dem;
std::map<std::string, SunObject> Suns;
std::map< std::string , std::vector< std::pair<double,double> > > masks;
static const double diffuse_thresh, soil_albedo, snow_albedo, snow_thresh; ///< parametrize the albedo from HS
static const double diffuse_thresh;
};
} //end namespace
......
......@@ -23,9 +23,6 @@ using namespace std;
namespace mio {
const double ProcUnventilatedT::dflt_albedo = .23;
const double ProcUnventilatedT::soil_albedo = .23; //grass
const double ProcUnventilatedT::snow_albedo = .85; //snow
const double ProcUnventilatedT::snow_thresh = .1; //if snow height greater than this threshold -> snow albedo
const double ProcUnventilatedT::vw_thresh = 0.1; //wind speed threshold
ProcUnventilatedT::ProcUnventilatedT(const std::vector<std::string>& vec_args, const std::string& name)
......
......@@ -69,8 +69,7 @@ class ProcUnventilatedT : public ProcessingBlock {
void parse_args(std::vector<std::string> vec_args);
double usr_albedo, usr_vw_thresh;
static const double dflt_albedo, soil_albedo, snow_albedo;
static const double snow_thresh, vw_thresh;
static const double dflt_albedo, vw_thresh;
bool nakamura; //use Nakamura or Huwald model
};
......
......@@ -191,6 +191,10 @@ ProcessingBlock* BlockFactory::getBlock(const std::string& blockname, const std:
}
const double ProcessingBlock::soil_albedo = .23; //grass
const double ProcessingBlock::snow_albedo = .85; //snow
const double ProcessingBlock::snow_thresh = .1; //if snow height greater than this threshold -> snow albedo
ProcessingBlock::ProcessingBlock(const std::string& name) : properties(), block_name(name)
{}
......
......@@ -76,13 +76,13 @@ class ProcessingBlock {
void convert_args(const size_t& min_nargs, const size_t& max_nargs,
const std::vector<std::string>& vec_args, std::vector<double>& dbl_args) const;
static bool is_soft(std::vector<std::string>& vec_args);
static void readCorrections(const std::string& filter, const std::string& filename, const char& c_type, const double& init, std::vector<double> &corrections);
ProcessingProperties properties;
const std::string block_name;
static const double soil_albedo, snow_albedo, snow_thresh; ///< parametrize the albedo from HS
};
class BlockFactory {
......
Supports Markdown
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