Skip to content

Commit e6cfda8

Browse files
committed
fully working vesrion in prep for nemo 4.2
1 parent cf17a05 commit e6cfda8

11 files changed

Lines changed: 113 additions & 35 deletions

File tree

bgcval2/bgcvaltools/generic_map_legend.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ def make_figure(region, orcaGridfn=None):
210210
#cbar = pyplot.colorbar(ax=ax_pc, cax=im3)
211211

212212
pyplot.suptitle(region+': '+getLongName(region))
213+
214+
area = calc_area(region, orcaGridfn=orcaGridfn)
215+
fig.text(
216+
0.5, 0.9, 'Area: '+str(f"{int(area):,d}")+' m$^2$', ha='center', va='center')
217+
213218
print('saving:', fig_fn)
214219
pyplot.savefig(fig_fn,dpi=300.)
215220
pyplot.savefig(fig_fn.replace('.png', '_trans.png'), transparent=True)
@@ -251,14 +256,15 @@ def calc_area(region, orcaGridfn = None):
251256

252257
new_area = np.ma.masked_where(region_mask + old_mask_flat, flat_area)
253258
total_area=new_area.sum()
254-
print('region:', total_area)
259+
print(region, ' Area:', total_area, 'm2')
255260

256261

257262
out_fn = bvt.folder('region_areas')+region+'.txt'
258263
txt = ''.join([region, ', ', str(int(total_area)), '\n'])
259264
fn = open(out_fn, 'w')
260265
fn.write(txt)
261266
fn.close()
267+
return total_area
262268

263269

264270

@@ -274,19 +280,18 @@ def main():
274280

275281

276282
regions = [
277-
# 'LIseas',
278-
# 'LIGINseas',
283+
279284
# 'GLINseas',
280285
# 'Ascension',
281286
# 'ITCZ',
282287
# 'TristandaCunha',
283288
# 'Pitcairn',
284289
# 'Cornwall',
285-
'BritishIsles',
290+
# 'BritishIsles',
286291
# 'SubtropicNorthAtlantic',
287292
# 'SPNA',
288293
# 'STNA',
289-
# 'SouthernOcean',
294+
'SouthernOcean',
290295
# 'subpolar',
291296
# 'NorthEastAtlantic',
292297
# 'ArcticOcean',
@@ -298,15 +303,17 @@ def main():
298303
# 'SouthPacificOcean',
299304
# 'NorthAtlanticOcean',
300305
# 'SouthAtlanticOcean',
301-
# 'GINseas',
302-
# 'LabradorSea',
303-
# 'IrmingerSea',
306+
# 'GINseas',
307+
# 'LabradorSea',
308+
# 'IrmingerSea',
309+
# 'LIseas',
310+
'LIGINseas',
304311
# 'EquatorialAtlanticOcean',
305312
# 'Global',
306313
# 'ignoreInlandSeas',
307314
]
308315
for region in regions[:]:
309-
calc_area(region, orcaGridfn=orcaGridfn)
316+
area = calc_area(region, orcaGridfn=orcaGridfn)
310317
make_figure(region, orcaGridfn=orcaGridfn)
311318

312319
if __name__ == "__main__":

bgcval2/bgcvaltools/pftnames.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ def makeLongNameDict():
324324
lnd['sossheig'] = "Sea Surface Height"
325325
lnd['FreshwaterFlux'] = "Freshwater Flux"
326326
lnd['hfbasinatlantic'] = 'Northward Atlantic heat transport'
327+
lnd['sltbasinatlantic'] = 'Northward Atlantic salt transport'
327328
lnd['exportRatio'] = "Export Ratio"
328329
lnd['LocalExportRatio'] = "Export Ratio"
329330
lnd['OCN_RHOSW'] = 'Density'
@@ -461,10 +462,14 @@ def makeLongNameDict():
461462
lnd['MaxMonthlyMLD'] = 'Annual Maximum Mixed Layer Depth'
462463
lnd['MinMonthlyMLD'] = 'Annual Minimum Mixed Layer Depth'
463464

464-
lnd['mld_DT02'] = 'MLD:Fixed Threshold Temperature '
465+
lnd['mld_DT02'] = 'MLD:Fixed Threshold Temperature'
465466
lnd['mld_DR003'] = 'MLD:Fixed Threshold Density'
466467
lnd['mld_DReqDTm02'] = 'MLD:Variable Threshold Density'
467468

