Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions mpas_analysis/ocean/ocean_regional_profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,7 @@ def run_task(self):
dsMesh = xr.open_dataset(meshFilename)
dsMesh = dsMesh.isel(Time=0)
areaCell = dsMesh.areaCell
openOceanMask = xr.where(dsMesh.landIceMask > 0, 0, 1)

nVertLevels = dsMesh.sizes['nVertLevels']

Expand Down Expand Up @@ -382,7 +383,9 @@ def run_task(self):
cellMasks = dsRegionMask.regionCellMasks
regionNamesVar = dsRegionMask.regionNames

totalArea = self._masked_area_sum(cellMasks, areaCell, vertDepthMask)
totalArea = self._masked_area_sum(
cellMasks, openOceanMask, areaCell, vertDepthMask
)

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

meanName = '{}_mean'.format(prefix)
dsLocal[meanName] = \
self._masked_area_sum(cellMasks, areaCell, var) / totalArea
dsLocal[meanName] = (
self._masked_area_sum(
cellMasks, openOceanMask, areaCell, var
) / totalArea
)

meanSquaredName = '{}_meanSquared'.format(prefix)
dsLocal[meanSquaredName] = \
self._masked_area_sum(cellMasks, areaCell, var**2) / \
totalArea
dsLocal[meanSquaredName] = (
self._masked_area_sum(
cellMasks, openOceanMask, areaCell, var**2
) / totalArea
)

# drop the original variables
dsLocal = dsLocal.drop_vars(variableList)
Expand Down Expand Up @@ -449,12 +457,15 @@ def run_task(self):
write_netcdf_with_fill(dsOut, outputFileName)

@staticmethod
def _masked_area_sum(cellMasks, areaCell, var):
def _masked_area_sum(cellMasks, openOceanMask, areaCell, var):
"""sum a variable over the masked areas"""
nRegions = cellMasks.sizes['nRegions']
totals = []
for index in range(nRegions):
mask = cellMasks.isel(nRegions=slice(index, index+1))
mask = (
cellMasks.isel(nRegions=slice(index, index+1)) *
openOceanMask
)
totals.append((mask * areaCell * var).sum('nCells'))

total = xr.concat(totals, 'nRegions')
Expand Down
8 changes: 4 additions & 4 deletions mpas_analysis/ocean/time_series_antarctic_melt.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ def run_task(self):

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

xLabel = 'Time (yr)'
yLabel = 'Melt Flux (GT/yr)'
yLabel = 'Melt Flux (Gt/yr)'

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

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

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

savefig(outFileName, config)

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

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

savefig(outFileName, config)

Expand Down
2 changes: 1 addition & 1 deletion mpas_analysis/ocean/time_series_ocean_regions.py
Original file line number Diff line number Diff line change
Expand Up @@ -1350,7 +1350,7 @@ def run_task(self):
# and cartopy doesn't play too well with tight_layout anyway
plt.tight_layout()

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

savefig(outFileName, config, tight=False)

Expand Down