Ejemplo n.º 1
0
def acquire_sounding_wind_data(date, station):
    """
    Get sounding data using siphon, extract necessary variables and return a
    dictionary with heigth and wind data for pyart FourDD algorithm.

    Parameters
    ----------
    date: date of the sounding (datetime.datetime)
    station: name of the METAR sounding station

    Returns
    -------
    d: "dictionary" of sounding wind data
    """

    sounding = WyomingUpperAir.request_data(date, station)
    sounding = sounding.dropna(subset=('height', 'speed', 'direction',
                                       'u_wind', 'v_wind'),
                               how='all')

    height = sounding['height'].values
    speed = sounding['speed'].values
    direction = sounding['direction'].values
    lat = sounding['latitude'].values
    lon = sounding['longitude'].values

    profile = HorizontalWindProfile(height,
                                    speed,
                                    direction,
                                    latitude=lat,
                                    longitude=lon)

    return profile
Ejemplo n.º 2
0
def test_horizontalwindprofile_from_u_and_v():
    height = np.arange(5)
    u_wind = [0, -1, 0, 1, -np.sqrt(2)/2.]
    v_wind = [-1, 0, 1, 0, -np.sqrt(2)/2.]
    hprofile = HorizontalWindProfile.from_u_and_v(height, u_wind, v_wind)

    assert_almost_equal(hprofile.height, [0, 1, 2, 3, 4])
    assert_almost_equal(hprofile.speed, [1, 1, 1, 1, 1])
    assert_almost_equal(hprofile.direction, [0, 90, 180, 270, 45])
    assert_almost_equal(hprofile.u_wind, [0, -1, 0, 1, -0.707], 3)
    assert_almost_equal(hprofile.v_wind, [-1, 0, 1, 0, -0.707], 3)
Ejemplo n.º 3
0
def test_horizontalwindprofile_class():
    height = np.arange(5)
    speed = np.ones(5)
    direction = np.array([0, 90, 180, 270, 45])
    hprofile = HorizontalWindProfile(height, speed, direction)

    assert_almost_equal(hprofile.height, [0, 1, 2, 3, 4])
    assert_almost_equal(hprofile.speed, [1, 1, 1, 1, 1])
    assert_almost_equal(hprofile.direction, [0, 90, 180, 270, 45])
    assert_almost_equal(hprofile.u_wind, [0, -1, 0, 1, -0.707], 3)
    assert_almost_equal(hprofile.v_wind, [-1, 0, 1, 0, -0.707], 3)
Ejemplo n.º 4
0
def velocity_azimuth_display(radar,
                             velocity,
                             z_want=None,
                             valid_ray_min=16,
                             gatefilter=None,
                             window=2,
                             weight='equal'):
    """
    Velocity azimuth display.

    Note: This code uses only one sweep. Before using the
    velocity_azimuth_display function, use, for example:
    one_sweep_radar = radar.extract_sweeps([0])

    Parameters
    ----------
    radar : Radar
        Radar object used.
    velocity : string
        Velocity field to use for VAD calculation.

    Other Parameters
    ----------------
    z_want : array
        Array of desired heights to be sampled for the vad
        calculation.
    valid_ray_min : int
        Amount of rays required to include that level in
        the VAD calculation.
    gatefilter : GateFilter
        A GateFilter indicating radar gates that should be excluded when
        from the import vad calculation.
    window : int
        Value to use for window when determing new values in the
        _Averag1D function.
    weight : string
        A string to indicate weighting method to use. 'equal' for
        equal weighting when interpolating or 'idw' for inverse
        distribution squared weighting for interpolating.
        Default is 'equal'.

    Returns
    -------
    height : array
        Heights in meters above sea level at which horizontal winds were
        sampled.
    speed : array
        Horizontal wind speed in meters per second at each height.
    direction : array
        Horizontal wind direction in degrees at each height.
    u_wind : array
        U-wind mean in meters per second.
    v_wind : array
        V-wind mean in meters per second.

    Reference
    ----------
    K. A. Browning and R. Wexler, 1968: The Determination
    of Kinematic Properties of a Wind Field Using Doppler
    Radar. J. Appl. Meteor., 7, 105–113

    """

    velocities = radar.fields[velocity]['data']
    if gatefilter is not None:
        velocities = np.ma.masked_where(gatefilter.gate_excluded, velocities)
    azimuths = radar.azimuth['data'][:]
    elevation = radar.fixed_angle['data'][0]

    u_wind, v_wind = _vad_calculation(velocities, azimuths, elevation,
                                      valid_ray_min)
    bad = np.logical_or(np.isnan(u_wind), np.isnan(v_wind))
    good_u_wind = u_wind[~bad]
    good_v_wind = v_wind[~bad]

    radar_height = radar.gate_z['data'][0]
    good_height = radar_height[~bad]
    if z_want is None:
        z_want = np.linspace(0, 1000, 100)[:50]
    else:
        z_want
    try:
        print('max height', np.max(good_height), ' meters')
        print('min height', np.min(good_height), ' meters')
    except ValueError:
        raise ValueError('Not enough data in this radar sweep ' \
                         'for a vad calculation.')

    u_interp = _Average1D(good_height, good_u_wind,
                          z_want[1] - z_want[0] / window, weight)
    v_interp = _Average1D(good_height, good_v_wind,
                          z_want[1] - z_want[0] / window, weight)

    u_wanted = u_interp(z_want)
    v_wanted = v_interp(z_want)
    u_wanted = np.ma.masked_equal(u_wanted, 99999.)
    v_wanted = np.ma.masked_equal(v_wanted, 99999.)

    vad = HorizontalWindProfile.from_u_and_v(z_want, u_wanted, v_wanted)
    return vad
