From 30538f7989cdf1418639a2a57cded73d7cbdddc2 Mon Sep 17 00:00:00 2001 From: Azure Pipelines Date: Thu, 29 Feb 2024 08:15:07 +0000 Subject: [PATCH] [skip ci] Update latest --- .../ocean/climatology_map_antarctic_melt.html | 206 ++++++++++++++++-- .../ocean/time_series_antarctic_melt.html | 60 ++--- 2 files changed, 216 insertions(+), 50 deletions(-) diff --git a/latest/_modules/mpas_analysis/ocean/climatology_map_antarctic_melt.html b/latest/_modules/mpas_analysis/ocean/climatology_map_antarctic_melt.html index 506e944d5..2bff6f484 100644 --- a/latest/_modules/mpas_analysis/ocean/climatology_map_antarctic_melt.html +++ b/latest/_modules/mpas_analysis/ocean/climatology_map_antarctic_melt.html @@ -179,7 +179,6 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

sectionName = self.taskName - mpasFieldName = 'timeMonthly_avg_landIceFreshwaterFlux' iselValues = None # read in what seasons we want to plot @@ -212,7 +211,7 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

mpasClimatologyTask=mpasClimatologyTask, parentTask=self, climatologyName=fieldName, - variableList=[mpasFieldName], + variableList=None, comparisonGridNames=comparisonGridNames, seasons=seasons, iselValues=iselValues) @@ -220,7 +219,7 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

if controlConfig is None: refTitleLabel = \ - 'Observations (Paolo et al, 2023)' + 'Observations (Paolo et al. 2023)' observationsDirectory = build_obs_path( config, 'ocean', 'meltSubdirectory') @@ -241,13 +240,10 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

f'{observationsDirectory}/Paolo/Paolo_2023_' \ f'iceshelf_melt_rates_1992-2017_v1.0_6000x6000km_{res:g}km_' \ f'Antarctic_stereo.20240220.nc' - refFieldName = 'meltRate' - outFileLabel = 'meltPaolo' - galleryName = 'Observations: Paolo et al. (2023)' remapObservationsSubtask = RemapObservedAntarcticMeltClimatology( parentTask=self, seasons=seasons, fileName=obsFileName, - outFilePrefix=refFieldName, + outFilePrefix='meltRate', comparisonGridNames=comparisonGridNames) self.add_subtask(remapObservationsSubtask) diffTitleLabel = 'Model - Observations' @@ -255,33 +251,117 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

