def __init__(self, config, mpasTimeSeriesTask):  # {{{
        """
        Construct the analysis task.

        Parameters
        ----------
        config :  instance of MpasAnalysisConfigParser
            Contains configuration options

        mpasTimeSeriesTask : ``MpasTimeSeriesTask``
            The task that extracts the time series from MPAS monthly output
        """
        # Authors
        # -------
        # Xylar Asay-Davis

        # first, call the constructor from the base class (AnalysisTask)
        super(TimeSeriesTemperatureAnomaly, self).__init__(
            config=config,
            taskName='timeSeriesTemperatureAnomaly',
            componentName='ocean',
            tags=['timeSeries', 'temperature', 'publicObs'])

        sectionName = 'hovmollerTemperatureAnomaly'
        regionNames = config.getExpression(sectionName, 'regions')
        movingAveragePoints = config.getint(sectionName, 'movingAveragePoints')

        mpasFieldName = 'timeMonthly_avg_avgValueWithinOceanLayerRegion_' \
            'avgLayerTemperature'

        timeSeriesFileName = 'regionAveragedTemperatureAnomaly.nc'

        anomalyTask = ComputeAnomalySubtask(
            parentTask=self,
            mpasTimeSeriesTask=mpasTimeSeriesTask,
            outFileName=timeSeriesFileName,
            variableList=[mpasFieldName],
            movingAveragePoints=movingAveragePoints)
        self.add_subtask(anomalyTask)

        for regionName in regionNames:
            caption = 'Trend of {} Potential Temperature Anomaly vs ' \
                      'Depth'.format(regionName)
            plotTask = PlotHovmollerSubtask(
                parentTask=self,
                regionName=regionName,
                inFileName=timeSeriesFileName,
                outFileLabel='TAnomalyZ',
                fieldNameInTitle='Potential Temperature Anomaly',
                mpasFieldName=mpasFieldName,
                unitsLabel=r'[$\degree$C]',
                sectionName=sectionName,
                thumbnailSuffix=u'Δϴ',
                imageCaption=caption,
                galleryGroup='Trends vs Depth',
                groupSubtitle=None,
                groupLink='trendsvsdepth',
                galleryName=None)

            plotTask.run_after(anomalyTask)
            self.add_subtask(plotTask)
