Exemplo n.º 1
0
    qrf = (zg / 20.0) + np.sqrt(yg ** 2 + xg ** 2) * \
        np.tan(1.0 * 1.5 * np.pi / 180.0) + 500.0 + \
        zg * 1000.0 * theta ** 2 / (45.0 ** 2) / 17000.
    return qrf


if __name__ == "__main__":
    process_version = "1.0E"
    vapname = "mmcg"
    site = "sgp"
    facility = "I7"
    level = "c0"
    ncfile = sys.argv[1]
    odir = sys.argv[2]
    cf_alt = 320.0 / 1000.0
    cf_lat = dms_to_d([36.0, 36.0, 18.35])
    cf_lon = -1.0*dms_to_d([97.0, 29.0, 10.69])
    #mync=netCDF4.Dataset(ncfile)
    #myradar=radar.Radar(mync)
    myradar = pyart.io.read_netcdf(ncfile)
    print myradar.time['data'][0]
    cp = corner_to_point([myradar.location['latitude']['data'],
                          myradar.location['longitude']['data']],
                         [cf_lat, cf_lon])
    #mync.close()
    mygrids = grid.pyGrid(
        (myradar,), nxyz=(241, 241, 35),
        xyzr=((-120000 - cp[0], 120000 - cp[0]),
             (-120000 - cp[1], 120000 - cp[1]),
             (0, 17000)),
        params=['reflectivity_horizontal'],
Exemplo n.º 2
0
    qrf = (zg / 20.0) + np.sqrt(yg ** 2 + xg ** 2) * \
        np.tan(1.0 * 1.5 * np.pi / 180.0) + 500.0 + \
        zg * 1000.0 * theta ** 2 / (45.0 ** 2) / 17000.
    return qrf


if __name__ == "__main__":
    process_version = "1.0E"
    vapname = "mmcg"
    site = "sgp"
    facility = "I7"
    level = "c0"
    ncfile = sys.argv[1]
    odir = sys.argv[2]
    cf_alt = 320.0 / 1000.0
    cf_lat = dms_to_d([36.0, 36.0, 18.35])
    cf_lon = -1.0 * dms_to_d([97.0, 29.0, 10.69])
    #mync=netCDF4.Dataset(ncfile)
    #myradar=radar.Radar(mync)
    myradar = pyart.io.read_netcdf(ncfile)
    print myradar.time['data'][0]
    cp = corner_to_point([
        myradar.location['latitude']['data'],
        myradar.location['longitude']['data']
    ], [cf_lat, cf_lon])
    #mync.close()
    mygrids = grid.pyGrid((myradar, ),
                          nxyz=(241, 241, 35),
                          xyzr=((-120000 - cp[0], 120000 - cp[0]),
                                (-120000 - cp[1], 120000 - cp[1]), (0, 17000)),
                          params=['reflectivity_horizontal'],
Exemplo n.º 3
0
def read_rsl(filename, add_meta=None):
    """
    Read a file supported by RSL

    Parameters
    ----------
    filename : str or RSL_radar
        Name of file whose format is supported by RSL.
    add_meta : dict or None
        Dictionary containing additional metadata to add to the created
        Radar object.  This will overwrite metadata extracted from the file.
        None is add no additional metadata.

    Returns
    -------
    radar : Radar
        Radar object.

    """
    rslfile = _rsl_interface.RslFile(filename)
    available_vols = rslfile.available_moments()
    first_volume = rslfile.get_volume(available_vols[0])
    first_sweep = first_volume.get_sweep(0)
    first_ray = first_sweep.get_ray(0)

    # TODO
    # An issue that needs to be resolved is that this code likes all
    # sweeps to have the same number of rays.. so for now we take
    # min(nrays) across sweeps and drop rays out side of this...
    # this is an "easy" issue to resolve caused by the fact I have been
    # treating things as cubes and then flattening them
    # what needs to be done is to make the field['data'] be masked arrays
    # and mask out location where the ray is Null

    # determine the shape parameters of the fields
    nsweeps = first_volume.nsweeps
    nrays = min(first_volume.get_nray_list())
    ngates = first_ray.nbins

    # scan_type, naz, and nele
    if first_sweep.azimuth == -999.0:
        scan_type = 'ppi'
        naz = nrays
        nele = nsweeps
    else:
        scan_type = 'rhi'
        naz = nsweeps
        nele = nrays

    # range
    _range = get_metadata('range')
    range_bin1 = first_ray.range_bin1
    gate_size = first_ray.gate_size
    _range['data'] = range_bin1 + gate_size * np.arange(ngates)
    _range['spacing_is_constant'] = 'true'
    _range['meters_to_center_of_first_gate'] = range_bin1
    _range['meters_between_gates'] = gate_size

    # azimuth and elevation
    _azimuth, _elevation = first_volume.get_azimuth_and_elev_array()
    azimuth = get_metadata('azimuth')
    azimuth['data'] = _azimuth.flatten()
    elevation = get_metadata('elevation')
    elevation['data'] = _elevation.flatten()

    # time
    last_sweep = first_volume.get_sweep(nsweeps - 1)
    last_ray = last_sweep.get_ray(nrays - 1)
    t_start = first_ray.get_datetime()
    t_end = last_ray.get_datetime()
    t_span = (t_end - t_start).seconds
    tu = make_tu_str(t_start)
    cal = "gregorian"
    time = get_metadata('time')
    time['data'] = np.linspace(0, t_span, nrays * nsweeps)
    time['units'] = tu
    time['calendar'] = cal

    # sweep parameters
    sweep_number = get_metadata('sweep_number')
    sweep_mode = get_metadata('sweep_mode')
    fixed_angle = get_metadata('fixed_angle')
    sweep_start_ray_index = get_metadata('sweep_start_ray_index')
    sweep_end_ray_index = get_metadata('sweep_end_ray_index')
    len_time = len(time['data'])

    if scan_type == 'ppi':
        nsweeps = nele
        sweep_number['data'] = range(nsweeps)
        sweep_mode['data'] = nsweeps * ['azimuth_surveillance    ']
        fixed_angle['data'] = first_volume.get_sweep_elevs()
        sweep_start_ray_index['data'] = np.arange(0, len_time, naz)
        sweep_end_ray_index['data'] = np.arange(naz - 1, len_time, naz)

    elif scan_type == 'rhi':
        nsweeps = naz
        sweep_number['data'] = range(nsweeps)
        sweep_mode['data'] = nsweeps * ['rhi                     ']
        fixed_angle['data'] = first_volume.get_sweep_azimuths()
        sweep_start_ray_index['data'] = np.arange(0, len_time, nele)
        sweep_end_ray_index['data'] = np.arange(nele - 1, len_time, nele)

    sweep_info = {
        'sweep_number': sweep_number,
        'sweep_mode': sweep_mode,
        'fixed_angle': fixed_angle,
        'sweep_start_ray_index': sweep_start_ray_index,
        'sweep_end_ray_index': sweep_end_ray_index}
    sweep_mode = np.array([scan_type] * nsweeps)
    sweep_number = np.linspace(0, nsweeps - 1, nsweeps)

    # metadata
    metadata = {'original_container': 'rsl'}
    rsl_dict = rslfile.get_radar_header()
    need_from_rsl_header = {
        'name': 'instrument_name', 'project': 'project', 'state': 'state',
        'country': 'country'}  # rsl_name : radar_metadata_name
    for rsl_key, metadata_key in need_from_rsl_header.iteritems():
        metadata[metadata_key] = rsl_dict[rsl_key]
    if add_meta is not None:
        metadata.update(add_meta)

    # location
    lat = get_metadata('latitude')
    lon = get_metadata('longitude')
    elv = get_metadata('altitude')
    latd = rsl_dict['latd']
    latm = rsl_dict['latm']
    lats = rsl_dict['lats']
    lat['data'] = dms_to_d((latd, latm, lats))

    lond = rsl_dict['lond']
    lonm = rsl_dict['lonm']
    lons = rsl_dict['lons']
    lon['data'] = dms_to_d((lond, lonm, lons))

    elv['data'] = rsl_dict['height']
    location = {'latitude': lat, 'longitude': lon, 'altitude': elv}

    # set instrument parameters attribute
    inst_params = {}
    inst_params['prt_mode'] = get_metadata('prt_mode')
    inst_params['nyquist_velocity'] = get_metadata('nyquist_velocity')
    inst_params['prt'] = get_metadata('prt')
    inst_params['unambiguous_range'] = get_metadata('unambiguous_range')

    pm_data, nv_data, pr_data, ur_data = first_volume.get_instr_params()
    inst_params['prt_mode']['data'] = pm_data
    inst_params['nyquist_velocity']['data'] = nv_data.flatten()
    inst_params['prt']['data'] = pr_data.flatten()
    inst_params['unambiguous_range']['data'] = ur_data.flatten()

    # fields
    # transfer only those which are available and have a standard name
    fields = {}
    available_vols = rslfile.available_moments()
    good_vols = VOLUMENUM2STANDARDNAME.keys()
    volumes_to_extract = [i for i in available_vols if i in good_vols]

    for volume_num in volumes_to_extract:

        # extract the field, mask and reshape
        data = rslfile.get_volume_array(volume_num)
        data[np.where(np.isnan(data))] = -9999.0
        data[np.where(data == 131072)] = -9999.0
        data = np.ma.masked_equal(data, -9999.0)
        data.shape = (data.shape[0] * data.shape[1], data.shape[2])

        # create the field dictionary
        standard_field_name = VOLUMENUM2STANDARDNAME[volume_num]
        fielddict = get_metadata(standard_field_name)
        fielddict['data'] = data
        fielddict['_FillValue'] = -9999.0
        fields[standard_field_name] = fielddict

    return Radar(nsweeps, nrays, ngates, scan_type, naz, nele, _range,
                 azimuth, elevation, tu, cal, time, fields, sweep_info,
                 sweep_mode, sweep_number, location, inst_params, metadata)