else: remapObservationsSubtask = None controlRunName = controlConfig.get('runs', 'mainRunName') - galleryName = None refTitleLabel = f'Control: {controlRunName}' + diffTitleLabel = 'Main - Control' + + totalFluxVar = 'timeMonthly_avg_landIceFreshwaterFluxTotal' + landIceFluxVar = 'timeMonthly_avg_landIceFreshwaterFlux' + frazilFluxVar = 'timeMonthly_avg_frazilIceFreshwaterFlux' + mpasFieldName = totalFluxVar + + if controlConfig is None: + refFieldName = 'meltRate' + else: refFieldName = mpasFieldName - outFileLabel = 'melt' - diffTitleLabel = 'Main - Control' for comparisonGridName in comparisonGridNames: for season in seasons: # make a new subtask for this season and comparison grid - subtask = PlotClimatologyMapSubtask( + subtaskName = f'plot_total_melt_{season}_{comparisonGridName}' + subtask = PlotAntarcticMeltSubtask( self, season, comparisonGridName, remapClimatologySubtask, - remapObservationsSubtask, controlConfig=controlConfig) + remapObservationsSubtask, controlConfig=controlConfig, + subtaskName=subtaskName) subtask.set_plot_info( - outFileLabel=outFileLabel, - fieldNameInTitle='Melt Rate', + outFileLabel='antMeltTotal', + fieldNameInTitle='Total Melt Flux', mpasFieldName=mpasFieldName, refFieldName=refFieldName, refTitleLabel=refTitleLabel, diffTitleLabel=diffTitleLabel, - unitsLabel=r'm a$^{-1}$', - imageCaption='Antarctic Melt Rate', + unitsLabel=r'm a$^{-1}$ freshwater equiv.', + imageCaption='Antarctic Total Melt Flux', galleryGroup='Melt Rate', groupSubtitle=None, groupLink='antarctic_melt', - galleryName=galleryName) + galleryName='Total Melt Flux') + + self.add_subtask(subtask) + + mpasFieldName = landIceFluxVar + + if controlConfig is None: + refFieldName = 'meltRate' + else: + refFieldName = mpasFieldName + + for comparisonGridName in comparisonGridNames: + for season in seasons: + # make a new subtask for this season and comparison grid + subtaskName = \ + f'plot_interface_melt_{season}_{comparisonGridName}' + subtask = PlotAntarcticMeltSubtask( + self, season, comparisonGridName, remapClimatologySubtask, + remapObservationsSubtask, controlConfig=controlConfig, + subtaskName=subtaskName) + + # In PlotAntarcticMeltSubtask, we will remove the obs from + # these plots if totalFluxVar is present so we only compare one + # field with obs + + subtask.set_plot_info( + outFileLabel='antMeltInterface', + fieldNameInTitle='Melt Rate at Interface', + mpasFieldName=mpasFieldName, + refFieldName=refFieldName, + refTitleLabel=refTitleLabel, + diffTitleLabel=diffTitleLabel, + unitsLabel=r'm a$^{-1}$ freshwater equiv.', + imageCaption='Antarctic Melt Rate at Interface', + galleryGroup='Melt Rate', + groupSubtitle=None, + groupLink='antarctic_melt_int', + galleryName='Melt Rate at the Ice-ocean Interface') + + self.add_subtask(subtask) + + mpasFieldName = frazilFluxVar + + if controlConfig is None: + refTitleLabel = None + refFieldName = None + diffTitleLabel = None + + else: + controlRunName = controlConfig.get('runs', 'mainRunName') + refTitleLabel = f'Control: {controlRunName}' + refFieldName = mpasFieldName + diffTitleLabel = 'Main - Control' + + for comparisonGridName in comparisonGridNames: + for season in seasons: + # make a new subtask for this season and comparison grid + subtaskName = \ + f'plot_interface_frazil_{season}_{comparisonGridName}' + subtask = PlotAntarcticMeltSubtask( + self, season, comparisonGridName, remapClimatologySubtask, + controlConfig=controlConfig, subtaskName=subtaskName) + + subtask.set_plot_info( + outFileLabel='antFrazil', + fieldNameInTitle='Frazil Accretion Rate, negative upward', + mpasFieldName=mpasFieldName, + refFieldName=refFieldName, + refTitleLabel=refTitleLabel, + diffTitleLabel=diffTitleLabel, + unitsLabel=r'm a$^{-1}$ freshwater equiv.', + imageCaption='Antarctic Accretion Rate', + galleryGroup='Melt Rate', + groupSubtitle=None, + groupLink='antarctic_frazil_flux', + galleryName='Frazil Accretion Rate') self.add_subtask(subtask)
@@ -317,11 +397,35 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

landIceMask : xarray.DataArray A mask indicating where there is land ice on the ocean grid (thus, where melt rates are valid) + + renameDict : dict + A dictionary use to rename variables in the climatology """ # Authors # ------- # Xylar Asay-Davis + def setup_and_check(self): + """ + Figure out which variable(s) to remap + """ + # Authors + # ------- + # Xylar Asay-Davis + + totalFluxVar = 'timeMonthly_avg_landIceFreshwaterFluxTotal' + landIceFluxVar = 'timeMonthly_avg_landIceFreshwaterFlux' + frazilFluxVar = 'timeMonthly_avg_frazilIceFreshwaterFlux' + + if totalFluxVar in self.mpasClimatologyTask.allVariables: + # include the total and constituent fluxes + self.variableList = [totalFluxVar, landIceFluxVar, frazilFluxVar] + else: + # we only have the old name without the frazil accretion rate + self.variableList = [landIceFluxVar] + + super().setup_and_check() + def run_task(self): """ Compute climatologies of melt rates from E3SM/MPAS output @@ -365,12 +469,14 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

# ------- # Xylar Asay-Davis - fieldName = self.variableList[0] + for fieldName in self.variableList: - # scale the field to m/yr from kg/m^2/s and mask out non-land-ice areas - climatology[fieldName] = \ - constants.sec_per_year / constants.rho_fw * \ - climatology[fieldName].where(self.landIceMask) + # scale the field to m/yr from kg/m^2/s and mask out non-land-ice + # areas + climatology[fieldName] = \ + constants.sec_per_year / constants.rho_fw * \ + climatology[fieldName].where(self.landIceMask) + climatology[fieldName].attrs['units'] = 'm yr^-1' return climatology @@ -527,7 +633,8 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

pool=ThreadPool(1)): # Load data: - inFileName = self.mpasClimatologyTask.get_file_name(self.season) + inFileName = \ + self.mpasClimatologyTask.get_file_name(self.season) mpasFieldName = 'timeMonthly_avg_landIceFreshwaterFlux' dsIn = xr.open_dataset(inFileName) freshwaterFlux = dsIn[mpasFieldName] @@ -550,7 +657,8 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