Ejemplo n.º 2
0
    def __init__(self, config, controlConfig=None):  # {{{
        '''
        Construct the analysis task.

        Parameters
        ----------
        config :  instance of MpasAnalysisConfigParser
            Contains configuration options

        mpasClimatologyTask : ``MpasClimatologyTask``
            The task that produced the climatology to be remapped and plotted

        controlConfig :  ``MpasAnalysisConfigParser``, optional
            Configuration options for a control run (if any)
        '''
        # Authors
        # -------
        # Xylar Asay-Davis

        # first, call the constructor from the base class (AnalysisTask)
        super(OceanRegionalProfiles,
              self).__init__(config=config,
                             taskName='oceanRegionalProfiles',
                             componentName='ocean',
                             tags=['profiles', 'climatology'])

        self.startYear = config.getint('climatology', 'startYear')
        self.endYear = config.getint('climatology', 'endYear')

        self.fields = config.getExpression('oceanRegionalProfiles', 'fields')

        self.seasons = config.getExpression('oceanRegionalProfiles', 'seasons')

        self.regionMaskSuffix = config.get('oceanRegionalProfiles',
                                           'regionMaskSuffix')

        self.regionNames = config.getExpression('oceanRegionalProfiles',
                                                'regionNames')

        plotHovmoller = config.getboolean('oceanRegionalProfiles',
                                          'plotHovmoller')

        self.regionMaskSuffix = config.get('oceanRegionalProfiles',
                                           'regionMaskSuffix')

        hovmollerGalleryGroup = config.get('oceanRegionalProfiles',
                                           'hovmollerGalleryGroup')

        masksFile = get_region_mask(config,
                                    '{}.geojson'.format(self.regionMaskSuffix))

        parallelTaskCount = config.getWithDefault('execute',
                                                  'parallelTaskCount',
                                                  default=1)

        masksSubtask = ComputeRegionMasksSubtask(
            self,
            masksFile,
            outFileSuffix=self.regionMaskSuffix,
            featureList=self.regionNames,
            subprocessCount=parallelTaskCount)

        if 'all' in self.regionNames:
            self.regionNames = get_feature_list(config, masksFile)

        self.masksSubtask = masksSubtask

        years = range(self.startYear, self.endYear + 1)

        # in the end, we'll combine all the time series into one, but we create
        # this task first so it's easier to tell it to run after all the
        # compute tasks
        combineSubtask = CombineRegionalProfileTimeSeriesSubtask(
            self, startYears=years, endYears=years)

        # run one subtask per year
        for year in years:
            computeSubtask = ComputeRegionalProfileTimeSeriesSubtask(
                self, startYear=year, endYear=year)
            computeSubtask.run_after(masksSubtask)
            combineSubtask.run_after(computeSubtask)

        if plotHovmoller:
            for field in self.fields:
                prefix = field['prefix']
                for regionName in self.regionNames:
                    subtaskName = 'plotHovmoller_{}_{}'.format(
                        prefix, regionName.replace(' ', '_'))
                    inFileName = '{}/{}_{:04d}-{:04d}.nc'.format(
                        self.regionMaskSuffix, self.regionMaskSuffix,
                        self.startYear, self.endYear)
                    titleName = field['titleName']
                    caption = 'Time series of {} {} vs ' \
                              'depth'.format(regionName.replace('_', ' '),
                                             titleName)
                    hovmollerSubtask = PlotHovmollerSubtask(
                        parentTask=self,
                        regionName=regionName,
                        inFileName=inFileName,
                        outFileLabel='{}_hovmoller'.format(prefix),
                        fieldNameInTitle=titleName,
                        mpasFieldName='{}_mean'.format(prefix),
                        unitsLabel=field['units'],
                        sectionName='{}OceanRegionalHovmoller'.format(prefix),
                        thumbnailSuffix='',
                        imageCaption=caption,
                        galleryGroup=hovmollerGalleryGroup,
                        groupSubtitle=None,
                        groupLink='ocnreghovs',
                        galleryName=titleName,
                        subtaskName=subtaskName)
                    hovmollerSubtask.run_after(combineSubtask)
                    self.add_subtask(hovmollerSubtask)

        for field in self.fields:
            prefix = field['prefix']
            for regionName in self.regionNames:
                for season in self.seasons:
                    plotSubtask = PlotRegionalProfileTimeSeriesSubtask(
                        self, season, regionName, field, controlConfig)
                    plotSubtask.run_after(combineSubtask)
                    self.add_subtask(plotSubtask)
    def __init__(self, config, mpasTimeSeriesTask, controlConfig=None):
        # {{{
        """
        Construct the analysis task.

        Parameters
        ----------
        config :  ``MpasAnalysisConfigParser``
            Configuration options

        mpasTimeSeriesTask : ``MpasTimeSeriesTask``
            The task that extracts the time series from MPAS monthly output

        controlConfig :  ``MpasAnalysisConfigParser``, optional
            Configuration options for a control run (if any)
        """
        # Authors
        # -------
        # Xylar Asay-Davis

        # first, call the constructor from the base class (AnalysisTask)
        super(TimeSeriesOHCAnomaly, self).__init__(
            config=config,
            taskName='timeSeriesOHCAnomaly',
            componentName='ocean',
            tags=['timeSeries', 'ohc', 'publicObs'])

        sectionName = 'timeSeriesOHCAnomaly'
        regionNames = config.getExpression(sectionName, 'regions')
        movingAveragePoints = config.getint(sectionName, 'movingAveragePoints')

        self.variableDict = {}
        for suffix in ['avgLayerTemperature', 'sumLayerMaskValue',
                       'avgLayerArea', 'avgLayerThickness']:
            key = 'timeMonthly_avg_avgValueWithinOceanLayerRegion_' + suffix
            self.variableDict[key] = suffix

        mpasFieldName = 'ohc'

        timeSeriesFileName = 'regionAveragedOHCAnomaly.nc'

        anomalyTask = ComputeAnomalySubtask(
            parentTask=self,
            mpasTimeSeriesTask=mpasTimeSeriesTask,
            outFileName=timeSeriesFileName,
            variableList=list(self.variableDict.keys()),
            movingAveragePoints=movingAveragePoints,
            alter_dataset=self._compute_ohc)
        self.add_subtask(anomalyTask)

        for regionName in regionNames:
            caption = 'Trend of {} OHC Anomaly vs depth'.format(
                regionName)
            plotTask = PlotHovmollerSubtask(
                parentTask=self,
                regionName=regionName,
                inFileName=timeSeriesFileName,
                outFileLabel='ohcAnomalyZ',
                fieldNameInTitle='OHC Anomaly',
                mpasFieldName=mpasFieldName,
                unitsLabel=r'[$\times 10^{22}$ J]',
                sectionName='hovmollerOHCAnomaly',
                thumbnailSuffix=u'ΔOHC',
                imageCaption=caption,
                galleryGroup='Trends vs Depth',
                groupSubtitle=None,
                groupLink='trendsvsdepth',
                galleryName=None)

            plotTask.run_after(anomalyTask)
            self.add_subtask(plotTask)

            caption = 'Running Mean of the Anomaly in {} Ocean Heat ' \
                'Content'.format(regionName)
            plotTask = PlotOHCAnomaly(
                parentTask=self,
                regionName=regionName,
                inFileName=timeSeriesFileName,
                outFileLabel='ohcAnomaly',
                fieldNameInTitle='OHC Anomaly',
                mpasFieldName=mpasFieldName,
                yAxisLabel=r'$\Delta$OHC [$\times 10^{22}$ J]',
                sectionName='timeSeriesOHCAnomaly',
                thumbnailSuffix=u'ΔOHC',
                imageCaption=caption,
                galleryGroup='Time Series',
                groupSubtitle=None,
                groupLink='timeseries',
                galleryName=None,
                controlConfig=controlConfig)

            plotTask.run_after(anomalyTask)
            self.add_subtask(plotTask)
