Skip to content

Commit d4d62ed

Browse files
committed
Added Fov
1 parent 85f9e4e commit d4d62ed

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

bgcval2/functions/circulation.py

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import os
3030
import numpy as np
3131
import math
32-
import itertools
32+
#import itertools
3333

3434
from bgcval2.bgcvaltools.dataset import dataset
3535
from bgcval2.bgcvaltools.bv2tools import maenumerate
@@ -87,7 +87,7 @@
8787

8888
def maenumerate(marr):
8989
mask = ~marr.mask.ravel()
90-
for i, m in itertools.izip(np.ndenumerate(marr), mask):
90+
for i, m in zip(np.ndenumerate(marr), mask):
9191
if m: yield i
9292

9393
def myhaversine(lon1, lat1, lon2, lat2):
@@ -96,12 +96,12 @@ def myhaversine(lon1, lat1, lon2, lat2):
9696
on the earth (specified in decimal degrees)
9797
"""
9898
# convert decimal degrees to radians
99-
[lon1, lat1, lon2, lat2] = [math.radians[l] for l in [lon1, lat1, lon2, lat2]]
99+
[lon1, lat1, lon2, lat2] = [math.radians(l) for l in [lon1, lat1, lon2, lat2]]
100100

101101
# haversine formula
102102
dlon = lon2 - lon1
103103
dlat = lat2 - lat1
104-
a = math.sin(dlat / 2.)**2 + math.cos(lat1) * math.cos(lat2) * mathsin(dlon / 2.)**2
104+
a = math.sin(dlat / 2.)**2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2.)**2
105105
c = 2. * math.asin(math.sqrt(a))
106106
dist = 6367000. * c
107107

@@ -201,7 +201,7 @@ def loadAtlanticMask_full(altmaskfile, maskname='tmaskatl', grid = 'eORCA1'):
201201
else:
202202
raise ValueError("Grid not recognised in this calculation: %s", grid)
203203
nc = dataset(altmaskfile, 'r')
204-
alttmask = nc.variables[maskname][latslice26Nnm, :]
204+
alttmask = nc.variables[maskname][:]
205205
nc.close()
206206
loadedAltMask_full = True
207207

@@ -383,7 +383,7 @@ def fov_sa(nc, keys, **kwargs):
383383
thkcello = nc.variables['thkcello'][:].squeeze()
384384

385385
lats = np.ma.masked_outside(lats, -30., -34.)
386-
lons = np.ma.masked_outside(lons, -100., 20.)
386+
lons = np.ma.masked_outside(lons, -65., 20.)
387387

388388
# lons = nc.variables['nav_lon'][:]
389389
lons_bounds_0 = nc.variables['bounds_lon'][:].min(2)
@@ -394,23 +394,23 @@ def fov_sa(nc, keys, **kwargs):
394394

395395
lons_diff = lons_bounds_1 - lons_bounds_0
396396
if lons_diff.min() != lons_diff.max():
397-
print('Can not assume that grid is even')
397+
print('Can not assume that longitude grid is even')
398398
assert 0
399399

400400
# Load Atlantic Mask
401401
if not loadedAltMask_full:
402+
altmaskfile = get_kwarg_file(kwargs, 'altmaskfile', default = 'bgcval2/data/basinlandmask_eORCA1.nc')
402403
loadAtlanticMask_full(altmaskfile, maskname='tmaskatl', grid=grid)
403404

404405
# Load and mask vso
405406
vso = np.ma.array(nc.variables['vso'][:]).squeeze() # #vso in PSU m/s
406407
vo = np.ma.array(nc.variables['vo'][:]).squeeze() # #vso in PSU m/s
407408
sal0 = vso/vo - sal_ref
408409

409-
mask_2d = alttmask + lats.mask + lons.mask
410-
410+
mask_2d = lats.mask + lons.mask
411+
#print(alttmask, alttmask.shape)
411412
unique_lats = {la:True for la in np.ma.masked_where(mask_2d, lats).compressed()}
412413
zonal_distances = {la: myhaversine(0, la, 1., la) for la in unique_lats.keys()}
413-
414414

415415
mask_3d = [mask_2d for _ in range(75)]
416416
mask_3d = np.stack(mask_3d, axis=0)
@@ -423,19 +423,44 @@ def fov_sa(nc, keys, **kwargs):
423423
sal0 = np.ma.masked_where(vso.mask + mask_3d + (sal0 == 0.), sal0) # shape alignment?
424424
xarea = np.ma.masked_where(sal0.mask, thkcello)
425425

426+
# from matplotlib import pyplot
427+
# for name, dat in zip(
428+
# ['vo', 'sal0', 'xarea', 'lats', 'lons', 'mask2d', 'mask3d', 'alttmask',],
429+
# [vo, sal0, xarea, lats, lons, mask_2d, mask_3d, alttmask]):
430+
# print('plotting', name)
431+
# if name in ['lats', 'lons', 'mask2d', 'alttmask']:
432+
# plot = dat
433+
# else:
434+
# plot = dat.mean(0)
435+
# pyplot.pcolormesh(plot)
436+
# pyplot.title(name)
437+
# pyplot.colorbar()
438+
# pyplot.savefig('images/'+name+'.png')
439+
# pyplot.close()
440+
426441
# calculate cross sectional area by multiplying zonal cell length by cell depth thickness
427442
for (z, y, x), thk in maenumerate(xarea):
428443
la = lats[y, x]
429444
xarea[z, y, x] = thk * zonal_distances[la]
430-
xarea_sum = xarea.sum(axis=(0,1))
445+
xarea_sum = xarea.sum(axis=(0,2))
431446

447+
#print('xarea', {f:True for f in xarea_sum.compressed()}.keys()) # should be 4 or 5 values.
448+
#assert 0
432449
# Take the zonal mean of the meridional velocity
450+
433451
total = vo * sal0 * xarea
434-
total = total.sum(axis=(0,1))/xarea_sum
452+
total = total.sum(axis=(0, 2))/xarea_sum
453+
#print('total', {f:True for f in total.compressed()}.keys())
454+
#pyplot.pcolormesh(vo[0] * sal0[0] * xarea[0])
455+
#pyplot.title('total')
456+
#pyplot.colorbar()
457+
#pyplot.savefig('images/total.png')
458+
#pyplot.close()
459+
435460
total = total.mean()
436-
output = (-1./sal_rf) * total
461+
output = (-1./sal_ref) * total
437462
print(output)
438-
assert 0
463+
#assert 0
439464
return output
440465

441466

input_yml/TerraFIRMA_ssp245_cmm.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,18 @@ jobs:
116116
#timerange: [1800, 2050]
117117
suite: *keylists
118118

119+
120+
u-dg327:
121+
description: 'Revised SSP236. '
122+
label: None
123+
# label: 'SSP2-4.5'
124+
colour: 'green'
125+
thickness: 1.2
126+
linestyle: '-'
127+
shifttime: 0.
128+
#timerange: [1800, 2050]
129+
suite: *keylists
130+
119131
# u-dg509:
120132
# description: 'TF OS SSP245 cmm - High freq nemo, no CFC/SF6 output from 2030 onwards - ssp245 extension of u-da917'
121133
# label: None

key_lists/physics.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ keys:
6060
sowflisf: True # Ice flux
6161
evs: True # Evaporation
6262
precip: True # Precipitation
63+
fov: True # Fov (Total salt flux in the Atlantic)
6364

6465

6566
# Misc fluxes:

0 commit comments

Comments
 (0)