Skip to content

Commit

Permalink
Merge pull request #157 from FESOM/workbench
Browse files Browse the repository at this point in the history
Workbench
  • Loading branch information
patrickscholz authored Oct 16, 2024
2 parents 1703bbb + 1c00402 commit b8af39c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 9 deletions.
42 changes: 36 additions & 6 deletions tripyview/sub_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,12 @@ def _preprocess(x, do_prec):
# remove variables that are not needed
#data = data.drop(labels=vname_drop)
data = data.drop_vars(vname_drop)


#___________________________________________________________________________
# This is for icepack data over thickness classes make class selection always
# based in indices
if ('ncat' in data.dims): depidx = True

#___________________________________________________________________________
# rename old vertices dimension name to new
# 'node' --> 'nod2'
Expand Down Expand Up @@ -403,7 +408,7 @@ def _preprocess(x, do_prec):
# select depth levels also for vertical interpolation
# found 3d data based mid-depth levels (temp, salt, pressure, ....)
# if ( ('nz1' in data[vname].dims) or ('nz' in data[vname].dims) ) and (depth is not None):
if ( bool(set(['nz1','nz']).intersection(data.dims)) ) and (depth is not None):
if ( bool(set(['nz1','nz', 'ncat']).intersection(data.dims)) ) and (depth is not None):
#print('~~ >-))))o> o0O ~~~ A')
#_______________________________________________________________________
data, str_ldep = do_select_levidx(data, mesh, depth, depidx)
Expand Down Expand Up @@ -433,10 +438,11 @@ def _preprocess(x, do_prec):
#___________________________________________________________________________
# select all depth levels but do vertical summation over it --> done for
# merid heatflux
elif ( bool(set(['nz1', 'nz']).intersection(data.dims)) ) and (depth is None) and (do_zarithm in ['sum','mean','wmean']):
elif ( bool(set(['nz1', 'nz', 'ncat']).intersection(data.dims)) ) and (depth is None) and (do_zarithm in ['sum','mean','wmean','wint', 'max', 'min']):
#print('~~ >-))))o> o0O ~~~ B')
if ('nz1' in data.dims): data = do_depth_arithmetic(data, do_zarithm, "nz1" )
elif ('nz' in data.dims): data = do_depth_arithmetic(data, do_zarithm, "nz" )
elif ('nz' in data.dims): data = do_depth_arithmetic(data, do_zarithm, "nz" )
elif ('ncat' in data.dims): data = do_depth_arithmetic(data, do_zarithm, "ncat")
# only 2D data found
else:
#print('~~ >-))))o> o0O ~~~ C')
Expand Down Expand Up @@ -476,6 +482,10 @@ def _preprocess(x, do_prec):
'do_zarithm':str_adep, 'str_ltim':str_ltim,'str_ldep':str_ldep,'str_lsave':str_lsave,
'is_data':is_data, 'is_ie2n':is_ie2n, 'do_compute':do_compute,
'descript':descript})

# in case of icepack data write thickness class as attribute
if ('ncat' in data.dims) and (depth is not None): attr_dict.update({'ncat':depth})

data = do_additional_attrs(data, vname, attr_dict)

#___________________________________________________________________________
Expand Down Expand Up @@ -666,6 +676,9 @@ def do_gridinfo_and_weights(mesh, data, do_hweight=True, do_zweight=False):

elif ('ndens' in data.dims):
dimv = 'ndens'

elif ('ncat' in data.dims):
dimv = 'ncat'

dimh = None
if ('nod2' in data.dims):
Expand Down Expand Up @@ -974,7 +987,7 @@ def do_select_levidx(data, mesh, depth, depidx):
#_______________________________________________________________________
# select vertical levels from data
data = data.isel(nz1=sel_levidx)

aux_strdep = 'depidx'
#___________________________________________________________________________
# found 3d data based on full-depth levels (w, Kv,...) --> compute
# selection index
Expand All @@ -987,17 +1000,34 @@ def do_select_levidx(data, mesh, depth, depidx):
#_______________________________________________________________________
# select vertical levels from data
data = data.isel(nz=sel_levidx)
aux_strdep = 'depidx'

#___________________________________________________________________________
# found 3d data based based on icepack thickness classes -->
# selection index
elif ('ncat' in data.dims) and (depth is not None):
#_______________________________________________________________________
# compute selection index either single layer of for interpolation
ndimax = data.sizes['ncat']
sel_levidx = do_comp_sel_levidx(np.arange(1,ndimax+1,1), depth, depidx, ndimax)
#_______________________________________________________________________
# select vertical levels from data
data = data.isel(ncat=sel_levidx)
aux_strdep = 'ncat'

#___________________________________________________________________________
# do depth information string
if (depth is not None):
if (depth is not None) and not depidx:
if isinstance(depth,(int, float)):
str_ldep = ', dep:{}m'.format(str(depth))
elif isinstance(depth,(list, np.ndarray, range)):
if len(depth)>0:
str_ldep = ', dep:{}-{}m'.format(str(depth[0]), str(depth[-1]))
else:
str_ldep = ', dep:{}-{}m'.format(str(mesh.zlev[0]), str(mesh.zlev[-1]))

elif (depth is not None) and depidx:
str_ldep = ', {}:{}'.format(aux_strdep, str(depth))
#___________________________________________________________________________
return(data, str_ldep)

Expand Down
11 changes: 8 additions & 3 deletions tripyview/sub_plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5841,14 +5841,19 @@ def do_setupcinfo(cinfo, data, do_rescale, mesh=None, tri=None, do_vec=False,
# clean colorstep levels
else:
dez = 0
ini_dez = np.int32(np.log10(np.abs(cref-cmin))) + 2
ini_dez = np.log10(np.abs(cref-cmin))
if ini_dez<0: ini_dez = -np.floor(ini_dez)
else : ini_dez = np.ceil(ini_dez)
ini_dez = np.int32(ini_dez) + 2
new_cref= prev_cref = cref
dc = cinfo['cmax']- cinfo['cmin']
#print(ini_dez, cref, new_cref, cmin, dc)
while True:
prev_cref = new_cref
new_cref = np.around(cref, ini_dez-dez)
print(prev_cref, new_cref)
if new_cref<cref-dc/10 or new_cref>cref+dc/10 or prev_cref==new_cref:
#print(prev_cref, new_cref, dez, ini_dez-dez)
#if (new_cref<cref-dc/10 or new_cref>cref+dc/10 or prev_cref==new_cref) and dez!=0:
if (new_cref<cref-dc/10 or new_cref>cref+dc/10 or dez>10) and dez!=0:
break
else:
dez=dez+1
Expand Down

0 comments on commit b8af39c

Please sign in to comment.