Skip to content

Commit dd6d55c

Browse files
committed
added new fields and a fix to the legend plotter to also calculate the area.
1 parent 3ead11b commit dd6d55c

File tree

5 files changed

+90
-35
lines changed

5 files changed

+90
-35
lines changed

bgcval2/bgcvaltools/generic_map_legend.py

Lines changed: 46 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,17 @@ def add_region(fig, ax, lons, lats, data):
133133
return fig, ax, im
134134

135135

136-
def make_figure(region):
136+
def make_figure(region, orcaGridfn=None):
137137
"""
138138
Make a figure for this region.
139139
"""
140140
fig_fn = bvt.folder('images/regions')+region+'.png'
141141

142-
paths_dict, config_user = get_run_configuration("defaults")
143-
# filter paths dict into an object that's usable below
144-
paths = paths_setter(paths_dict)
145-
orcaGridfn = paths.orcaGridfn
142+
if not orcaGridfn:
143+
paths_dict, config_user = get_run_configuration("defaults")
144+
# filter paths dict into an object that's usable below
145+
paths = paths_setter(paths_dict)
146+
orcaGridfn = paths.orcaGridfn
146147

147148
nc = Dataset(orcaGridfn, 'r')
148149
dat = nc.variables['mbathy'][:].squeeze()
@@ -216,19 +217,21 @@ def make_figure(region):
216217

217218

218219

219-
def calc_area(region):
220+
def calc_area(region, orcaGridfn = None):
220221
"""
221222
Calculate the area for this region.
222223
"""
223224

224-
paths_dict, config_user = get_run_configuration("defaults")
225-
# filter paths dict into an object that's usable below
226-
paths = paths_setter(paths_dict)
227-
orcaGridfn = paths.orcaGridfn
225+
if not orcaGridfn:
226+
paths_dict, config_user = get_run_configuration("defaults")
227+
paths = paths_setter(paths_dict)
228+
orcaGridfn = paths.orcaGridfn
229+
print('calc_area: opening:', orcaGridfn)
228230

229231
nc = Dataset(orcaGridfn, 'r')
230232
dat = nc.variables['mbathy'][:].squeeze()
231-
area = nc.variables['area'][:].squeeze()
233+
#area = nc.variables['area'][:].squeeze()
234+
area = nc.variables['e2t'][:]* nc.variables['e1t'][:]
232235
lats = nc.variables['nav_lat'][:].squeeze()
233236
lons = nc.variables['nav_lon'][:].squeeze()
234237
lons = bvt.makeLonSafeArr(lons)
@@ -247,12 +250,12 @@ def calc_area(region):
247250
region_mask = makeMask('bathy', region, xt, xz, xy, xx, xd, debug=True)
248251

249252
new_area = np.ma.masked_where(region_mask + old_mask_flat, flat_area)
250-
251-
print('region:', new_area.sum())
253+
total_area=new_area.sum()
254+
print('region:', total_area)
252255

253256

254257
out_fn = bvt.folder('region_areas')+region+'.txt'
255-
txt = ''.join([region, ', ', str(int(area)), '\n'])
258+
txt = ''.join([region, ', ', str(int(total_area)), '\n'])
256259
fn = open(out_fn, 'w')
257260
fn.write(txt)
258261
fn.close()
@@ -264,38 +267,46 @@ def calc_area(region):
264267

265268
def main():
266269
# paths_dict, config_user = get_run_configuration("defaults")
270+
paths_dict, config_user = get_run_configuration("defaults")
271+
# filter paths dict into an object that's usable below
272+
paths = paths_setter(paths_dict)
273+
orcaGridfn = paths.orcaGridfn
274+
267275

