Skip to content

Commit 6178d90

Browse files
committed
added fix for AMOC in new grid
1 parent e6cfda8 commit 6178d90

1 file changed

Lines changed: 135 additions & 15 deletions

File tree

bgcval2/functions/circulation.py

Lines changed: 135 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,9 @@
7373

7474

7575
#eORCA1_latslice26N = slice(227,228)
76-
eORCA1_latslice26Nnm = slice(228,229)
76+
eORCA1_latslice26Nnm = slice(228,229) #(332, 362
77+
eORCA1_latslice26Nnm_331_by_360 = slice(228,229) # latitude slice is the same, as extra pixel is at the noirthern edge.
78+
7779
eORCA1_latslice40N = slice(245,246)
7880
eORCA1_latslice55N = slice(272,273)
7981

@@ -108,6 +110,13 @@
108110
alttmask_AMOC26N = 0
109111
alttmask_AMOC40N = 0
110112
alttmask_AMOC55N = 0
113+
atttmask_lats = 0
114+
atttmask_lons = 0
115+
116+
grid_lons = 0
117+
grid_lats = 0
118+
grid_lats_26 = 0
119+
grid_lons_26 = 0
111120

112121
alttmask = 0
113122
loadedArea = False
@@ -159,6 +168,10 @@ def loadDataMask(gridfn, maskname, grid):
159168
global tmask_AMOC26N
160169
global tmask_AMOC40N
161170
global tmask_AMOC55N
171+
global grid_lons
172+
global grid_lats
173+
global grid_lats_26
174+
global grid_lons_26
162175

163176
global loadedArea
164177
# global loadedAltMask
@@ -184,6 +197,8 @@ def loadDataMask(gridfn, maskname, grid):
184197
nc = dataset(gridfn, 'r')
185198
e2u_drake = nc.variables['e2u'][..., LAT0:LAT1, LON]
186199
umask_drake = nc.variables['umask'][..., LAT0:LAT1, LON]
200+
grid_lats = nc.variables['nav_lat'][:]#..., LAT0:LAT1, LON]
201+
grid_lons = nc.variables['nav_lon'][:]#..., LAT0:LAT1, LON]
187202
print('circulation loadDataMask:', gridfn, nc.variables['e2u'].shape, nc.variables['umask'].shape, e2u_drake.shape, umask_drake.shape)
188203

189204
if 'e3v_0' in nc.variables.keys():
@@ -203,7 +218,8 @@ def loadDataMask(gridfn, maskname, grid):
203218
e1v_davis = nc.variables['e1v'][eORCA1_davis_LON, eORCA1_davis_LAT0:eORCA1_davis_LAT1]
204219
e1v_norway = nc.variables['e1v'][eORCA1_norway_LON, eORCA1_norway_LAT0:eORCA1_norway_LAT1]
205220

206-
221+
grid_lats_26 = nc.variables['nav_lat'][latslice26Nnm, lonslice26N]#..., LAT0:LAT1, LON]
222+
grid_lons_26 = nc.variables['nav_lon'][latslice26Nnm, lonslice26N]#..., LAT0:LAT1, LON]
207223

208224
else:
209225
e3v_AMOC26N = nc.variables['e3v'][..., latslice26Nnm, :] # z level height 3D
@@ -221,6 +237,9 @@ def loadDataMask(gridfn, maskname, grid):
221237
e1v_davis = nc.variables['e1v'][eORCA1_davis_LON, eORCA1_davis_LAT0:eORCA1_davis_LAT1]
222238
e1v_norway = nc.variables['e1v'][eORCA1_norway_LON, eORCA1_norway_LAT0:eORCA1_norway_LAT1]
223239

240+
grid_lats_26 = nc.variables['nav_lat'][latslice26Nnm, :]#..., LAT0:LAT1, LON]
241+
grid_lons_26 = nc.variables['nav_lon'][latslice26Nnm, :]#..., LAT0:LAT1, LON]
242+
224243
#print('e3v_AMOC26N: loaded')#e3v_AMOC26N, latslice26Nnm, e3v_AMOC26N.shape)
225244
nc.close()
226245
loadedArea = True
@@ -252,6 +271,9 @@ def loadAtlanticMask(altmaskfile, maskname='tmaskatl', grid = 'eORCA1'):
252271
global alttmask_AMOC26N
253272
global alttmask_AMOC40N
254273
global alttmask_AMOC55N
274+
global atttmask_lons
275+
global atttmask_lats
276+
255277

256278
global loadedAltMask
257279
if grid == 'eORCA1':
@@ -265,6 +287,9 @@ def loadAtlanticMask(altmaskfile, maskname='tmaskatl', grid = 'eORCA1'):
265287
alttmask_AMOC26N = nc.variables[maskname][latslice26Nnm, :]
266288
alttmask_AMOC40N = nc.variables[maskname][latslice40N, :]
267289
alttmask_AMOC55N = nc.variables[maskname][latslice55N, :]
290+
atttmask_lats = nc.variables['nav_lat'][:]
291+
atttmask_lons = nc.variables['nav_lon'][:]
292+
268293
nc.close()
269294
loadedAltMask = True
270295