469+
lnd['tnpeo'] = 'Tendency of ocean potential energy content'
470+
lnd['mldzintt0_2'] = 'MLD - mldzintt0_2' # mldr0_3 T based, what was o
471+
lnd['mldr0_3'] = 'MLD mldr0_3' #: rho-based, surface reference, output in u-dv346
472+
468473
#####
469474
# Depth layers/transects.
470475
lnd['AtlanticTransect'] = "Atlantic Transect"

bgcval2/functions/circulation.py

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ def drakePassage(nc, keys, **kwargs):
325325
assert 0
326326
print('drakePassage:', grid, 'LON', LON, 'LAT0',LAT0, 'LAT1', LAT1)
327327

328-
all_e3u_keys = ['thkcello', 'e3u']
328+
all_e3u_keys = ['thkcello', 'thkcelluo', 'e3u']
329329
e3u_keys = find_keys_in_nc(nc, all_e3u_keys)
330330
e3u = nc.variables[e3u_keys[0]][0, :, LAT0:LAT1, LON]
331331

@@ -371,7 +371,15 @@ def davisstraightflux(nc, keys, straight='Davis', **kwargs):
371371
print('These needs to be multiplied by the thkcello.')
372372
assert 0
373373

374-
thkcello = nc.variables['thkcello'][0, :, LAT0:LAT1, LON]
374+
375+
if 'thkcello' in nc.variables.keys():
376+
thkcello = nc.variables['thkcello'][0, :, LAT0:LAT1, LON]
377+
elif 'thkcelluo' in nc.variables.keys():
378+
thkcello = nc.variables['thkcelluo'][0, :, LAT0:LAT1, LON]
379+
elif 'thkcellvo' in nc.variables.keys():
380+
thkcello = nc.variables['thkcellvo'][0, :, LAT0:LAT1, LON]
381+
else: assert 0
382+
#thkcello = nc.variables['thkcello'][0, :, LAT0:LAT1, LON]
375383

376384
print('Davis straight:', grid, 'LON', LON, 'LAT0',LAT0, 'LAT1', LAT1)
377385

@@ -503,11 +511,19 @@ def TwentySixNorth(nc, keys, lat='26N', return_max_depth=False, **kwargs):
503511

504512
atlmoc = np.array(np.zeros_like(zv[0, :, :, 0]))
505513

514+
# if 'thkcello' in nc.variables.keys():
515+
# thkcello = nc.variables['thkcello'][0, :, latslice, :]
516+
506517
if 'thkcello' in nc.variables.keys():
507518
thkcello = nc.variables['thkcello'][0, :, latslice, :]
508-
thkcello = np.ma.masked_where(thkcello.mask + zv[0].mask, thkcello)
519+
elif 'thkcelluo' in nc.variables.keys():
520+
thkcello = nc.variables['thkcelluo'][0, :, latslice, :]
521+
elif 'thkcellvo' in nc.variables.keys():
522+
thkcello = nc.variables['thkcellvo'][0, :, latslice, :]
509523
else:
510524
thkcello = e3v_AMOC[:]
525+
thkcello = np.ma.array(thkcello)
526+
thkcello = np.ma.masked_where(thkcello.mask + zv[0].mask, thkcello)
511527

512528
depths = np.ma.abs(np.cumsum(thkcello, axis=0))
513529

@@ -635,9 +651,16 @@ def gulfstream_depth(nc, keys, **kwargs):
635651
print(lats, lons)
636652

637653
vo = nc.variables[keys[0]][0, :, latslice26Nnm, lonslice_70W].squeeze() # m/s
638-
thickness = nc.variables['thkcello'][0,:,latslice26Nnm, lonslice_70W].squeeze()
654+
# thickness = nc.variables['thkcello'][0,:,latslice26Nnm, lonslice_70W].squeeze()
639655
depth = np.abs(np.cumsum(thickness, axis=0))# depth array
640656

657+
if 'thkcello' in nc.variables.keys():
658+
thickness = nc.variables['thkcello'][0,:,latslice26Nnm, lonslice_70W].squeeze()
659+
elif 'thkcelluo' in nc.variables.keys():
660+
thickness = nc.variables['thkcelluo'][0,:,latslice26Nnm, lonslice_70W].squeeze()
661+
elif 'thkcellvo' in nc.variables.keys():
662+
thickness = nc.variables['thkcellvo'][0,:,latslice26Nnm, lonslice_70W].squeeze()
663+
641664
vo = np.ma.masked_where(vo.mask + (vo == 0.), vo)
642665

