Example #1
0
    def recieve_atmosphere(self):
        """
        Bundles up functionality to recieve a generic atmosphere file 

        Uses one of the following methods to get atmosphere fields into PISM
        compatiable input:
        1. downscale_static
            Downscales atmospheric temperature and precipitation using a lapse
            rate and precipitation reduction factor. See the method
            documentation for ``regrid_downscale`` for more information.
        2. interpolate
            Uses bilinear interpolation provided by CDO to interpolate to the
            PISM grid.
        3. regrid
            Uses conservative remapping to regrid to the PISM grid.
        """
        logging.info("\t\t *   Recieving information from a generic atmosphere model...")
        PISM_ATMO_couple_method = os.environ.get("PISM_ATMO_couple_method", "downscale_static")
        logging.info("\t\t *   Using coupling method: %s", PISM_ATMO_couple_method)
        if PISM_ATMO_couple_method == "downscale_static":
            forcing_file = self.regrid_downscale_static()
        elif PISM_ATMO_couple_method == "interpolate":
            forcing_file = self.regrid_remap()
        elif PISM_ATMO_couple_method == "remap":
            forcing_file = self.regrid_remap()
        self.files['forcing']['atmosphere_given'] = ComponentFile(
                src=forcing_file,
                dest=self.forcing_dir+"/atmo_given_file_"+self.calendar.current_date.format(form=0)+".nc")
        self.files['forcing']['atmosphere_given'].digest()
Example #2
0
 def _describe_grid(self):
     """ Gets the currently appropriate PISM grid in the couple dir """
     self.files["couple"][self.Type+"_grid"] = ComponentFile(src=self.POOL_DIR+"/".join(["", "grids", self.Domain])
                                                             + "/"
                                                             + "_".join([self.EXECUTABLE, self.Domain, self.LateralResolution])
                                                             +".griddes",
                                                             dest=self.couple_dir+"/"+self.TYPE+".griddes")
Example #3
0
    def _generate_ice_forcing_file(self):
        """Makes a forcing file for an ice sheet.

        The following information is included:
        + ...
        """
        logging.info(
            "\t\t Preparing %s file for processing in an ice sheet model...",
            self.NAME)

        start_year = self.calendar.coupling_start_date[self.TYPE].year
        end_year = self.calendar.coupling_end_date[self.TYPE].year

        file_list = self._construct_input_list(start_year, end_year)
        files_with_selected_variables = self._select_relevant_variables(
            file_list)

        final_output = self._concatenate_files(
            files_with_selected_variables,
            start_date=self.calendar.coupling_start_date[self.TYPE])

        if self.ECHAM_TO_ISM_multiyear_mean:
            final_output = self._multiyear_mean(final_output)
        if self.ECHAM_TO_ISM_time_mean:
            final_output = self._time_mean(final_output)

        self.files["couple"]["atmosphere_file_for_ice"] = ComponentFile(
            src=final_output,
            dest=self.couple_dir + "/atmosphere_file_for_ice.nc")
        logging.info("\t\t ...done!")
Example #4
0
 def _define_couple_files(self, other_model_type):
     for other_model_type in self.COMPATIBLE_COUPLE_TYPES:
         other_model_couple_dir = self.couple_attrs[other_model_type]["parent_dir"]+"/couple/"+other_model_type
         self.files["couple"][other_model_type+"_file"] = \
             ComponentFile(src=other_model_couple_dir+"/"+other_model_type+"_file_for_"+self.TYPE+".nc",
                                           dest=self.couple_dir+"/"+"_".join([other_model_type,
                                                                              "file",
                                                                              str(self.calendar.current_date.format(form=0))])+".nc")
             self.files["couple"][other_model_type+"_grid"] = \
                             ComponentFile(src=other_model_couple_dir+"/"+other_model_type+".griddes",
                                           dest=self.couple_dir+"/"+"_".join([other_model_type,
                                                                              "grid",
                                                                              str(self.calendar.current_date.format(form=0))]))
             self.files["couple"][other_model_type+"_vars"] = \
                             ComponentFile(src=other_model_couple_dir+"/"+other_model_type+"_vars.json",
                                           dest=self.couple_dir+"/"+"_".join([other_model_type,
                                                                              "vars",
                                                                              str(self.calendar.current_date.format(form=0))]))
Example #5
0
    def _generate_solid_earth_forcing_file(self):
        """ Generates a solid earth forcing from ice output.

        Some questions that still need to be clarified:
        1. Do we want to send the newest timestep?
        2. What happens if PISM restarts during a few chunks?
        """
        last_timestep_of_extra_file = self.CDO.seltimestep("-1", input=self.files["outdata"]["extra"]._current_location)
        ofile = self.CDO.selvar("thk", input=last_timestep_of_extra_file)
        self.files["couple"][self.Type+"_file"] = ComponentFile(src=ofile, dest=self.couple_dir+"/"+self.Type+"_file_for_solid_earth.nc")