@@ -316,6 +341,12 @@ def drakePassage(nc, keys, **kwargs):
316341
LON = eORCA1_drake_LON
317342
LAT0 = eORCA1_drake_LAT0
318343
LAT1 = eORCA1_drake_LAT1
344+
345+
if nc.variables['nav_lat'].shape == (332, 362):
346+
print('Classic grid')
347+
else:
348+
assert 0
349+
319350
elif grid == 'eORCA025':
320351
LON = eORCA025_drake_LON
321352
LAT0 = eORCA025_drake_LAT0
@@ -367,6 +398,11 @@ def davisstraightflux(nc, keys, straight='Davis', **kwargs):
367398
else:
368399
assert 0
369400

401+
if nc.variables['nav_lat'].shape == (332, 362):
402+
print('Classic grid')
403+
else:
404+
assert 0
405+
370406
if keys[0] in ['vo', 'uo']:
371407
print('These needs to be multiplied by the thkcello.')
372408
assert 0
@@ -472,20 +508,28 @@ def TwentySixNorth(nc, keys, lat='26N', return_max_depth=False, **kwargs):
472508
if grid == 'eORCA1':
473509
if lat == '26N':
474510
latslice = eORCA1_latslice26Nnm
511+
latslice2 = eORCA1_latslice26Nnm_331_by_360
512+
475513
e1v_AMOC = e1v_AMOC26N
476514
alttmask_AMOC = alttmask_AMOC26N[:]
477515
tmask_AMOC = tmask_AMOC26N
478516
e3v_AMOC = e3v_AMOC26N
517+
grid_amoc_lats = grid_lats_26
518+
grid_amoc_lons = grid_lons_26
479519

480520
elif lat == '40N':
481521
latslice = eORCA1_latslice40N
522+
latslice2 = eORCA1_latslice40N
523+
482524
e1v_AMOC = e1v_AMOC40N
483525
alttmask_AMOC = alttmask_AMOC40N[:]
484526
tmask_AMOC = tmask_AMOC40N
485527
e3v_AMOC = e3v_AMOC40N
486528

487529
elif lat == '55N':
488530
latslice = eORCA1_latslice55N
531+
latslice2 = eORCA1_latslice55N
532+
489533
e1v_AMOC = e1v_AMOC55N
490534
alttmask_AMOC = alttmask_AMOC55N[:]
491535
tmask_AMOC = tmask_AMOC55N
@@ -506,22 +550,87 @@ def TwentySixNorth(nc, keys, lat='26N', return_max_depth=False, **kwargs):
506550
# Atlantic Mask not loaded
507551
raise ValueError('TwentySixNorth: Mask not loaded: ed: %s', grid)
508552

509-
zv = np.ma.array(nc.variables[keys[0]][..., latslice, :]) # m/s
510-
zv = np.ma.masked_where(zv.mask + (zv == 0.), zv)
553+
# vshape = nc.variables[keys[0]].shape
554+
# print(vshape)
555+
556+
# print(grid_lons.shape, grid_lats.shape)
557+
live_lons_v = nc.variables['nav_lon'][:]
558+
live_lats_v = nc.variables['nav_lat'][:]
559+
# print(live_lons.shape, live_lats.shape)
560+
561+
if live_lons_v.shape == (332, 362):
562+
print('Classic grid')
563+
# Standard, old school function.
564+
zv = np.ma.array(nc.variables[keys[0]][..., latslice, :]) # m/s
565+
zv = np.ma.masked_where(zv.mask + (zv == 0.), zv)
566+
567+
if 'thkcello' in nc.variables.keys():
568+
thkcello = nc.variables['thkcello'][0, :, latslice, :]
569+
elif 'thkcelluo' in nc.variables.keys():
570+
thkcello = nc.variables['thkcelluo'][0, :, latslice, :]
571+
elif 'thkcellvo' in nc.variables.keys():
572+
thkcello = nc.variables['thkcellvo'][0, :, latslice, :]
573+
else:
574+
assert 0
511575

512-
atlmoc = np.array(np.zeros_like(zv[0, :, :, 0]))
576+
# thkcello = e3v_AMOC[:]
513577

514-
# if 'thkcello' in nc.variables.keys():
515-
# thkcello = nc.variables['thkcello'][0, :, latslice, :]
578+
elif live_lons_v.shape == (331, 360):
579+
print('New shorter grid AMOC')
580+
516581

