cleopy 0.57.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. cleopy/__init__.py +22 -0
  2. cleopy/cxx2py.py +136 -0
  3. cleopy/editconfigfile.py +61 -0
  4. cleopy/gbxboundariesbinary_src/__init__.py +16 -0
  5. cleopy/gbxboundariesbinary_src/create_gbxboundaries.py +197 -0
  6. cleopy/gbxboundariesbinary_src/read_gbxboundaries.py +350 -0
  7. cleopy/geninitconds.py +144 -0
  8. cleopy/initsuperdropsbinary_src/__init__.py +15 -0
  9. cleopy/initsuperdropsbinary_src/attrsgen.py +206 -0
  10. cleopy/initsuperdropsbinary_src/crdgens.py +101 -0
  11. cleopy/initsuperdropsbinary_src/create_initsuperdrops.py +360 -0
  12. cleopy/initsuperdropsbinary_src/dryrgens.py +31 -0
  13. cleopy/initsuperdropsbinary_src/probdists.py +239 -0
  14. cleopy/initsuperdropsbinary_src/read_initsuperdrops.py +465 -0
  15. cleopy/initsuperdropsbinary_src/rgens.py +81 -0
  16. cleopy/readbinary.py +120 -0
  17. cleopy/readconfigfile.py +61 -0
  18. cleopy/sdmout_src/__init__.py +16 -0
  19. cleopy/sdmout_src/massmoms.py +83 -0
  20. cleopy/sdmout_src/pygbxsdat.py +59 -0
  21. cleopy/sdmout_src/pysetuptxt.py +90 -0
  22. cleopy/sdmout_src/pyzarr.py +158 -0
  23. cleopy/sdmout_src/sdtracing.py +141 -0
  24. cleopy/sdmout_src/superdrops.py +428 -0
  25. cleopy/sdmout_src/supersdata.py +228 -0
  26. cleopy/sdmout_src/thermodata.py +146 -0
  27. cleopy/sdmout_src/thermoeqns.py +129 -0
  28. cleopy/sdmout_src/timedata.py +54 -0
  29. cleopy/thermobinary_src/__init__.py +16 -0
  30. cleopy/thermobinary_src/create_thermodynamics.py +256 -0
  31. cleopy/thermobinary_src/read_thermodynamics.py +498 -0
  32. cleopy/thermobinary_src/thermodyngen.py +56 -0
  33. cleopy/thermobinary_src/thermogen.py +466 -0
  34. cleopy/thermobinary_src/windsgen.py +228 -0
  35. cleopy/writebinary.py +218 -0
  36. cleopy-0.57.4.dist-info/METADATA +47 -0
  37. cleopy-0.57.4.dist-info/RECORD +39 -0
  38. cleopy-0.57.4.dist-info/WHEEL +4 -0
  39. cleopy-0.57.4.dist-info/licenses/LICENSE.md +43 -0
