Пример #1
0
    def _add_ref_tasks(self, seasons, comparisonGridNames, hemisphere,
                       hemisphereLong, remapClimatologySubtask, controlConfig,
                       mpasFieldName, fieldName, iselValues):  # {{{

        controlRunName = controlConfig.get('runs', 'mainRunName')
        galleryName = None
        refTitleLabel = 'Control: {}'.format(controlRunName)

        for season in seasons:
            for comparisonGridName in comparisonGridNames:

                imageDescription = \
                    '{} Climatology Map of {}-Hemisphere Sea-Ice ' \
                    'Concentration'.format(season, hemisphereLong)
                imageCaption = imageDescription
                galleryGroup = \
                    '{}-Hemisphere Sea-Ice Concentration'.format(
                        hemisphereLong)
                # make a new subtask for this season and comparison
                # grid
                subtask = PlotClimatologyMapSubtask(
                    self,
                    hemisphere,
                    season,
                    comparisonGridName,
                    remapClimatologySubtask,
                    controlConfig=controlConfig)

                subtask.set_plot_info(
                    outFileLabel='iceconc{}'.format(hemisphere),
                    fieldNameInTitle='Sea ice concentration',
                    mpasFieldName=mpasFieldName,
                    refFieldName=mpasFieldName,
                    refTitleLabel=refTitleLabel,
                    diffTitleLabel='Main - Control',
                    unitsLabel=r'fraction',
                    imageDescription=imageDescription,
                    imageCaption=imageCaption,
                    galleryGroup=galleryGroup,
                    groupSubtitle=None,
                    groupLink='{}_conc'.format(hemisphere.lower()),
                    galleryName=galleryName)

                self.add_subtask(subtask)
    def __init__(self,
                 config,
                 mpasClimatologyTask,
                 hemisphere,
                 controlConfig=None):  # {{{
        """
        Construct the analysis task.

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

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

        hemisphere : {'NH', 'SH'}
            The hemisphere to plot

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

        taskName = 'climatologyMapIcebergConc{}'.format(hemisphere)

        fieldName = 'IcebergConc'

        tags = ['icebergs', 'climatology', 'horizontalMap', fieldName]
        if hemisphere == 'NH':
            tags = tags + ['arctic']
        else:
            tags = tags + ['antarctic']

        # call the constructor from the base class (AnalysisTask)
        super(ClimatologyMapIcebergConc, self).__init__(config=config,
                                                        taskName=taskName,
                                                        componentName='seaIce',
                                                        tags=tags)

        mpasFieldName = 'timeMonthly_avg_bergAreaCell'
        iselValues = None

        sectionName = taskName

        if hemisphere == 'NH':
            hemisphereLong = 'Northern'
        else:
            hemisphereLong = 'Southern'

        # read in what seasons we want to plot
        seasons = config.getExpression(sectionName, 'seasons')

        if len(seasons) == 0:
            raise ValueError('config section {} does not contain valid list '
                             'of seasons'.format(sectionName))

        comparisonGridNames = config.getExpression(sectionName,
                                                   'comparisonGrids')

        if len(comparisonGridNames) == 0:
            raise ValueError('config section {} does not contain valid list '
                             'of comparison grids'.format(sectionName))

        # the variable self.mpasFieldName will be added to mpasClimatologyTask
        # along with the seasons.
        remapClimatologySubtask = RemapMpasClimatologySubtask(
            mpasClimatologyTask=mpasClimatologyTask,
            parentTask=self,
            climatologyName='{}{}'.format(fieldName, hemisphere),
            variableList=[mpasFieldName],
            comparisonGridNames=comparisonGridNames,
            seasons=seasons,
            iselValues=iselValues)

        if controlConfig is None:
            refTitleLabel = 'Observations (Altiberg)'
            galleryName = 'Observations: Altiberg'
            diffTitleLabel = 'Model - Observations'
            refFieldName = 'icebergConc'
            obsFileName = build_obs_path(
                config, 'iceberg',
                'concentrationAltiberg{}'.format(hemisphere))

            remapObservationsSubtask = RemapAltibergConcClimatology(
                parentTask=self,
                seasons=seasons,
                fileName=obsFileName,
                outFilePrefix='{}{}'.format(refFieldName, hemisphere),
                comparisonGridNames=comparisonGridNames)
            self.add_subtask(remapObservationsSubtask)

        else:
            controlRunName = controlConfig.get('runs', 'mainRunName')
            galleryName = None
            refTitleLabel = 'Control: {}'.format(controlRunName)
            refFieldName = mpasFieldName
            diffTitleLabel = 'Main - Control'

            remapObservationsSubtask = None

        for season in seasons:
            for comparisonGridName in comparisonGridNames:

                imageDescription = \
                    '{} Climatology Map of {}-Hemisphere Iceberg ' \
                    'Concentration.'.format(season, hemisphereLong)
                imageCaption = imageDescription
                galleryGroup = \
                    '{}-Hemisphere Iceberg Concentration'.format(
                        hemisphereLong)
                # make a new subtask for this season and comparison grid
                subtask = PlotClimatologyMapSubtask(self, hemisphere, season,
                                                    comparisonGridName,
                                                    remapClimatologySubtask,
                                                    remapObservationsSubtask,
                                                    controlConfig)

                subtask.set_plot_info(
                    outFileLabel='bergconc{}'.format(hemisphere),
                    fieldNameInTitle='Iceberg concentration',
                    mpasFieldName=mpasFieldName,
                    refFieldName=refFieldName,
                    refTitleLabel=refTitleLabel,
                    diffTitleLabel=diffTitleLabel,
                    unitsLabel=r'fraction',
                    imageDescription=imageDescription,
                    imageCaption=imageCaption,
                    galleryGroup=galleryGroup,
                    groupSubtitle=None,
                    groupLink='{}_conc'.format(hemisphere.lower()),
                    galleryName=galleryName,
                    maskValue=None)

                self.add_subtask(subtask)
    def _add_obs_tasks(self, seasons, comparisonGridNames, hemisphere,
                       hemisphereLong, remapClimatologySubtask,
                       mpasFieldName):  # {{{
        config = self.config
        obsFieldName = 'seaIceConc'

        observationPrefixes = config.getExpression(self.taskName,
                                                   'observationPrefixes')
        for prefix in observationPrefixes:
            for season in seasons:
                observationTitleLabel = \
                    'Observations (SSM/I {})'.format(prefix)

                obsFileName = build_config_full_path(
                    config, 'seaIceObservations',
                    'concentration{}{}_{}'.format(prefix, hemisphere, season))

                remapObservationsSubtask = RemapObservedConcClimatology(
                    parentTask=self,
                    seasons=[season],
                    fileName=obsFileName,
                    outFilePrefix='{}{}{}_{}'.format(obsFieldName, prefix,
                                                     hemisphere, season),
                    comparisonGridNames=comparisonGridNames,
                    subtaskName='remapObservations_{}{}'.format(
                        prefix, season))
                self.add_subtask(remapObservationsSubtask)
                for comparisonGridName in comparisonGridNames:

                    imageDescription = \
                        '{} Climatology Map of {}-Hemisphere Sea-Ice ' \
                        'Concentration'.format(season, hemisphereLong)
                    imageCaption = \
                        '{}. <br> Observations: SSM/I {}'.format(
                            imageDescription, prefix)
                    galleryGroup = \
                        '{}-Hemisphere Sea-Ice Concentration'.format(
                                hemisphereLong)
                    # make a new subtask for this season and comparison
                    # grid
                    subtask = PlotClimatologyMapSubtask(
                        self,
                        hemisphere,
                        season,
                        comparisonGridName,
                        remapClimatologySubtask,
                        remapObsClimatologySubtask=remapObservationsSubtask,
                        subtaskSuffix=prefix)

                    subtask.set_plot_info(
                        outFileLabel='iceconc{}{}'.format(prefix, hemisphere),
                        fieldNameInTitle='Sea ice concentration',
                        mpasFieldName=mpasFieldName,
                        refFieldName=obsFieldName,
                        refTitleLabel=observationTitleLabel,
                        diffTitleLabel='Model - Observations',
                        unitsLabel=r'fraction',
                        imageDescription=imageDescription,
                        imageCaption=imageCaption,
                        galleryGroup=galleryGroup,
                        groupSubtitle=None,
                        groupLink='{}_conc'.format(hemisphere.lower()),
                        galleryName='Observations: SSM/I {}'.format(prefix))

                    self.add_subtask(subtask)
    def __init__(self,
                 config,
                 mpasClimatologyTask,
                 hemisphere,
                 refConfig=None):  # {{{
        """
        Construct the analysis task.

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

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

        hemisphere : {'NH', 'SH'}
            The hemisphere to plot

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

        taskName = 'climatologyMapSeaIceThick{}'.format(hemisphere)

        fieldName = 'seaIceThick'
        # call the constructor from the base class (AnalysisTask)
        super(ClimatologyMapSeaIceThick,
              self).__init__(config=config,
                             taskName=taskName,
                             componentName='seaIce',
                             tags=['climatology', 'horizontalMap', fieldName])

        mpasFieldName = 'timeMonthly_avg_iceVolumeCell'
        iselValues = None

        sectionName = taskName

        if hemisphere == 'NH':
            hemisphereLong = 'Northern'
        else:
            hemisphereLong = 'Southern'

        # read in what seasons we want to plot
        seasons = config.getExpression(sectionName, 'seasons')

        if len(seasons) == 0:
            raise ValueError('config section {} does not contain valid list '
                             'of seasons'.format(sectionName))

        comparisonGridNames = config.getExpression(sectionName,
                                                   'comparisonGrids')

        if len(comparisonGridNames) == 0:
            raise ValueError('config section {} does not contain valid list '
                             'of comparison grids'.format(sectionName))

        # the variable self.mpasFieldName will be added to mpasClimatologyTask
        # along with the seasons.
        remapClimatologySubtask = RemapMpasClimatologySubtask(
            mpasClimatologyTask=mpasClimatologyTask,
            parentTask=self,
            climatologyName='{}{}'.format(fieldName, hemisphere),
            variableList=[mpasFieldName],
            comparisonGridNames=comparisonGridNames,
            seasons=seasons,
            iselValues=iselValues)

        if refConfig is None:
            refTitleLabel = 'Observations (ICESat)'
            galleryName = 'Observations: ICESat'
            diffTitleLabel = 'Model - Observations'
            refFieldName = 'seaIceThick'
        else:
            refRunName = refConfig.get('runs', 'mainRunName')
            galleryName = None
            refTitleLabel = 'Ref: {}'.format(refRunName)
            refFieldName = mpasFieldName
            diffTitleLabel = 'Main - Reference'

            remapObservationsSubtask = None

        for season in seasons:
            if refConfig is None:
                obsFileName = build_config_full_path(
                    config, 'seaIceObservations',
                    'thickness{}_{}'.format(hemisphere, season))

                remapObservationsSubtask = RemapObservedThickClimatology(
                    parentTask=self,
                    seasons=[season],
                    fileName=obsFileName,
                    outFilePrefix='{}{}_{}'.format(refFieldName, hemisphere,
                                                   season),
                    comparisonGridNames=comparisonGridNames,
                    subtaskName='remapObservations{}'.format(season))
                self.add_subtask(remapObservationsSubtask)

            for comparisonGridName in comparisonGridNames:

                imageDescription = \
                    '{} Climatology Map of {}-Hemisphere Sea-Ice ' \
                    'Thickness.'.format(season, hemisphereLong)
                imageCaption = imageDescription
                galleryGroup = \
                    '{}-Hemisphere Sea-Ice Thickness'.format(
                            hemisphereLong)
                # make a new subtask for this season and comparison grid
                subtask = PlotClimatologyMapSubtask(self, hemisphere, season,
                                                    comparisonGridName,
                                                    remapClimatologySubtask,
                                                    remapObservationsSubtask,
                                                    refConfig)

                subtask.set_plot_info(
                    outFileLabel='icethick{}'.format(hemisphere),
                    fieldNameInTitle='Sea ice thickness',
                    mpasFieldName=mpasFieldName,
                    refFieldName=refFieldName,
                    refTitleLabel=refTitleLabel,
                    diffTitleLabel=diffTitleLabel,
                    unitsLabel=r'm',
                    imageDescription=imageDescription,
                    imageCaption=imageCaption,
                    galleryGroup=galleryGroup,
                    groupSubtitle=None,
                    groupLink='{}_thick'.format(hemisphere.lower()),
                    galleryName=galleryName,
                    maskValue=0)

                self.add_subtask(subtask)