Ejemplo n.º 5
0
def velocity_azimuth_display(radar, velocity,
                             z_want=None, gatefilter=None):
    """
    Velocity azimuth display.

    Parameters
    ----------
    radar : Radar
        Radar object used.
    velocity : string
        Velocity field to use for VAD calculation.

    Other Parameters
    ----------------
    z_want : array
        Heights for where to sample vads from.
        None will result in np.linespace(0, 10000, 100).
    gatefilter : GateFilter
        A GateFilter indicating radar gates that should be excluded when
        from the import vad calculation.

    Returns
    -------
    height : array
        Heights in meters above sea level at which horizontal winds were
        sampled.
    speed : array
        Horizontal wind speed in meters per second at each height.
    direction : array
        Horizontal wind direction in degrees at each height.
    u_wind : array
        U-wind mean in meters per second.
    v_wind : array
        V-wind mean in meters per second.

    Reference
    ----------
    Michelson, D. B., Andersson, T., Koistinen, J., Collier, C. G., Riedl, J.,
    Szturc, J., Gjertsen, U., Nielsen, A. and Overgaard, S. (2000) BALTEX Radar
    Data Centre Products and their Methodologies. In SMHI Reports. Meteorology
    and Climatology. Swedish Meteorological and Hydrological Institute,
    Norrkoping.

    """

    speed = []
    angle = []
    heights = []
    z_gate_data = radar.gate_z['data']
    if z_want is None:
        z_want = np.linspace(0, 10000, 100)
    else:
        z_want

    for i in range(len(radar.sweep_start_ray_index['data'])):
        index_start = radar.sweep_start_ray_index['data'][i]
        index_end = radar.sweep_end_ray_index['data'][i]
        if (index_end - index_start) % 2 == 0:
            print("even, all good")
        else:
            index_end = index_end - 1

        velocities = radar.fields[
            velocity]['data'][index_start:index_end]
        if gatefilter is not None:
            velocities = np.ma.masked_where(
                gatefilter.gate_excluded, velocities)
        # mask=velocities.mask
        # velocities[np.where(mask)]=np.nan
        azimuth = radar.azimuth['data'][index_start:index_end]
        elevation = radar.fixed_angle['data'][i]
        one_level = _vad_calculation(velocities,
                                     azimuth, elevation)
        bad = (np.isnan(one_level['speed']))
        print('max height', z_gate_data[index_start, :][~bad].max(),
              ' meters')
        speed.append(one_level['speed'][~bad])
        angle.append(one_level['angle'][~bad])
        heights.append(z_gate_data[index_start, :][~bad])

    speed_array = np.concatenate(speed)
    angle_array = np.concatenate(angle)
    height_array = np.concatenate(heights)
    arg_order = height_array.argsort()
    speed_ordered = speed_array[arg_order]
    height_ordered = height_array[arg_order]
    angle_ordered = angle_array[arg_order]

    u_ordered, v_ordered = _sd_to_uv(speed_ordered, angle_ordered)
    u_mean = _interval_mean(u_ordered, height_ordered, z_want)
    v_mean = _interval_mean(v_ordered, height_ordered, z_want)
    vad = HorizontalWindProfile.from_u_and_v(z_want, u_mean,
                                             v_mean)
    return vad
