Beispiel #1
0
    def test_temperature_to_virtual_temperature(self):
        """Ensures correct output from temperature_to_virtual_temperature."""

        these_virtual_temps_kelvins = (
            moisture_conversions.temperature_to_virtual_temperature(
                temperatures_kelvins=TEMPERATURES_KELVINS,
                total_pressures_pascals=TOTAL_PRESSURES_PASCALS,
                vapour_pressures_pascals=VAPOUR_PRESSURES_PASCALS))
        self.assertTrue(
            numpy.allclose(these_virtual_temps_kelvins,
                           VIRTUAL_TEMPERATURES_KELVINS,
                           atol=TOLERANCE))
Beispiel #2
0
def _get_air_density(example_dict):
    """Computes profiles of air density.

    E = number of examples
    H = number of heights

    :param example_dict: Dictionary of examples (in the format returned by
        `read_file`).
    :return: air_density_matrix_kg_m03: E-by-H numpy array of densities
        (kg m^-3).
    """

    specific_humidity_matrix_kg_kg01 = example_utils.get_field_from_dict(
        example_dict=example_dict,
        field_name=example_utils.SPECIFIC_HUMIDITY_NAME)
    temperature_matrix_kelvins = example_utils.get_field_from_dict(
        example_dict=example_dict, field_name=example_utils.TEMPERATURE_NAME)
    pressure_matrix_pascals = example_utils.get_field_from_dict(
        example_dict=example_dict, field_name=example_utils.PRESSURE_NAME)

    mixing_ratio_matrix_kg_kg01 = (
        moisture_conv.specific_humidity_to_mixing_ratio(
            specific_humidity_matrix_kg_kg01))
    vapour_pressure_matrix_pascals = (
        moisture_conv.mixing_ratio_to_vapour_pressure(
            mixing_ratios_kg_kg01=mixing_ratio_matrix_kg_kg01,
            total_pressures_pascals=pressure_matrix_pascals))
    virtual_temp_matrix_kelvins = (
        moisture_conv.temperature_to_virtual_temperature(
            temperatures_kelvins=temperature_matrix_kelvins,
            total_pressures_pascals=pressure_matrix_pascals,
            vapour_pressures_pascals=vapour_pressure_matrix_pascals))

    denominator_matrix = (moisture_conv.DRY_AIR_GAS_CONSTANT_J_KG01_K01 *
                          virtual_temp_matrix_kelvins)
    return pressure_matrix_pascals / denominator_matrix
    soundings.FIELD_NAMES_KEY: NEW_FIELD_NAMES
}

SOUNDING_DICT_P_COORDS_NO_THETA_V = {
    soundings.SOUNDING_MATRIX_KEY: THIS_SOUNDING_MATRIX,
    soundings.FIELD_NAMES_KEY: NEW_FIELD_NAMES
}

# The following constants are used to test _get_virtual_potential_temperatures.
THESE_VAPOUR_PRESSURES_PASCALS = (
    moisture_conversions.dewpoint_to_vapour_pressure(THESE_DEWPOINTS_KELVINS)
)

THESE_VIRTUAL_TEMPS_KELVINS = (
    moisture_conversions.temperature_to_virtual_temperature(
        temperatures_kelvins=THESE_TEMPERATURES_KELVINS,
        total_pressures_pascals=THESE_PRESSURES_PASCALS,
        vapour_pressures_pascals=THESE_VAPOUR_PRESSURES_PASCALS)
)

THESE_THETA_V_KELVINS = (
    temperature_conversions.temperatures_to_potential_temperatures(
        temperatures_kelvins=THESE_VIRTUAL_TEMPS_KELVINS,
        total_pressures_pascals=THESE_PRESSURES_PASCALS)
)

THIS_NEW_MATRIX = numpy.reshape(THESE_THETA_V_KELVINS, (1, 5, 1))
THIS_SOUNDING_MATRIX = numpy.concatenate(
    (THIS_SOUNDING_MATRIX, THIS_NEW_MATRIX), axis=-1
)

NEW_FIELD_NAMES = THESE_FIELD_NAMES + [