def test_1ms_vel_message(): # read in a velocity message from a MSG1 file uncompressed_file = bz2.BZ2File( pyart.testing.NEXRAD_ARCHIVE_MSG1_FILE, 'rb') # seek pack the volume header, compression header and reflectivity data uncompressed_file.seek(24 + 12 + 897408) buf = uncompressed_file.read(2432) # read a record # create a fake message with a 1 m/s velocity resolution fake_buf = buf[:16+43] + b'\x04' + buf[16+44:] # check the velocity scale new_pos, dic = nexrad_level2._get_record_from_buf(fake_buf, 0) assert dic['VEL']['scale'] == 1.0
def test_1ms_vel_message(): # read in a velocity message from a MSG1 file uncompressed_file = bz2.BZ2File(pyart.testing.NEXRAD_ARCHIVE_MSG1_FILE, 'rb') # seek pack the volume header, compression header and reflectivity data uncompressed_file.seek(24 + 12 + 897408) buf = uncompressed_file.read(2432) # read a record # create a fake message with a 1 m/s velocity resolution fake_buf = buf[:16 + 43] + b'\x04' + buf[16 + 44:] # check the velocity scale new_pos, dic = nexrad_level2._get_record_from_buf(fake_buf, 0) assert dic['VEL']['scale'] == 1.0
# read in the first 134 records as write as is out.write(fin.read(24 + 12 + RECORD_SIZE * 134)) # read the rest of the file, and create a array of int8 buf = fin.read() buf_length = len(buf) buf_data = np.frombuffer(buf, dtype='i1') fin.close() # replace all radial data with a single value so it compresses well pos = 0 while pos < buf_length: # retrieve the record (msg31) new_pos, record = nexrad._get_record_from_buf(buf, pos) if record['header']['type'] != 31: pos += RECORD_SIZE continue # dummy out all moments for bp_number in [4, 5, 6, 7, 8, 9]: bp_str = 'block_pointer_' + str(bp_number) block_pointer = record['msg_header'][bp_str] if block_pointer != 0: bpos = pos + block_pointer + MSG_HEADER_SIZE d = nexrad._unpack_from_buf(buf, bpos, nexrad.GENERIC_DATA_BLOCK) points = d['ngates'] if d['data_name'] == 'PHI': points *= 2 start = pos + MSG_HEADER_SIZE + DATA_BLOCK_SIZE + block_pointer