Skip to content

Commit

Permalink
added zbot option to adjust_thickness
Browse files Browse the repository at this point in the history
	- with this option, cell interfaces
  	are no deeper than zbot, for partial
   	columns.
  • Loading branch information
MJHarrison-GFDL committed Apr 30, 2019
1 parent ed7dcc6 commit 9232eda
Showing 1 changed file with 38 additions and 26 deletions.
64 changes: 38 additions & 26 deletions midas/rectgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,7 @@ def create_field(self,expression,name,var_dict=None):
"""

cmd = ''.join(['self.',name,'=',expression])
print(cmd)
# print(cmd)
ld=locals()
exec(cmd,globals(),ld)
# vars(self)[name]=ld[name]
Expand Down Expand Up @@ -2301,11 +2301,11 @@ def time_avg(self,field=None,vol_weight=True,target=None):
return None

cmd='sout=self.'+field
print(cmd)
# print(cmd)
ld=locals()
exec(cmd,globals(),ld)
sout=ld['sout']
print(sout.shape)
# print(sout.shape)
var_dict = dict.copy(self.var_dict[field]) # inherit variable dictionary from parent


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


cmd = ''.join(['sout=self.',field])
print(cmd)
# print(cmd)
ld=locals()
exec(cmd,globals(),ld)
sout=ld['sout']
print(sout.shape)
# print(sout.shape)



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



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

dz = self.var_dict[field]['dz']

dz=numpy.ma.filled(dz,0.)

nz = vars(self)[field].shape[1]
D = numpy.tile(self.grid.D,(nz+1,1,1))
ztop = numpy.zeros((nz+1,self.grid.jm,self.grid.im))
zbot = numpy.zeros((nz+1,self.grid.jm,self.grid.im))

if z_top is not None:
ztop = z_top
ztop = numpy.tile(ztop,(nz+1,1,1))
ztop[:] = z_top
# ztop = numpy.tile(ztop,(nz+1,1,1))
if z_bot is not None:
zbot[:] = z_bot
# zbot = numpy.tile(zbot,(nz+1,1,1))

if self.var_dict[field]['Zdir']==-1:
zb=self.var_dict[field]['z_interfaces'].copy()
zb[zb>ztop]=ztop[zb>ztop]
if z_top is not None:
zb[zb>ztop]=ztop[zb>ztop]
if z_bot is not None:
zb[zb<-zbot]=-zbot[zb<-zbot]
zb[zb<-D]=-D[zb<-D]
zbot=sq(zb[-1,:])
if not compress_only:
zbot[zbot>-self.grid.D]=-self.grid.D[zbot>-self.grid.D]
zb[-1,:]=zbot
zbot_=sq(zb[-1,:])
if not compress_only and z_bot is None:
zbot_[zbot_>-self.grid.D]=-self.grid.D[zbot_>-self.grid.D]
zb[-1,:]=zbot_
dz = zb[:-1]-zb[1:]

ztop=ztop[0,:]
ztop=zb[0,:]
ztop=ztop[numpy.newaxis,:]
zb=ztop-numpy.cumsum(dz,axis=0)
zb=numpy.concatenate((ztop,zb),axis=0)

else:
zb=self.var_dict[field]['z_interfaces'].copy()
zb=numpy.ma.filled(zb,0.)
zb[zb<ztop]=ztop[zb<ztop]
if z_top is not None:
zb[zb<ztop]=ztop[zb<ztop]
# print('zb max before compress=',zb.max())
if z_bot is not None:
zb[zb>zbot]=zbot[zb>zbot]
zb[zb>D]=D[zb>D]
zbot=sq(zb[-1,:])
# print('zb max after compress=',zb.max())
zbot_=sq(zb[-1,:])
Depth=numpy.ma.filled(self.grid.D,0)
if not compress_only:
iind=numpy.where(zbot<Depth)
zbot[iind]=Depth[iind]
zb[-1,:]=zbot

if not compress_only and z_bot is None:
iind=numpy.where(zbot_<Depth)
zbot_[iind]=Depth[iind]
zb[-1,:]=zbot_
dz = zb[1:]-zb[:-1]

ztop=ztop[0,:]
ztop=zb[0,:]
ztop=ztop[numpy.newaxis,:]
zb=ztop+numpy.cumsum(dz,axis=0)
zb=numpy.concatenate((ztop,zb),axis=0)
Expand All @@ -3160,6 +3168,10 @@ def adjust_thickness(self,field=None,min_thickness=0.0,z_top=None,compress_only=
self.var_dict[field]['z_interfaces']=zb
else:

if z_top is not None or z_bot is not None:
print('Dyaamic grid adjustment not configured yet.')
return None

dz = self.var_dict[field]['dz']
dz = numpy.ma.filled(dz,0.)

Expand Down

0 comments on commit 9232eda

Please sign in to comment.