Exemplo n.º 1
0
    def SunPhotometerDistribution(cls, r, dvdlogr, refr_real, refr_imag):
        """Set 6S to use an aerosol parameterisation from Sun Photometer measurements.

        Wavelength dependent values must be input at the following wavelengths (given in micrometers):
        0.350, 0.400, 0.412, 0.443, 0.470, 0.488, 0.515, 0.550, 0.590, 0.633, 0.670, 0.694, 0.760,
        0.860, 1.240, 1.536, 1.650, 1.950, 2.250, 3.750

        Arguments:

        * ``r`` -- A list of radius measurements from a sun photometer (microns)
        * ``dvdlogr`` -- A list of dV/d(logr) measurements from a sun photometer, for the radiuses as above (cm^3/cm^2/micron)
        * ``refr_real`` -- The real part of the refractive indices for each of the 20 wavelengths (above)
        * ``refr_imag`` -- The imaginary part of the refractive indices for each of the 20 wavelengths (above)

        """
        header = "11 (Sun Photometric Distribution)\n"

        # Check lengths of r and dvdlorg are the same
        if len(r) != len(dvdlogr):
            raise ParameterError("R and dV/d(log r)",
                                 "These must be the same length")

        num = "%d\n" % len(r)

        ds = ""
        comp = ""

        for i in range(len(r)):
            ds += "%f %f\n" % (r[i], dvdlogr[i])

        try:
            if len(refr_real) != 20:
                raise ParameterError(
                    "Aerosol Distribution Real Refractive Index",
                    "You must specify the real part of the Refractive Index at 20 wavelengths."
                )
        except TypeError:
            raise ParameterError(
                "Aerosol Distribution Imaginary Refractive Index",
                "You must specify the imaginary part of the Refractive Index at 20 wavelengths."
            )

        try:
            if len(refr_imag) != 20:
                raise ParameterError(
                    "Aerosol Distribution Imaginary Refractive Index",
                    "You must specify the imaginary part of the Refractive Index at 20 wavelengths."
                )
        except TypeError:
            raise ParameterError(
                "Aerosol Distribution Imaginary Refractive Index",
                "You must specify the imaginary part of the Refractive Index at 20 wavelengths."
            )

        real = map(str, refr_real)
        imag = map(str, refr_imag)
        comp += ' '.join(real) + '\n'
        comp += ' '.join(imag) + '\n'

        return header + num + ds + comp + "0 no results saved"
Exemplo n.º 2
0
        def add_component(self, rmean, sigma, percentage_density, refr_real,
                          refr_imag):
            """Adds a component to the aerosol distribution.

            Wavelength dependent values must be input at the following wavelengths (given in micrometers):
            0.350, 0.400, 0.412, 0.443, 0.470, 0.488, 0.515, 0.550, 0.590, 0.633, 0.670, 0.694, 0.760,
            0.860, 1.240, 1.536, 1.650, 1.950, 2.250, 3.750


            Arguments:

            * ``rmean`` -- The mean radius of the aerosols
            * ``sigma`` -- Sigma, as defined by the distribution (Log Normal etc)
            * ``percentage_density`` -- The percentage density of the aerosol
            * ``refr_real`` -- A 20-element iterable giving the real part of the refractive indices at the specified wavelengths (see above)
            * ``refr_imag`` -- A 20-element iterable giving the imaginary part of the refractive indices at the specified wavelengths (see above)

            """
            if len(self.values) >= 4:
                raise ParameterError(
                    "Aerosol Distribution components",
                    "You can only add a maximum of 4 components",
                )

            if len(refr_real) != 20:
                raise ParameterError(
                    "Aerosol Distribution Real Refractive Index",
                    "You must specify the real part of the Refractive Index at 20 wavelengths.",
                )

            if len(refr_imag) != 20:
                raise ParameterError(
                    "Aerosol Distribution Imaginary Refractive Index",
                    "You must specify the imaginary part of the Refractive Index at 20 wavelengths.",
                )

            comp = "%f %f %f\n" % (rmean, sigma, percentage_density)
            real = map(str, refr_real)
            imag = map(str, refr_imag)

            if sys.version_info[0] >= 3:
                real = list(real)
                imag = list(imag)

            comp += " ".join(real) + "\n"
            comp += " ".join(imag) + "\n"

            self.values.append(comp)
Exemplo n.º 3
0
    def User(cls, **kwargs):
        """Set 6S to use a user-defined aerosol profile based on proportions of standard aerosol components.

        The profile is set as a mixture of pre-defined components, each given as an optional keyword.
        Not all keywords need to be given, but the values for the keywords given must sum to 1, or a
        ParameterError will be raised.

        Optional keywords:

        * ``dust`` -- The proportion of dust-like aerosols
        * ``water`` -- The proportion of water-like aerosols
        * ``oceanic`` -- The proportion of oceanic aerosols
        * ``soot`` -- The proportion of soot-like aerosols

        Example usage::

          s.aero_profile = AeroProfile.User(dust=0.3, oceanic=0.7)
          s.aero_profile = AeroProfile.User(soot = 0.1, water = 0.3, oceanic = 0.05, dust = 0.55)

        """
        d = defaultdict(lambda: 0, kwargs)

        dust = d["dust"]
        water = d["water"]
        oceanic = d["oceanic"]
        soot = d["soot"]

        if ((dust + water + oceanic + soot) - 1) > 0.01:
            raise ParameterError("Aerosol Profile",
                                 "User aerosol components don't sum to 1.0")

        return "4 (User's Components)\n%f, %f, %f, %f" % (dust, water, oceanic,
                                                          soot)
Exemplo n.º 4
0
    def RadiosondeProfile(cls, data):
        """Set 6S to use an atmosphere defined by a profile from a radiosonde measurements.

        Arguments:

        * ``data`` -- A dictionary containing five iterables (eg. lists) with the radiosonde measurements in them. The dictionary must have the following keys:
            * ``altitude`` -- in km
            * ``pressure`` -- in mb
            * ``temperature`` -- in k
            * ``water`` -- in g/m^3
            * ``ozone`` -- in g/m^3

        There must be 34 items in each iterable, or a :class:`ParameterExeception` will be thrown.

        """

        # Check to make sure all iterables have 34 items
        all_lists = [data['altitude'], data['pressure'], data['temperature'], data['water'], data['ozone']]
        if not all(len(x) == 34 for x in all_lists):
            raise ParameterError("radiosonde levels", "There must be 34 values in the lists for each radiosonde attribute (altitude, pressure, temperature, water, ozone)")

        result = ""

        for i in range(34):
            result = result + "%f %f %f %f %f\n" % (data['altitude'][i], data['pressure'][i], data['temperature'][i], data['water'][i], data['ozone'][i])

        return "7 User's data base profile\n" + result