268276
regions = [
269-
# 'LIseas',
270-
# 'LIGINseas',
271-
# 'GLINseas',
272-
# 'Ascension',
273-
# 'ITCZ',
277+
'LIseas',
278+
'LIGINseas',
279+
'GLINseas',
280+
'Ascension',
281+
# 'ITCZ',
274282
# 'TristandaCunha',
275283
# 'Pitcairn',
276-
# 'Cornwall',
277-
# 'SubtropicNorthAtlantic',
278-
# 'SPNA',
279-
# 'STNA',
284+
'Cornwall',
285+
'SubtropicNorthAtlantic',
286+
'SPNA',
287+
'STNA',
280288
'SouthernOcean',
281289
'subpolar',
282290
'NorthEastAtlantic',
283-
# 'ArcticOcean',
284-
# 'Equator10',
285-
# 'NorthPacificOcean',
291+
'ArcticOcean',
292+
'Equator10',
293+
'NorthPacificOcean',
294+
'SouthAtlanticOcean',
295+
'NorthernSubpolarPacific',
296+
'NorthernSubpolarAtlantic',
297+
'SouthPacificOcean',
298+
'NorthAtlanticOcean',
286299
'SouthAtlanticOcean',
287-
# 'SouthPacificOcean',
288-
# 'NorthAtlanticOcean',
289-
# 'SouthAtlanticOcean',
290-
# 'GINseas',
291-
# 'LabradorSea',
292-
# 'IrmingerSea',
300+
'GINseas',
301+
'LabradorSea',
302+
'IrmingerSea',
293303
'EquatorialAtlanticOcean',
294-
# 'Global',
295-
# 'ignoreInlandSeas',
304+
'Global',
305+
'ignoreInlandSeas',
296306
]
297307
for region in regions[:]:
298-
make_figure(region)
308+
calc_area(region, orcaGridfn=orcaGridfn)
309+
make_figure(region, orcaGridfn=orcaGridfn)
299310

300311
if __name__ == "__main__":
301312
main()

bgcval2/bgcvaltools/pftnames.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ def makeLongNameDict():
210210
lnd['INT_PD'] = 'Int. Diatoms'
211211
lnd['INT_PN'] = 'Int. Non-Diatoms'
212212

213+
lnd['PRN'] = 'Non-Diatom Production'
214+
lnd['PRD'] = 'Diatom Production'
213215
lnd['ZI_GROW'] = 'Microzooplankton Growth'
214216
lnd['ZE_GROW'] = 'Mesozooplankton Growth'
215217
lnd['MPD'] = "Diatom non-grazing losses"

key_files/prd.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
# Diatom production
3+
name : PRD
4+
units : mmol N/m^2/d
5+
model : MEDUSA
6+
modelgrid : eORCA1
7+
dimensions : 2
8+
9+
# The filenames
10+
modelFiles : $BASEDIR_MODEL/$JOBID/medusa*$JOBIDo_1y_*_diad-T.nc
11+
modelFile_p2p : $BASEDIR_MODEL/$JOBID/medusa*$JOBIDo_1y_*$YEAR????_diad-T.nc
12+
13+
# # Model coordinates/dimension names
14+
model_vars : PRD
15+
model_convert : NoChange
16+
17+
18+
layers : layerless
19+
regions : Global ignoreInlandSeas SouthernOcean ArcticOcean Equator10 NorthPacificOcean SouthPacificOcean NorthAtlanticOcean SouthAtlanticOcean SPNA
20+

key_files/prn.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
# Non-Diatom production
3+
name : PRN
4+
units : mmol N/m^2/d
5+
model : MEDUSA
6+
modelgrid : eORCA1
7+
dimensions : 2
8+
9+
# The filenames
10+
modelFiles : $BASEDIR_MODEL/$JOBID/medusa*$JOBIDo_1y_*_diad-T.nc
11+
modelFile_p2p : $BASEDIR_MODEL/$JOBID/medusa*$JOBIDo_1y_*$YEAR????_diad-T.nc
12+
13+
# # Model coordinates/dimension names
14+
model_vars : PRN
15+
model_convert : NoChange
16+
17+
18+
layers : layerless
19+
regions : Global ignoreInlandSeas SouthernOcean ArcticOcean Equator10 NorthPacificOcean SouthPacificOcean NorthAtlanticOcean SouthAtlanticOcean SPNA
20+

key_lists/ecosystem.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ keys:
1414
det: True
1515

1616
# diag:
17+
prn: True
18+
prd: True
1719
zi_grow: True
1820
ze_grow: True
1921
mpd: True

0 commit comments

Comments
 (0)