ReFRACtor
atmosphere.py
Go to the documentation of this file.
1 import os
2 
3 import numpy as np
4 
5 from .base import Creator, ParamPassThru, CreatorError
6 from .value import CreatorFlaggedValue
7 from .. import param
8 
9 from refractor import framework as rf
10 
12  "Creates an atmosphere object"
13 
14  pressure = param.InstanceOf(rf.Pressure)
15  temperature = param.InstanceOf(rf.Temperature)
16  altitude = param.ObjectVector("altitude")
17  absorber = param.InstanceOf(rf.Absorber)
18  relative_humidity = param.InstanceOf(rf.RelativeHumidity)
19  ground = param.InstanceOf(rf.Ground, required=False)
20  aerosol = param.InstanceOf(rf.Aerosol, required=False)
21  surface_temperature = param.InstanceOf(rf.SurfaceTemperature, required=False)
22  constants = param.InstanceOf(rf.Constant)
23 
24  def create(self, **kwargs):
25 
26  pressure = self.common_store["pressure"] = self.pressure()
27  temperature = self.common_store["temperature"] = self.temperature()
28  altitude = self.common_store["altitude"] = self.altitude()
29  absorber = self.common_store["absorber"] = self.absorber()
30  relative_humidity = self.common_store["relative_humidity"] = self.relative_humidity()
31  aerosol = self.common_store["aerosol"] = self.aerosol()
32  ground = self.common_store["ground"] = self.ground()
33  surf_temp = self.common_store["surface_temperature"] = self.surface_temperature()
34 
35  if surf_temp and not ground:
36  raise CreatorError("Surface temperature can not be defined without ground being defined for atmosphere setup")
37 
38  if aerosol and ground and surf_temp:
39  return rf.AtmosphereOco(absorber, pressure, temperature, aerosol, relative_humidity, ground, surf_temp, altitude, self.constants())
40  if ground and surf_temp:
41  return rf.AtmosphereOco(absorber, pressure, temperature, relative_humidity, ground, surf_temp, altitude, self.constants())
42  elif aerosol and ground:
43  return rf.AtmosphereOco(absorber, pressure, temperature, aerosol, relative_humidity, ground, altitude, self.constants())
44  elif aerosol:
45  return rf.AtmosphereOco(absorber, pressure, temperature, aerosol, relative_humidity, altitude, self.constants())
46  elif ground:
47  return rf.AtmosphereOco(absorber, pressure, temperature, relative_humidity, ground, altitude, self.constants())
48  else:
49  return rf.AtmosphereOco(absorber, pressure, temperature, relative_humidity, altitude, self.constants())
50 
51 
53  "Creates a PressureSigma object statisfying the AtmosphereCreator's pressure parameter"
54 
55  a_coeff = param.Array(dims=1)
56  b_coeff = param.Array(dims=1)
57 
58  def create(self, **kwargs):
59  # value and flag loaded as arrays, so just get first value
60  psurf = self.value()[0]
61  ret_flag = bool(self.retrieval_flag()[0])
62 
63  return rf.PressureSigma(self.a_coeff(), self.b_coeff(), psurf, ret_flag)
64 
66  "Creates a PressureSigma object statisfying the AtmosphereCreator's pressure parameter"
67 
68  pressure_levels = param.Array(dims=1)
69 
70  def create(self, **kwargs):
71  # ap and flag loaded as arrays, so just get first value
72  psurf = self.value()[0]
73  ret_flag = bool(self.retrieval_flag()[0])
74 
75  return rf.PressureSigma(self.pressure_levels(), psurf, ret_flag)
76 
78  "Creates a TemperatureMet object statisfying the AtmosphereCreator's temperature parameter"
79 
80  met = param.InstanceOf(rf.Meteorology)
81  pressure = param.InstanceOf(rf.Pressure)
82 
83  def create(self, **kwargs):
84  offset = self.value()[0]
85  ret_flag = bool(self.retrieval_flag()[0])
86 
87  return rf.TemperatureMet(self.met(), self.pressure(), offset, ret_flag)
88 
90  "Creates a SurfaceTemperature object for use by AtmospherCreator"
91 
92  def create(self, **kwargs):
93 
94  return rf.SurfaceTemperatureDirect(self.value(), self.retrieval_flag())
95 
97  "Creates a TemperatureMet object statisfying the AtmosphereCreator's temperature parameter"
98 
99  temperature_levels = param.Array(dims=1)
100  pressure = param.InstanceOf(rf.Pressure)
101 
102  def create(self, **kwargs):
103  offset = self.value()[0]
104  ret_flag = bool(self.retrieval_flag()[0])
105 
106  return rf.TemperatureLevelOffset(self.pressure(), self.temperature_levels(), offset, ret_flag)
107 
109  "Creates a AltitudeHydrostatic object statisfying the AtmosphereCreator's altitude parameter"
110 
111  latitude = param.ArrayWithUnit(dims=1)
112  surface_height = param.ArrayWithUnit(dims=1)
113 
114  pressure = param.InstanceOf(rf.Pressure)
115  temperature = param.InstanceOf(rf.Temperature)
116 
117  num_channels = param.Scalar(int)
118 
119  def create(self, **kwargs):
120  # These are per channel
121  latitudes = self.latitude()
122  surface_heights = self.surface_height()
123 
124  altitude = rf.vector_altitude()
125  for chan_idx in range(self.num_channels()):
126  chan_alt = rf.AltitudeHydrostatic(self.pressure(), self.temperature(), latitudes[chan_idx], surface_heights[chan_idx])
127  altitude.push_back(chan_alt)
128 
129  return altitude
130 
132 
133  pressure = param.InstanceOf(rf.Pressure)
134  value = param.Scalar()
135 
136  def create(self, **kwargs):
137  return np.full(self.pressure().max_number_level, self.value())
138 
140 
141  pressure = param.InstanceOf(rf.Pressure)
142  temperature = param.InstanceOf(rf.Temperature)
143  absorber = param.InstanceOf(rf.Absorber)
144 
145  def create(self, **kwargs):
146  return rf.RelativeHumidity(self.absorber(), self.temperature(), self.pressure())

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