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,350 @@
1
+ """
2
+ Copyright (c) 2024 MPI-M, Clara Bayley
3
+
4
+
5
+ ----- CLEO -----
6
+ File: read_gbxboundaries.py
7
+ Project: gbxboundariesbinary_src
8
+ Created Date: Wednesday 17th January 2024
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 pathlib import Path
21
+
22
+ from .create_gbxboundaries import get_COORD0_from_constsfile
23
+ from ..readbinary import readbinary
24
+
25
+
26
+ def get_gridboxboundaries(
27
+ grid_filename, COORD0=False, constants_filename="", isprint=True
28
+ ):
29
+ """get gridbox boundaries from binary file and
30
+ re-dimensionalise usign COORD0 const from constants_filename"""
31
+
32
+ if not COORD0:
33
+ COORD0 = get_COORD0_from_constsfile(constants_filename)
34
+
35
+ gbxbounds = read_dimless_gbxboundaries_binary(
36
+ grid_filename, COORD0, isprint=isprint
37
+ )
38
+
39
+ zhalf, xhalf, yhalf = halfcoords_from_gbxbounds(gbxbounds, isprint=isprint)
40
+
41
+ return zhalf, xhalf, yhalf
42
+
43
+
44
+ def get_domainvol_from_grid_filename(
45
+ grid_filename, COORD0=False, constants_filename=""
46
+ ):
47
+ """get total domain volume from binary file"""
48
+
49
+ zhalf, xhalf, yhalf = get_gridboxboundaries(
50
+ grid_filename, COORD0=COORD0, constants_filename=constants_filename
51
+ )
52
+
53
+ return calc_domainvol(zhalf, xhalf, yhalf)
54
+
55
+
56
+ def get_gbxvols_from_gridfile(
57
+ grid_filename, COORD0=False, constants_filename="", isprint=True
58
+ ):
59
+ """get total domain volume from binary file"""
60
+
61
+ if not COORD0:
62
+ COORD0 = get_COORD0_from_constsfile(constants_filename)
63
+
64
+ gbxbounds = read_dimless_gbxboundaries_binary(
65
+ grid_filename, COORD0, isprint=isprint
66
+ )
67
+
68
+ return calc_gridboxvols(gbxbounds)
69
+
70
+
71
+ def fullcell(halfcell):
72
+ """return fullcell corods (cell centres)
73
+ given half coords in a direction"""
74
+
75
+ return (halfcell[1:] + halfcell[:-1]) / 2
76
+
77
+
78
+ def cellwidth(halfcell):
79
+ """return cell spacing (width) given half coords
80
+ in a direction"""
81
+
82
+ delta = abs(halfcell[1:] - halfcell[:-1])
83
+
84
+ return delta
85
+
86
+
87
+ def fullcell_fromhalfcoords(zhalf, xhalf, yhalf):
88
+ zfull = fullcell(zhalf)
89
+ xfull = fullcell(xhalf)
90
+ yfull = fullcell(yhalf)
91
+
92
+ return zfull, xfull, yfull
93
+
94
+
95
+ def fullcoords_forallgridboxes(gbxbounds, ndims):
96
+ """returns (x,y,z) centres of gridboxes in domain"""
97
+
98
+ zhalf, xhalf, yhalf = halfcoords_from_gbxbounds(gbxbounds, isprint=False)
99
+ zfull, xfull, yfull = fullcell_fromhalfcoords(zhalf, xhalf, yhalf)
100
+
101
+ zfullcoords = np.tile(
102
+ zfull, int(ndims[1] * ndims[2])
103
+ ) # zfull of every gridbox in order of gbxindex
104
+ xfullcoords = np.tile(np.repeat(xfull, ndims[0]), int(ndims[2]))
105
+ yfullcoords = np.repeat(yfull, ndims[0] * ndims[1])
106
+
107
+ return zfullcoords, xfullcoords, yfullcoords
108
+
109
+
110
+ def coords_forgridboxfaces(gbxbounds, ndims, face):
111
+ """returns (x,y,z) coordinates of gridboxes faces
112
+ in a particular direction"""
113
+
114
+ ndims = [int(n) for n in ndims]
115
+ zhalf, xhalf, yhalf = halfcoords_from_gbxbounds(gbxbounds, isprint=False)
116
+ zfull, xfull, yfull = fullcell_fromhalfcoords(zhalf, xhalf, yhalf)
117
+
118
+ if face == "z":
119
+ nz, nx, ny = ndims[0] + 1, ndims[1], ndims[2]
120
+ zfaces = np.tile(zhalf, nx * ny) # zfull of every gridbox in order of gbxindex
121
+ xfulls = np.tile(np.repeat(xfull, nz), ny)
122
+ yfulls = np.repeat(yfull, nz * nx)
123
+ return zfaces, xfulls, yfulls
124
+
125
+ elif face == "x":
126
+ nz, nx, ny = ndims[0], ndims[1] + 1, ndims[2]
127
+ zfulls = np.tile(zfull, nx * ny) # zfull of every gridbox in order of gbxindex
128
+ xfaces = np.tile(np.repeat(xhalf, nz), ny)
129
+ yfulls = np.repeat(yfull, nz * nx)
130
+ return zfulls, xfaces, yfulls
131
+
132
+ elif face == "y":
133
+ nz, nx, ny = ndims[0], ndims[1], ndims[2] + 1
134
+ zfulls = np.tile(zfull, nx * ny) # zfull of every gridbox in order of gbxindex
135
+ xfulls = np.tile(np.repeat(xfull, nz), ny)
136
+ yfaces = np.repeat(yhalf, nz * nx)
137
+ return zfulls, xfulls, yfaces
138
+
139
+
140
+ def read_dimless_gbxboundaries_binary(
141
+ filename, COORD0=False, return_ndims=False, isprint=True
142
+ ):
143
+ """return dictionary for gbx indicies to gbx boundaries by
144
+ reading binary file. Return dimensionless version if COORD0
145
+ not give (=False)."""
146
+
147
+ data, ndata_pervar = readbinary(filename, isprint=isprint)
148
+ datatypes = [np.uint, np.uintc, np.double]
149
+
150
+ ll = [0, 0] # indexs for division of data list between each variable
151
+ for n in range(1, len(ndata_pervar)):
152
+ ll[n - 1] = np.sum(ndata_pervar[:n])
153
+
154
+ ndims = np.asarray(data[: ll[0]], dtype=datatypes[0])
155
+ gbxidxs = np.asarray(data[ll[0] : ll[1]], dtype=datatypes[1])
156
+
157
+ ngridboxes = int(np.prod(ndims))
158
+ if len(gbxidxs) != ngridboxes:
159
+ err = "number of gridbox indexes not consistent with (z,x,y) dims"
160
+ raise ValueError(err)
161
+
162
+ boundsdata = np.asarray(data[ll[1] :], dtype=datatypes[2])
163
+ boundsdata = np.reshape(boundsdata, [ngridboxes, len(boundsdata) // ngridboxes])
164
+
165
+ if COORD0:
166
+ boundsdata = boundsdata * COORD0
167
+
168
+ gbxbounds = {gbxidxs[i]: boundsdata[i] for i in range(ngridboxes)}
169
+
170
+ if return_ndims:
171
+ return gbxbounds, ndims
172
+ else:
173
+ return gbxbounds
174
+
175
+
176
+ def halfcoords_from_gbxbounds(gbxbounds, isprint=True):
177
+ """returns half coords of gbx boundaries in lists obtained
178
+ from gbxbounds dictionary"""
179
+
180
+ boundsdata = np.asarray(list(gbxbounds.values()))
181
+
182
+ zhalf = np.unique(np.sort(boundsdata[:, 0]))
183
+ zhalf = np.append(zhalf, np.amax(boundsdata[:, 1]))
184
+
185
+ xhalf = np.unique(np.sort(boundsdata[:, 2]))
186
+ xhalf = np.append(xhalf, np.amax(boundsdata[:, 3]))
187
+
188
+ yhalf = np.unique(np.sort(boundsdata[:, 4]))
189
+ yhalf = np.append(yhalf, np.amax(boundsdata[:, 5]))
190
+
191
+ if isprint:
192
+ print("zhalf: ", zhalf)
193
+ print("xhalf: ", xhalf)
194
+ print("yhalf: ", yhalf)
195
+
196
+ return zhalf, xhalf, yhalf
197
+
198
+
199
+ def plot_gridboxboundaries(
200
+ constants_filename,
201
+ grid_filename,
202
+ savefig=False,
203
+ savefigpath=None,
204
+ savelabel="",
205
+ ):
206
+ plt.rcParams.update({"font.size": 14})
207
+
208
+ zhalf, xhalf, yhalf = get_gridboxboundaries(
209
+ grid_filename, constants_filename=constants_filename
210
+ )
211
+
212
+ halfs = [zhalf, xhalf, yhalf]
213
+ fulls, deltas = [], []
214
+ for half in halfs:
215
+ fulls.append(fullcell(half))
216
+ deltas.append(cellwidth(half))
217
+
218
+ fig, axs = plt.subplots(nrows=1, ncols=3, figsize=(10, 5))
219
+
220
+ for i, crd in enumerate(["z", "x", "y"]):
221
+ xlims = [0.8 * np.amin(deltas[i]) / 1000, np.amax(deltas[i]) / 1000 * 1.2]
222
+ ylims = [np.amin(halfs[i]) / 1000, np.amax(halfs[i]) / 1000]
223
+ axs[i].scatter(deltas[i] / 1000, fulls[i] / 1000, color="k", label="centres")
224
+ axs[i].hlines(
225
+ halfs[i] / 1000,
226
+ xlims[0],
227
+ xlims[1],
228
+ color="grey",
229
+ alpha=0.8,
230
+ linewidth=0.8,
231
+ label="boundaries",
232
+ )
233
+ axs[i].set_xlim(xlims)
234
+ axs[i].set_ylim(ylims)
235
+ axs[i].set_xlabel("gridbox spacing, \u0394 " + crd + " /km")
236
+ axs[i].set_ylabel("gridbox centres, " + crd + "f /km")
237
+ axs[i].legend()
238
+
239
+ fig.tight_layout()
240
+
241
+ if savefig:
242
+ savename = savefigpath / Path(f"gridboxboundaries{savelabel}.png")
243
+ fig.savefig(
244
+ savename,
245
+ dpi=400,
246
+ bbox_inches="tight",
247
+ facecolor="w",
248
+ format="png",
249
+ )
250
+ print("Figure .png saved as: " + str(savename))
251
+
252
+
253
+ def calc_domainvol(zhalf, xhalf, yhalf):
254
+ widths = []
255
+ for half in [zhalf, xhalf, yhalf]:
256
+ widths.append(np.amax(half) - np.amin(half))
257
+
258
+ domainvol = np.prod(widths)
259
+
260
+ return domainvol
261
+
262
+
263
+ def calc_gridboxvols(gbxbounds):
264
+ gbxvols = []
265
+ for gbxindex, bounds in gbxbounds.items():
266
+ zwidth = bounds[1] - bounds[0]
267
+ xwidth = bounds[3] - bounds[2]
268
+ ywidth = bounds[5] - bounds[4]
269
+
270
+ gbxvols.append(zwidth * xwidth * ywidth)
271
+
272
+ return gbxvols
273
+
274
+
275
+ def domaininfo(gbxbounds, isprint=True):
276
+ zhalf, xhalf, yhalf = halfcoords_from_gbxbounds(gbxbounds, isprint=isprint)
277
+ domainvol = calc_domainvol(zhalf, xhalf, yhalf)
278
+
279
+ gridboxvols = calc_gridboxvols(gbxbounds)
280
+ ngridboxes = len(gridboxvols)
281
+
282
+ return domainvol, gridboxvols, ngridboxes
283
+
284
+
285
+ def grid_dimensions(gbxbounds):
286
+ zhalf, xhalf, yhalf = halfcoords_from_gbxbounds(gbxbounds, isprint=False)
287
+
288
+ if len(zhalf) == 2:
289
+ griddims = 0
290
+ elif len(xhalf) == 2:
291
+ griddims = 1
292
+ elif len(yhalf) == 2:
293
+ griddims = 2
294
+ else:
295
+ griddims = 3
296
+
297
+ extents, spacings = [], []
298
+ for half in [zhalf, xhalf, yhalf]:
299
+ extents.append([np.amin(half), np.amax(half)])
300
+ spacings.append(abs(half[1:] - half[:-1]))
301
+
302
+ return extents, spacings, griddims
303
+
304
+
305
+ def print_domain_info(constants_filename, grid_filename):
306
+ """prints information about domain read from grid_filename and constants file"""
307
+
308
+ isprint = True
309
+ COORD0 = get_COORD0_from_constsfile(constants_filename)
310
+ gbxbounds = read_dimless_gbxboundaries_binary(
311
+ grid_filename, COORD0, isprint=isprint
312
+ )
313
+
314
+ domainvol, gridboxvols, ngridboxes = domaininfo(gbxbounds, isprint=isprint)
315
+ xtns, spacings, griddims = grid_dimensions(gbxbounds)
316
+ ztot = abs(xtns[0][0] - xtns[0][1])
317
+ xtot = abs(xtns[1][0] - xtns[1][1])
318
+ ytot = abs(xtns[2][0] - xtns[2][1])
319
+
320
+ inforstr = (
321
+ "\n------ DOMAIN / GRIDBOXES INFO ------\n"
322
+ + "------------- "
323
+ + str(griddims)
324
+ + "-D MODEL -------------\n"
325
+ + "domain dimensions: ({:3g}x{:3g}x{:3g})m^3\n".format(ztot, xtot, ytot)
326
+ + "domain no. gridboxes: "
327
+ + str(len(spacings[0]))
328
+ + "x"
329
+ + str(len(spacings[1]))
330
+ + "x"
331
+ + str(len(spacings[2]))
332
+ + "\n"
333
+ + "domain z limits: ({:3g},{:3g})m\n".format(np.amin(xtns[0]), np.amax(xtns[0]))
334
+ + "domain x limits: ({:3g}, {:3g})m\n".format(
335
+ np.amin(xtns[1]), np.amax(xtns[1])
336
+ )
337
+ + "domain y limits: ({:3g}, {:3g})m\n".format(
338
+ np.amin(xtns[2]), np.amax(xtns[2])
339
+ )
340
+ + "mean gridbox z spacing: {:3g} m\n".format(np.mean(spacings[0]))
341
+ + "mean gridbox x spacing: {:3g} m\n".format(np.mean(spacings[1]))
342
+ + "mean gridbox y spacing: {:3g} m\n".format(np.mean(spacings[2]))
343
+ + "mean gridbox volume: {:3g}".format(np.mean(gridboxvols))
344
+ + " m^3\n"
345
+ + "total domain volume: {:3g} m^3\n".format(domainvol)
346
+ + "total no. gridboxes: "
347
+ + str(ngridboxes)
348
+ + "\n------------------------------------\n"
349
+ )
350
+ print(inforstr)
cleopy/geninitconds.py ADDED
@@ -0,0 +1,144 @@
1
+ """
2
+ Copyright (c) 2024 MPI-M, Clara Bayley
3
+
4
+
5
+ ----- CLEO -----
6
+ File: geninitconds.py
7
+ Project: cleopy
8
+ Created Date: Friday 8th November 2024
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
+ Script to help with generating and plotting input files
17
+ """
18
+
19
+
20
+ import matplotlib.pyplot as plt
21
+
22
+
23
+ def generate_gridbox_boundaries(
24
+ grid_filename,
25
+ zgrid,
26
+ xgrid,
27
+ ygrid,
28
+ constants_filename,
29
+ isprintinfo=False,
30
+ isfigures=[False, False],
31
+ savefigpath=None,
32
+ savelabel="",
33
+ ):
34
+ """write gridbox boundaries binary. [shows, saves] figures if isfigures = [True, True]"""
35
+ from .gbxboundariesbinary_src import create_gbxboundaries as cgrid
36
+ from .gbxboundariesbinary_src import read_gbxboundaries as rgrid
37
+
38
+ cgrid.write_gridboxboundaries_binary(
39
+ grid_filename, zgrid, xgrid, ygrid, constants_filename
40
+ )
41
+
42
+ if isprintinfo:
43
+ rgrid.print_domain_info(constants_filename, grid_filename)
44
+
45
+ if any(isfigures):
46
+ rgrid.plot_gridboxboundaries(
47
+ constants_filename,
48
+ grid_filename,
49
+ savefig=isfigures[1],
50
+ savefigpath=savefigpath,
51
+ savelabel=savelabel,
52
+ )
53
+ if isfigures[0]:
54
+ plt.show()
55
+ plt.close("all")
56
+
57
+
58
+ def generate_initial_superdroplet_conditions(
59
+ initattrsgen,
60
+ initsupers_filename,
61
+ config_filename,
62
+ constants_filename,
63
+ grid_filename,
64
+ nsupers,
65
+ numconc,
66
+ numconc_tolerance=0.0,
67
+ isprintinfo=False,
68
+ isfigures=[False, False],
69
+ savefigpath=None,
70
+ gbxs2plt=0,
71
+ savelabel="",
72
+ ):
73
+ """write initial superdroplets binary. [shows, saves] figures if isfigures = [True, True]"""
74
+ from .initsuperdropsbinary_src import create_initsuperdrops as csupers
75
+ from .initsuperdropsbinary_src import read_initsuperdrops as rsupers
76
+
77
+ csupers.write_initsuperdrops_binary(
78
+ initsupers_filename,
79
+ initattrsgen,
80
+ config_filename,
81
+ constants_filename,
82
+ grid_filename,
83
+ nsupers,
84
+ numconc,
85
+ numconc_tolerance=numconc_tolerance,
86
+ isprint=isprintinfo,
87
+ )
88
+
89
+ if isprintinfo:
90
+ rsupers.print_initsupers_infos(
91
+ initsupers_filename, config_filename, constants_filename, grid_filename
92
+ )
93
+
94
+ if any(isfigures):
95
+ rsupers.plot_initGBxs_distribs(
96
+ config_filename,
97
+ constants_filename,
98
+ initsupers_filename,
99
+ grid_filename,
100
+ gbxs2plt,
101
+ savefig=isfigures[1],
102
+ savefigpath=savefigpath,
103
+ savelabel=savelabel,
104
+ )
105
+ if isfigures[0]:
106
+ plt.show()
107
+ plt.close("all")
108
+
109
+
110
+ def generate_thermodynamics_conditions_fromfile(
111
+ thermofiles,
112
+ thermodyngen,
113
+ config_filename,
114
+ constants_filename,
115
+ grid_filename,
116
+ isfigures=[False, False],
117
+ savefigpath=None,
118
+ savelabel="",
119
+ ):
120
+ """write thermodynamics binaries. [shows, saves] figures if isfigures = [True, True]"""
121
+ from .thermobinary_src import create_thermodynamics as cthermo
122
+ from .thermobinary_src import read_thermodynamics as rthermo
123
+
124
+ cthermo.write_thermodynamics_binary(
125
+ thermofiles,
126
+ thermodyngen,
127
+ config_filename,
128
+ constants_filename,
129
+ grid_filename,
130
+ )
131
+
132
+ if any(isfigures):
133
+ rthermo.plot_thermodynamics(
134
+ constants_filename,
135
+ config_filename,
136
+ grid_filename,
137
+ thermofiles,
138
+ savefig=isfigures[1],
139
+ savefigpath=savefigpath,
140
+ savelabel=savelabel,
141
+ )
142
+ if isfigures[0]:
143
+ plt.show()
144
+ plt.close("all")
@@ -0,0 +1,15 @@
1
+ """
2
+ ----- CLEO -----
3
+ File: __init__.py
4
+ Project: initsuperdropsbinary_src
5
+ Created Date: Wednesday 22nd November 2023
6
+ Author: Clara Bayley (CB)
7
+ Additional Contributors:
8
+ -----
9
+ License: BSD 3-Clause "New" or "Revised" License
10
+ https://opensource.org/licenses/BSD-3-Clause
11
+ -----
12
+ Copyright (c) 2023 MPI-M, Clara Bayley
13
+ -----
14
+ File Description:
15
+ """