コード例 #1
0
def _vertical_rules(cube, pp):
    """
    Rules for setting vertical levels for the PP field.

    Args:
        cube: the cube being saved as a series of PP fields.
        pp: the current PP field having save rules applied.

    Returns:
        The PP field with updated metadata.

    """
    # Define commonly-used coords.
    air_pres_coord = scalar_coord(cube, 'air_pressure')
    apt_coord = scalar_coord(cube, 'air_potential_temperature')
    depth_coord = scalar_coord(cube, 'depth')
    height_coord = scalar_coord(cube, 'height')
    level_height_coord = scalar_coord(cube, 'level_height')
    mln_coord = scalar_coord(cube, 'model_level_number')
    pressure_coord = scalar_coord(cube, 'pressure')
    pseudo_level_coord = scalar_coord(cube, 'pseudo_level')
    sigma_coord = scalar_coord(cube, 'sigma')
    soil_mln_coord = scalar_coord(cube, 'soil_model_level_number')

    # Define commonly-used aux factories.
    try:
        height_factory = aux_factory(cube, HybridHeightFactory)
    except ValueError:
        height_factory = None
    try:
        pressure_factory = aux_factory(cube, HybridPressureFactory)
    except ValueError:
        pressure_factory = None

    # Set `lbuser[5]`.
    if (pseudo_level_coord is not None and not pseudo_level_coord.bounds):
        pp.lbuser[4] = pseudo_level_coord.points[0]

    # Single height level.
    if (height_coord is not None and not height_coord.bounds
            and height_coord.points[0] == 1.5
            and cube.name() == 'air_temperature'):
        pp.lbvc = 129
        pp.blev = -1

    if pp.lbvc == 0 and height_coord is not None and not height_coord.bounds:
        pp.lbvc = 1
        pp.blev = cube.coord('height').points[0]

    # Single air_pressure level.
    if air_pres_coord is not None and not air_pres_coord.bounds:
        pp.lbvc = 8
        pp.blev = air_pres_coord.points[0]

    # Single pressure level.
    if pressure_coord is not None and not pressure_coord.bounds:
        pp.lbvc = 8
        pp.blev = pressure_coord.points[0]

    # Single depth level (non cross-section).
    if (mln_coord is not None and not mln_coord.bounds
            and depth_coord is not None and not depth_coord.bounds):
        pp.lbvc = 2
        pp.lblev = mln_coord.points[0]
        pp.blev = depth_coord.points[0]

    # Single depth level (Non-dimensional soil model level).
    if (soil_mln_coord is not None and not soil_mln_coord.has_bounds()
            and air_pres_coord is None and depth_coord is None
            and height_coord is None and pressure_coord is None
            and cube.standard_name is not None
            and 'soil' in cube.standard_name):
        pp.lbvc = 6
        pp.lblev = soil_mln_coord.points[0]
        pp.blev = pp.lblev
        pp.brsvd[0] = 0
        pp.brlev = 0

    # Single depth level (soil depth).
    if (depth_coord is not None and depth_coord.has_bounds()
            and air_pres_coord is None and soil_mln_coord is None
            and mln_coord is None and height_coord is None
            and pressure_coord is None and cube.standard_name is not None
            and 'soil' in cube.standard_name):
        pp.lbvc = 6
        pp.blev = depth_coord.points[0]
        pp.brsvd[0] = depth_coord.bounds[0, 0]
        pp.brlev = depth_coord.bounds[0, 1]

    # Single potential-temperature level.
    if (apt_coord is not None and not apt_coord.bounds
            and air_pres_coord is None and depth_coord is None
            and height_coord is None and pressure_coord is None
            and mln_coord is None):
        pp.lbvc = 19
        pp.lblev = apt_coord.points[0]
        pp.blev = apt_coord.points[0]

    # Single hybrid_height level
    # (without aux factory e.g. due to missing orography).
    if (not has_aux_factory(cube, HybridHeightFactory)
            and mln_coord is not None and mln_coord.bounds is None
            and level_height_coord is not None
            and level_height_coord.bounds is not None
            and sigma_coord is not None and sigma_coord.bounds is not None):
        pp.lbvc = 65
        pp.lblev = mln_coord.points[0]
        pp.blev = level_height_coord.points[0]
        pp.brlev = level_height_coord.bounds[0, 0]
        pp.brsvd[0] = level_height_coord.bounds[0, 1]
        pp.bhlev = sigma_coord.points[0]
        pp.bhrlev = sigma_coord.bounds[0, 0]
        pp.brsvd[1] = sigma_coord.bounds[0, 1]

    # Single hybrid_height level (with aux factory).
    if (has_aux_factory(cube, HybridHeightFactory) and mln_coord is not None
            and mln_coord.bounds is None
            and height_factory.dependencies['delta'] is not None
            and height_factory.dependencies['delta'].bounds is not None
            and height_factory.dependencies['sigma'] is not None
            and height_factory.dependencies['sigma'].bounds is not None):
        pp.lbvc = 65
        pp.lblev = mln_coord.points[0]
        pp.blev = height_factory.dependencies['delta'].points[0]
        pp.brlev = height_factory.dependencies['delta'].bounds[0, 0]
        pp.brsvd[0] = height_factory.dependencies['delta'].bounds[0, 1]
        pp.bhlev = height_factory.dependencies['sigma'].points[0]
        pp.bhrlev = height_factory.dependencies['sigma'].bounds[0, 0]
        pp.brsvd[1] = height_factory.dependencies['sigma'].bounds[0, 1]

    # Single hybrid pressure level.
    if (has_aux_factory(cube, HybridPressureFactory) and mln_coord is not None
            and mln_coord.bounds is None
            and pressure_factory.dependencies['delta'] is not None
            and pressure_factory.dependencies['delta'].bounds is not None
            and pressure_factory.dependencies['sigma'] is not None
            and pressure_factory.dependencies['sigma'].bounds is not None):
        pp.lbvc = 9
        pp.lblev = mln_coord.points[0]
        pp.blev = pressure_factory.dependencies['sigma'].points[0]
        pp.brlev = pressure_factory.dependencies['sigma'].bounds[0, 0]
        pp.brsvd[0] = pressure_factory.dependencies['sigma'].bounds[0, 1]
        pp.bhlev = pressure_factory.dependencies['delta'].points[0]
        pp.bhrlev = pressure_factory.dependencies['delta'].bounds[0, 0]
        pp.brsvd[1] = pressure_factory.dependencies['delta'].bounds[0, 1]

    return pp