Ejemplo n.º 4
0
    def __init__(self,
                 config,
                 regionMasksTask,
                 oceanRegionalProfilesTask,
                 controlConfig=None):  # {{{
        """
        Construct the analysis task.

        Parameters
        ----------
        config :  instance of MpasAnalysisConfigParser
            Contains configuration options

        regionMasksTask : ``ComputeRegionMasks``
            A task for computing region masks

        oceanRegionalProfilesTask : mpas_analysis.ocean.OceanRegionalProfiles
            A task for computing ocean regional profiles

        controlConfig :  ``MpasAnalysisConfigParser``, optional
            Configuration options for a control run (if any)
        """
        # Authors
        # -------
        # Xylar Asay-Davis

        # first, call the constructor from the base class (AnalysisTask)
        super(HovmollerOceanRegions,
              self).__init__(config=config,
                             taskName='hovmollerOceanRegions',
                             componentName='ocean',
                             tags=['profiles', 'timeSeries', 'hovmoller'])

        startYear = config.getint('timeSeries', 'startYear')
        endYear = config.get('timeSeries', 'endYear')
        if endYear == 'end':
            # a valid end year wasn't found, so likely the run was not found,
            # perhaps because we're just listing analysis tasks
            endYear = startYear
        else:
            endYear = int(endYear)

        regionGroups = config.getExpression('hovmollerOceanRegions',
                                            'regionGroups')

        for regionGroup in regionGroups:
            suffix = regionGroup[0].upper() + regionGroup[1:].replace(' ', '')
            regionGroupSection = 'hovmoller{}'.format(suffix)
            regionNames = config.getExpression(regionGroupSection,
                                               'regionNames')
            if len(regionNames) == 0:
                return

            computeAnomaly = config.getboolean(regionGroupSection,
                                               'computeAnomaly')

            fields = config.getExpression(regionGroupSection, 'fields')

            masksSubtask = regionMasksTask.add_mask_subtask(regionGroup)
            masksFile = masksSubtask.geojsonFileName
            timeSeriesName = regionGroup.replace(' ', '')

            regionNames = masksSubtask.expand_region_names(regionNames)

            self.masksSubtask = masksSubtask

            oceanRegionalProfilesTask.add_region_group(regionMasksTask,
                                                       regionGroup,
                                                       regionNames, fields,
                                                       startYear, endYear)

            combineSubtask = oceanRegionalProfilesTask.combineSubtasks[
                regionGroup][(startYear, endYear)]

            movingAverageMonths = config.getint(regionGroupSection,
                                                'movingAverageMonths')

            baseDirectory = build_config_full_path(config, 'output',
                                                   'timeSeriesSubdirectory')

            # PlotHovmollerSubtask requires a relative path
            inFileName = \
                '{}/regionalProfiles_{}_{:04d}-{:04d}.nc'.format(
                    timeSeriesName, timeSeriesName,
                    startYear, endYear)
            if computeAnomaly:
                inFullPath = '{}/{}'.format(baseDirectory, inFileName)
                outFileName = \
                    '{}/anomaly_{}_{:04d}-{:04d}.nc'.format(
                        timeSeriesName, timeSeriesName,
                        startYear, endYear)
                outFullPath = '{}/{}'.format(baseDirectory, outFileName)
                anomalySubtask = ComputeHovmollerAnomalySubtask(
                    self, inFullPath, outFullPath, movingAverageMonths)
                self.add_subtask(anomalySubtask)
                anomalySubtask.run_after(combineSubtask)
                # PlotHovmollerSubtask requires a relative path
                inFileName = outFileName
            else:
                anomalySubtask = None

            for field in fields:
                prefix = field['prefix']
                suffix = prefix[0].upper() + prefix[1:]
                fieldSectionName = 'hovmollerOceanRegions{}'.format(suffix)

                config.set(fieldSectionName, 'movingAverageMonths',
                           '{}'.format(movingAverageMonths))

                for regionName in regionNames:
                    if computeAnomaly:
                        titleName = '{} Anomaly'.format(field['titleName'])
                        caption = 'Anomaly of {} {} vs ' \
                                  'depth'.format(regionName.replace('_', ' '),
                                                 titleName)
                        galleryGroup = '{} Anomaly vs Depths'.format(
                            regionGroup)
                    else:
                        titleName = field['titleName']
                        anomalySubtask = None
                        caption = 'Time series of {} {} vs ' \
                                  'depth'.format(regionName.replace('_', ' '),
                                                 titleName)
                        galleryGroup = '{} Time Series vs Depths'.format(
                            regionGroup)

                    subtaskName = 'plotHovmoller_{}_{}'.format(
                        prefix, regionName.replace(' ', '_'))
                    hovmollerSubtask = PlotHovmollerSubtask(
                        parentTask=self,
                        regionName=regionName,
                        inFileName=inFileName,
                        outFileLabel='{}_hovmoller'.format(prefix),
                        fieldNameInTitle=titleName,
                        mpasFieldName='{}_mean'.format(prefix),
                        unitsLabel=field['units'],
                        sectionName=fieldSectionName,
                        thumbnailSuffix='',
                        imageCaption=caption,
                        galleryGroup=galleryGroup,
                        groupSubtitle=None,
                        groupLink='ocnreghovs_{}'.format(
                            regionGroup.replace(' ', '').lower()),
                        galleryName=titleName,
                        subtaskName=subtaskName,
                        controlConfig=controlConfig,
                        regionMaskFile=masksFile)
                    if computeAnomaly:
                        hovmollerSubtask.run_after(anomalySubtask)
                    else:
                        hovmollerSubtask.run_after(combineSubtask)
                    self.add_subtask(hovmollerSubtask)

        self.run_after(oceanRegionalProfilesTask)