Ejemplo n.º 1
0
def calculate(x, mass, mask):
    output = iris.cube.CubeList()
    for cube in x:
        xcoord = grid.extract_dim_coord(cube, 'X')
        ycoord = grid.extract_dim_coord(cube, 'Y')
        zcoord = grid.extract_dim_coord(cube, 'Z')
        cube.data = np.ma.masked_where(mask, cube.data)
        output.append(
            cube.collapsed([xcoord, ycoord, zcoord], MEAN, weights=mass.data))
        output.append(cube.collapsed([xcoord, ycoord, zcoord], STD_DEV))

    return output
Ejemplo n.º 2
0
def main(cubes):
    """Find all points within 1km of the tropopause that have a negative PV
    anomaly
    """
    # Find negative pv anomalies
    diff = convert.calc('total_minus_advection_only_pv', cubes)
    negative_pv = diff.data < -1

    # Find the tropopause height
    ztrop, fold_t, fold_b = tropopause.height(cubes)

    # Find point below the tropopause
    z = diff.coord('altitude').points
    tropopause_relative = np.logical_and(z < ztrop, z > ztrop - 2000)

    # Combine criteria
    criteria = np.logical_and(negative_pv, tropopause_relative)

    # Get indices where criterion is met
    indices = np.where(criteria)

    # Convert to lon, lat, z
    longitude = diff.coord('grid_longitude').points
    lons = np.array([longitude[idx] for idx in indices[2]])
    latitude = diff.coord('grid_latitude').points
    lats = np.array([latitude[idx] for idx in indices[1]])
    height = grid.extract_dim_coord(diff, 'z').points
    altitude = np.array([height[idx] for idx in indices[0]])

    # Scatterplot the locations
    fig = plt.figure()
    ax = fig.add_subplot(111, projection='3d')
    ax.scatter(lons, lats, altitude)
    plt.show()
Ejemplo n.º 3
0
def make_plot(cubes, name, mass, mask, **kwargs):
    pv = convert.calc(name, cubes)
    pv.data = np.ma.masked_where(mask, pv.data)

    z = grid.extract_dim_coord(pv, 'z')
    pv_ave = pv.collapsed(z.name(), MEAN, weights=mass.data)

    im = iplt.pcolormesh(pv_ave, **kwargs)
    add_map()

    return im
Ejemplo n.º 4
0
def redo_cubes(cubes, basis_cube, stash_maps=[], slices=None, time=None):
    # Coordinates to copy to analyses
    z = grid.extract_dim_coord(basis_cube, 'z')

    # Define attributes of custom variables by stash mapping
    for stash_map in stash_maps:
        stash_map.remap_cubelist(cubes)

    newcubelist = CubeList()
    for cube in cubes:
        print(cube)
        newcube = cube.copy()
        # Remove unneccessary time coordinates
        for coord in ['forecast_period', 'forecast_reference_time']:
            try:
                newcube.remove_coord(coord)
            except iris.exceptions.CoordinateNotFoundError:
                pass

        if newcube.ndim == 3:
            # Use the hybrid height coordinate as the main vertical coordinate
            try:
                newcube.remove_coord('model_level_number')
            except iris.exceptions.CoordinateNotFoundError:
                pass
            newcube.coord('level_height').rename(z.name())
            iris.util.promote_aux_coord_to_dim_coord(newcube, z.name())

            # Remap the cubes to theta points
            newcube = interpolate.remap_3d(newcube, basis_cube, z.name())

        else:
            # Regrid in the horizontal
            newcube = newcube.regrid(basis_cube, Linear())

        # Convert the main time coordinate
        if time is not None:
            newcube.coord('time').convert_units(time)

        newcubelist.append(newcube)

    return newcubelist
Ejemplo n.º 5
0
"""

import datetime
import iris
from iris.cube import CubeList
from iris.util import squeeze
from irise import constants, grid
from myscripts import datadir
from myscripts import files

# Define which area of grid to subset
slices = slice(0, 50), slice(15, -15), slice(15, -15)

# Load basis cube
basis_cube = iris.load_cube(datadir + 'xjjhl/basis_cube.nc', 'air_temperature')
lat = grid.extract_dim_coord(basis_cube, 'y')
lon = grid.extract_dim_coord(basis_cube, 'x')

raw_cubes = iris.load(datadir + 'xjjhl/xjjhl.astart')

# Define how to rename variables
name_pairs = [('u', 'x_wind'), ('v', 'y_wind'),
              ('dz_dt', 'upward_air_velocity'),
              ('theta', 'air_potential_temperature'),
              ('unspecified', 'air_density'),
              ('field7', 'dimensionless_exner_function'),
              ('q', 'specific_humidity'),
              ('QCL', 'mass_fraction_of_cloud_liquid_water_in_air'),
              ('QCF', 'mass_fraction_of_cloud_ice_in_air')]

# Correct units for some cubes