# select only those regions we want to plot dsRegionMask = dsRegionMask.isel(nRegions=regionIndices) - cellMasks = dsRegionMask.regionCellMasks.chunk({'nRegions': 10}) + cellMasks = \ + dsRegionMask.regionCellMasks.chunk({'nRegions': 10}) restartFileName = \ self.runStreams.readpath('restart')[0] @@ -653,6 +761,56 @@

Source code for mpas_analysis.ocean.climatology_map_antarctic_melt

row[controlRunName] = \ f'{dsControl.totalMeltFlux[index].values}' writer.writerow(row) + + +class PlotAntarcticMeltSubtask(PlotClimatologyMapSubtask): + """ + A subtask for plotting antarctic melt fields if available + + Attributes + ---------- + doPlot : bool + Whether the required variable from the climatology is available so that + a plot should be generated + """ + # Authors + # ------- + # Xylar Asay-Davis + + def setup_and_check(self): + """ + Perform steps to set up the analysis and check for errors in the setup. + """ + allVariables = \ + self.remapMpasClimatologySubtask.mpasClimatologyTask.allVariables + + totalFluxVar = 'timeMonthly_avg_landIceFreshwaterFluxTotal' + landIceFluxVar = 'timeMonthly_avg_landIceFreshwaterFlux' + plotAll = (totalFluxVar in allVariables) + + if self.mpasFieldName == landIceFluxVar and plotAll and \ + self.controlConfig is None: + # need to remove obs because we only wnat to plot them vs the + # total flux + self.remapObsClimatologySubtask = None + self.refTitleLabel = None + self.refFieldName = None + self.diffTitleLabel = None + + self.doPlot = (self.mpasFieldName == landIceFluxVar or plotAll) + + if self.doPlot: + super().setup_and_check() + else: + # still need to call the base class's method + AnalysisTask.setup_and_check(self=self) + + def run_task(self): + """ + Plot the variable if available + """ + if self.doPlot: + super().run_task()
diff --git a/latest/_modules/mpas_analysis/ocean/time_series_antarctic_melt.html b/latest/_modules/mpas_analysis/ocean/time_series_antarctic_melt.html index cecbdd8f3..d3f84a155 100644 --- a/latest/_modules/mpas_analysis/ocean/time_series_antarctic_melt.html +++ b/latest/_modules/mpas_analysis/ocean/time_series_antarctic_melt.html @@ -183,7 +183,8 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

# nothing else to do return - masksSubtask = regionMasksTask.add_mask_subtask(regionGroup=regionGroup) + masksSubtask = \ + regionMasksTask.add_mask_subtask(regionGroup=regionGroup) self.iceShelfMasksFile = masksSubtask.geojsonFileName iceShelvesToPlot = masksSubtask.expand_region_names(iceShelvesToPlot) @@ -290,8 +291,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

