WSL/SLF GitLab Repository

Commit 84a8c69f authored by Mathias Bavay's avatar Mathias Bavay
Browse files

Spatial resampling has been added. This is still quite primitive (no end-user...

Spatial resampling has been added. This is still quite primitive (no end-user front end or interaction, only nearest neighbor or bilinear), but can nevertheless be convenient. Since the "round" function call was needed, the VC++ implementation has been moved to IOUtils so no matter what is the compiler, we can use "round" in the code (this is NOT in the IOUtils namespace, but still in the mio namespace). 

Several obsolte comments/hacks have been removed and the DEBUG_ARITHM flag commented out, since it does not belong into a library (this is per process, not per object). The VC++ "equivalent" flag still needs to be checked (ie: is it per process or per object?). A missing "required" flag for cmake for Oracle has been added.

Finally, the lsm file had been forgotten in the last release... this is now in order.
parent d1dfa76b
......@@ -20,16 +20,19 @@ SET(CMAKE_IMPORT_LIBRARY_PREFIX "lib") #for Visual C++ import libraries
###########################################################
#platform specific. First, compiler specific flags, then system specific flags
SET(DEBUG_ARITHM ON CACHE BOOL "Force crash the application when doing an arithmetic exception")
#SET(DEBUG_ARITHM ON CACHE BOOL "Force crash the application when doing an arithmetic exception")
OPTION( BUILD_SHARED_LIBS "Set to OFF to build only static libraries" ON )
IF(CMAKE_COMPILER_IS_GNUCXX)
SET(WARNINGS "-Wall")
SET(PROFILING "-pg -fprofile-arcs")
SET(EXTRA_WARNINGS "-Wextra -ansi -pedantic")
IF(DEBUG_ARITHM)
LIST(APPEND CFLAGS " -DDEBUG_ARITHM -D_USE_MATH_DEFINES") #USE_MATH_DEFINES needed for Win32
ENDIF(DEBUG_ARITHM)
IF(WIN32)
LIST(APPEND CFLAGS " -D_USE_MATH_DEFINES") #USE_MATH_DEFINES needed for Win32
ENDIF(WIN32)
#IF(DEBUG_ARITHM)
# LIST(APPEND CFLAGS " -DDEBUG_ARITHM")
#ENDIF(DEBUG_ARITHM)
SET(OPTIM "-g -O3 -DNDEBUG")
EXECUTE_PROCESS(COMMAND ${CMAKE_CXX_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION)
IF (GCC_VERSION VERSION_GREATER 4.2 OR GCC_VERSION VERSION_EQUAL 4.2)
......@@ -48,9 +51,9 @@ IF(MSVC)
SET(ARCH_SAFE "")
SET(DEBUG "/Z7 /Od /D__DEBUG /MDd")
LIST(APPEND CFLAGS " /D_CRT_SECURE_NO_WARNINGS /D_USE_MATH_DEFINES") #Za: strict ansi
IF(DEBUG_ARITHM)
LIST(APPEND CFLAGS " /EHa ")
ENDIF(DEBUG_ARITHM)
#IF(DEBUG_ARITHM)
# LIST(APPEND CFLAGS " /EHa ")
#ENDIF(DEBUG_ARITHM)
ENDIF(MSVC)
IF(UNIX)
......
......@@ -79,6 +79,7 @@ METEOIO_OBJ = $(SRCDIR)/IOManager.o \
$(SRCDIR)/IOPlugin.o \
$(SRCDIR)/MeteoProcessor.o \
$(SRCDIR)/ResamplingAlgorithms.o \
$(SRCDIR)/ResamplingAlgorithms2D.o \
$(SRCDIR)/Meteo1DInterpolator.o \
$(SRCDIR)/InterpolationAlgorithms.o \
$(SRCDIR)/A3DIO.o \
......
Begin4
Title: MeteoIO
Version: 2.1.0
Entered-date: 2011-06-24
Entered-date: 2011-06-27
Description: Meteorological data preprocessing library: it covers data retrieval, data filtering, data transformations and statistical spatial interpolations. Convenience classes are also available for related issues.
Keywords: meteorological data access filtering spatial interpolation
Author: bavay@slf.ch (Mathias Bavay)
Maintained-by: bavay@slf.ch (Mathias Bavay)
Primary-site: http://slfsmm.indefero.net p/meteoio/downloads/
Primary-site: http://slfsmm.indefero.net p/meteoio/downloads/55/get/
1.2 M MeteoIO-2.1.0-src.tgz
Home-page: http://slfsmm.indefero.net/p/meteoio/
Platforms: Linux and other Unices, Windows, OsX
......
......@@ -21,6 +21,7 @@ SET(meteoio_sources
IOPlugin.cc
MeteoProcessor.cc
ResamplingAlgorithms.cc
ResamplingAlgorithms2D.cc
Meteo1DInterpolator.cc
InterpolationAlgorithms.cc
A3DIO.cc
......
......@@ -33,6 +33,23 @@
namespace mio {
#ifdef _MSC_VER
//This is C99, Microsoft should move on and suppport it, it is almost 15 years old!!
double round(const double& x) {
//middle value point test
if (ceil(x+0.5) == floor(x+0.5)) {
const int a = (int)ceil(x);
if (a%2 == 0) {
return ceil(x);
} else {
return floor(x);
}
} else {
return floor(x+0.5);
}
}
#endif
bool IOUtils::checkEpsilonEquality(const double& val1, const double& val2, const double& epsilon)
{
if (((val1-epsilon) < val2) && ((val1+epsilon) > val2)) {
......
......@@ -51,6 +51,10 @@
namespace mio {
#ifdef _MSC_VER
double round(const double& x);
#endif
class MeteoData;
class Coords;
class Config;
......
......@@ -68,6 +68,7 @@
#include <meteoio/meteolaws/Suntrajectory.h>
#include <meteoio/MeteoProcessor.h>
#include <meteoio/ResamplingAlgorithms.h>
#include <meteoio/ResamplingAlgorithms2D.h>
#include <meteoio/StationData.h>
#include <meteoio/Timer.h>
......
/***********************************************************************************/
/* Copyright 2011 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#include <meteoio/IOUtils.h>
#include <meteoio/ResamplingAlgorithms2D.h>
#include <cmath>
using namespace std;
namespace mio {
/**
* @brief Bilinear spatial data resampling
*/
const Grid2DObject ResamplingAlgorithms2D::BilinearResampling(const Grid2DObject &i_grid, const double &factor)
{
const double cellsize = i_grid.cellsize/factor;
const unsigned int ncols = (unsigned int)round( i_grid.ncols*factor );
const unsigned int nrows = (unsigned int)round( i_grid.nrows*factor );
Grid2DObject o_grid(ncols, nrows, cellsize, i_grid.llcorner);
Bilinear_nodata(o_grid, i_grid); //GridObjects always keep nodata
return o_grid;
}
void ResamplingAlgorithms2D::NearestNeighbor(Grid2DObject &o_grid, const Grid2DObject &i_grid)
{
const unsigned int org_ncols = i_grid.ncols;
const unsigned int org_nrows = i_grid.nrows;
const double scale_x = (double)o_grid.ncols / (double)org_ncols;
const double scale_y = (double)o_grid.nrows / (double)org_nrows;
for (unsigned int jj=0; jj<o_grid.nrows; jj++) {
unsigned int org_jj = (unsigned int) round( (double)jj/scale_y );
if(org_jj>=org_nrows) org_jj=org_nrows;
for (unsigned int ii=0; ii<o_grid.ncols; ii++) {
unsigned int org_ii = (unsigned int) round( (double)ii/scale_x );
if(org_ii>=org_ncols) org_ii=org_ncols;
o_grid(ii,jj) = i_grid(org_ii, org_jj);
}
}
}
void ResamplingAlgorithms2D::Bilinear_raw(Grid2DObject &o_grid, const Grid2DObject &i_grid)
{
const unsigned int org_ncols = i_grid.ncols;
const unsigned int org_nrows = i_grid.nrows;
const double scale_x = (double)o_grid.ncols / (double)org_ncols;
const double scale_y = (double)o_grid.nrows / (double)org_nrows;
for (unsigned int jj=0; jj<o_grid.nrows; jj++) {
const double org_y = (double)jj/scale_y;
const unsigned int org_jj = (unsigned int) floor(org_y);
const double y = org_y - (double)org_jj; //normalized y, between 0 and 1
for (unsigned int ii=0; ii<o_grid.ncols; ii++) {
const double org_x = (double)ii/scale_x;
const unsigned int org_ii = (unsigned int) floor(org_x);
const double x = org_x - (double)org_ii; //normalized x, between 0 and 1
if(org_jj>=(org_nrows-1) || org_ii>=(org_ncols-1)) {
o_grid(ii,jj) = i_grid(org_ii, org_jj);
continue;
}
const double f_0_0 = i_grid(org_ii, org_jj);
const double f_1_0 = i_grid(org_ii+1, org_jj);
const double f_0_1 = i_grid(org_ii, org_jj+1);
const double f_1_1 = i_grid(org_ii+1, org_jj+1);
o_grid(ii,jj) = f_0_0 * (1.-x)*(1.-y) + f_1_0 * x*(1.-y) + f_0_1 * (1.-x)*y + f_1_1 *x*y;
}
}
}
void ResamplingAlgorithms2D::Bilinear_nodata(Grid2DObject &o_grid, const Grid2DObject &i_grid)
{
const unsigned int org_ncols = i_grid.ncols;
const unsigned int org_nrows = i_grid.nrows;
const double scale_x = (double)o_grid.ncols / (double)org_ncols;
const double scale_y = (double)o_grid.nrows / (double)org_nrows;
for (unsigned int jj=0; jj<o_grid.nrows; jj++) {
const double org_y = (double)jj/scale_y;
const unsigned int org_jj = (unsigned int) floor(org_y);
const double y = org_y - (double)org_jj; //normalized y, between 0 and 1
for (unsigned int ii=0; ii<o_grid.ncols; ii++) {
const double org_x = (double)ii/scale_x;
const unsigned int org_ii = (unsigned int) floor(org_x);
const double x = org_x - (double)org_ii; //normalized x, between 0 and 1
if(org_jj>=(org_nrows-1) || org_ii>=(org_ncols-1)) {
o_grid(ii,jj) = i_grid(org_ii, org_jj);
continue;
}
const double f_0_0 = i_grid(org_ii, org_jj);
const double f_1_0 = i_grid(org_ii+1, org_jj);
const double f_0_1 = i_grid(org_ii, org_jj+1);
const double f_1_1 = i_grid(org_ii+1, org_jj+1);
double avg_value = 0.;
unsigned int avg_count = 0;
if(f_0_0!=IOUtils::nodata) {
avg_value += f_0_0;
avg_count++;
}
if(f_1_0!=IOUtils::nodata) {
avg_value += f_1_0;
avg_count++;
}
if(f_0_1!=IOUtils::nodata) {
avg_value += f_0_1;
avg_count++;
}
if(f_1_1!=IOUtils::nodata) {
avg_value += f_1_1;
avg_count++;
}
if(avg_count<=2) {
o_grid(ii,jj) = IOUtils::nodata;
continue;
}
if(avg_count==4) {
o_grid(ii,jj) = f_0_0 * (1.-x)*(1.-y) + f_1_0 * x*(1.-y) + f_0_1 * (1.-x)*y + f_1_1 *x*y;
continue;
}
double value = 0.;
const double avg = avg_value/(double)avg_count;
if(f_0_0!=IOUtils::nodata) value += f_0_0 * (1.-x)*(1.-y);
else value += avg * (1.-x)*(1.-y);
if(f_1_0!=IOUtils::nodata) value += f_1_0 * x*(1.-y);
else value += avg * x*(1.-y);
if(f_0_1!=IOUtils::nodata) value += f_0_1 * (1.-x)*y;
else value += avg * (1.-x)*y;
if(f_1_1!=IOUtils::nodata) value += f_1_1 *x*y;
else value += avg *x*y;
o_grid(ii,jj) = value;
}
}
}
} //namespace
/***********************************************************************************/
/* Copyright 2011 WSL Institute for Snow and Avalanche Research SLF-DAVOS */
/***********************************************************************************/
/* This file is part of MeteoIO.
MeteoIO is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
MeteoIO is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with MeteoIO. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __RESAMPLINGALGORITHMS2D_H__
#define __RESAMPLINGALGORITHMS2D_H__
#include <meteoio/Grid2DObject.h>
#include <iostream>
#include <string>
namespace mio {
/**
* @class ResamplingAlgorithms2D
* @brief Spatial resampling algorithms
*
* @ingroup stats
* @author Mathias Bavay
* @date 2011-06-29
*/
class ResamplingAlgorithms2D {
public:
//Available algorithms
//static void NearestNeighbour(const Grid2DObject &i_grid, const double &factor);
static const Grid2DObject BilinearResampling(const Grid2DObject &i_grid, const double &factor);
private:
static void Bilinear_raw(Grid2DObject &o_grid, const Grid2DObject &i_grid);
static void Bilinear_nodata(Grid2DObject &o_grid, const Grid2DObject &i_grid);
static void NearestNeighbor(Grid2DObject &o_grid, const Grid2DObject &i_grid);
};
} //end namespace
#endif
......@@ -169,7 +169,7 @@ double Interpol1D::std_dev(const std::vector<double>& X)
}
double Interpol1D::covariance(const std::vector<double>& X, const std::vector<double>& Y)
{//HACK: we should use a compensated formula here, similarly to the variance computation!
{//this is a simple but still compensated covariance computation (see the notes on the variance)
if(X.size()!=Y.size())
throw IOException("Vectors should have the same size for covariance!", AT);
const size_t n = X.size();
......
......@@ -349,7 +349,7 @@ void marshal_DOUBLE2D(POPBuffer &buf, DOUBLE2D &data, int maxsize, int flag, POP
}
void marshal_DOUBLE3D(POPBuffer &buf, DOUBLE3D &data, int maxsize, int flag, POPMemspool *temp)
{//HACK: this marshalling is sub-optimal!!
{
(void)maxsize;
(void)*temp;
if (flag & FLAG_MARSHAL) {
......
......@@ -148,7 +148,7 @@ IF(PLUGIN_GSNIO)
ENDIF(PLUGIN_GSNIO)
IF(PLUGIN_IMISIO)
FIND_PACKAGE(OCCI)
FIND_PACKAGE(OCCI REQUIRED)
INCLUDE_DIRECTORIES(${INCLUDE_DIRECTORIES} ${OCCI_INCLUDE_DIR})
ADD_LIBRARY(${IMISIONAME} ImisIO.cc)
TARGET_LINK_LIBRARIES(${IMISIONAME} ${OCCI_LIBRARIES} ${SHAREDNAME})
......
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