ReFRACtor
temperature_fixed_level.cc
Go to the documentation of this file.
1 #include <boost/bind.hpp>
3 #include "fp_exception.h"
4 #include "pressure_fixed_level.h"
5 #include "ostream_pad.h"
6 #include "linear_interpolate.h"
7 #include <boost/lexical_cast.hpp>
8 using namespace FullPhysics;
9 using namespace blitz;
10 
11 #ifdef HAVE_LUA
12 #include "register_lua.h"
14 .def(luabind::constructor<const blitz::Array<bool, 1>&, bool,
15  const blitz::Array<double, 1>&,
16  double,
20 #endif
21 
22 //-----------------------------------------------------------------------
24 //-----------------------------------------------------------------------
25 
27 (const blitz::Array<bool, 1>& Flag_temp,
28  bool Flag_offset, const blitz::Array<double, 1>& Temp,
29  double T_offset,
30  const boost::shared_ptr<Pressure>& Press,
31  const boost::shared_ptr<PressureLevelInput>& Press_level)
32 : press_level(Press_level)
33 {
34  if(Flag_temp.rows() != Temp.rows())
35  throw Exception("Flag_temp and Temp need to be the same size");
36  Range trange(1, Flag_temp.rows());
37  Array<bool, 1> flag(Flag_temp.rows() + 1);
38  Array<double, 1> val(flag.shape());
39  flag(0) = Flag_offset;
40  val(0) = T_offset;
41  flag(trange) = Flag_temp;
42  val(trange) = Temp;
43  // When marking, only include the temperature values if they are below the
44  // number of levels given by Press.
45  init(val, flag, Press, true, 1);
46 }
47 
48 //-----------------------------------------------------------------------
57 //-----------------------------------------------------------------------
58 
60 {
61  AutoDerivative<double> p = log(press->surface_pressure().value);
62  std::vector<AutoDerivative<double> > plist;
63  std::vector<AutoDerivative<double> > tlist;
64  for(int i = 0; i < press->pressure_grid().rows() - 1; ++i) {
65  plist.push_back(press->pressure_grid()(i).value);
66  tlist.push_back(temperature_levels()(i));
67  }
68  int i = press->pressure_grid().rows() - 1;
69  double p1 = log(press_level->pressure_level()(i - 1));
71  t1 = temperature_levels()(i - 1);
72  double p2 = log(press_level->pressure_level()(i));
73  t2 = temperature_levels()(i);
74  AutoDerivative<double> t = t1 + (p - p1) * (t2 - t1) / (p2 - p1);
75  plist.push_back(press->surface_pressure().value);
76  tlist.push_back(t);
78  lin_type;
80  (new lin_type(plist.begin(), plist.end(), tlist.begin()));
81  tgrid = boost::bind(&lin_type::operator(), lin, _1);
82 }
83 
84 // See base class for description of this function
85 
88 {
90  (new TemperatureFixedLevel(used_flag_value()(temperature_range()),
91  used_flag_value()(0),
92  coefficient()(temperature_range()).value(),
93  coefficient()(0).value(), Press, press_level));
94  return res;
95 }
96 
97 // See base class for description of this function.
98 
100 {
101  if(i ==0)
102  return "Temperature Offset (Kelvin)";
103  return "Temperature (Kelvin) for Pressure Level " +
104  boost::lexical_cast<std::string>(i);
105 }
106 
107 //-----------------------------------------------------------------------
110 //-----------------------------------------------------------------------
111 
114 {
116  res(coefficient()(temperature_range()).copy());
117  for(int i = 0; i < res.rows(); ++i)
118  res(i) = res(i) + coefficient()(0);
119  return res;
120 }
121 
122 //-----------------------------------------------------------------------
124 //-----------------------------------------------------------------------
125 
127 {
128  if(!used_flag_value()(0) ||
129  cov.rows() == 0 ||
130  cov(0,0) < 0)
131  return 0.0;
132  return sqrt(cov(0,0));
133 }
134 
135 void TemperatureFixedLevel::print(std::ostream& Os) const
136 {
137  OstreamPad opad(Os, " ");
138  Os << "TemperatureFixedLevel:\n"
139  << " Temperature offset: " << temperature_offset() << "\n"
140  << " Retrieval flag offset: " << (used_flag_value()(0) ?
141  "True\n" : "False\n")
142  << " Temperature:\n";
144  temp(coefficient()(temperature_range()));
145  opad << temp.value() << "\n";
146  opad.strict_sync();
147  Os << " Temperature flag:\n";
148  opad << used_flag_value()(temperature_range()) << "\n";
149  opad.strict_sync();
150 }
ArrayAd< double, 1 > temperature_levels() const
Return the temperature on the fixed levels (which may include values from below the surface)...
This is a filtering stream that adds a pad to the front of every line written out.
Definition: ostream_pad.h:32
This class takes a set of points and values, and linearly interpolates between those values...
virtual boost::shared_ptr< Temperature > clone() const
Clone a Temperature object.
double temperature_offset_uncertainty() const
Uncertainty of temperature offset.
This is the base of the exception hierarchy for Full Physics code.
Definition: fp_exception.h:16
#define REGISTER_LUA_DERIVED_CLASS(X, Y)
Definition: register_lua.h:136
TemperatureFixedLevel(const blitz::Array< bool, 1 > &Flag_temp, bool Flag_offset, const blitz::Array< double, 1 > &Temp, double T_offset, const boost::shared_ptr< Pressure > &Press, const boost::shared_ptr< PressureLevelInput > &Press_level)
Create an Temperature.
This class maintains the temperature portion of the state.
Apply value function to a blitz array.
const blitz::Array< T, D > & value() const
Definition: array_ad.h:306
Contains classes to abstract away details in various Spurr Radiative Transfer software.
Definition: doxygen_python.h:1
#define REGISTER_LUA_END()
Definition: register_lua.h:134
virtual std::string state_vector_name_i(int i) const
Return state vector name for ith entry in coeff.
This class maintains the temperature portion of the state.
Definition: temperature.h:22
void calc_temperature_grid() const
This calculates temperature grid to use for layer retrieval.
double value(const FullPhysics::AutoDerivative< double > &Ad)
int rows() const
Definition: array_ad.h:368
virtual void print(std::ostream &Os) const
Print to stream.

Copyright © 2017, California Institute of Technology.
ALL RIGHTS RESERVED.
U.S. Government Sponsorship acknowledged.
Generated Fri Aug 24 2018 15:44:08