Skip to content

Commit 796ff0e

Browse files
authored
Merge pull request #1112 from irenavankova/no_inset
Time series edits
2 parents 96d05b4 + 45d447f commit 796ff0e

File tree

3 files changed

+24
-13
lines changed

3 files changed

+24
-13
lines changed

mpas_analysis/ocean/ocean_regional_profiles.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ def run_task(self):
349349
dsMesh = xr.open_dataset(meshFilename)
350350
dsMesh = dsMesh.isel(Time=0)
351351
areaCell = dsMesh.areaCell
352+
openOceanMask = xr.where(dsMesh.landIceMask > 0, 0, 1)
352353

353354
nVertLevels = dsMesh.sizes['nVertLevels']
354355

@@ -382,7 +383,9 @@ def run_task(self):
382383
cellMasks = dsRegionMask.regionCellMasks
383384
regionNamesVar = dsRegionMask.regionNames
384385

385-
totalArea = self._masked_area_sum(cellMasks, areaCell, vertDepthMask)
386+
totalArea = self._masked_area_sum(
387+
cellMasks, openOceanMask, areaCell, vertDepthMask
388+
)
386389

387390
datasets = []
388391
for timeIndex, fileName in enumerate(inputFiles):
@@ -410,13 +413,18 @@ def run_task(self):
410413
var = dsLocal[variableName].where(vertDepthMask)
411414

412415
meanName = '{}_mean'.format(prefix)
413-
dsLocal[meanName] = \
414-
self._masked_area_sum(cellMasks, areaCell, var) / totalArea
416+
dsLocal[meanName] = (
417+
self._masked_area_sum(
418+
cellMasks, openOceanMask, areaCell, var
419+
) / totalArea
420+
)
415421

416422
meanSquaredName = '{}_meanSquared'.format(prefix)
417-
dsLocal[meanSquaredName] = \
418-
self._masked_area_sum(cellMasks, areaCell, var**2) / \
419-
totalArea
423+
dsLocal[meanSquaredName] = (
424+
self._masked_area_sum(
425+
cellMasks, openOceanMask, areaCell, var**2
426+
) / totalArea
427+
)
420428

421429
# drop the original variables
422430
dsLocal = dsLocal.drop_vars(variableList)
@@ -449,12 +457,15 @@ def run_task(self):
449457
write_netcdf_with_fill(dsOut, outputFileName)
450458

451459
@staticmethod
452-
def _masked_area_sum(cellMasks, areaCell, var):
460+
def _masked_area_sum(cellMasks, openOceanMask, areaCell, var):
453461
"""sum a variable over the masked areas"""
454462
nRegions = cellMasks.sizes['nRegions']
455463
totals = []
456464
for index in range(nRegions):
457-
mask = cellMasks.isel(nRegions=slice(index, index+1))
465+
mask = (
466+
cellMasks.isel(nRegions=slice(index, index+1)) *
467+
openOceanMask
468+
)
458469
totals.append((mask * areaCell * var).sum('nCells'))
459470

460471
total = xr.concat(totals, 'nRegions')

mpas_analysis/ocean/time_series_antarctic_melt.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ def run_task(self):
342342

343343
dsOut = xarray.concat(objs=datasets, dim='Time')
344344
dsOut['regionNames'] = dsRegionMask.regionNames
345-
dsOut.integratedMeltFlux.attrs['units'] = 'GT a$^{-1}$'
345+
dsOut.integratedMeltFlux.attrs['units'] = 'Gt a$^{-1}$'
346346
dsOut.integratedMeltFlux.attrs['description'] = \
347347
'Integrated melt flux summed over each ice shelf or region'
348348
dsOut.meltRates.attrs['units'] = 'm a$^{-1}$'
@@ -662,7 +662,7 @@ def run_task(self):
662662
suffix = self.iceShelf.replace(' ', '_')
663663

664664
xLabel = 'Time (yr)'
665-
yLabel = 'Melt Flux (GT/yr)'
665+
yLabel = 'Melt Flux (Gt/yr)'
666666

667667
timeSeries = integratedMeltFlux.isel(nRegions=self.regionIndex)
668668

@@ -723,7 +723,7 @@ def run_task(self):
723723
# and cartopy doesn't play too well with tight_layout anyway
724724
plt.tight_layout()
725725

726-
add_inset(fig, fc, width=2.0, height=2.0)
726+
add_inset(fig, fc, width=1.0, height=1.0, lowerleft=[0.0, 0.0], xbuffer=0.01, ybuffer=0.01)
727727

728728
savefig(outFileName, config)
729729

@@ -788,7 +788,7 @@ def run_task(self):
788788
# and cartopy doesn't play too well with tight_layout anyway
789789
plt.tight_layout()
790790

791-
add_inset(fig, fc, width=2.0, height=2.0)
791+
add_inset(fig, fc, width=1.0, height=1.0, lowerleft=[0.0, 0.0], xbuffer=0.01, ybuffer=0.01)
792792

793793
savefig(outFileName, config)
794794

mpas_analysis/ocean/time_series_ocean_regions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ def run_task(self):
13501350
# and cartopy doesn't play too well with tight_layout anyway
13511351
plt.tight_layout()
13521352

1353-
add_inset(fig, fc, width=2.0, height=2.0)
1353+
add_inset(fig, fc, width=1.0, height=1.0, lowerleft=[0.0, 0.0], xbuffer=0.01, ybuffer=0.01)
13541354

13551355
savefig(outFileName, config, tight=False)
13561356

0 commit comments

Comments
 (0)