Skip to content

Commit 9232eda

Browse files
added zbot option to adjust_thickness
- with this option, cell interfaces are no deeper than zbot, for partial columns.
1 parent ed7dcc6 commit 9232eda

File tree

1 file changed

+38
-26
lines changed

1 file changed

+38
-26
lines changed

midas/rectgrid.py

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,7 +1640,7 @@ def create_field(self,expression,name,var_dict=None):
16401640
"""
16411641

16421642
cmd = ''.join(['self.',name,'=',expression])
1643-
print(cmd)
1643+
# print(cmd)
16441644
ld=locals()
16451645
exec(cmd,globals(),ld)
16461646
# vars(self)[name]=ld[name]
@@ -2301,11 +2301,11 @@ def time_avg(self,field=None,vol_weight=True,target=None):
23012301
return None
23022302

23032303
cmd='sout=self.'+field
2304-
print(cmd)
2304+
# print(cmd)
23052305
ld=locals()
23062306
exec(cmd,globals(),ld)
23072307
sout=ld['sout']
2308-
print(sout.shape)
2308+
# print(sout.shape)
23092309
var_dict = dict.copy(self.var_dict[field]) # inherit variable dictionary from parent
23102310

23112311

@@ -2486,11 +2486,11 @@ def monthly_avg(self,field=None,vol_weight=True, year_ref=None,DEBUG=False):
24862486

24872487

24882488
cmd = ''.join(['sout=self.',field])
2489-
print(cmd)
2489+
# print(cmd)
24902490
ld=locals()
24912491
exec(cmd,globals(),ld)
24922492
sout=ld['sout']
2493-
print(sout.shape)
2493+
# print(sout.shape)
24942494

24952495

24962496

@@ -3090,7 +3090,7 @@ def remap_ALE(self,fields=None,z_bounds=None,zbax_data=None,method='pcm',bndy_ex
30903090

30913091

30923092

3093-
def adjust_thickness(self,field=None,min_thickness=0.0,z_top=None,compress_only=False):
3093+
def adjust_thickness(self,field=None,min_thickness=0.0,z_top=None,z_bot=None,compress_only=False):
30943094
"""
30953095
30963096
Adjust cell thicknesses based on grid.D
@@ -3107,46 +3107,54 @@ def adjust_thickness(self,field=None,min_thickness=0.0,z_top=None,compress_only=
31073107
if self.var_dict[field]['Ztype'] == 'Fixed':
31083108

31093109
dz = self.var_dict[field]['dz']
3110-
31113110
dz=numpy.ma.filled(dz,0.)
3112-
31133111
nz = vars(self)[field].shape[1]
31143112
D = numpy.tile(self.grid.D,(nz+1,1,1))
31153113
ztop = numpy.zeros((nz+1,self.grid.jm,self.grid.im))
3114+
zbot = numpy.zeros((nz+1,self.grid.jm,self.grid.im))
3115+
31163116
if z_top is not None:
3117-
ztop = z_top
3118-
ztop = numpy.tile(ztop,(nz+1,1,1))
3117+
ztop[:] = z_top
3118+
# ztop = numpy.tile(ztop,(nz+1,1,1))
3119+
if z_bot is not None:
3120+
zbot[:] = z_bot
3121+
# zbot = numpy.tile(zbot,(nz+1,1,1))
31193122

31203123
if self.var_dict[field]['Zdir']==-1:
31213124
zb=self.var_dict[field]['z_interfaces'].copy()
3122-
zb[zb>ztop]=ztop[zb>ztop]
3125+
if z_top is not None:
3126+
zb[zb>ztop]=ztop[zb>ztop]
3127+
if z_bot is not None:
3128+
zb[zb<-zbot]=-zbot[zb<-zbot]
31233129
zb[zb<-D]=-D[zb<-D]
3124-
zbot=sq(zb[-1,:])
3125-
if not compress_only:
3126-
zbot[zbot>-self.grid.D]=-self.grid.D[zbot>-self.grid.D]
3127-
zb[-1,:]=zbot
3130+
zbot_=sq(zb[-1,:])
3131+
if not compress_only and z_bot is None:
3132+
zbot_[zbot_>-self.grid.D]=-self.grid.D[zbot_>-self.grid.D]
3133+
zb[-1,:]=zbot_
31283134
dz = zb[:-1]-zb[1:]
3129-
3130-
ztop=ztop[0,:]
3135+
ztop=zb[0,:]
31313136
ztop=ztop[numpy.newaxis,:]
31323137
zb=ztop-numpy.cumsum(dz,axis=0)
31333138
zb=numpy.concatenate((ztop,zb),axis=0)
31343139

31353140
else:
31363141
zb=self.var_dict[field]['z_interfaces'].copy()
31373142
zb=numpy.ma.filled(zb,0.)
3138-
zb[zb<ztop]=ztop[zb<ztop]
3143+
if z_top is not None:
3144+
zb[zb<ztop]=ztop[zb<ztop]
3145+
# print('zb max before compress=',zb.max())
3146+
if z_bot is not None:
3147+
zb[zb>zbot]=zbot[zb>zbot]
31393148
zb[zb>D]=D[zb>D]
3140-
zbot=sq(zb[-1,:])
3149+
# print('zb max after compress=',zb.max())
3150+
zbot_=sq(zb[-1,:])
31413151
Depth=numpy.ma.filled(self.grid.D,0)
3142-
if not compress_only:
3143-
iind=numpy.where(zbot<Depth)
3144-
zbot[iind]=Depth[iind]
3145-
zb[-1,:]=zbot
3146-
3152+
if not compress_only and z_bot is None:
3153+
iind=numpy.where(zbot_<Depth)
3154+
zbot_[iind]=Depth[iind]
3155+
zb[-1,:]=zbot_
31473156
dz = zb[1:]-zb[:-1]
3148-
3149-
ztop=ztop[0,:]
3157+
ztop=zb[0,:]
31503158
ztop=ztop[numpy.newaxis,:]
31513159
zb=ztop+numpy.cumsum(dz,axis=0)
31523160
zb=numpy.concatenate((ztop,zb),axis=0)
@@ -3160,6 +3168,10 @@ def adjust_thickness(self,field=None,min_thickness=0.0,z_top=None,compress_only=
31603168
self.var_dict[field]['z_interfaces']=zb
31613169
else:
31623170

3171+
if z_top is not None or z_bot is not None:
3172+
print('Dyaamic grid adjustment not configured yet.')
3173+
return None
3174+
31633175
dz = self.var_dict[field]['dz']
31643176
dz = numpy.ma.filled(dz,0.)
31653177

0 commit comments

Comments
 (0)