643666

@@ -726,8 +749,14 @@ def gulfstream(nc, keys, **kwargs):
726749
lons = nc.variables['nav_lon'][latslice26Nnm, lonslice_70W]
727750
vo = np.ma.array(nc.variables[keys[0]][0, :, latslice26Nnm, lonslice_70W]) # m/s
728751
vo = np.ma.masked_where(vo.mask + (vo <= 0.), vo)
752+
753+
if 'thkcello' in nc.variables.keys():
754+
thickness = nc.variables['thkcello'][0,:,latslice26Nnm, lonslice_70W]
755+
elif 'thkcelluo' in nc.variables.keys():
756+
thickness = nc.variables['thkcelluo'][0,:,latslice26Nnm, lonslice_70W]
757+
elif 'thkcellvo' in nc.variables.keys():
758+
thickness = nc.variables['thkcellvo'][0,:,latslice26Nnm, lonslice_70W]
729759

730-
thickness = nc.variables['thkcello'][0,:,latslice26Nnm, lonslice_70W]
731760
depth = np.abs(np.cumsum(thickness, axis=0))# depth array
732761
#print(vo.shape, thickness.shape, e1v_AMOC26N.shape)
733762
gs = 0.
@@ -767,7 +796,16 @@ def twentysixnorth025(nc, keys, **kwargs):
767796
latslice26N = eORCA025_latslice26Nnm
768797
lonslice26N = eORCA025_lonslice26Nnm
769798
vo = np.ma.array(nc.variables[keys[0]][..., latslice26N, lonslice26N]) # #vo in m/s
770-
thkcello = np.ma.array(nc.variables['thkcello'][..., latslice26N, lonslice26N]) # #thickness
799+
# thkcello = np.ma.array(nc.variables['thkcello'][..., latslice26N, lonslice26N]) # #thickness
800+
801+
if 'thkcello' in nc.variables.keys():
802+
thkcello = nc.variables['thkcello'][..., latslice26N, lonslice26N] # #thickness
803+
elif 'thkcelluo' in nc.variables.keys():
804+
thkcello = nc.variables['thkcelluo'][..., latslice26N, lonslice26N] # #thickness
805+
elif 'thkcellvo' in nc.variables.keys():
806+
thkcello = nc.variables['thkcellvo'][..., latslice26N, lonslice26N] # #thickness
807+
thkcello = np.ma.array(thkcello)
808+
771809
depths = np.ma.cumsum(thkcello, axis=1)
772810

773811
depths = np.ma.masked_where(thkcello.mask + np.abs(depths)<500., depths) # masked above 500m depth.

bgcval2/functions/standard_functions.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,17 +145,40 @@ def maskzeroes(nc, keys):
145145
print('maskzeroes:', arr.min(), '->', arr.max(), arr.dtype, arr.mean())
146146
return arr
147147

148+
# def chose_best_mask_zeroes(nc, keys):
149+
# """
150+
# Chooses the best variable from keys, then masks all instances of exactly zero.
151+
# """
152+
# var0 = find_best_var(nc, keys)
153+
# arr = np.ma.array(nc.variables[var0][:]) #, dtype=np.float64)
154+
# arr = np.ma.masked_where(arr == 0. + arr.mask, arr)
155+
# print('chose_best_mask_zeroes:', arr.min(), '->', arr.max(), arr.dtype, arr.mean())
156+
# return arr
157+
148158
def sums(nc,keys):
149159
"""
150160
Loads Key[0] from the netcdf, then sums the other keys.
151161
"""
152162
a = nc.variables[keys[0]][:]
163+
153164
for k in keys[1:]:
154165
a += nc.variables[k]
155166
a = np.ma.masked_where(a == 0. + a.mask, a)
156167
return a
157168

158169

