def test_nyquist_vel(): ufile = UFFile(pyart.testing.UF_FILE) ufile.rays[0].field_headers[1].pop('nyquist') assert ufile.get_nyquists() is None ufile = UFFile(pyart.testing.UF_FILE) ray = UFRay(ufile.rays[0]._buf) ray.field_headers[1].pop('nyquist') ufile.rays.append(ray) ufile.nrays = 2 assert ufile.get_nyquists() is None
def test_datetime(): ufile = UFFile(pyart.testing.UF_FILE) ray = ufile.rays[0] assert ray.get_datetime() == datetime(2011, 5, 20, 10, 54, 16) # test case where midnight is incorrectly represented as 24:00:00 ray.mandatory_header['hour'] = 24 ray.mandatory_header['minute'] = 0 ray.mandatory_header['second'] = 0 assert ray.get_datetime() == datetime(2011, 5, 21, 0, 0, 0)
def test_scan_type(): ufile = UFFile(pyart.testing.UF_FILE) ufray = ufile.rays[0] scan_type = pyart.io.uf._get_scan_type(ufray) assert scan_type == 'ppi' # An invalid scan mode should throw a warning ufray.mandatory_header['sweep_mode'] = 99 assert_warns(UserWarning, pyart.io.uf._get_scan_type, ufray)
def test_ray_full(): ufile = UFFile(pyart.testing.UF_FILE) ref_ray = ufile.rays[0]._buf[:] ufile.close() radar = pyart.io.read_uf(pyart.testing.UF_FILE, file_field_names=True) radar.fields['PH']['_UF_scale_factor'] = 10 field_write_order = ['DZ', 'VR', 'SW', 'CZ', 'ZT', 'DR', 'ZD', 'RH', 'PH', 'KD', 'SQ', 'HC'] volume_start = netCDF4.num2date(radar.time['data'][0], radar.time['units']) volume_start -= datetime.timedelta(seconds=8) ufraycreator = UFRayCreator( radar, FIELD_MAPPING, field_write_order, volume_start=volume_start, templates_extra=TEMPLATES_EXTRA) tst_ray = ufraycreator.make_ray(0) tst_ray = tst_ray[:204] + b'\x00\x00' + tst_ray[206:] # DZ edit_code tst_ray = tst_ray[:5696] + b'\x00\x00' + tst_ray[5698:] # ZT edit_code assert ref_ray == tst_ray
def test_range_start(): radar = pyart.io.read_uf(pyart.testing.UF_FILE) radar.range['meters_to_center_of_first_gate'] += 1500. in_mem = StringIO() write_uf(in_mem, radar) in_mem.seek(0) ufile = UFFile(in_mem) field_header = ufile.rays[0].field_headers[0] assert field_header['range_start_km'] == 1 assert field_header['range_start_m'] == 500
def test_frequency(): ufile = UFFile(pyart.testing.UF_FILE) filemetadata = pyart.config.FileMetadata('uf') ip = pyart.io.uf._get_instrument_parameters(ufile, filemetadata) assert 'frequency' in ip assert_almost_equal(ip['frequency']['data'][0], 9.69026150e+09, -3) # An invalid wavelength should throw a warning ufile.rays[0].field_headers[0]['wavelength_cm'] = 0 assert_warns(UserWarning, pyart.io.uf._get_instrument_parameters, ufile, filemetadata)
def test_polarization(): ufile = UFFile(pyart.testing.UF_FILE) ufile.rays[0].field_headers[0]['polarization'] = 99 assert ufile.get_sweep_polarizations()[0] == 'elliptical'
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()
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()