def run_task(self): # {{{ """ Plots a comparison of ACME/MPAS output to SST, MLD or SSS observations or a reference run """ # Authors # ------- # Luke Van Roekel, Xylar Asay-Davis, Milena Veneziani season = self.season depth = self.depth comparisonGridName = self.comparisonGridName self.logger.info("\nPlotting 2-d maps of {} climatologies for {} on " "the {} grid...".format(self.fieldNameInTitle, season, comparisonGridName)) # first read the model climatology remappedFileName = \ self.remapMpasClimatologySubtask.get_remapped_file_name( season=season, comparisonGridName=comparisonGridName) remappedModelClimatology = xr.open_dataset(remappedFileName) if depth is not None: if str(depth) not in remappedModelClimatology.depthSlice.values: raise KeyError('The climatology you are attempting to perform ' 'depth slices of was originally created\n' 'without depth {}. You will need to delete and ' 'regenerate the climatology'.format(depth)) remappedModelClimatology = remappedModelClimatology.sel( depthSlice=str(depth), drop=True) # now the observations or reference run if self.remapObsClimatologySubtask is not None: remappedFileName = self.remapObsClimatologySubtask.get_file_name( stage='remapped', season=season, comparisonGridName=comparisonGridName) remappedRefClimatology = xr.open_dataset(remappedFileName) elif self.refConfig is not None: climatologyName = self.remapMpasClimatologySubtask.climatologyName remappedFileName = \ get_remapped_mpas_climatology_file_name( self.refConfig, season=season, componentName=self.componentName, climatologyName=climatologyName, comparisonGridName=comparisonGridName) remappedRefClimatology = xr.open_dataset(remappedFileName) refStartYear = self.refConfig.getint('climatology', 'startYear') refEndYear = self.refConfig.getint('climatology', 'endYear') if refStartYear != self.startYear or refEndYear != self.endYear: self.refTitleLabel = '{}\n(years {:04d}-{:04d})'.format( self.refTitleLabel, refStartYear, refEndYear) else: remappedRefClimatology = None if remappedRefClimatology is not None and depth is not None: if str(depth) not in remappedRefClimatology.depthSlice.values: raise KeyError('The climatology you are attempting to perform ' 'depth slices of was originally created\n' 'without depth {}. You will need to delete and ' 'regenerate the climatology'.format(depth)) remappedRefClimatology = remappedRefClimatology.sel( depthSlice=str(depth), drop=True) if self.removeMean: if remappedRefClimatology is None: remappedModelClimatology[self.mpasFieldName] = \ remappedModelClimatology[self.mpasFieldName] - \ remappedModelClimatology[self.mpasFieldName].mean() else: masked = remappedModelClimatology[self.mpasFieldName].where( remappedRefClimatology[self.refFieldName].notnull()) remappedModelClimatology[self.mpasFieldName] = \ remappedModelClimatology[self.mpasFieldName] - \ masked.mean() masked = remappedRefClimatology[self.refFieldName].where( remappedModelClimatology[self.mpasFieldName].notnull()) remappedRefClimatology[self.refFieldName] = \ remappedRefClimatology[self.refFieldName] - \ masked.mean() if self.comparisonGridName == 'latlon': self._plot_latlon(remappedModelClimatology, remappedRefClimatology) elif self.comparisonGridName == 'antarctic': self._plot_antarctic(remappedModelClimatology, remappedRefClimatology)
def run_task(self): # {{{ """ Performs analysis of sea-ice properties by comparing with previous model results and/or observations. """ # Authors # ------- # Xylar Asay-Davis, Milena Veneziani config = self.config season = self.season comparisonGridName = self.comparisonGridName self.logger.info("\nPlotting 2-d maps of {} climatologies for " "{} against {}...".format( self.fieldNameInTitle, season, self.refTitleLabel)) mainRunName = config.get('runs', 'mainRunName') startYear = self.startYear endYear = self.endYear hemisphere = self.hemisphere sectionName = self.taskName vertical = config.getboolean(sectionName, 'vertical') if hemisphere == 'NH': plotProjection = 'npstere' else: plotProjection = 'spstere' referenceLongitude = config.getfloat(sectionName, 'referenceLongitude') minimumLatitude = config.getfloat(sectionName, 'minimumLatitude') remappedFileName = \ self.remapMpasClimatologySubtask.get_remapped_file_name( season=season, comparisonGridName=comparisonGridName) remappedClimatology = xr.open_dataset(remappedFileName) modelOutput = remappedClimatology[self.mpasFieldName].values if self.maskValue is not None: modelOutput = ma.masked_values(modelOutput, self.maskValue) lon = remappedClimatology['lon'].values lat = remappedClimatology['lat'].values lonTarg, latTarg = np.meshgrid(lon, lat) if self.remapObsClimatologySubtask is not None: remappedFileName = self.remapObsClimatologySubtask.get_file_name( stage='remapped', season=season, comparisonGridName=comparisonGridName) remappedRefClimatology = xr.open_dataset(remappedFileName) refOutput = remappedRefClimatology[self.refFieldName].values if self.maskValue is not None: refOutput = ma.masked_values(refOutput, self.maskValue) difference = modelOutput - refOutput elif self.refConfig is not None: climatologyName = self.remapMpasClimatologySubtask.climatologyName remappedFileName = \ get_remapped_mpas_climatology_file_name( self.refConfig, season=season, componentName=self.componentName, climatologyName=climatologyName, comparisonGridName=comparisonGridName) remappedRefClimatology = xr.open_dataset(remappedFileName) refStartYear = self.refConfig.getint('climatology', 'startYear') refEndYear = self.refConfig.getint('climatology', 'endYear') if refStartYear != self.startYear or refEndYear != self.endYear: self.refTitleLabel = '{}\n(years {:04d}-{:04d})'.format( self.refTitleLabel, refStartYear, refEndYear) else: remappedRefClimatology = None if remappedRefClimatology is None: refOutput = None difference = None else: refOutput = remappedRefClimatology[self.refFieldName].values if self.maskValue is not None: refOutput = ma.masked_values(refOutput, self.maskValue) difference = modelOutput - refOutput startYear = self.startYear endYear = self.endYear filePrefix = self.filePrefix title = '{} ({}, years {:04d}-{:04d})'.format( self.fieldNameInTitle, season, startYear, endYear) fileout = '{}/{}.png'.format(self.plotsDirectory, filePrefix) plot_polar_comparison( config, lonTarg, latTarg, modelOutput, refOutput, difference, sectionName, title=title, fileout=fileout, plotProjection=plotProjection, latmin=minimumLatitude, lon0=referenceLongitude, modelTitle=mainRunName, refTitle=self.refTitleLabel, diffTitle=self.diffTitleLabel, cbarlabel=self.unitsLabel, vertical=vertical) write_image_xml( config, filePrefix, componentName='Sea Ice', componentSubdirectory='sea_ice', galleryGroup=self.galleryGroup, groupSubtitle=self.groupSubtitle, groupLink=self.groupLink, gallery=self.galleryName, thumbnailDescription=season, imageDescription=self.imageDescription, imageCaption=self.imageCaption)
def run_task(self): # {{{ """ Plots a comparison of ACME/MPAS output to SST, MLD or SSS observations or a reference run """ # Authors # ------- # Xylar Asay-Davis, Greg Streletz season = self.season transectName = self.transectName self.logger.info("\nPlotting {} over season {}" "...".format(self.fieldNameInTitle, season)) # first read the model climatology remappedFileName = \ self.remapMpasClimatologySubtask.get_remapped_file_name( season=season, comparisonGridName=transectName) remappedModelClimatology = xr.open_dataset(remappedFileName) # now the observations or reference run if self.plotObs: verticalComparisonGridName = \ self.remapMpasClimatologySubtask.verticalComparisonGridName remappedFileName = \ self.remapMpasClimatologySubtask.obsDatasets.get_out_file_name( transectName, verticalComparisonGridName) remappedRefClimatology = xr.open_dataset(remappedFileName) # if Time is an axis, take the appropriate avarage to get the # climatology if 'Time' in remappedRefClimatology.dims: monthValues = constants.monthDictionary[season] remappedRefClimatology = compute_climatology( remappedRefClimatology, monthValues, maskVaries=True) elif self.refConfig is not None: climatologyName = self.remapMpasClimatologySubtask.climatologyName remappedFileName = \ get_remapped_mpas_climatology_file_name( self.refConfig, season=season, componentName=self.componentName, climatologyName=climatologyName, comparisonGridName=transectName) remappedRefClimatology = xr.open_dataset(remappedFileName) refStartYear = self.refConfig.getint('climatology', 'startYear') refEndYear = self.refConfig.getint('climatology', 'endYear') if refStartYear != self.startYear or refEndYear != self.endYear: self.refTitleLabel = '{}\n(years {:04d}-{:04d})'.format( self.refTitleLabel, refStartYear, refEndYear) else: remappedRefClimatology = None self._plot_transect(remappedModelClimatology, remappedRefClimatology) remappedModelClimatology.close() if remappedRefClimatology is not None: remappedRefClimatology.close()
def run_task(self): # {{{ """ Performs analysis of sea-ice properties by comparing with previous model results and/or observations. """ # Authors # ------- # Xylar Asay-Davis, Milena Veneziani config = self.config season = self.season comparisonGridName = self.comparisonGridName self.logger.info("\nPlotting 2-d maps of {} climatologies for " "{} against {}...".format(self.fieldNameInTitle, season, self.refTitleLabel)) mainRunName = config.get('runs', 'mainRunName') startYear = self.startYear endYear = self.endYear hemisphere = self.hemisphere sectionName = self.taskName vertical = config.getboolean(sectionName, 'vertical') if hemisphere == 'NH': plotProjection = 'npstere' else: plotProjection = 'spstere' referenceLongitude = config.getfloat(sectionName, 'referenceLongitude') minimumLatitude = config.getfloat(sectionName, 'minimumLatitude') remappedFileName = \ self.remapMpasClimatologySubtask.get_remapped_file_name( season=season, comparisonGridName=comparisonGridName) remappedClimatology = xr.open_dataset(remappedFileName) modelOutput = remappedClimatology[self.mpasFieldName].values # mask nans modelOutput = np.ma.masked_array(modelOutput, np.isnan(modelOutput)) lon = remappedClimatology['lon'].values lat = remappedClimatology['lat'].values if self.remapObsClimatologySubtask is not None: remappedFileName = self.remapObsClimatologySubtask.get_file_name( stage='remapped', season=season, comparisonGridName=comparisonGridName) remappedRefClimatology = xr.open_dataset(remappedFileName) elif self.controlConfig is not None: climatologyName = self.remapMpasClimatologySubtask.climatologyName remappedFileName = \ get_remapped_mpas_climatology_file_name( self.controlConfig, season=season, componentName=self.componentName, climatologyName=climatologyName, comparisonGridName=comparisonGridName, op=self.remapMpasClimatologySubtask.op) remappedRefClimatology = xr.open_dataset(remappedFileName) controlStartYear = self.controlConfig.getint( 'climatology', 'startYear') controlEndYear = self.controlConfig.getint('climatology', 'endYear') if controlStartYear != self.startYear or \ controlEndYear != self.endYear: self.refTitleLabel = '{}\n(years {:04d}-{:04d})'.format( self.refTitleLabel, controlStartYear, controlEndYear) else: remappedRefClimatology = None if remappedRefClimatology is None: refOutput = None difference = None else: refOutput = remappedRefClimatology[self.refFieldName].values # mask nans refOutput = np.ma.masked_array(refOutput, np.isnan(refOutput)) difference = modelOutput - refOutput # mask with maskValue only after taking the diff if self.maskValue is not None: mask = np.logical_or(refOutput.mask, refOutput == self.maskValue) refOutput = np.ma.masked_array(refOutput, mask) difference = np.ma.masked_array(difference, mask) # mask with maskValue only after taking the diff if self.maskValue is not None: mask = np.logical_or(modelOutput.mask, modelOutput == self.maskValue) modelOutput = np.ma.masked_array(modelOutput, mask) # for log plots, make sure the data is all positive to avoid masking if config.has_option(sectionName, 'normTypeResult'): normType = config.get(sectionName, 'normTypeResult') normArgs = config.getExpression(sectionName, 'normArgsResult') if normType == 'log': epsilon = 1e-2 * normArgs['vmin'] modelOutput = np.maximum(modelOutput, epsilon) if refOutput is not None: refOutput = np.maximum(refOutput, epsilon) startYear = self.startYear endYear = self.endYear filePrefix = self.filePrefix title = '{} ({}, years {:04d}-{:04d})'.format(self.fieldNameInTitle, season, startYear, endYear) fileout = '{}/{}.png'.format(self.plotsDirectory, filePrefix) plot_polar_comparison(config, lon, lat, modelOutput, refOutput, difference, sectionName, title=title, fileout=fileout, plotProjection=plotProjection, latmin=minimumLatitude, lon0=referenceLongitude, modelTitle=mainRunName, refTitle=self.refTitleLabel, diffTitle=self.diffTitleLabel, cbarlabel=self.unitsLabel, vertical=vertical) write_image_xml(config, filePrefix, componentName='Sea Ice', componentSubdirectory='sea_ice', galleryGroup=self.galleryGroup, groupSubtitle=self.groupSubtitle, groupLink=self.groupLink, gallery=self.galleryName, thumbnailDescription=season, imageDescription=self.imageDescription, imageCaption=self.imageCaption)