Ejemplo n.º 6
0
def velocity_azimuth_display(radar, velocity, z_want=None, gatefilter=None):
    """
    Velocity azimuth display.

    Parameters
    ----------
    radar : Radar
        Radar object used.
    velocity : string
        Velocity field to use for VAD calculation.

    Other Parameters
    ----------------
    z_want : array
        Heights for where to sample vads from.
        None will result in np.linespace(0, 10000, 100).
    gatefilter : GateFilter
        A GateFilter indicating radar gates that should be excluded when
        from the import vad calculation.

    Returns
    -------
    height : array
        Heights in meters above sea level at which horizontal winds were
        sampled.
    speed : array
        Horizontal wind speed in meters per second at each height.
    direction : array
        Horizontal wind direction in degrees at each height.
    u_wind : array
        U-wind mean in meters per second.
    v_wind : array
        V-wind mean in meters per second.

    Reference
    ----------
    Michelson, D. B., Andersson, T., Koistinen, J., Collier, C. G., Riedl, J.,
    Szturc, J., Gjertsen, U., Nielsen, A. and Overgaard, S. (2000) BALTEX Radar
    Data Centre Products and their Methodologies. In SMHI Reports. Meteorology
    and Climatology. Swedish Meteorological and Hydrological Institute,
    Norrkoping.

    """

    speed = []
    angle = []
    heights = []
    z_gate_data = radar.gate_z['data']
    if z_want is None:
        z_want = np.linspace(0, 10000, 100)
    else:
        z_want

    for i in range(len(radar.sweep_start_ray_index['data'])):
        index_start = radar.sweep_start_ray_index['data'][i]
        index_end = radar.sweep_end_ray_index['data'][i]
        if (index_end - index_start) % 2 == 0:
            print("even, all good")
        else:
            index_end = index_end - 1

        velocities = radar.fields[velocity]['data'][index_start:index_end]
        if gatefilter is not None:
            velocities = np.ma.masked_where(gatefilter.gate_excluded,
                                            velocities)
        # mask=velocities.mask
        # velocities[np.where(mask)]=np.nan
        azimuth = radar.azimuth['data'][index_start:index_end]
        elevation = radar.fixed_angle['data'][i]
        one_level = _vad_calculation(velocities, azimuth, elevation)
        bad = (np.isnan(one_level['speed']))
        print('max height', z_gate_data[index_start, :][~bad].max(), ' meters')
        speed.append(one_level['speed'][~bad])
        angle.append(one_level['angle'][~bad])
        heights.append(z_gate_data[index_start, :][~bad])

    speed_array = np.concatenate(speed)
    angle_array = np.concatenate(angle)
    height_array = np.concatenate(heights)
    arg_order = height_array.argsort()
    speed_ordered = speed_array[arg_order]
    height_ordered = height_array[arg_order]
    angle_ordered = angle_array[arg_order]

    u_ordered, v_ordered = _sd_to_uv(speed_ordered, angle_ordered)
    u_mean = _interval_mean(u_ordered, height_ordered, z_want)
    v_mean = _interval_mean(v_ordered, height_ordered, z_want)
    vad = HorizontalWindProfile.from_u_and_v(z_want, u_mean, v_mean)
    return vad
Ejemplo n.º 7
0
def velocity_azimuth_display(
        radar, velocity, z_want=None,
        valid_ray_min=16, gatefilter=None, window=2,
        weight='equal'):
    """
    Velocity azimuth display.

    Note: This code uses only one sweep. Before using the
    velocity_azimuth_display function, use, for example:
    one_sweep_radar = radar.extract_sweeps([0])

    Parameters
    ----------
    radar : Radar
        Radar object used.
    velocity : string
        Velocity field to use for VAD calculation.

    Other Parameters
    ----------------
    z_want : array
        Array of desired heights to be sampled for the vad
        calculation.
    valid_ray_min : int
        Amount of rays required to include that level in
        the VAD calculation.
    gatefilter : GateFilter
        A GateFilter indicating radar gates that should be excluded when
        from the import vad calculation.
    window : int
        Value to use for window when determing new values in the
        _Averag1D function.
    weight : string
        A string to indicate weighting method to use. 'equal' for
        equal weighting when interpolating or 'idw' for inverse
        distribution squared weighting for interpolating.
        Default is 'equal'.

    Returns
    -------
    height : array
        Heights in meters above sea level at which horizontal winds were
        sampled.
    speed : array
        Horizontal wind speed in meters per second at each height.
    direction : array
        Horizontal wind direction in degrees at each height.
    u_wind : array
        U-wind mean in meters per second.
    v_wind : array
        V-wind mean in meters per second.

    Reference
    ----------
    K. A. Browning and R. Wexler, 1968: The Determination
    of Kinematic Properties of a Wind Field Using Doppler
    Radar. J. Appl. Meteor., 7, 105–113

    """

    velocities = radar.fields[velocity]['data']
    if gatefilter is not None:
        velocities = np.ma.masked_where(
            gatefilter.gate_excluded, velocities)
    azimuths = radar.azimuth['data'][:]
    elevation = radar.fixed_angle['data'][0]

    u_wind, v_wind = _vad_calculation(velocities, azimuths,
                                      elevation, valid_ray_min)
    bad = np.logical_or(np.isnan(u_wind), np.isnan(v_wind))
    good_u_wind = u_wind[~bad]
    good_v_wind = v_wind[~bad]

    radar_height = radar.gate_z['data'][0]
    good_height = radar_height[~bad]
    if z_want is None:
        z_want = np.linspace(0, 1000, 100)[:50]
    else:
        z_want
    try:
        print('max height', np.max(good_height), ' meters')
        print('min height', np.min(good_height), ' meters')
    except ValueError:
        raise ValueError('Not enough data in this radar sweep ' \
                         'for a vad calculation.')

    u_interp = _Average1D(good_height, good_u_wind,
                          z_want[1] - z_want[0] / window, weight)
    v_interp = _Average1D(good_height, good_v_wind,
                          z_want[1] - z_want[0] / window, weight)

    u_wanted = u_interp(z_want)
    v_wanted = v_interp(z_want)
    u_wanted = np.ma.masked_equal(u_wanted, 99999.)
    v_wanted = np.ma.masked_equal(v_wanted, 99999.)

    vad = HorizontalWindProfile.from_u_and_v(
        z_want, u_wanted, v_wanted)
    return vad