コード例 #2
0
ファイル: pp_save_rules.py プロジェクト: SciTools/iris
def _vertical_rules(cube, pp):
    """
    Rules for setting vertical levels for the PP field.

    Args:
        cube: the cube being saved as a series of PP fields.
        pp: the current PP field having save rules applied.

    Returns:
        The PP field with updated metadata.

    """
    # Define commonly-used coords.
    air_pres_coord = scalar_coord(cube, 'air_pressure')
    apt_coord = scalar_coord(cube, 'air_potential_temperature')
    depth_coord = scalar_coord(cube, 'depth')
    height_coord = scalar_coord(cube, 'height')
    level_height_coord = scalar_coord(cube, 'level_height')
    mln_coord = scalar_coord(cube, 'model_level_number')
    pressure_coord = scalar_coord(cube, 'pressure')
    pseudo_level_coord = scalar_coord(cube, 'pseudo_level')
    sigma_coord = scalar_coord(cube, 'sigma')
    soil_mln_coord = scalar_coord(cube, 'soil_model_level_number')

    # Define commonly-used aux factories.
    try:
        height_factory = aux_factory(cube, HybridHeightFactory)
    except ValueError:
        height_factory = None
    try:
        pressure_factory = aux_factory(cube, HybridPressureFactory)
    except ValueError:
        pressure_factory = None

    # Set `lbuser[5]`.
    if (pseudo_level_coord is not None and
            not pseudo_level_coord.bounds):
        pp.lbuser[4] = pseudo_level_coord.points[0]

    # Single height level.
    if (height_coord is not None and
            not height_coord.bounds and
            height_coord.points[0] == 1.5 and
            cube.name() == 'air_temperature'):
        pp.lbvc = 129
        pp.blev = -1

    if pp.lbvc == 0 and height_coord is not None and not height_coord.bounds:
        pp.lbvc = 1
        pp.blev = cube.coord('height').points[0]

    # Single air_pressure level.
    if air_pres_coord is not None and not air_pres_coord.bounds:
        pp.lbvc = 8
        pp.blev = air_pres_coord.points[0]

    # Single pressure level.
    if pressure_coord is not None and not pressure_coord.bounds:
        pp.lbvc = 8
        pp.blev = pressure_coord.points[0]

    # Single depth level (non cross-section).
    if (mln_coord is not None and
            not mln_coord.bounds and
            depth_coord is not None and
            not depth_coord.bounds):
        pp.lbvc = 2
        pp.lblev = mln_coord.points[0]
        pp.blev = depth_coord.points[0]

    # Single depth level (Non-dimensional soil model level).
    if (soil_mln_coord is not None and
            not soil_mln_coord.has_bounds() and
            air_pres_coord is None and
            depth_coord is None and
            height_coord is None and
            pressure_coord is None and
            cube.standard_name is not None and
            'soil' in cube.standard_name):
        pp.lbvc = 6
        pp.lblev = soil_mln_coord.points[0]
        pp.blev = pp.lblev
        pp.brsvd[0] = 0
        pp.brlev = 0

    # Single depth level (soil depth).
    if (depth_coord is not None and
            depth_coord.has_bounds() and
            air_pres_coord is None and
            soil_mln_coord is None and
            mln_coord is None and
            height_coord is None and
            pressure_coord is None and
            cube.standard_name is not None and
            'soil' in cube.standard_name):
        pp.lbvc = 6
        pp.blev = depth_coord.points[0]
        pp.brsvd[0] = depth_coord.bounds[0, 0]
        pp.brlev = depth_coord.bounds[0, 1]

    # Single potential-temperature level.
    if (apt_coord is not None and
            not apt_coord.bounds and
            air_pres_coord is None and
            depth_coord is None and
            height_coord is None and
            pressure_coord is None and
            mln_coord is None):
        pp.lbvc = 19
        pp.lblev = apt_coord.points[0]
        pp.blev = apt_coord.points[0]

    # Single hybrid_height level
    # (without aux factory e.g. due to missing orography).
    if (not has_aux_factory(cube, HybridHeightFactory) and
            mln_coord is not None and
            mln_coord.bounds is None and
            level_height_coord is not None and
            level_height_coord.bounds is not None and
            sigma_coord is not None and
            sigma_coord.bounds is not None):
        pp.lbvc = 65
        pp.lblev = mln_coord.points[0]
        pp.blev = level_height_coord.points[0]
        pp.brlev = level_height_coord.bounds[0, 0]
        pp.brsvd[0] = level_height_coord.bounds[0, 1]
        pp.bhlev = sigma_coord.points[0]
        pp.bhrlev = sigma_coord.bounds[0, 0]
        pp.brsvd[1] = sigma_coord.bounds[0, 1]

    # Single hybrid_height level (with aux factory).
    if (has_aux_factory(cube, HybridHeightFactory) and
            mln_coord is not None and
            mln_coord.bounds is None and
            height_factory.dependencies['delta'] is not None and
            height_factory.dependencies['delta'].bounds is not None and
            height_factory.dependencies['sigma'] is not None and
            height_factory.dependencies['sigma'].bounds is not None):
        pp.lbvc = 65
        pp.lblev = mln_coord.points[0]
        pp.blev = height_factory.dependencies['delta'].points[0]
        pp.brlev = height_factory.dependencies['delta'].bounds[0, 0]
        pp.brsvd[0] = height_factory.dependencies['delta'].bounds[0, 1]
        pp.bhlev = height_factory.dependencies['sigma'].points[0]
        pp.bhrlev = height_factory.dependencies['sigma'].bounds[0, 0]
        pp.brsvd[1] = height_factory.dependencies['sigma'].bounds[0, 1]

    # Single hybrid pressure level.
    if (has_aux_factory(cube, HybridPressureFactory) and
            mln_coord is not None and
            mln_coord.bounds is None and
            pressure_factory.dependencies['delta'] is not None and
            pressure_factory.dependencies['delta'].bounds is not None and
            pressure_factory.dependencies['sigma'] is not None and
            pressure_factory.dependencies['sigma'].bounds is not None):
        pp.lbvc = 9
        pp.lblev = mln_coord.points[0]
        pp.blev = pressure_factory.dependencies['sigma'].points[0]
        pp.brlev = pressure_factory.dependencies['sigma'].bounds[0, 0]
        pp.brsvd[0] = pressure_factory.dependencies['sigma'].bounds[0, 1]
        pp.bhlev = pressure_factory.dependencies['delta'].points[0]
        pp.bhrlev = pressure_factory.dependencies['delta'].bounds[0, 0]
        pp.brsvd[1] = pressure_factory.dependencies['delta'].bounds[0, 1]

    return pp