WSL/SLF GitLab Repository

Commit 8ad5d61f authored by Mathias Bavay's avatar Mathias Bavay
Browse files

This addresses the 2D part of issue 168: the ability to specify which meteo...

This addresses the 2D part of issue 168: the ability to specify which meteo parameter and time step to read/write from/to a 2D grid. This should be the prefered reading method in the future, since it leaves to the plugin the task of building the file name, extension, database table, etc This also provides added metadata and more control over the writing process.
parent 71ee4ea8
......@@ -100,6 +100,12 @@ void A3DIO::read2DGrid(Grid2DObject&, const std::string&)
throw IOException("Nothing implemented here", AT);
}
void A3DIO::read2DGrid(Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::readDEM(DEMObject& dem_out)
{
//Nothing so far
......@@ -128,6 +134,12 @@ void A3DIO::write2DGrid(const Grid2DObject&, const std::string&)
throw IOException("Nothing implemented here", AT);
}
void A3DIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void A3DIO::writeMeteoData(const std::vector< std::vector<MeteoData> >& vec_data, const std::string&)
{
if(vec_data.size() > 0) {
......
......@@ -39,6 +39,7 @@ class A3DIO : public IOInterface {
~A3DIO() throw();
virtual void read2DGrid(Grid2DObject& dem_out, const std::string& name="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
......@@ -56,6 +57,7 @@ class A3DIO : public IOInterface {
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
static const double plugin_nodata; //plugin specific nodata value, e.g. -9999
......
......@@ -63,6 +63,13 @@ void BufferedIOHandler::read2DGrid(Grid2DObject& in_grid2Dobj, const std::string
in_grid2Dobj = tmpgrid2D;
}
void BufferedIOHandler::read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date)
{
std::stringstream ss;
ss << MeteoGrids::getParameterName(parameter) << "::" << date.toString(Date::ISO);
read2DGrid(grid_out, ss.str());
}
void BufferedIOHandler::readDEM(DEMObject& in_grid2Dobj)
{
std::map<std::string, Grid2DObject>::iterator it = mapBufferedGrids.find("/:DEM");
......@@ -316,9 +323,14 @@ void BufferedIOHandler::readSpecialPoints(std::vector<Coords>& in_cpa)
iohandler.readSpecialPoints(in_cpa);
}
void BufferedIOHandler::write2DGrid(const Grid2DObject& in_grid2Dobj, const std::string& in_name)
void BufferedIOHandler::write2DGrid(const Grid2DObject& grid_in, const std::string& in_name)
{
iohandler.write2DGrid(grid_in, in_name);
}
void BufferedIOHandler::write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date)
{
iohandler.write2DGrid(in_grid2Dobj, in_name);
iohandler.write2DGrid(grid_in, parameter, date);
}
void BufferedIOHandler::clearBuffer(){
......
......@@ -96,6 +96,7 @@ class BufferedIOHandler : public IOInterface {
void clearBuffer();
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM(DEMObject& dem_out);
virtual void readAssimilationData(const Date& date_in, Grid2DObject& da_out);
virtual void readLanduse(Grid2DObject& landuse_out);
......@@ -111,6 +112,7 @@ class BufferedIOHandler : public IOInterface {
const std::string& name="");
#endif
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& options="");
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
/**
* @brief Returns the average sampling rate in the data.
......
......@@ -201,10 +201,16 @@ IOInterface* IOHandler::getPlugin(const std::string& cfgkey, const std::string&
return (mapit->second).io;
}
void IOHandler::read2DGrid(Grid2DObject& out_grid, const std::string& i_filename)
void IOHandler::read2DGrid(Grid2DObject& grid_out, const std::string& i_filename)
{
IOInterface *plugin = getPlugin("GRID2D", "Input");
plugin->read2DGrid(out_grid, i_filename);
plugin->read2DGrid(grid_out, i_filename);
}
void IOHandler::read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date)
{
IOInterface *plugin = getPlugin("GRID2D", "Input");
plugin->read2DGrid(grid_out, parameter, date);
}
void IOHandler::readDEM(DEMObject& dem_out)
......@@ -285,6 +291,12 @@ void IOHandler::write2DGrid(const Grid2DObject& grid_in, const std::string& name
plugin->write2DGrid(grid_in, name);
}
void IOHandler::write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date)
{
IOInterface *plugin = getPlugin("GRID2D", "Output");
plugin->write2DGrid(grid_in, parameter, date);
}
void IOHandler::parse_copy_config()
{
/**
......
......@@ -58,6 +58,7 @@ class IOHandler : public IOInterface {
//methods defined in the IOInterface class
virtual void read2DGrid(Grid2DObject& out_grid, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
virtual void readStationData(const Date& date,
......@@ -77,6 +78,7 @@ class IOHandler : public IOInterface {
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
#ifndef _POPC_
friend std::ostream& operator<<(std::ostream& os, const IOHandler& data);
......
......@@ -50,6 +50,7 @@ parclass IOHandler {
//methods defined in the IOInterface class
virtual void read2DGrid([out]Grid2DObject& out_grid, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM([out]DEMObject& dem_out);
virtual void readLanduse([out]Grid2DObject& landuse_out);
virtual void readStationData([in]const Date& date,
......@@ -63,13 +64,14 @@ parclass IOHandler {
virtual void readAssimilationData([in] const Date&,[out] Grid2DObject& da_out);
virtual void readSpecialPoints([out,proc=marshal_vec_coords]std::vector<Coords>& pts);
virtual void write2DGrid([in]const Grid2DObject& grid_in, [in]const std::string& name);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
//friend std::ostream& operator<<(std::ostream& os, const IOHandler& data); //not "friends" in a parclass!
std::string toString()/* const*/; //HACK for POPC
private:
void loadDynamicPlugins();
void loadPlugin(const std::string& libname, const std::string& classname,
void loadPlugin(const std::string& libname, const std::string& classname,
DynamicLibrary*& dynLibrary, IOInterface*& io);
void deletePlugin(DynamicLibrary*& dynLibrary, IOInterface*& io);
void registerPlugins();
......
......@@ -102,6 +102,15 @@ class IOInterface : public PluginObject {
*/
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="") = 0;
/**
* @brief Read the given meteo parameter into a Grid2DObject.
* Each plugin has its own logic for finding the requested meteo parameter grid.
* @param grid_out A Grid2DObject instance
* @param parameter The meteo parameter grid type to return (ie: air temperature, wind component, etc)
* @param date date of the data to read
*/
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date) = 0;
/**
* @brief Parse the DEM (Digital Elevation Model) into the Grid2DObject
*
......@@ -224,6 +233,14 @@ class IOInterface : public PluginObject {
* @param options (string) Identifier usefull for the output plugin (it could become part of a file name, a db table, etc)
*/
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& options="") = 0;
/**
* @brief Write a Grid2DObject comtaining a known meteorological parameter
* @param grid_in (Grid2DObject) The grid to write
* @param parameter The meteo parameter grid type of the provided grid object (ie: air temperature, wind component, etc)
* @param date date of the data to write
*/
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date) = 0;
};
} //end namespace
......
......@@ -282,6 +282,15 @@ void IOManager::read2DGrid(Grid2DObject& grid2D, const std::string& filename)
}
}
void IOManager::read2DGrid(Grid2DObject& grid2D, const MeteoGrids::Parameters& parameter, const Date& date)
{
if (processing_level == IOManager::raw){
rawio.read2DGrid(grid2D, parameter, date);
} else {
bufferedio.read2DGrid(grid2D, parameter, date);
}
}
void IOManager::readDEM(DEMObject& grid2D)
{
if (processing_level == IOManager::raw){
......@@ -327,6 +336,15 @@ void IOManager::write2DGrid(const Grid2DObject& grid2D, const std::string& name)
}
}
void IOManager::write2DGrid(const Grid2DObject& grid2D, const MeteoGrids::Parameters& parameter, const Date& date)
{
if (processing_level == IOManager::raw){
rawio.write2DGrid(grid2D, parameter, date);
} else {
bufferedio.write2DGrid(grid2D, parameter, date);
}
}
std::string IOManager::toString() const {
stringstream os;
......
......@@ -39,11 +39,13 @@ class IOManager {
//Legacy support to support functionality of the IOInterface superclass:
void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
void readDEM(DEMObject& dem_out);
void readAssimilationData(const Date& date_in, Grid2DObject& da_out);
void readLanduse(Grid2DObject& landuse_out);
void readSpecialPoints(std::vector<Coords>& pts);
void write2DGrid(const Grid2DObject& grid_in, const std::string& options="");
void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
//end legacy support
size_t getStationData(const Date& date, STATION_TIMESERIE& vecStation);
......
......@@ -44,11 +44,13 @@ parclass IOManager {
//Legacy support to support functionality of the IOInterface superclass:
void read2DGrid([out]Grid2DObject& grid_out, [in]const std::string& parameter="");
void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
void readDEM([out]DEMObject& dem_out);
void readAssimilationData([in]const Date& date_in, [out]Grid2DObject& da_out);
void readLanduse([out]Grid2DObject& landuse_out);
void readSpecialPoints([out]std::vector<Coords>& pts);
void write2DGrid([in]const Grid2DObject& grid_in, [in]const std::string& options="");
void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
//end legacy support
unsigned int getStationData([in]const Date& date, [out, proc=marshal_STATION_TIMESERIE]STATION_TIMESERIE& vecStation);
......@@ -57,13 +59,13 @@ parclass IOManager {
[out, proc=marshal_vector_METEO_TIMESERIE]std::vector< METEO_TIMESERIE >& vecMeteo);
unsigned int getMeteoData([in]const Date& i_date, [out, proc=marshal_METEO_TIMESERIE]METEO_TIMESERIE& vecMeteo);
void interpolate([in]const Date& date, [in]const DEMObject& dem, [in, proc=marshal_MeteoParameters]/*const*/ MeteoData::Parameters& meteoparam,
[out]Grid2DObject& result, [out]std::string& info_string);
void interpolate([in]const Date& date, [in]const DEMObject& dem, [in, proc=marshal_MeteoParameters]/*const*/ MeteoData::Parameters& meteoparam,
[out]Grid2DObject& result); //HACK popc
void setProcessingLevel([in]const unsigned int& i_level);
double getAvgSamplingRate();
......
......@@ -21,6 +21,44 @@
using namespace std;
namespace mio {
/************************************************************
* static section *
************************************************************/
const size_t MeteoGrids::nrOfParameters = MeteoGrids::lastparam - MeteoGrids::firstparam + 1;
std::vector<std::string> MeteoGrids::paramname;
const bool MeteoGrids::__init = MeteoGrids::initStaticData();
bool MeteoGrids::initStaticData()
{
//the order must be the same as in the enum
paramname.push_back("TA");
paramname.push_back("RH");
paramname.push_back("VW");
paramname.push_back("DW");
paramname.push_back("VW_MAX");
paramname.push_back("ISWR");
paramname.push_back("RSWR");
paramname.push_back("ILWR");
paramname.push_back("HS");
paramname.push_back("HNW");
paramname.push_back("TSG");
paramname.push_back("TSS");
paramname.push_back("P");
paramname.push_back("U");
paramname.push_back("V");
paramname.push_back("W");
return true;
}
const std::string& MeteoGrids::getParameterName(const size_t& parindex)
{
if (parindex >= MeteoGrids::nrOfParameters)
throw IndexOutOfBoundsException("Trying to get name for parameter that does not exist", AT);
return paramname[parindex];
}
/************************************************************
* static section *
************************************************************/
......
......@@ -30,6 +30,47 @@
namespace mio {
/**
* @class MeteoGrids
* @brief A class to represent the meteorological parameters that could be contained in a grid.
* This should be very close to MeteoData with a few additions (like the wind u,v,w)
* @ingroup data_str
* @author Mathias Bavay
* @date 2011-12-22
*/
class MeteoGrids {
public:
/// \anchor meteogrids this enum provides names for possible meteogrids (from an ARPS file, etc)
enum Parameters {firstparam=0,
TA=firstparam, ///< Air temperature
RH, ///< Relative humidity
VW, ///< Wind velocity
DW, ///< Wind direction
VW_MAX, ///< Maximum wind velocity
ISWR, ///< Incoming short wave radiation
RSWR, ///< Reflected short wave radiation
ILWR, ///< Incoming long wave radiation
HS, ///< Snow height
HNW, ///< New water equivalent height
TSG, ///< Temperature ground surface
TSS, ///< Temperature snow surface
P, ///< Air pressure
U, ///< East component of wind
V, ///< North component of wind
W, ///< Vertical component of wind
lastparam=W};
static const size_t nrOfParameters; ///<holds the number of meteo parameters stored in MeteoData
static const std::string& getParameterName(const size_t& parindex);
private:
//static methods
static std::vector<std::string> paramname;
static const bool __init; ///<helper variable to enable the init of static collection data
static bool initStaticData();///<initialize the static map meteoparamname
};
/**
* @class MeteoData
* @brief A class to represent a singular measurement received from one station at a certain time (represented by the Date object)
......@@ -129,7 +170,7 @@ class MeteoData {
Date date; ///<Timestamp of the measurement
StationData meta; ///<The meta data of the measurement
private:
private:
//static methods
static std::map<size_t, std::string> static_meteoparamname; ///<Associate a name with meteo parameters in Parameters
static std::vector<std::string> s_default_paramname;
......
......@@ -31,6 +31,8 @@ namespace mio {
*
* These specifications should reflect commonly accepted practise.
*
* Finally, the naming scheme for meteo grids should be: YYYYMMDDHHmm_{MeteoGrids::Parameters}.asc
*
* @section lus_format Land Use Format
* The landuse codes are coming from PREVAH and have the format 1LLDC where:
* - LL is the land use code as given in the table given below
......@@ -213,6 +215,13 @@ void ARCIO::read2DGrid(Grid2DObject& grid_out, const std::string& filename)
cleanup();
}
void ARCIO::read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date)
{
std::stringstream ss;
ss << date.toString(Date::NUM) << "_" << MeteoGrids::getParameterName(parameter) << ".asc";
read2DGrid(grid_out, ss.str());
}
void ARCIO::readDEM(DEMObject& dem_out)
{
string filename="";
......@@ -303,6 +312,13 @@ void ARCIO::write2DGrid(const Grid2DObject& grid_in, const std::string& name)
cleanup();
}
void ARCIO::write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date)
{
std::stringstream ss;
ss << date.toString(Date::NUM) << "_" << MeteoGrids::getParameterName(parameter) << ".asc";
write2DGrid(grid_in, ss.str());
}
#ifndef _METEOIO_JNI
extern "C"
{
......
......@@ -50,6 +50,7 @@ class ARCIO : public IOInterface {
~ARCIO() throw();
virtual void read2DGrid(Grid2DObject& dem_out, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
......@@ -63,6 +64,7 @@ class ARCIO : public IOInterface {
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
void cleanup() throw();
......
......@@ -90,6 +90,11 @@ void ARPSIO::read2DGrid(Grid2DObject& grid_out, const std::string& /*_name*/)
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::read2DGrid(Grid2DObject& /*grid_out*/, const MeteoGrids::Parameters& /*parameter*/, const Date& /*date*/) {
//Nothing so far... TODO
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::read3DGrid(Grid3DObject& grid_out, const std::string& /*in_name*/)
{
std::string meteopathname;
......@@ -183,6 +188,12 @@ void ARPSIO::write2DGrid(const Grid2DObject& /*grid_in*/, const std::string& /*n
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void ARPSIO::initializeGRIDARPS()
{
double v1, v2;
......
......@@ -54,6 +54,7 @@ class ARPSIO : public IOInterface {
~ARPSIO() throw();
virtual void read2DGrid(Grid2DObject& grid_out, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
......@@ -69,6 +70,7 @@ class ARPSIO : public IOInterface {
virtual void readAssimilationData(const Date&, Grid2DObject& da_out);
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& filename);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
void read3DGrid(Grid3DObject& grid_out, const std::string& in_name);
......
......@@ -83,10 +83,15 @@ void BormaIO::cleanup() throw()
}
}
void BormaIO::read2DGrid(Grid2DObject&, const std::string& filename)
void BormaIO::read2DGrid(Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::read2DGrid(Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
(void)filename;
throw IOException("Nothing implemented here", AT);
}
......@@ -446,10 +451,15 @@ void BormaIO::readSpecialPoints(std::vector<Coords>&)
throw IOException("Nothing implemented here", AT);
}
void BormaIO::write2DGrid(const Grid2DObject&, const std::string& name)
void BormaIO::write2DGrid(const Grid2DObject&, const std::string&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void BormaIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
(void)name;
throw IOException("Nothing implemented here", AT);
}
......
......@@ -52,6 +52,7 @@ class BormaIO : public IOInterface {
~BormaIO() throw();
virtual void read2DGrid(Grid2DObject& dem_out, const std::string& parameter="");
virtual void read2DGrid(Grid2DObject& grid_out, const MeteoGrids::Parameters& parameter, const Date& date);
virtual void readDEM(DEMObject& dem_out);
virtual void readLanduse(Grid2DObject& landuse_out);
......@@ -68,6 +69,7 @@ class BormaIO : public IOInterface {
virtual void readSpecialPoints(std::vector<Coords>& pts);
virtual void write2DGrid(const Grid2DObject& grid_in, const std::string& name);
virtual void write2DGrid(const Grid2DObject& grid_in, const MeteoGrids::Parameters& parameter, const Date& date);
private:
void convertUnits(MeteoData& meteo);
......
......@@ -95,6 +95,12 @@ void CosmoXMLIO::read2DGrid(Grid2DObject& /*grid_out*/, const std::string& /*_na
throw IOException("Nothing implemented here", AT);
}
void CosmoXMLIO::read2DGrid(Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void CosmoXMLIO::readDEM(DEMObject& /*dem_out*/)
{
//Nothing so far
......@@ -499,6 +505,12 @@ void CosmoXMLIO::write2DGrid(const Grid2DObject& /*grid_in*/, const std::string&
throw IOException("Nothing implemented here", AT);
}
void CosmoXMLIO::write2DGrid(const Grid2DObject&, const MeteoGrids::Parameters&, const Date&)
{
//Nothing so far
throw IOException("Nothing implemented here", AT);
}
void CosmoXMLIO::cleanup() throw()
{
......
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