Example #6
0
    def _prepare_files_from_dataset(self):
        """
        Uses the Dataset to populate the appropriate file dictionaries.

        This replaces the normal steps for files_from_forcing_in and
        files_from_input_in.

        For each file type described in the Dataset, the current year is used
        to determine the appropriate file to copy from the pool directory. The
        determination is done via the Dataset's ``find`` method, which returns
        a generator. The generator returns files, which may vary based on the
        scenario selected and the current year of the simulation. These files
        are then added to the file dictionary for each file type, which can
        then be used for copying from the filesystem to the experiment file
        tree.

        Notes
        -----
        The following information needed in this method is determined by
        ``EchamCompute`` attributes:
            + The pool directory is machine dependent, and is retrived from the
              ``machine`` attribute attached to ``EchamCompute``.
            + The current year is determined by ``EchamCompute``'s calendar
              attribute, which has an attribute ``current_date.date``. Entry 0 is the
              year.

        The Dataset currently implements paths for the following filetypes:
        + ``forcing``
        + ``input``

        The restart filetype dictionary is propulated in
        _prepare_files_from_restart_in


        See Also
        --------
            Dataset.find : Yields human readable names and filepaths
                appropriate for the year
        """
        for filetype in self._filetypes:
            if hasattr(self.dataset, filetype+'_in_pool'):
                files_for_this_year = self.dataset.find(
                    filetype=filetype+'_in_pool',
                    year=self.calendar.current_date.year
                    )
                for human_readable_name, current_file in files_for_this_year:
                    self.files[filetype][human_readable_name] = ComponentFile(
                        src=self.pool_dir+current_file,
                        dest=getattr(self, filetype+'_dir')
                        )
Example #7
0
    def _prepare_files_from_restart_in(self):
        """
        Gets the restart files to be used for the experiment that are relevant
        for echam.

        This method gets restart files from either:
        + Somewhere on the filesystem (If you are doing a "cold start",
          restarts are taken from the pool directory, if you are doing a restart
          from a different experiment, restarts are taken from the environmental
          variables INI_RESTART_DIR_echam)
        + The experiments own restart directory

        Notes
        -----
        The following relevant variables can be set in the shell runscript to
        override certain defaults:
        + INI_PARENT_EXP_ID_echam
        + INI_PARENT_DATE_echam
        + INI_RESTART_DIR_echam
        """
        if self.calendar.run_number == 1:
            restart_expid = os.environ.get('INI_PARENT_EXP_ID_echam', 'khw0030')
            restart_date = os.environ.get('INI_PARENT_DATE_echam', '22941231')
            restart_files_directory = os.environ.get(
                'INI_RESTART_DIR_echam',
                self.pool_dir+'/../MPIESM/restart/dev/'+restart_expid+'/restart/echam6'
                )
        else:
            restart_expid = self.expid
            restart_date = self.calendar.previous_date
            restart_files_directory = self.restart_dir

        # Get the restart files
        invalid_streams = ['yasso', 'jsbid', 'jsbach', 'surf', 'nitro', 'veg', 'land']
        all_files_in_restart_dir = os.listdir(restart_files_directory)
        # Use a set to automatically discard duplicates, since we are going
        # over two loops:
        restart_files = set()
        for invalid_stream in invalid_streams:
            for f in all_files_in_restart_dir:
                if invalid_stream in f:
                    continue
                if f.startswith('restart_'+restart_expid) and restart_date in f:
                    restart_files.add(f)
        for f in restart_files:
            self.files['restart'][f] = ComponentFile(
                src=restart_files_directory+'/'+f,
                dest=self.restart_dir
                )
Example #8
0
 def _write_grid_description(self):
     """ Writes echam6 grid descrption to atmosphere.griddes """
     logging.info(
         "\t\t Writing echam6 grid description to generic file atmosphere.griddes..."
     )
     logging.info("\t\t *   generatic griddes")
     griddes = self.CDO.griddes(
         input=self.files["couple"]["atmosphere_file_for_ice"].src)
     ofile = open(self.couple_dir + "/griddes_file", "w")
     ofile.write("\n".join(griddes))
     ofile.flush()
     self.files["couple"]["atmosphere_grid_description"] = ComponentFile(
         src=ofile.name, dest=self.couple_dir + "/atmosphere.griddes")
     self._cleanup_list.append(ofile.name)
     logging.info("\t\t ...done!")
Example #9
0
 def __init__(self, **PismComputeArgs):
     super(PismCouple, self).__init__(**PismComputeArgs)
     self.files['couple']['ice_grid'] = ComponentFile(
         src=self.POOL_DIR + "grids/" + self.Domain + "/pismr_" + self.Domain + "_" + self.LateralResolution + ".griddes",
         dest=self.couple_dir)