517-
if 'thkcello' in nc.variables.keys():
518-
thkcello = nc.variables['thkcello'][0, :, latslice, :]
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, :]
582+
# we need to account for no border.
583+
# Standard, old school function.
584+
zv = np.ma.array(nc.variables[keys[0]][..., latslice2, :]) # m/s
585+
zv = np.ma.masked_where(zv.mask + (zv == 0.), zv)
586+
587+
if 'thkcello' in nc.variables.keys():
588+
thkcello = nc.variables['thkcello'][0, :, latslice2, :]
589+
elif 'thkcelluo' in nc.variables.keys():
590+
thkcello = nc.variables['thkcelluo'][0, :, latslice2, :]
591+
elif 'thkcellvo' in nc.variables.keys():
592+
thkcello = nc.variables['thkcellvo'][0, :, latslice2, :]
593+
else:
594+
assert 0
595+
thkcello = e3v_AMOC[:]
596+
597+
lats2 = live_lats_v[:, :]
598+
lats1 = grid_lats[:-1, 1:-1]
599+
lats_diff = lats2 - lats1
600+
601+
lons2 = live_lons_v[:, :]
602+
lons1 = grid_lons[:-1, 1:-1]
603+
lons_diff = lons2 - lons1
604+
if alttmask_AMOC.shape == (1, 362):
605+
alttmask_AMOC = alttmask_AMOC[:, 1:-1]
606+
607+
print('alttmask_AMOC:', alttmask_AMOC.shape, live_lons_v.shape)
608+
609+
print(tmask_AMOC.shape)
610+
if tmask_AMOC.shape == (75, 1, 362):
611+
tmask_AMOC = tmask_AMOC[:, :, 1:-1]
612+
613+
# assert 0
614+
# WE don't exppect a T grid to match a V grid!
615+
#
616+
# if lats_diff.max()!= 0. or lons_diff.max() !=0.:
617+
# print('lattitude differences:', lats_diff.min(), lats_diff.mean(), lats_diff.max())
618+
# print('longitude differences:', lons_diff.min(), lons_diff.mean(), lons_diff.max())
619+
# print('GRID DOES NOT MATCH EORCA1')
620+
# assert 0
523621
else:
524-
thkcello = e3v_AMOC[:]
622+
# if live_lons.shape != grid_lons.shape or live_lats.shape != grid_lats.shape:
623+
print('Grid lons/lats shape', grid_lons.shape, grid_lats.shape)
624+
print('Live lons/lats shape', live_lons_v.shape, live_lats_v.shape)
625+
raise ValueError('Grid lons/lats shape does not match live lons/lats shape. Check the grid and the netcdf file.')
626+
627+
# assert 0
628+
629+
#chcek that lat and lon are the same.
630+
# grid_amoc_lons
631+
632+
atlmoc = np.array(np.zeros_like(zv[0, :, :, 0]))
633+
525634
thkcello = np.ma.array(thkcello)
526635
thkcello = np.ma.masked_where(thkcello.mask + zv[0].mask, thkcello)
527636

@@ -636,7 +745,12 @@ def gulfstream_depth(nc, keys, **kwargs):
636745
# -76.50126349, -75.50128329, -74.50130118, -73.50131712,
637746
# -72.50133107, -71.50134301, -70.50135293, -69.50136079,
638747
# -68.50136658],
639-
lonslice_70W = slice(211, 217)
748+
if nc.variables[keys[0]].shape == (332, 362):
749+
print('Classic grid')
750+
lonslice_70W = slice(211, 217)
751+
else:
752+
assert 0
753+
# elif nc.variables[keys[0]].shape == (332, 362):
640754

641755
altmaskfile = get_kwarg_file(kwargs, 'altmaskfile', default = 'bgcval2/data/basinlandmask_eORCA1.nc')
642756
elif grid == 'eORCA025':
@@ -734,6 +848,11 @@ def gulfstream(nc, keys, **kwargs):
734848
altmaskfile = get_kwarg_file(kwargs, 'altmaskfile', default = 'bgcval2/data/basinlandmask_eORCA1.nc')
735849
if not loadedAltMask:
736850
loadAtlanticMask(altmaskfile, maskname='tmaskatl', grid=grid)
851+
852+
if nc.variables[keys[0]].shape == (332, 362):
853+
print('Classic grid')
854+
else:
855+
assert 0
737856
elif grid == 'eORCA025':
738857
latslice26Nnm = eORCA025_latslice26Nnm
739858
else:
@@ -745,6 +864,7 @@ def gulfstream(nc, keys, **kwargs):
745864
raise ValueError('gulfstream: Mask not loaded: ed: %s', grid)
746865
assert 0
747866

867+
748868
lats = nc.variables['nav_lat'][latslice26Nnm, lonslice_70W]
749869
lons = nc.variables['nav_lon'][latslice26Nnm, lonslice_70W]
750870
vo = np.ma.array(nc.variables[keys[0]][0, :, latslice26Nnm, lonslice_70W]) # m/s

0 commit comments

Comments
 (0)