コード例 #1
0
def test_missing_instrument_parameters():
    radar = pyart.io.read_uf(pyart.testing.UF_FILE, file_field_names=True)
    radar.instrument_parameters = None
    field_write_order = ['DZ', 'VR', 'SW', 'CZ', 'ZT', 'DR', 'ZD', 'RH', 'PH',
                         'KD', 'SQ', 'HC']
    ufraycreator = UFRayCreator(radar, FIELD_MAPPING, field_write_order)

    field_header = ufraycreator.field_header_template
    assert field_header['beam_width_h'] == UF_MISSING_VALUE
    assert field_header['beam_width_v'] == UF_MISSING_VALUE
    assert field_header['bandwidth'] == UF_MISSING_VALUE
    assert field_header['wavelength_cm'] == UF_MISSING_VALUE

    ufraycreator.make_field_header(999, 0, 100)
    field_header = ufraycreator.field_header_template
    assert field_header['pulse_width_m'] == UF_MISSING_VALUE
    assert field_header['prt_ms'] == UF_MISSING_VALUE
    assert field_header['polarization'] == 1

    bstring = ufraycreator.make_fsi_vel(0, 100)
    nyq = struct.unpack('>h', bstring[:2])[0]
    assert nyq == UF_MISSING_VALUE
コード例 #2
0
ファイル: test_uf_write.py プロジェクト: rtanamachi/pyart
def test_ray_section_by_section():

    ufile = UFFile(pyart.testing.UF_FILE)
    uray = ufile.rays[0]
    ref_ray_buf = uray._buf
    ufile.close()

    radar = pyart.io.read_uf(pyart.testing.UF_FILE, file_field_names=True)
    volume_start = netCDF4.num2date(radar.time['data'][0], radar.time['units'])
    volume_start -= datetime.timedelta(seconds=8)
    nfields = len(radar.fields)
    field_write_order = [
        'DZ', 'VR', 'SW', 'CZ', 'ZT', 'DR', 'ZD', 'RH', 'PH', 'KD', 'SQ', 'HC'
    ]
    ufraycreator = UFRayCreator(radar,
                                FIELD_MAPPING,
                                field_write_order,
                                volume_start=volume_start,
                                templates_extra=TEMPLATES_EXTRA)

    # mandatory header
    ref_man_header = ref_ray_buf[:90]
    tst_man_header = ufraycreator.make_mandatory_header(0)
    assert tst_man_header == ref_man_header

    # optional header
    ref_opt_header = uray._buf[90:118]
    tst_opt_header = ufraycreator.make_optional_header()
    assert tst_opt_header == ref_opt_header

    # data headers
    ref_data_header = uray._buf[118:124]
    tst_data_header = ufraycreator.make_data_header()
    assert tst_data_header == ref_data_header

    # field position info
    ref_field_position = uray._buf[124:124 + 4 * nfields]
    tst_field_position = ufraycreator.make_field_position()
    assert tst_field_position == ref_field_position

    # DZ field header
    ref_field_header = uray._buf[172:172 + 38]
    ufraycreator.field_header_template['edit_code'] = b'\x00\x00'
    tst_field_header = ufraycreator.make_field_header(106, 0, 100)
    assert tst_field_header == ref_field_header

    # DZ data
    ref_dz_data = uray.field_raw_data[0]
    tst_dz_data = ufraycreator.make_data_array('DZ', 0)
    assert np.array_equal(ref_dz_data, tst_dz_data)

    # DZ data buffer
    ref_dz_data_buf = uray._buf[210:1544]
    assert ref_dz_data_buf == ref_dz_data.tobytes()
    assert ref_dz_data_buf == tst_dz_data.tobytes()

    # VR field header
    ref_field_header = uray._buf[1544:1544 + 42]
    ufraycreator.field_header_template['edit_code'] = b'  '
    tst_field_header = ufraycreator.make_field_header(794, 0, 100)
    vel_header = ufraycreator.make_fsi_vel(0, 100)
    assert tst_field_header + vel_header == ref_field_header

    # VR data
    ref_vr_data = uray.field_raw_data[1]
    tst_vr_data = ufraycreator.make_data_array('VR', 0)
    assert np.array_equal(ref_vr_data, tst_vr_data)

    # VR data buffer
    ref_vr_data_buf = uray._buf[1586:2920]
    assert ref_vr_data_buf == ref_vr_data.tobytes()
    assert ref_vr_data_buf == tst_vr_data.tobytes()

    # SW field header
    ref_field_header = uray._buf[2920:2920 + 38]
    ufraycreator.field_header_template['edit_code'] = b'  '
    tst_field_header = ufraycreator.make_field_header(1480, 0, 100)
    assert tst_field_header == ref_field_header

    # SW data
    ref_sw_data = uray.field_raw_data[2]
    tst_sw_data = ufraycreator.make_data_array('SW', 0)
    assert np.array_equal(ref_sw_data, tst_sw_data)

    # SW data buffer
    ref_sw_data_buf = uray._buf[2958:4292]
    assert ref_sw_data_buf == ref_sw_data.tobytes()
    assert ref_sw_data_buf == tst_sw_data.tobytes()

    # ZT field header
    ref_field_header = uray._buf[5664:5664 + 38]
    ufraycreator.field_header_template['edit_code'] = b'\x00\x00'
    tst_field_header = ufraycreator.make_field_header(2852, 0, 100)
    assert tst_field_header == ref_field_header

    # PH field header
    ref_field_header = uray._buf[11152:11152 + 38]
    ufraycreator.field_header_template['edit_code'] = b'  '
    tst_field_header = ufraycreator.make_field_header(5596, 0, 10)
    assert tst_field_header == ref_field_header

    # PH data
    ref_ph_data = uray.field_raw_data[8]
    tst_ph_data = ufraycreator.make_data_array('PH', 0, 10.)
    assert np.array_equal(ref_ph_data, tst_ph_data)

    # PH data buffer
    ref_ph_data_buf = uray._buf[11152 + 38:12524]
    assert ref_ph_data_buf == ref_ph_data.tobytes()
    assert ref_ph_data_buf == tst_ph_data.tobytes()
