MI - Fimex
CDMInterpolator.h
Go to the documentation of this file.
1 /*
2  * Fimex
3  *
4  * (C) Copyright 2008, met.no
5  *
6  * Project Info: https://wiki.met.no/fimex/start
7  *
8  * This library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation; either version 2.1 of the License, or
11  * (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
15  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
16  * License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
21  * USA.
22  */
23 
24 #ifndef CDMINTERPOLATOR_H_
25 #define CDMINTERPOLATOR_H_
26 
27 #include <vector>
28 #include <map>
29 #include "fimex/CDMReader.h"
33 #include "fimex/deprecated.h"
34 
35 
36 namespace MetNoFimex
37 {
38 // forward decl
39 class CoordinateSystem;
40 struct CDMInterpolatorInternals;
41 
49 public:
50  virtual void operator()(float* array, size_t nx, size_t ny) = 0;
51  virtual ~InterpolatorProcess2d() {};
52 };
53 
55 private:
56  float relaxCrit_;
57  float corrEff_;
58  size_t maxLoop_;
59 public:
60  InterpolatorFill2d(float relaxCrit, float corrEff, size_t maxLoop)
61  : relaxCrit_(relaxCrit), corrEff_(corrEff), maxLoop_(maxLoop) {}
62  virtual void operator()(float* array, size_t nx, size_t ny) {size_t nChanged; mifi_fill2d_f(nx, ny, array, relaxCrit_, corrEff_, maxLoop_, &nChanged);};
63 };
64 
66 private:
67  unsigned short repeat_;
68  char setWeight_;
69 public:
70  InterpolatorCreepFill2d(unsigned short repeat, char setWeight)
71  : repeat_(repeat), setWeight_(setWeight) {}
72  virtual void operator()(float* array, size_t nx, size_t ny) {size_t nChanged; mifi_creepfill2d_f(nx, ny, array, repeat_, setWeight_, &nChanged);};
73 };
74 
76 private:
77  unsigned short repeat_;
78  char setWeight_;
79  float defVal_;
80 public:
81  InterpolatorCreepFillVal2d(unsigned short repeat, char setWeight, float defaultValue)
82  : repeat_(repeat), setWeight_(setWeight), defVal_(defaultValue) {}
83  virtual void operator()(float* array, size_t nx, size_t ny) {size_t nChanged; mifi_creepfillval2d_f(nx, ny, array, defVal_, repeat_, setWeight_, &nChanged);};
84 };
85 
86 
97 {
98 private:
99  // the pimpl
100  class boost::shared_ptr<CDMInterpolatorInternals> p_;
102  void axisString2Vector(const std::string& axis, std::vector<double>& axis_vals, int axisId);
103  void changeProjectionByProjectionParameters(int method, const std::string& proj_input, const std::vector<double>& out_x_axis, const std::vector<double>& out_y_axis, const std::string& out_x_axis_unit, const std::string& out_y_axis_unit, CDMDataType out_x_axis_type, CDMDataType out_y_axis_type);
104  void changeProjectionByCoordinates(int method, const std::string& proj_input, const std::vector<double>& out_x_axis, const std::vector<double>& out_y_axis, const std::string& out_x_axis_unit, const std::string& out_y_axis_unit, CDMDataType out_x_axis_type, CDMDataType out_y_axis_type);
105  void changeProjectionByForwardInterpolation(int method, const std::string& proj_input, const std::vector<double>& out_x_axis, const std::vector<double>& out_y_axis, const std::string& out_x_axis_unit, const std::string& out_y_axis_unit, CDMDataType out_x_axis_type, CDMDataType out_y_axis_type);
106 
107  void changeProjectionByProjectionParametersToLatLonTemplate(int method,
108  const std::string& proj_input,
109  const std::vector<double>& out_x_axis,
110  const std::vector<double>& out_y_axis,
111  const std::string& out_x_axis_unit,
112  const std::string& out_y_axis_unit,
113  CDMDataType out_x_axis_type,
114  CDMDataType out_y_axis_type,
115  DataPtr templateLatValues,
116  DataPtr templateLonValues);
117 
121  std::map<std::string, boost::shared_ptr<const CoordinateSystem> > findBestCoordinateSystemsAndProjectionVars(bool withProjection);
126  bool hasXYSpatialVectors() const;
134  bool allXYSpatialVectorsHaveSameHorizontalId(std::string horizontalId, std::string& exampleVar1, std::string& exampleVar2) const;
135 public:
136  CDMInterpolator(boost::shared_ptr<CDMReader> dataReader);
137  virtual ~CDMInterpolator();
143  virtual DataPtr getDataSlice(const std::string& varName, size_t unLimDimPos = 0);
148  virtual DataPtr getDataSlice(const std::string& varName, const SliceBuilder& sb);
149 
162  virtual void changeProjection(int method, const std::string& proj_input, const std::vector<double>& out_x_axis, const std::vector<double>& out_y_axis, const std::string& out_x_axis_unit, const std::string& out_y_axis_unit, CDMDataType out_x_axis_type, CDMDataType out_y_axis_type);
175  MIFI_DEPRECATED(virtual void changeProjection(int method, const std::string& proj_input, const std::vector<double>& out_x_axis, const std::vector<double>& out_y_axis, const std::string& out_x_axis_unit, const std::string& out_y_axis_unit));
189  virtual void changeProjection(int method, const std::string& proj_input, const std::string& out_x_axis, const std::string& out_y_axis, const std::string& out_x_axis_unit, const std::string& out_y_axis_unit, const std::string& out_x_axis_type = "double", const std::string& out_y_axis_type = "double");
203  virtual void changeProjection(int method, const std::string& netcdf_template_file);
211  virtual void changeProjection(int method, const std::vector<double>& lonVals, const std::vector<double>& latVals);
225  virtual void changeProjectionToCrossSections(int method, const std::vector<CrossSectionDefinition>& crossSections);
230  virtual void setLatitudeName(const std::string& latName);
234  virtual const std::string& getLatitudeName() const;
239  virtual void setLongitudeName(const std::string& lonName);
243  virtual const std::string& getLongitudeName() const;
255  virtual double getMaxDistanceOfInterest(const std::vector<double>& out_y_axis, const std::vector<double>& out_x_axis, bool isMetric) const;
262  virtual void setDistanceOfInterest(double dist);
268  virtual void addPreprocess(boost::shared_ptr<InterpolatorProcess2d> process);
274  virtual void addPostprocess(boost::shared_ptr<InterpolatorProcess2d> process);
275 };
276 
283 extern boost::shared_array<float> data2InterpolationArray(const DataPtr& inData, double badValue);
284 
293 extern DataPtr interpolationArray2Data(CDMDataType newType, boost::shared_array<float> iData, size_t size, double badValue);
294 
295 
296 }
297 
298 #endif /*CDMINTERPOLATOR_H_*/
Definition: CDMInterpolator.h:54
int mifi_creepfillval2d_f(size_t nx, size_t ny, float *field, float defaultVal, unsigned short repeat, char setWeight, size_t *nChanged)
Method to fill undefined values in a 2d field in stable time.
basic_string< char > string
boost::shared_ptr< Data > DataPtr
Definition: DataDecl.h:39
Definition: CDMInterpolator.h:48
virtual void operator()(float *array, size_t nx, size_t ny)=0
STL class.
Definition: SliceBuilder.h:46
int mifi_fill2d_f(size_t nx, size_t ny, float *field, float relaxCrit, float corrEff, size_t maxLoop, size_t *nChanged)
Method to fill undefined values in a 2d field.
MIFI_DEPRECATED(std::vector< CDMAttribute > projStringToAttributes(std::string projStr))
convert a proj4 string to a list of CDMAttributes usable for CF-1.0 projection variable ...
InterpolatorFill2d(float relaxCrit, float corrEff, size_t maxLoop)
Definition: CDMInterpolator.h:60
virtual DataPtr getDataSlice(const std::string &varName, size_t unLimDimPos)=0
data-reading function to be called from the CDMWriter
Definition: C_CDMReader.h:35
Basic interface for CDM reading and manipulation classes.
Definition: CDMReader.h:53
DataPtr interpolationArray2Data(CDMDataType newType, boost::shared_array< float > iData, size_t size, double badValue)
Definition: CDMInterpolator.h:65
Definition: CDMInterpolator.h:96
virtual void operator()(float *array, size_t nx, size_t ny)
Definition: CDMInterpolator.h:83
InterpolatorCreepFillVal2d(unsigned short repeat, char setWeight, float defaultValue)
Definition: CDMInterpolator.h:81
virtual void operator()(float *array, size_t nx, size_t ny)
Definition: CDMInterpolator.h:72
Definition: CDMInterpolator.h:75
int mifi_creepfill2d_f(size_t nx, size_t ny, float *field, unsigned short repeat, char setWeight, size_t *nChanged)
Method to fill undefined values in a 2d field in stable time.
CDMDataType
Definition: CDMDataType.h:35
virtual ~InterpolatorProcess2d()
Definition: CDMInterpolator.h:51
InterpolatorCreepFill2d(unsigned short repeat, char setWeight)
Definition: CDMInterpolator.h:70
virtual void operator()(float *array, size_t nx, size_t ny)
Definition: CDMInterpolator.h:62
boost::shared_array< float > data2InterpolationArray(const DataPtr &inData, double badValue)