Source code for cleopy.initsuperdropsbinary_src.crdgens
"""----- CLEO -----File: crdgens.pyProject: initsuperdropsbinary_srcCreated Date: Friday 13th October 2023Author: Clara Bayley (CB)Additional Contributors:-----License: BSD 3-Clause "New" or "Revised" Licensehttps://opensource.org/licenses/BSD-3-Clause-----Copyright (c) 2023 MPI-M, Clara Bayley-----File Description:various ways of generating spatialcoordinates for superdroplet initialconditions"""importnumpyasnpfrom..gbxboundariesbinary_srcimportread_gbxboundariesasrgrid
[docs]defnsupers_at_domain_base(grid_filename,constants_filename,nsupers,zlim):"""create dict for sd initialisation where nsupers only occur in gridboxes with upper bound <= zlim"""COORD0=rgrid.get_COORD0_from_constsfile(constants_filename)gbxbounds,ndims=rgrid.read_dimless_gbxboundaries_binary(grid_filename,COORD0=COORD0,return_ndims=True,isprint=False)nsupersdict={}foriiingbxbounds.keys():gbx_zupper=gbxbounds[ii][1]# z upper bound of gridboxifgbx_zupper<=zlim:nsupersdict[ii]=nsuperselse:nsupersdict[ii]=0returnnsupersdict
[docs]defnsupers_at_domain_top(grid_filename,constants_filename,nsupers,zlim):"""create dict for sd initialisation where nsupers only occur in gridboxes with lower bound >= zlim"""COORD0=rgrid.get_COORD0_from_constsfile(constants_filename)gbxbounds,ndims=rgrid.read_dimless_gbxboundaries_binary(grid_filename,COORD0=COORD0,return_ndims=True,isprint=False)nsupersdict={}foriiingbxbounds.keys():gbx_zlower=gbxbounds[ii][0]# z lower bound of gridboxifgbx_zlower>=zlim:nsupersdict[ii]=nsuperselse:nsupersdict[ii]=0returnnsupersdict
[docs]classMonoCoordGen:"""method to generate superdroplets with coord all equal to coord0"""def__init__(self,coord0):self.coord0=coord0def__call__(self,nsupers,coordrange):"""Returns coord for nsupers all with the value of coord0"""ifself.coord0>=coordrange[0]andself.coord0<coordrange[1]:attrs=np.full(nsupers,self.coord0)else:attrs=np.array([])returnattrs
[docs]classSampleCoordGen:"""method to generate 'nsupers' no. of superdroplets' coord [m] by sampling in range bewteen coordspan"""def__init__(self,random):self.random=randomdef__call__(self,nsupers,coordrange):"""Returns coord3 for nsupers sampled from coord3span [m]"""ifnotself.random:coord=np.linspace(coordrange[0],coordrange[1],nsupers,endpoint=False)else:coord=np.random.uniform(low=coordrange[0],high=coordrange[1],size=nsupers)returncoord# units [m]