def run_task(self):  # {{{
        '''
        Compute the requested climatologies
        '''
        # Authors
        # -------
        # Xylar Asay-Davis

        if len(self.variableList.keys()) == 0:
            # nothing to do
            return

        if not self.useNcclimo:
            # subtasks will take care of it, so nothing to do
            return

        self.logger.info('\nComputing MPAS climatologies from files:\n'
                         '    {} through\n    {}'.format(
                             os.path.basename(self.inputFiles[0]),
                             os.path.basename(self.inputFiles[-1])))

        seasonsToCheck = list(constants.abrevMonthNames)

        for season in self.variableList:
            if season not in seasonsToCheck:
                seasonsToCheck.append(season)

        allExist = True
        for season in seasonsToCheck:

            climatologyFileName = self.get_file_name(season)
            climatologyDirectory = get_unmasked_mpas_climatology_directory(
                self.config, self.op)

            if not os.path.exists(climatologyFileName):
                allExist = False
                break

        if allExist:
            for season in seasonsToCheck:
                if season not in self.variableList:
                    continue
                # make sure all the necessary variables are also present
                with xarray.open_dataset(self.get_file_name(season)) as ds:
                    for variableName in self.variableList[season]:
                        if variableName not in ds.variables:
                            allExist = False
                            break

        if not allExist:
            self._compute_climatologies_with_ncclimo(
                inDirectory=self.symlinkDirectory,
                outDirectory=climatologyDirectory)
Beispiel #2
0
    def run_task(self):  # {{{
        '''
        Compute the requested climatologies
        '''
        # Authors
        # -------
        # Xylar Asay-Davis

        if len(self.variableList) == 0:
            # nothing to do
            return

        self.logger.info('\nComputing MPAS climatologies from files:\n'
                         '    {} through\n    {}'.format(
                                 os.path.basename(self.inputFiles[0]),
                                 os.path.basename(self.inputFiles[-1])))

        if self.seasons[0] is 'none':
            seasonsToCheck = ['{:02d}'.format(month) for month in range(1, 13)]
        else:
            seasonsToCheck = self.seasons

        allExist = True
        for season in seasonsToCheck:

            climatologyFileName = self.get_file_name(season)
            climatologyDirectory = get_unmasked_mpas_climatology_directory(
                    self.config)

            if not os.path.exists(climatologyFileName):
                allExist = False
                break

        if allExist:
            # make sure all the necessary variables are also present
            ds = xarray.open_dataset(self.get_file_name(seasonsToCheck[0]))

            for variableName in self.variableList:
                if variableName not in ds.variables:
                    allExist = False
                    break

        if not allExist:
            self._compute_climatologies_with_ncclimo(
                    inDirectory=self.symlinkDirectory,
                    outDirectory=climatologyDirectory)
    def run_task(self):  # {{{
        '''
        Compute the requested climatologies
        '''
        # Authors
        # -------
        # Xylar Asay-Davis

        season = self.season
        parentTask = self.parentTask
        if season not in parentTask.variableList:
            # nothing to do
            return

        variableList = parentTask.variableList[season]

        if len(variableList) == 0:
            # nothing to do
            return

        self.logger.info('\nComputing MPAS climatology from files:\n'
                         '    {} through\n    {}'.format(
                             os.path.basename(parentTask.inputFiles[0]),
                             os.path.basename(parentTask.inputFiles[-1])))

        climatologyFileName = parentTask.get_file_name(season)
        climatologyDirectory = get_unmasked_mpas_climatology_directory(
            self.config)

        allExist = False
        if os.path.exists(climatologyFileName):
            allExist = True
            # make sure all the necessary variables are also present
            with xarray.open_dataset(climatologyFileName) as ds:
                for variableName in variableList:
                    if variableName not in ds.variables:
                        allExist = False
                        break

        if not allExist:
            with dask.config.set(schedular='threads',
                                 pool=ThreadPool(self.daskThreads)):
                self._compute_climatologies_with_xarray(
                    inDirectory=parentTask.symlinkDirectory,
                    outDirectory=climatologyDirectory)