170+
#def area_sum(nc, keys):
171+
# """
172+
# Loads Key[0] from the netcdf, then calculates the sum over the area.
173+
# """
174+
# a = nc.variables[keys[0]][:]
175+
# for k in keys[1:]:
176+
# a += nc.variables[k]
177+
# a = np.ma.masked_where(a == 0. + a.mask, a)
178+
# return a
179+
180+
181+
159182
def oxconvert(nc,keys):
160183
"""
161184
Loads keys[0] from the netcdf, but multiplies by 44.771 (to convert oxygen units ).

key_files/hfy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ modelFiles : $BASEDIR_MODEL/$JOBID/nemo_$JOBIDo_1y_*_grid-V.nc
2222
gridFile : $PATHS_GRIDFILE
2323

2424
# Model coordinates/dimension names
25-
model_vars : hfy
25+
model_vars : hfy hfyint
2626
model_convert : maskzeroes
2727

2828
metrics : mean

key_files/sowaflup.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ modelFile_p2p : $BASEDIR_MODEL/$JOBID/nemo*$JOBIDo_1y_*$YEAR????_grid-T.nc
2222
gridFile : $PATHS_GRIDFILE
2323

2424
# Model coordinates/dimension names
25-
model_vars : sowaflup
25+
model_vars : sowaflup empmr
2626
model_convert : choose_best_var
2727

2828
layers : layerless

key_lists/debug.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ keys:
1919
# DavisStraightMassFlux: True
2020
# NorwegianSeaMassFlux: True
2121

22+
sltbasinatlantic: True
2223
# pbsi3: True
2324
# agessc: True
2425
# int_pn: True
@@ -47,7 +48,7 @@ keys:
4748
# SouthernTotalIceArea: True
4849

4950
#ZOS: True
50-
sowindsp: True
51+
# sowindsp: True
5152
#sowflisf: True
5253
#evs: True
5354
#precip: True

key_lists/kmf.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ keys:
1313
# NoCaspianAirSeaFluxCO2: True
1414
# IntPP_OSU: True
1515
# GlobalExportRatio: True
16-
TotalIceExtent: True
16+
# TotalIceExtent: True
1717
# NorthernTotalIceExtent: True
1818
# SouthernTotalIceExtent: True
1919
# GlobalMeanSalinity: True

key_lists/physics.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ keys:
2626
# MinMonthlyMLD: True # MLD Monthly min
2727

2828
# Ice keys:
29-
TotalIceArea: True # work in progress
30-
NorthernTotalIceArea: True # work in progress
31-
SouthernTotalIceArea: True # work in progress
29+
# TotalIceArea: True # work in progress
30+
# NorthernTotalIceArea: True # work in progress
31+
# SouthernTotalIceArea: True # work in progress
3232

3333
#WeddelTotalIceArea: True
34-
TotalIceExtent: True # work in progress
35-
NorthernTotalIceExtent: True # work in progress
36-
SouthernTotalIceExtent: True # work in progress
34+
# TotalIceExtent: True # work in progress
35+
# NorthernTotalIceExtent: True # work in progress
36+
# SouthernTotalIceExtent: True # work in progress
3737
# WeddelIceExent: True # work in progress
3838
# NorthernMIZArea: True
3939
# SouthernMIZArea: True
@@ -52,16 +52,16 @@ keys:
5252
# MeridionalCurrent: True # Meridional Veloctity
5353
# VerticalCurrent: True # Vertical Veloctity
5454
GulfStream: True
55-
GulfStream_depth: True
55+
# GulfStream_depth: True
5656

5757

58-
somesatr: True # salt flow # Work in progress in debug
58+
# somesatr: True # salt flow # Work in progress in debug
5959

6060
ZOS: True # Sea Surface Height
61-
sowindsp: True # Wind speed
61+
# sowindsp: True # Wind speed
6262
# sowflisf: True # Ice flux
6363
evs: True # Evaporation
64-
precip: True # Precipitation
64+
# precip: True # Precipitation
6565
# fov: True # Fov (Total salt flux in the Atlantic)
6666

6767

key_lists/tfamoc.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ keys:
1515
AtlanticSubtropicSalinity: True
1616
GINSalinity: True
1717
MLD: True
18+
somxzint1: True
19+
sltbasinatlantic: True
20+
21+
1822
TotalAirSeaFluxCO2: True
1923
# NoCaspianAirSeaFluxCO2: True
2024
# IntPP_OSU: True
@@ -29,9 +33,9 @@ keys:
2933
hfds: True
3034
hfy: True
3135
sosafldo: True
32-
somesatr: True
33-
hfbasinatlantic: True
34-
sowindsp: True
36+
# somesatr: True
37+
# hfbasinatlantic: True
38+
# sowindsp: True
3539
friver: True
3640
soicecov: True
3741
agessc: True

0 commit comments

Comments
 (0)