@@ -0,0 +1,498 @@
1
+ """
2
+ Copyright (c) 2024 MPI-M, Clara Bayley
3
+
4
+
5
+ ----- CLEO -----
6
+ File: read_thermodynamics.py
7
+ Project: thermobinary_src
8
+ Created Date: Friday 13th October 2023
9
+ Author: Clara Bayley (CB)
10
+ Additional Contributors:
11
+ -----
12
+ License: BSD 3-Clause "New" or "Revised" License
13
+ https://opensource.org/licenses/BSD-3-Clause
14
+ -----
15
+ File Description:
16
+ """
17
+
18
+ import numpy as np
19
+ import matplotlib.pyplot as plt
20
+ from matplotlib import colors
21
+ from pathlib import Path
22
+
23
+ from .create_thermodynamics import thermoinputsdict, DimlessThermodynamics
24
+ from .thermogen import saturation_press
25
+ from ..readbinary import readbinary
26
+ from ..gbxboundariesbinary_src import read_gbxboundaries as rgrid
27
+
28
+
29
+ def relative_humidity(press, temp, qvap, Mr_ratio):
30
+ pv = qvap * press / (Mr_ratio + qvap) # vapour pressure
31
+ psat = saturation_press(temp)
32
+ relh = pv / psat
33
+
34
+ qsat = Mr_ratio * psat / (press - pv)
35
+ supersat = qvap / qsat - 1
36
+
37
+ return relh, supersat
38
+
39
+
40
+ def potential_temperature(press, temp, press_ref, RGAS, CP):
41
+ theta = temp * (press_ref / press) ** (RGAS / CP)
42
+
43
+ return theta
44
+
45
+
46
+ class ThermoOnGrid:
47
+ def __init__(self, thermodata, inputs, ndims):
48
+ dth = DimlessThermodynamics(inputs=inputs)
49
+ thermodata = dth.redimensionalise(thermodata)
50
+
51
+ ntime = inputs["ntime"]
52
+ ndims = [int(n) for n in ndims]
53
+ cen = [inputs["ntime"]] + list(np.flip(ndims))
54
+ zface = [ntime, ndims[2], ndims[1], ndims[0] + 1]
55
+ xface = [ntime, ndims[2], ndims[1] + 1, ndims[0]]
56
+ yface = [ntime, ndims[2] + 1, ndims[1], ndims[0]]
57
+
58
+ self.vars = ["press", "temp", "qvap", "qcond"]
59
+ self.press = np.reshape(thermodata["press"], cen)
60
+ self.temp = np.reshape(thermodata["temp"], cen)
61
+ self.qvap = np.reshape(thermodata["qvap"], cen)
62
+ self.qcond = np.reshape(thermodata["qcond"], cen)
63
+
64
+ if "wvel" in thermodata.keys():
65
+ self.wvel = np.reshape(thermodata["wvel"], zface)
66
+ self.wvel_cens = (self.wvel[:, :, :, 1:] + self.wvel[:, :, :, :-1]) / 2
67
+ self.vars += ["wvel", "wvel_cens"]
68
+ if "uvel" in thermodata.keys():
69
+ self.uvel = np.reshape(thermodata["uvel"], xface)
70
+ self.uvel_cens = (self.uvel[:, :, 1:, :] + self.uvel[:, :, :-1, :]) / 2
71
+ self.vars += ["uvel", "uvel_cens"]
72
+ if "vvel" in thermodata.keys():
73
+ self.vvel = np.reshape(thermodata["vvel"], yface)
74
+ self.vvel_cens = (
75
+ self.vvel[:, 1:, :, :] + self.vvel[:, :-1, :, :]
76
+ ) / 2
77
+ self.vars += ["vvel", "vvel_cens"]
78
+
79
+ def __getitem__(self, key):
80
+ if key not in self.vars:
81
+ err = "no variable " + key + " in ThermoOnGrid"
82
+ raise ValueError(err)
83
+ elif key == "press":
84
+ return self.press
85
+ elif key == "temp":
86
+ return self.temp
87
+ elif key == "qvap":
88
+ return self.qvap
89
+ elif key == "qcond":
90
+ return self.qcond
91
+
92
+ elif key == "wvel":
93
+ return self.wvel
94
+ elif key == "uvel":
95
+ return self.uvel
96
+ elif key == "vvel":
97
+ return self.vvel
98
+
99
+ elif key == "wvel_cens":
100
+ return self.wvel_cens
101
+ elif key == "uvel_cens":
102
+ return self.uvel_cens
103
+ elif key == "vvel_cens":
104
+ return self.vvel_cens
105
+
106
+ def xymean(self, var):
107
+ """mean over x and y"""
108
+
109
+ return np.mean(var, axis=(1, 2)) # d ims [time, z]
110
+
111
+ def ytmean(self, var):
112
+ """mean over time and y"""
113
+
114
+ return np.mean(var, axis=(0, 1)) # dims [x, z]
115
+
116
+ def xytmean(self, var):
117
+ """mean over time, x and y"""
118
+
119
+ return np.mean(var, axis=(0, 1, 2)) # dims [z]
120
+
121
+
122
+ def thermovar_from_binary(var, thermofiles, shape, ntime, ndims, dtype, isprint=True):
123
+ filename = f"{thermofiles.stem}_{var}{thermofiles.suffix}"
124
+ filename = thermofiles.parent / filename
125
+ data, ndata = readbinary(filename, isprint=isprint)
126
+
127
+ if ndata != int(np.prod(shape)):
128
+ err = (
129
+ str(ndata)
130
+ + " is incorrect data length for "
131
+ + var
132
+ + " defined for "
133
+ + str(ntime)
134
+ + " timesteps"
135
+ + " on grid with dims = "
136
+ + str(ndims)
137
+ )
138
+ raise ValueError(err)
139
+ else:
140
+ data = np.reshape(np.asarray(data, dtype=dtype), shape)
141
+
142
+ return data
143
+
144
+
145
+ def read_dimless_thermodynamics_binary(thermofiles, ndims, ntime, nspacedims):
146
+ # expected lengths of data defined on gridbox centres or faces
147
+ cen = [ntime, int(np.prod(ndims))]
148
+ zface = [ntime, int(ndims[2] * ndims[1] * (ndims[0] + 1))]
149
+ xface = [ntime, int(ndims[2] * (ndims[1] + 1) * ndims[0])]
150
+ yface = [ntime, int((ndims[2] + 1) * ndims[1] * ndims[0])]
151
+
152
+ thermodata = {}
153
+
154
+ vars = ["press", "temp", "qvap", "qcond"]
155
+ datatypes = [np.double] * 4
156
+ for v, var in enumerate(vars):
157
+ thermodata[var] = thermovar_from_binary(
158
+ var, thermofiles, cen, ntime, ndims, datatypes[v], isprint=False
159
+ )
160
+
161
+ datatypes = [np.double] * 3
162
+ if nspacedims >= 1:
163
+ thermodata["wvel"] = thermovar_from_binary(
164
+ "wvel", thermofiles, zface, ntime, ndims, datatypes[0], isprint=False
165
+ )
166
+ if nspacedims >= 2:
167
+ thermodata["uvel"] = thermovar_from_binary(
168
+ "uvel", thermofiles, xface, ntime, ndims, datatypes[1], isprint=False
169
+ )
170
+ if nspacedims >= 3:
171
+ thermodata["vvel"] = thermovar_from_binary(
172
+ "vvel",
173
+ thermofiles,
174
+ yface,
175
+ ntime,
176
+ ndims,
177
+ datatypes[2],
178
+ isprint=False,
179
+ )
180
+
181
+ return thermodata
182
+
183
+
184
+ def get_thermodynamics_from_thermofiles(
185
+ thermofiles, ndims, inputs=False, constants_filename="", config_filename=""
186
+ ):
187
+ if not inputs:
188
+ inputs = thermoinputsdict(config_filename, constants_filename)
189
+
190
+ thermodata = read_dimless_thermodynamics_binary(
191
+ thermofiles, ndims, inputs["ntime"], inputs["nspacedims"]
192
+ ) # dimensionless data [time, gridboxes]
193
+ thermodata = ThermoOnGrid(thermodata, inputs, ndims)
194
+
195
+ return thermodata # data with units in 4D arrays with dims [time, y, x, z]
196
+
197
+
198
+ def plot_thermodynamics(
199
+ constants_filename,
200
+ config_filename,
201
+ grid_filename,
202
+ thermofiles,
203
+ savefig=False,
204
+ savefigpath=None,
205
+ savelabel="",
206
+ ):
207
+ plt.rcParams.update({"font.size": 14})
208
+
209
+ inputs = thermoinputsdict(config_filename, constants_filename)
210
+ gbxbounds, ndims = rgrid.read_dimless_gbxboundaries_binary(
211
+ grid_filename, COORD0=inputs["COORD0"], return_ndims=True, isprint=False
212
+ )
213
+ xyzhalf = rgrid.halfcoords_from_gbxbounds(gbxbounds, isprint=False) # [m]
214
+ zhalf, xhalf, yhalf = [half / 1000 for half in xyzhalf] # convery [m] to [km]
215
+ zfull, xfull, yfull = rgrid.fullcell_fromhalfcoords(zhalf, xhalf, yhalf) # [m]
216
+
217
+ thermodata = get_thermodynamics_from_thermofiles(thermofiles, ndims, inputs=inputs)
218
+
219
+ plot_1dprofiles(
220
+ zfull,
221
+ thermodata,
222
+ inputs["Mr_ratio"],
223
+ inputs["RGAS_DRY"],
224
+ inputs["CP_DRY"],
225
+ savefigpath,
226
+ savefig,
227
+ savelabel=savelabel,
228
+ )
229
+
230
+ if inputs["nspacedims"] > 1:
231
+ xxh, zzh = np.meshgrid(xhalf, zhalf, indexing="ij") # dims [xdims, zdims]
232
+ xxf, zzf = np.meshgrid(xfull, zfull, indexing="ij") # dims [xdims, zdims]
233
+ plot_2dcolormaps(
234
+ zzh,
235
+ xxh,
236
+ zzf,
237
+ xxf,
238
+ thermodata,
239
+ inputs,
240
+ savefigpath,
241
+ savefig,
242
+ savelabel=savelabel,
243
+ )
244
+ plot_2dwindfield(
245
+ zzh,
246
+ xxh,
247
+ zzf,
248
+ xxf,
249
+ thermodata["wvel_cens"],
250
+ thermodata["uvel_cens"],
251
+ savefigpath,
252
+ savefig,
253
+ savelabel=savelabel,
254
+ )
255
+
256
+
257
+ def try1dplot(ax, nplots, data, zfull, label):
258
+ try:
259
+ ax.plot(data, zfull, marker="x") # (fails for 0D model)
260
+ except ValueError as e:
261
+ print("Plotting failed with ValueError:", e, " using ax.scatter instead.")
262
+ ax.scatter(data, zfull, marker="x")
263
+
264
+ ax.set_xlabel(label)
265
+
266
+ return nplots + 1
267
+
268
+
269
+ def plot_1dthermodynamics(axs, n, zfull, thermodata, Mr_ratio, RGAS_DRY, CP_DRY):
270
+ vars = ["press", "temp", "qvap", "qcond"]
271
+ units = [" /Pa", " /K", "", ""]
272
+
273
+ for var, unit in zip(vars, units):
274
+ if var in thermodata.vars:
275
+ profalltime = thermodata.xymean(thermodata[var]) # 1d profile at all times
276
+ label = var + unit
277
+ n = try1dplot(axs[n], n, profalltime.T, zfull[None, :].T, label)
278
+
279
+ pressxy = thermodata.xymean(thermodata.press)
280
+ tempxy = thermodata.xymean(thermodata.temp)
281
+ qvapxy = thermodata.xymean(thermodata.qvap)
282
+ supersat = relative_humidity(pressxy, tempxy, qvapxy, Mr_ratio)[1]
283
+ label = "supersaturation"
284
+ n = try1dplot(axs[n], n, supersat.T, zfull[None, :].T, label)
285
+
286
+ press_ref = pressxy[0, 0]
287
+ theta = potential_temperature(pressxy, tempxy, press_ref, RGAS_DRY, CP_DRY)
288
+ label = "\u03F4 /K"
289
+ n = try1dplot(axs[n], n, theta.T, zfull[None, :].T, label)
290
+
291
+ return n
292
+
293
+
294
+ def plot_1dwindprofiles(axs, n, zfull, thermodata):
295
+ vars = ["wvel_cens", "uvel_cens", "vvel_cens"]
296
+ units = [" /ms$^{-1}$"] * 3
297
+
298
+ for var, unit in zip(vars, units):
299
+ if var in thermodata.vars:
300
+ profalltime = thermodata.xymean(thermodata[var]) # 1d profile at all times
301
+ label = var + unit
302
+ n = try1dplot(axs[n], n, profalltime.T, zfull[None, :].T, label)
303
+
304
+ return n
305
+
306
+
307
+ def plot_1dprofiles(
308
+ zfull, thermodata, Mr_ratio, RGAS_DRY, CP_DRY, savefigpath, savefig, savelabel=""
309
+ ):
310
+ fig, axs = plt.subplots(nrows=3, ncols=3, figsize=(16, 8))
311
+ axs = axs.flatten()
312
+
313
+ nplots = plot_1dthermodynamics(
314
+ axs, 0, zfull, thermodata, Mr_ratio, RGAS_DRY, CP_DRY
315
+ )
316
+ nplots = plot_1dwindprofiles(axs, nplots, zfull, thermodata)
317
+
318
+ for a in range(nplots, len(axs), 1):
319
+ axs[a].remove() # delete unused axes
320
+ for ax in [axs[0], axs[3], axs[6]]:
321
+ ax.set_ylabel("z /km")
322
+
323
+ fig.tight_layout()
324
+
325
+ if savefig:
326
+ savename = savefigpath / Path(f"thermo1dalltimeprofiles{savelabel}.png")
327
+ fig.savefig(
328
+ savename,
329
+ dpi=400,
330
+ bbox_inches="tight",
331
+ facecolor="w",
332
+ format="png",
333
+ )
334
+ print("Figure .png saved as: " + str(savefigpath))
335
+
336
+
337
+ def plot_2dmean(ax, meanfunc, xxh, zzh, var, label, unit, norm, cmap):
338
+ mean2d = meanfunc(var) # avg over time and y axes
339
+ if np.nanmin(mean2d) != np.nanmax(mean2d):
340
+ pcm = ax.pcolormesh(xxh[:, :], zzh[:, :], mean2d, cmap=cmap, norm=norm)
341
+ cb = plt.colorbar(pcm, ax=ax, location="top", label=label + unit)
342
+ return mean2d, pcm, cb
343
+ else:
344
+ txt = label + " = {:.2f}".format(np.nanmin(mean2d)) + unit
345
+ ax.text(0.5, 0.5, txt, ha="center")
346
+ return np.nanmin(mean2d), False, False
347
+
348
+
349
+ def plot_2dcontour(ax, xxf, zzf, mean2d, contour, cb, cbticks):
350
+ cb.ax.set_xticks(cbticks)
351
+ cb.ax.set_xticklabels(["{:.3g}".format(c) for c in cbticks])
352
+
353
+ try:
354
+ ax.contour(
355
+ xxf, zzf, mean2d, levels=[contour], linestyles=["--"], colors=["grey"]
356
+ )
357
+ except ValueError as e:
358
+ print("Plotting failed with ValueError:", e, "WARNING: not plotting contour")
359
+
360
+ cb.ax.plot([contour] * 2, [0, 1], color="grey", linewidth=0.95)
361
+
362
+
363
+ def relh_supersat_theta_colomaps(
364
+ axs, zzh, xxh, zzf, xxf, thermodata, Mr_ratio, RGAS_DRY, CP_DRY
365
+ ):
366
+ relh, supersat = relative_humidity(
367
+ thermodata.press, thermodata.temp, thermodata.qvap, Mr_ratio
368
+ )
369
+ relh = relh * 100 # convert relative humidity to %
370
+
371
+ press_ref = thermodata.xymean(thermodata.press)[0, 0]
372
+ theta = potential_temperature(
373
+ thermodata.press, thermodata.temp, press_ref, RGAS_DRY, CP_DRY
374
+ )
375
+
376
+ vars = [relh, supersat, theta]
377
+ labels = ["% relative humidity", "supersaturation", "\u03F4"]
378
+ units = ["", "", " /K"]
379
+ cmaps = ["Blues", "PuOr", "RdBu_r"]
380
+ norms = [
381
+ colors.CenteredNorm(vcenter=np.mean(relh)),
382
+ colors.TwoSlopeNorm(vcenter=0.0),
383
+ colors.CenteredNorm(vcenter=np.nanmin(theta)),
384
+ ]
385
+ contours = [1.0, 0.0, None]
386
+
387
+ n = 0
388
+ for var, label, unit, norm, cmap, cont in zip(
389
+ vars, labels, units, norms, cmaps, contours
390
+ ):
391
+ mean2d, pcm, cb = plot_2dmean(
392
+ axs[n], thermodata.ytmean, xxh, zzh, var, label, unit, norm, cmap
393
+ )
394
+
395
+ if pcm is not False:
396
+ if n == 1:
397
+ cbticks = [pcm.norm.vmin, pcm.norm.vcenter, pcm.norm.vmax]
398
+ else:
399
+ cbticks = np.linspace(pcm.norm.vmin, pcm.norm.vmax, 5)
400
+ plot_2dcontour(axs[n], xxf, zzf, mean2d, cont, cb, cbticks)
401
+
402
+ n += 1
403
+
404
+
405
+ def plot_2dcolormaps(
406
+ zzh, xxh, zzf, xxf, thermodata, inputs, savefigpath, savefig, savelabel=""
407
+ ):
408
+ vars = ["press", "temp", "qvap", "qcond"]
409
+ units = [" /Pa", " /K", "", ""]
410
+ cmaps = ["PRGn", "RdBu_r", "BrBG", "BrBG"]
411
+ cmapcens = [
412
+ np.nanmin(thermodata.press),
413
+ np.nanmin(thermodata.temp),
414
+ np.mean(thermodata.qvap),
415
+ 0.0,
416
+ ]
417
+
418
+ fig, axs = plt.subplots(nrows=2, ncols=4, figsize=(13, 8))
419
+ axs = axs.flatten()
420
+ axs[-1].remove()
421
+
422
+ n = 0
423
+ for var, unit, cmapcen, cmap in zip(vars, units, cmapcens, cmaps):
424
+ norm = colors.CenteredNorm(vcenter=cmapcen)
425
+ plot_2dmean(
426
+ axs[n], thermodata.ytmean, xxh, zzh, thermodata[var], var, unit, norm, cmap
427
+ )
428
+ n += 1
429
+
430
+ relh_supersat_theta_colomaps(
431
+ [axs[4], axs[5], axs[6]],
432
+ zzh,
433
+ xxh,
434
+ zzf,
435
+ xxf,
436
+ thermodata,
437
+ inputs["Mr_ratio"],
438
+ inputs["RGAS_DRY"],
439
+ inputs["CP_DRY"],
440
+ )
441
+
442
+ for ax in axs:
443
+ ax.set_aspect("equal")
444
+
445
+ axs[0].set_ylabel("z /km")
446
+ axs[3].set_ylabel("z /km")
447
+ for ax in axs[3:]:
448
+ ax.set_xlabel("x /km")
449
+
450
+ fig.tight_layout()
451
+
452
+ if savefig:
453
+ savename = savefigpath / Path(f"thermo2dmeanprofiles{savelabel}.png")
454
+ fig.savefig(
455
+ savename,
456
+ dpi=400,
457
+ bbox_inches="tight",
458
+ facecolor="w",
459
+ format="png",
460
+ )
461
+ print("Figure .png saved as: " + str(savename))
462
+
463
+
464
+ def plot_2dwindfield(
465
+ zzh, xxh, zzf, xxf, wvel_cens, uvel_cens, savefigpath, savefig, savelabel=""
466
+ ):
467
+ wcen = np.mean(wvel_cens, axis=(0, 1)) # avg over y and time axes
468
+ ucen = np.mean(uvel_cens, axis=(0, 1))
469
+ norm = np.sqrt(wcen**2 + ucen**2)
470
+
471
+ fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(9, 6))
472
+ axs = axs.flatten()
473
+
474
+ label = ["w", "u", "|wind velocity|"]
475
+ units = " / m s$^{-1}$"
476
+ cmaps = ["coolwarm"] * 3
477
+ for v, vel in enumerate([wcen, ucen, norm]):
478
+ pcm = axs[v].pcolormesh(xxh, zzh, vel, cmap=cmaps[v])
479
+ plt.colorbar(pcm, ax=axs[v], location="top", label=label[v] + units)
480
+ axs[2].quiver(xxf, zzf, ucen, wcen)
481
+
482
+ axs[0].set_ylabel("z /km")
483
+ for ax in axs:
484
+ ax.set_xlabel("x /km")
485
+ ax.set_aspect("equal")
486
+
487
+ fig.tight_layout()
488
+
489
+ if savefig:
490
+ savename = savefigpath / Path(f"thermowindprofiles{savelabel}.png")
491
+ fig.savefig(
492
+ savename,
493
+ dpi=400,
494
+ bbox_inches="tight",
495
+ facecolor="w",
496
+ format="png",
497
+ )
498
+ print("Figure .png saved as: " + str(savename))
@@ -0,0 +1,56 @@
1
+ """
2
+ Copyright (c) 2024 MPI-M, Clara Bayley
3
+
4
+
5
+ ----- CLEO -----
6
+ File: thermodyngen.py
7
+ Project: thermobinary_src
8
+ Created Date: Wednesday 26th March 2025
9
+ Author: Clara Bayley (CB)
10
+ Additional Contributors:
11
+ -----
12
+ License: BSD 3-Clause "New" or "Revised" License
13
+ https://opensource.org/licenses/BSD-3-Clause
14
+ -----
15
+ File Description:
16
+ Thermodyanmics generator to generate winds, temperature, pressure, qvap and qcond fields
17
+ from thermo and winds generators in order to create files which CLEO can read for fromfile dynamics.
18
+ """
19
+
20
+
21
+ class ThermodynamicsGenerator:
22
+ """create thermodynamics from winds generator (for wvel, vvel and uvel) and thermo generator
23
+ (for temperature, pressure, qvap and qcond) flow field"""
24
+
25
+ def __init__(
26
+ self,
27
+ thermogen,
28
+ windsgen,
29
+ ):
30
+ self.thermogen = thermogen
31
+ self.windsgen = windsgen
32
+
33
+ """
34
+ create thermodynamics from winds generator (for wvel, vvel and uvel) and thermo generator
35
+ (for temperature, pressure, qvap and qcond) flow field
36
+
37
+ THERMODATA is dictionary with keys: "temp", "press" "qvap" "qcond"
38
+ WINDSDATA is dictionary with keys: "wwvel", "vvel" and "uvel"
39
+ THERMODYNDATA is combination of two dictionaries. Note if keys are not distinct error thrown,
40
+ or data from key in THERMODATA is overwritten by data from matching key in WINDDATA
41
+ """
42
+
43
+ def generate_thermodyn(self, gbxbounds, ndims, ntime):
44
+ THERMODATA = self.thermogen.generate_thermo(gbxbounds, ndims, ntime) # dict
45
+ WINDDATA = self.windsgen.generate_winds(
46
+ gbxbounds, ndims, ntime, THERMODATA
47
+ ) # dict
48
+
49
+ matching_keys = set(THERMODATA.keys()) & set(WINDDATA.keys())
50
+ assert (
51
+ not matching_keys
52
+ ) and "THERMODATA and WINDDATA cannot have matching keys, unsafe overwriting"
53
+
54
+ THERMODYNDATA = {**THERMODATA, **WINDDATA}
55
+
56
+ return THERMODYNDATA