UFO
SpatialBinSelector.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 Met Office UK
3  *
4  * This software is licensed under the terms of the Apache Licence Version 2.0
5  * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6  */
7 
8 #include <algorithm>
9 #include <cmath>
10 #include <vector>
11 
12 #include "ufo/utils/Constants.h"
15 
16 namespace ufo {
17 
19  SpatialBinCountRoundingMode roundingMode,
20  bool metOfficeOpsCompatibilityMode)
21  : metOfficeOpsCompatibilityMode_(metOfficeOpsCompatibilityMode),
22  latitudeBinSelector_(latitudeLowerBound_, latitudeUpperBound_, numLatitudeBins) {
23  longitudeBinSelectors_.reserve(numLatitudeBins);
24  for (IndexType latBin = 0; latBin < numLatitudeBins; ++latBin) {
25  ValueType latBinCenter = latitudeBinCenter(latBin);
26 
27  const int equatorToMeridianLengthRatio = 2;
28  const float tentativeNumLongitudeBins =
29  equatorToMeridianLengthRatio * numLatitudeBins *
30  std::cos(latBinCenter * static_cast<float>(Constants::deg2rad));
31  const IndexType numLonBins = roundNumBins(tentativeNumLongitudeBins, roundingMode);
32 
33  if (metOfficeOpsCompatibilityMode)
34  longitudeBinSelectors_.emplace_back(
38  else
39  longitudeBinSelectors_.emplace_back(
40  static_cast<ValueType>(longitudeLowerBound_),
41  static_cast<ValueType>(longitudeUpperBound_), numLonBins);
42  }
43 }
44 
46  bool metOfficeOpsCompatibilityMode)
47  : metOfficeOpsCompatibilityMode_(metOfficeOpsCompatibilityMode),
48  latitudeBinSelector_(latitudeLowerBound_, latitudeUpperBound_, numLatitudeBins),
49  longitudeBinSelectors_(numLatitudeBins,
50  metOfficeOpsCompatibilityMode ?
52  opsCompatibilityModeLongitudeLowerBound_,
53  opsCompatibilityModeLongitudeUpperBound_,
54  opsCompatibilityModeRelativeLongitudeRange_ * numLongitudeBins) :
56  longitudeLowerBound_,
57  longitudeUpperBound_,
58  numLongitudeBins))
59 {}
60 
62  size_t n = 0;
64  n += *selector.numBins();
67  return n;
68 }
69 
71  float idealNumBins, SpatialBinCountRoundingMode roundingMode) {
72  IndexType numBins = static_cast<IndexType>(
73  roundingMode == SpatialBinCountRoundingMode::DOWN ?
74  idealNumBins : std::round(idealNumBins));
75  return std::max(1, numBins);
76 }
77 
78 } // namespace ufo
static constexpr ValueType longitudeUpperBound_
IndexType totalNumBins() const
Return the number of bins into which the sphere is split.
ValueType latitudeBinCenter(IndexType latitudeBin) const
Return the latitude at the center of the zonal band of bins with index latitudeBin.
static constexpr int opsCompatibilityModeRelativeLongitudeRange_
std::vector< TruncatingEquispacedBinSelector > longitudeBinSelectors_
static constexpr ValueType longitudeLowerBound_
static constexpr ValueType opsCompatibilityModeLongitudeUpperBound_
SpatialBinSelector(IndexType numLatitudeBins, SpatialBinCountRoundingMode roundingMode, bool metOfficeOpsCompatibilityMode=false)
Partition a sphere into bins whose centers lie on a reduced Gaussian grid.
static constexpr ValueType opsCompatibilityModeLongitudeLowerBound_
static IndexType roundNumBins(float idealNumBins, SpatialBinCountRoundingMode roundingMode)
Return idealNumBins rounded to a positive integer according to the rounding strategy roundingMode.
Represents a finite set of consecutive intervals (bins) of the same width, each closed from the left ...
Definition: RunCRTM.h:27
SpatialBinCountRoundingMode
static constexpr double deg2rad
Definition: Constants.h:21