コード例 #1
0
    def __init__(self, phlev):
        """Initialise atmosphere component.

        Parameters:
            phlev (``np.ndarray``): Atmospheric pressure at half-levels
              (surface to top) [Pa].
        """
        super().__init__()

        if not utils.is_decreasing(phlev):
            raise ValueError(
                "The atmospheric pressure grid has to be monotonically decreasing."
            )

        plev = utils.plev_from_phlev(phlev)

        self.coords = {
            "time": np.array([]),  # time dimension
            "plev": plev,  # pressure at full-levels
            "phlev": phlev,  # pressure at half-levels
        }

        for varname in self.atmosphere_variables:
            self.create_variable(varname, np.zeros_like(plev))

        # TODO: Combine with ``tracegases_rcemip``?
        self.create_variable(
            name="T",
            data=utils.standard_atmosphere(plev, coordinates="pressure"),
        )
        self.update_height()

        self.tracegases_rcemip()
コード例 #2
0
    def __init__(self, phlev):
        """Initialise atmosphere component.

        Parameters:
            phlev (``np.ndarray``): Atmospheric pressure at half-levels
              (surface to top) [Pa].
        """
        super().__init__()
        plev = utils.plev_from_phlev(phlev)

        self.coords = {
            'time': np.array([]),  # time dimension
            'plev': plev,  # pressure at full-levels
            'phlev': phlev,  # pressure at half-levels
        }

        for varname in self.atmosphere_variables:
            self.create_variable(varname, np.zeros_like(plev))

        # TODO: Combine with ``tracegases_rcemip``?
        self.create_variable(
            name='T',
            data=utils.standard_atmosphere(plev, coordinates='pressure'),
        )
        self.update_height()

        self.tracegases_rcemip()
コード例 #3
0
    def refine_plev(self, phlev, **kwargs):
        """Refine the pressure grid of an atmosphere object.

        Note:
              This method returns a **new** object,
              the original object is maintained!

        Parameters:
            phlev (ndarray): New half-level-pressure grid [Pa].
            **kwargs: Additional keyword arguments are collected
                and passed to :func:`scipy.interpolate.interp1d`

        Returns:
              Atmosphere: A **new** atmosphere object.
        """
        # Initialize an empty directory to fill it with interpolated data.
        # The dictionary is later used to create a new object using the
        # Atmosphere.from_dict() classmethod. This allows to circumvent the
        # fixed dimension size in xarray.DataArrays.
        datadict = dict()

        # Store new pressure grid.
        datadict["phlev"] = phlev
        plev = utils.plev_from_phlev(phlev)

        # Loop over all atmospheric variables...
        for variable in self.atmosphere_variables:
            # and create an interpolation function using the original data.
            f = interp1d(
                self["plev"],
                self[variable],
                axis=-1,
                fill_value="extrapolate",
                **kwargs,
            )

            # Store the interpolated new data in the data directory.
            datadict[variable] = f(plev).ravel()

        # Create a new atmosphere object from the filled data directory.
        new_atmosphere = type(self).from_dict(datadict)

        # Keep attributes of original atmosphere object.
        # This is **extremely** important because references to e.g. the
        # convection scheme or the humidity handling are stored as attributes!
        new_atmosphere.attrs.update({**self.attrs})

        # Calculate the geopotential height.
        new_atmosphere.update_height()

        return new_atmosphere