コード例 #3
0
ファイル: test_uf_write.py プロジェクト: ARM-DOE/pyart
def test_ray_section_by_section():

    ufile = UFFile(pyart.testing.UF_FILE)
    uray = ufile.rays[0]
    ref_ray_buf = uray._buf
    ufile.close()

    radar = pyart.io.read_uf(pyart.testing.UF_FILE, file_field_names=True)
    volume_start = netCDF4.num2date(radar.time['data'][0], radar.time['units'])
    volume_start -= datetime.timedelta(seconds=8)
    nfields = len(radar.fields)
    field_write_order = ['DZ', 'VR', 'SW', 'CZ', 'ZT', 'DR', 'ZD', 'RH', 'PH',
                         'KD', 'SQ', 'HC']
    ufraycreator = UFRayCreator(
        radar, FIELD_MAPPING, field_write_order, volume_start=volume_start,
        templates_extra=TEMPLATES_EXTRA)

    # mandatory header
    ref_man_header = ref_ray_buf[:90]
    tst_man_header = ufraycreator.make_mandatory_header(0)
    assert tst_man_header == ref_man_header

    # optional header
    ref_opt_header = uray._buf[90:118]
    tst_opt_header = ufraycreator.make_optional_header()
    assert tst_opt_header == ref_opt_header

    # data headers
    ref_data_header = uray._buf[118:124]
    tst_data_header = ufraycreator.make_data_header()
    assert tst_data_header == ref_data_header

    # field position info
    ref_field_position = uray._buf[124:124 + 4 * nfields]
    tst_field_position = ufraycreator.make_field_position()
    assert tst_field_position == ref_field_position

    # DZ field header
    ref_field_header = uray._buf[172:172+38]
    ufraycreator.field_header_template['edit_code'] = b'\x00\x00'
    tst_field_header = ufraycreator.make_field_header(106, 0, 100)
    assert tst_field_header == ref_field_header

    # DZ data
    ref_dz_data = uray.field_raw_data[0]
    tst_dz_data = ufraycreator.make_data_array('DZ', 0)
    assert np.array_equal(ref_dz_data, tst_dz_data)

    # DZ data buffer
    ref_dz_data_buf = uray._buf[210:1544]
    assert ref_dz_data_buf == ref_dz_data.tostring()
    assert ref_dz_data_buf == tst_dz_data.tostring()

    # VR field header
    ref_field_header = uray._buf[1544:1544+42]
    ufraycreator.field_header_template['edit_code'] = b'  '
    tst_field_header = ufraycreator.make_field_header(794, 0, 100)
    vel_header = ufraycreator.make_fsi_vel(0, 100)
    assert tst_field_header + vel_header == ref_field_header

    # VR data
    ref_vr_data = uray.field_raw_data[1]
    tst_vr_data = ufraycreator.make_data_array('VR', 0)
    assert np.array_equal(ref_vr_data, tst_vr_data)

    # VR data buffer
    ref_vr_data_buf = uray._buf[1586:2920]
    assert ref_vr_data_buf == ref_vr_data.tostring()
    assert ref_vr_data_buf == tst_vr_data.tostring()

    # SW field header
    ref_field_header = uray._buf[2920:2920+38]
    ufraycreator.field_header_template['edit_code'] = b'  '
    tst_field_header = ufraycreator.make_field_header(1480, 0, 100)
    assert tst_field_header == ref_field_header

    # SW data
    ref_sw_data = uray.field_raw_data[2]
    tst_sw_data = ufraycreator.make_data_array('SW', 0)
    assert np.array_equal(ref_sw_data, tst_sw_data)

    # SW data buffer
    ref_sw_data_buf = uray._buf[2958:4292]
    assert ref_sw_data_buf == ref_sw_data.tostring()
    assert ref_sw_data_buf == tst_sw_data.tostring()

    # ZT field header
    ref_field_header = uray._buf[5664:5664+38]
    ufraycreator.field_header_template['edit_code'] = b'\x00\x00'
    tst_field_header = ufraycreator.make_field_header(2852, 0, 100)
    assert tst_field_header == ref_field_header

    # PH field header
    ref_field_header = uray._buf[11152:11152+38]
    ufraycreator.field_header_template['edit_code'] = b'  '
    tst_field_header = ufraycreator.make_field_header(5596, 0, 10)
    assert tst_field_header == ref_field_header

    # PH data
    ref_ph_data = uray.field_raw_data[8]
    tst_ph_data = ufraycreator.make_data_array('PH', 0, 10.)
    assert np.array_equal(ref_ph_data, tst_ph_data)

    # PH data buffer
    ref_ph_data_buf = uray._buf[11152+38:12524]
    assert ref_ph_data_buf == ref_ph_data.tostring()
    assert ref_ph_data_buf == tst_ph_data.tostring()