151 :param method: must be 'linear' or 'quadartic'
153 if method ==
'linear':
154 values = numpy.array([.5 * (values[i] + values[i + 1])
155 for i
in range(self.
len - 1)])
156 elif method ==
'quadratic':
158 update = (0, values[1] / 2.)
159 elif values[-1] == 0.:
160 update = (-1, values[-2] / 2.)
163 values = numpy.array([numpy.sqrt(values[i] * values[i + 1])
164 for i
in range(self.
len - 1)])
165 if update
is not None:
166 values[update[0]] = update[1]
168 raise Phyex1DError(
"method must be 'linear' or 'quadartic'")
173 Returns the level pressures
174 :param position: must be among grid.MASS + .grid.FLUX
175 :param state: dictionary containing the current state
176 :param pronostic_variables: list of pronostic variables
178 if self.
kind ==
'hybridP' and position == self.
position:
179 if 'Ps' not in state:
180 raise Phyex1DError(
"Surface pressure ('Ps') is needed to compute the pressures")
182 for i
in range(self.
len)])
184 self.
ascending = numpy.all(pressure[1:] < pressure[:-1])
188 self.
ascending = numpy.all(pressure[1:] < pressure[:-1])
189 elif self.
kind in (
'P',
'hybridP'):
192 elif self.
kind in (
'H',
'hybridH'):
196 if 'qv' in pronostic_variables:
197 gas_constant = self.
cst.Rd + state[
'qv'] * (self.
cst.Rv - self.
cst.Rd)
198 for var
in (
'qc',
'qr',
'qi',
'qs',
'qg',
'qh'):
199 if var
in pronostic_variables:
200 gas_constant += - state[var] * self.
cst.Rd
201 elif 'rv' in pronostic_variables:
202 div = 1 + state[
'rv']
203 for var
in (
'rc',
'rr',
'ri',
'rs',
'rg',
'rh'):
204 if var
in pronostic_variables:
206 gas_constant = (self.
cst.Rd + state[
'rv'] * self.
cst.Rv) / div
207 z_flux = self.
get_altitude(
'FLUX', state, pronostic_variables)
208 dx = - self.
cst.g / gas_constant * numpy.diff(z_flux)
209 if 'T' in pronostic_variables:
211 elif 'Theta' in pronostic_variables:
212 dx = dx / state[
'Theta'] * self.
cst.Rd / self.
cst.Cpd
215 x_flux = numpy.zeros(z_flux.shape)
217 x_flux[1:] = numpy.cumsum(dx)
219 x_flux[:-1] = numpy.cumsum(-dx[::-1])[::-1]
220 if 'T' in pronostic_variables:
221 x_flux += numpy.log(state[
'Ps'])
222 pressure_flux = numpy.exp(x_flux)
224 x_flux += (state[
'Ps'] / 1.E5) ** (self.
cst.Rd / self.
cst.Cpd)
225 pressure_flux = x_flux ** (self.
cst.Cpd / self.
cst.Rd) * 1.E5
226 if position ==
'FLUX':
227 pressure = pressure_flux
230 z_mass = self.
get_altitude(
'MASS', state, pronostic_variables)
231 dx = - self.
cst.g / gas_constant
233 dx = dx * (z_mass - z_flux[:-1])
235 dx = dx * (z_mass - z_flux[1:])
237 temp = pressure_flux[:-1]
239 temp = pressure_flux[1:]
240 if 'T' in pronostic_variables:
242 pressure = numpy.exp(numpy.log(temp) + dx)
243 elif 'Theta' in pronostic_variables:
244 dx = dx / state[
'Theta'] * self.
cst.Rd / self.
cst.Cpd
245 pressure = ((temp / 1.E5) ** (self.
cst.Rd / self.
cst.Cpd) + dx
246 ) ** (self.
cst.Cpd / self.
cst.Rd) * 1.E5
256 Returns the level altitudes
257 :param position: must be among grid.MASS + .grid.FLUX
258 :param state: dictionary containing the current state
259 :param pronostic_variables: list of pronostic variables
261 if self.
kind ==
'hybridH' and position == self.
position:
262 if 'Zs' not in state:
263 raise Phyex1DError(
"Surface altitude ('Zs') is needed to compute the altitudes")
265 for i
in range(self.
len)])
267 self.
ascending = numpy.all(altitude[1:] > altitude[:-1])
271 self.
ascending = numpy.all(altitude[1:] > altitude[:-1])
272 elif self.
kind in (
'H',
'hybridH'):
275 elif self.
kind in (
'P',
'hybridP'):
279 if 'T' in pronostic_variables:
280 temperature = state[
'T']
281 elif 'Theta' in pronostic_variables:
282 pressure_mass = self.
get_pressure(
'MASS', state, pronostic_variables)
283 exner = (pressure_mass / 1.E5) ** (self.
cst.Rd / self.
cst.Cpd)
284 temperature = exner * state[
'Theta']
287 if 'qv' in pronostic_variables:
288 gas_constant = self.
cst.Rd + state[
'qv'] * (self.
cst.Rv - self.
cst.Rd)
289 for var
in (
'qc',
'qr',
'qi',
'qs',
'qg',
'qh'):
290 if var
in pronostic_variables:
291 gas_constant += - state[var] * self.
cst.Rd
292 elif 'rv' in pronostic_variables:
293 div = 1 + state[
'rv']
294 for var
in (
'rc',
'rr',
'ri',
'rs',
'rg',
'rh'):
295 if var
in pronostic_variables:
297 gas_constant = (self.
cst.Rd + state[
'rv'] * self.
cst.Rv) / div
298 pressure_flux = self.
get_pressure(
'FLUX', state, pronostic_variables)
299 dz = -gas_constant * temperature / self.
cst.g * numpy.diff(numpy.log(pressure_flux))
300 z_flux = numpy.zeros(pressure_flux.shape)
302 z_flux[1:] = numpy.cumsum(dz)
304 z_flux[:-1] = numpy.cumsum(-dz[::-1])[::-1]
305 z_flux += state[
'Zs']
306 if position ==
'FLUX':
310 if pressure_mass
is None:
311 pressure_mass = self.
get_pressure(
'MASS', state, pronostic_variables)
313 dlnp = numpy.log(pressure_mass) - numpy.log(pressure_flux[:-1])
315 dlnp = numpy.log(pressure_mass) - numpy.log(pressure_flux[1:])
316 dz = -gas_constant * temperature / self.
cst.g * dlnp
318 altitude = z_flux[:-1] + dz
320 altitude = z_flux[1:] + dz