self.endYear = endYear self.startDate = f'{self.startYear:04d}-01-01_00:00:00' self.endDate = f'{self.endYear:04d}-12-31_23:59:59' - self.variableList = \ - ['timeMonthly_avg_landIceFreshwaterFlux'] + self.variableList = None def setup_and_check(self): """ @@ -335,6 +335,13 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

raise IOError('No MPAS-O restart file found: need at least one ' 'restart file for Antarctic melt calculations') + totalFluxVar = 'timeMonthly_avg_landIceFreshwaterFluxTotal' + landIceFluxVar = 'timeMonthly_avg_landIceFreshwaterFlux' + if totalFluxVar in self.mpasTimeSeriesTask.allVariables: + self.variableList = [totalFluxVar] + else: + self.variableList = [landIceFluxVar] + self.mpasTimeSeriesTask.add_variables(variableList=self.variableList) return @@ -414,17 +421,18 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

regionNames = decode_strings(dsRegionMask.regionNames) + fluxVar = self.variableList[0] + datasets = [] nTime = dsIn.sizes['Time'] for tIndex in range(nTime): self.logger.info(f' {tIndex + 1}/{nTime}') - freshwaterFlux = \ - dsIn.timeMonthly_avg_landIceFreshwaterFlux.isel(Time=tIndex) + freshwaterFlux = dsIn[fluxVar].isel(Time=tIndex) nRegions = dsRegionMask.sizes['nRegions'] meltRates = numpy.zeros((nRegions,)) - totalMeltFluxes = numpy.zeros((nRegions,)) + integratedMeltFluxes = numpy.zeros((nRegions,)) for regionIndex in range(nRegions): self.logger.info(f' {regionNames[regionIndex]}') @@ -432,7 +440,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

dsRegionMask.regionCellMasks.isel(nRegions=regionIndex) # convert from kg/s to kg/yr - totalMeltFlux = constants.sec_per_year * \ + integratedMeltFlux = constants.sec_per_year * \ (cellMask * areaCell * freshwaterFlux).sum(dim='nCells') totalArea = \ @@ -440,23 +448,23 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

# from kg/m^2/yr to m/yr meltRates[regionIndex] = ((1. / constants.rho_fw) * - (totalMeltFlux / totalArea)) + (integratedMeltFlux / totalArea)) # convert from kg/yr to GT/yr - totalMeltFlux /= constants.kg_per_GT - totalMeltFluxes[regionIndex] = totalMeltFlux + integratedMeltFlux /= constants.kg_per_GT + integratedMeltFluxes[regionIndex] = integratedMeltFlux dsOut = xarray.Dataset() dsOut.coords['Time'] = dsIn.Time.isel(Time=tIndex) - dsOut['totalMeltFlux'] = (('nRegions',), totalMeltFluxes) + dsOut['integratedMeltFlux'] = (('nRegions',), integratedMeltFluxes) dsOut['meltRates'] = (('nRegions',), meltRates) datasets.append(dsOut) dsOut = xarray.concat(objs=datasets, dim='Time') dsOut['regionNames'] = dsRegionMask.regionNames - dsOut.totalMeltFlux.attrs['units'] = 'GT a$^{-1}$' - dsOut.totalMeltFlux.attrs['description'] = \ - 'Total melt flux summed over each ice shelf or region' + 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}$' dsOut.meltRates.attrs['description'] = \ 'Melt rate averaged over each ice shelf or region' @@ -641,17 +649,17 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

fc.add_feature(feature) break - totalMeltFlux, meltRates = self._load_ice_shelf_fluxes(config) + integratedMeltFlux, meltRates = self._load_ice_shelf_fluxes(config) plotControl = self.controlConfig is not None if plotControl: controlRunName = self.controlConfig.get('runs', 'mainRunName') - refTotalMeltFlux, refMeltRates = \ + refintegratedMeltFlux, refMeltRates = \ self._load_ice_shelf_fluxes(self.controlConfig) else: controlRunName = None - refTotalMeltFlux = None + refintegratedMeltFlux = None refMeltRates = None # Load observations from multiple files and put in dictionary based @@ -700,7 +708,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

index = region_names.index(self.iceShelf) ds_shelf = ds_adusumilli.isel(nRegions=index) obsDict['Adusumilli et al. (2020)'] = { - 'meltFlux': ds_shelf.totalMeltFlux.values, + 'meltFlux': ds_shelf.integratedMeltFlux.values, 'meltFluxUncertainty': ds_shelf.meltFluxUncertainty.values, 'meltRate': ds_shelf.meanMeltRate.values, 'meltRateUncertainty': ds_shelf.meltRateUncertainty.values} @@ -776,7 +784,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

xLabel = 'Time (yr)' yLabel = 'Melt Flux (GT/yr)' - timeSeries = totalMeltFlux.isel(nRegions=self.regionIndex) + timeSeries = integratedMeltFlux.isel(nRegions=self.regionIndex) filePrefix = f'melt_flux_{suffix}' outFileName = f'{self.plotsDirectory}/{filePrefix}.png' @@ -786,7 +794,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

lineWidths = [2.5] legendText = [mainRunName] if plotControl: - fields.append(refTotalMeltFlux.isel(nRegions=self.regionIndex)) + fields.append(refintegratedMeltFlux.isel(nRegions=self.regionIndex)) lineColors.append(config.get('timeSeries', 'controlColor')) lineWidths.append(1.2) legendText.append(controlRunName) @@ -839,7 +847,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

savefig(outFileName, config) - caption = f'Running Mean of Total Melt Flux under Ice Shelves in ' \ + caption = f'Running Mean of Integrated Melt Flux under Ice Shelves in ' \ f'the {title} Region' write_image_xml( config=config, @@ -848,13 +856,13 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

componentSubdirectory='ocean', galleryGroup='Antarctic Melt Time Series', groupLink='antmelttime', - gallery='Total Melt Flux', + gallery='Integrated Melt Flux', thumbnailDescription=title, imageDescription=caption, imageCaption=caption) xLabel = 'Time (yr)' - yLabel = 'Melt Rate (m/yr)' + yLabel = 'Melt Rate (m/yr) freshwater equiv.' timeSeries = meltRates.isel(nRegions=self.regionIndex) @@ -921,8 +929,8 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

@staticmethod def _load_ice_shelf_fluxes(config): """ - Reads melt flux time series and computes regional total melt flux and - mean melt rate. + Reads melt flux time series and computes regional integrated melt flux + and mean melt rate. """ # Authors # ------- @@ -940,7 +948,7 @@

Source code for mpas_analysis.ocean.time_series_antarctic_melt

f'{startYear:04d}-{endYear:04d}.nc' dsOut = xarray.open_dataset(outFileName) - return dsOut.totalMeltFlux, dsOut.meltRates + return dsOut.integratedMeltFlux, dsOut.meltRates