UFO
ObsTimeOperUtil.cc
Go to the documentation of this file.
1 /*
2  * (C) Copyright 2019 UK Met Office
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 
9 #include <algorithm>
10 #include <ostream>
11 #include <string>
12 #include <vector>
13 
14 #include "ioda/ObsVector.h"
15 
16 #include "oops/util/DateTime.h"
17 #include "oops/util/Duration.h"
18 #include "oops/util/Logger.h"
20 
21 namespace ufo {
22 
23 
24 //--------------------------------------------------------------------------------------------------
25 std::vector<std::vector<float>> timeWeightCreate(const ioda::ObsSpace & odb_,
26  const eckit::Configuration & config) {
27  util::DateTime windowBegin(odb_.windowStart());
28  util::Duration windowSub;
29  windowSub = util::Duration(config.getString("windowSub"));
30  int64_t windowSubSec = windowSub.toSeconds();
31 
32  std::size_t nlocs = odb_.nlocs();
33 
34  oops::Log::debug() << "nlocs = " << nlocs << std::endl;
35 
36  std::vector<float> TimeWeightObsAfterState(nlocs, 0.0);
37 
38  std::vector<util::DateTime> dateTimeIn(nlocs);
39  odb_.get_db("MetaData", "datetime", dateTimeIn);
40 
41  oops::Log::debug() << "datetime = " << dateTimeIn[0].toString() << std::endl;
42 
43  for (std::size_t i = 0; i < nlocs; ++i) {
44  util::Duration timeFromStart = dateTimeIn[i] - windowBegin;
45  int64_t timeFromStartSec = timeFromStart.toSeconds();
46  int64_t StateTimeFromStartSec =
47  (timeFromStartSec / windowSubSec) * windowSubSec;
48  if ((timeFromStartSec - StateTimeFromStartSec) == 0) {
49  TimeWeightObsAfterState[i] = 1.0f;
50  } else {
51  TimeWeightObsAfterState[i] = 1.0f - static_cast<float>(timeFromStartSec -
52  StateTimeFromStartSec)/
53  static_cast<float>(windowSubSec);
54  }
55  oops::Log::debug() << " timeFromStartSec = " << timeFromStartSec
56  << " windowSubSec = " << windowSubSec
57  << " StateTimeFromStartSec = " << StateTimeFromStartSec
58  << std::endl;
59  }
60  for (std::size_t i=0; i < TimeWeightObsAfterState.size(); ++i) {
61  oops::Log::debug() << "timeweights [" << i << "] = "
62  << TimeWeightObsAfterState[i] << std::endl;
63  }
64 
65  std::vector<float> TimeWeightObsBeforeState(nlocs, 0.0);
66  transform(TimeWeightObsAfterState.cbegin(), TimeWeightObsAfterState.cend(),
67  TimeWeightObsBeforeState.begin(),
68  [] (float element) {return 1.0f - element;});
69 
70  std::vector<std::vector<float>> timeWeights;
71  timeWeights.push_back(TimeWeightObsAfterState);
72  timeWeights.push_back(TimeWeightObsBeforeState);
73 
74  for (auto i : timeWeights[0]) {
75  oops::Log::debug() << "TimeOperUtil::timeWeights[0] = " << i << std::endl;
76  }
77  for (auto i : timeWeights[1]) {
78  oops::Log::debug() << "TimeOperUtil::timeWeights[1] = " << i << std::endl;
79  }
80 
81  return timeWeights;
82 }
83 // -----------------------------------------------------------------------------
84 
85 } // namespace ufo
integer function nlocs(this)
Return the number of observational locations in this Locations object.
Definition: RunCRTM.h:27
std::vector< std::vector< float > > timeWeightCreate(const ioda::ObsSpace &odb_, const eckit::Configuration &config)