def read(fpath, navcrs, body): rdata = garlic(fpath) rdata.fn = fpath.split("/")[-1][:-4] rdata.dtype = "rimfax" print("----------------------------------------") print("Loading: " + rdata.fn) f = pd.read_csv(rdata.fpath, header=0, skiprows=range(1, 6)) f = f.loc[f["record_type"] == 0] rdata.dat = np.array(f.iloc[:, 85:]).T rdata.set_proc(np.abs(rdata.dat)) rdata.set_sim(np.ones(rdata.dat.shape)) rdata.snum = np.max(f["n_samples"]) # samples per trace in rgram rdata.tnum = len(f) # number of traces in rgram rdata.dt = f.loc[0, "sample_time_increment"] # sampling interval, sec # rdata.prf = f["param_records"]["radar"]["prf"][0][0] # pulse repitition frequency rdata.nchan = 1 # parse nav rdata.navdf = navparse.getnav_rimfax(fpath, navcrs, body) rdata.set_srfElev(dat=np.repeat(np.nan, rdata.tnum)) # rdata.info["PRF [kHz]"] = rdata.prf * 1e-3 return rdata
def read(fpath, simpath, navcrs, body): fn = fpath.split("/")[-1] root = fpath.rstrip(fn) print("----------------------------------------") print("Loading: " + fn) rdata = garlic(fpath) rdata.fn = fn.rstrip("_rgram.img") rdata.dtype = "sharad" # convert binary .img PDS RGRAM to numpy array # reshape array with 3600 lines dtype = np.dtype("float32") with open(fpath, "rb") as f: rdata.dat = np.fromfile(f, dtype) l = len(rdata.dat) rdata.snum = 3600 rdata.tnum = int(len(rdata.dat) / rdata.snum) rdata.dt = .0375e-6 rdata.prf = 700.28 rdata.nchan = 1 rdata.dat = rdata.dat.reshape(rdata.snum, rdata.tnum) rdata.set_proc(rdata.dat) # convert binary .img clutter sim product to numpy array if simpath: simpath = simpath + fn.replace("rgram", "geom_combined") else: simpath = root + fn.replace("rgram", "geom_combined") if os.path.isfile(simpath): with open(simpath, "rb") as f: sim = np.fromfile(f, dtype) sim = sim.reshape(rdata.snum, rdata.tnum) else: print( "Clutter simulation not found:\t{}\nSpecify alternate path in configuration file." .format(simpath)) sim = np.ones(rdata.dat.shape) rdata.set_sim(sim) # assign signal info rdata.info["signal type"] = "chirp" rdata.info["cf [MHz]"] = 20 rdata.info["badwidth [%]"] = 50 rdata.info["pulse length [\u03BCs]"] = 85 rdata.info["prf [Hz]"] = rdata.prf # open geom nav file for rgram geom_path = fpath.replace("rgram", "geom").replace("img", "tab") # parse nav rdata.navdf = navparse.getnav_sharad(geom_path, navcrs, body) rdata.set_srfElev(dat=np.repeat(np.nan, rdata.tnum)) return rdata
def read_mat(fpath, navcrs, body): rdata = garlic(fpath) rdata.fn = fpath.split("/")[-1][:-4] rdata.dtype = "cresis_snow" f = h5py.File(rdata.fpath, "r") # assign signal info rdata.info["System"] = str(f["param_records"]["radar_name"][:], 'utf-16') if "snow" not in rdata.info["System"]: raise ValueError("Not snow radar data") return print("----------------------------------------") print("Loading: " + rdata.fn) rdata.dat = np.array(f["Data"][:]).T rdata.set_proc(np.abs(rdata.dat)) rdata.set_sim(np.ones(rdata.dat.shape)) rdata.snum = rdata.dat.shape[0] # samples per trace in rgram rdata.tnum = rdata.dat.shape[1] # number of traces in rgram rdata.dt = np.mean(np.diff(f["Time"])) # sampling interval, sec rdata.prf = f["param_records"]["radar"]["prf"][0][ 0] # pulse repitition frequency rdata.nchan = 1 # parse nav rdata.navdf = navparse.getnav_cresis_mat(fpath, navcrs, body) # pull surface elevation and initilize horizon rdata.set_srfElev(dat=f["Surface"][:].flatten()) rdata.pick.horizons["srf"] = utils.twtt2sample(rdata.get_srfElev(), rdata.dt) # rdata.set_srfElev(rdata.navdf["elev"] - utils.twtt2depth(rdata.pick.horizons["srf"], eps_r=1)) rdata.pick.srf = "srf" rdata.info["PRF [kHz]"] = rdata.prf * 1e-3 f.close() # close the file return rdata
def read_dt1(fpath, navcrs, body): """ read Sensors and Software .DT1 data files. modified from gprpy/toolbox/gprIO_DT1.readdt1 INPUT: fpath data file name including the .DT1 extension navcrs nav data coordinate reference system body planetary body for coordinate transformation OUTPUT: rdata garlic class object Load data from a pulse_ekko file.""" rdata = garlic(fpath) rdata.fn = fpath.split("/")[-1][:-4] rdata.dtype = "pekko" print("----------------------------------------") print("Loading: " + rdata.fn) infile_gps = fpath[:-4] + ".GPS" if not os.path.isfile(infile_gps): infile_gps = fpath[:-4] + ".GP2" infile_hd = fpath[:-4] + ".HD" headlen = 32 with open(fpath,"rb") as datafile: datafile.seek(8,0) # 0 is beginning of file snum, = struct.unpack('f',datafile.read(4)) rdata.snum = int(snum) dimtrace = rdata.snum*2+128 datafile.seek(-dimtrace,2) # 2 stands for end of file tnum, = struct.unpack('f',datafile.read(4)) rdata.tnum = int(tnum) # Initialize matrix rdata.dat = np.zeros((rdata.snum,rdata.tnum)) head = np.zeros((headlen,rdata.tnum)) # Set the reader to the beginning of the file datafile.seek(0,0) for j in range(0,rdata.tnum): # Read the header info for k in range(0,headlen): info, = struct.unpack('f',datafile.read(4)) head[k,j] = info # Now the actual data for k in range(0,rdata.snum): # 2 is the size of short, 'h' is the symbol pnt, = struct.unpack('h',datafile.read(2)) rdata.dat[k,j] = pnt datafile.seek(dimtrace*(j+1),0) # known vars that are not really set rdata.nchan = 1 rdata.trace_num = np.arange(rdata.tnum) + 1 # read in header file and return info dict rdata.info = read_hd(infile_hd) # get sampling frequency rdata.dt = rdata.info["Total_time_window"] / rdata.snum * 1.0e-9 rdata.info.pop("Total_time_window") # convert signed int amplitude to floating point for displaying rdata.set_proc(rdata.dat.astype(np.float)) rdata.set_sim(np.ones(rdata.dat.shape)) # place holder for clutter data # create nav object to hold lon, lat, elev rdata.navdf = navparse.getnav_pulseekko(infile_gps, rdata.tnum, navcrs, body) # for ground-based GPR, elev_gnd is the same as GPS recorded elev rdata.set_srfElev(dat = rdata.navdf["elev"]) return rdata
def read(fpath, navcrs, body): fn = fpath.split("/")[-1] print("----------------------------------------") print("Loading: " + fn) rdata = garlic(fpath) rdata.fn = fn[:-4] rdata.dtype = "gssi" # modified readgssi readdzt.dzt reader (credit, DOI: 10.5281/zenodo.3352438) with open(rdata.fpath, "rb") as f: # skip around and read necessary attributes f.seek(2) data_offset = struct.unpack( "<h", f.read(2))[0] # offset to data array [bits] rdata.snum = struct.unpack('<h', f.read(2))[0] # number of samples per trace bits = struct.unpack('<h', f.read(2))[0] # number of bits - datatype f.seek(10) rdata.prf = struct.unpack('<f', f.read(4))[0] # scans per second (prf) f.seek(26) range_ns = struct.unpack( '<f', f.read(4))[0] # data range [ns] - record time per trace f.seek(52) rdata.nchan = struct.unpack('<h', f.read(2))[0] # number of data channels rdata.dt = range_ns / rdata.snum * 1.0e-9 # sampling interval rdata.fs = 1 / rdata.dt # sampling freq if bits == 8: dtype = np.uint8 # 8-bit unsigned elif bits == 16: dtype = np.uint16 # 16-bit unsigned elif bits == 32: dtype = np.int32 # 32-bit signed else: print("ingest_gssi.read error: undefined data type. #bits = " + bits) exit(1) # skip ahead to data if data_offset < 1024: # whether or not the header is normal or big-->determines offset to data array didx = 1024 * data_offset else: didx = 1024 * rdata.chan # skip to data index f.seek(didx) # read in data - need to transpose to get correct shape rdata.dat = np.fromfile(f, dtype).reshape(-1, (rdata.snum * rdata.nchan)).T # ensure data file is not empty if not np.any(rdata.dat): raise ValueError("gssi_read error: file contains no radar data") rdata.tnum = rdata.dat.shape[1] # convert gssi signed int amplitude to floating point for displaying rdata.set_proc(rdata.dat.astype(np.float)) rdata.set_sim(np.ones(rdata.dat.shape)) # place holder for clutter data # assign signal info rdata.info["Signal Type"] = "Impulse" rdata.info["Sampling Frequency [MHz]"] = rdata.fs * 1e-6 rdata.info["PRF [kHz]"] = rdata.prf * 1e-3 # read in gps data if exists infile_gps = fpath.replace(".DZT", ".DZG") # create nav object to hold lon, lat, hgt rdata.navdf = navparse.getnav_gssi(infile_gps, rdata.tnum, navcrs, body) # for ground-based GPR, elev_gnd is the same as GPS recorded elev rdata.set_srfElev(dat=rdata.navdf["elev"]) return rdata
def read(fpath, simpath, navcrs, body): fn = fpath.split("/")[-1] root = fpath.rstrip(fn) print("----------------------------------------") print("Loading: " + fn) # Get # of traces fd = open(fpath, 'r') lbl = fd.read().split('\n') fd.close() rdata = garlic(fpath.replace(".lbl", ".img")) # get number of traces (file records in lbl file) and samples per trace rdata.tnum = int(lbl[19].split('=')[1]) rdata.snum = 1000 rdata.fn = fn.rstrip(".lbl") rdata.dtype = "lrs" # convert binary .img RGRAM to numpy array - data begins after 55 bytes of header info with open(rdata.fpath, "rb") as f: f.seek(rdata.tnum * 55) data = f.read(rdata.tnum * rdata.snum) rdata.dat = np.frombuffer(data, np.uint8) l = len(rdata.dat) rdata.dt = 305.17578125e-09 rdata.prf = 20 rdata.nchan = 1 rdata.dat = rdata.dat.reshape(rdata.snum, rdata.tnum) rdata.set_proc(rdata.dat) # convert binary .img clutter sim product to numpy array if simpath: simpath = simpath + "/" + fn.replace(".lbl", "_geom_combined.img") else: simpath = root + "/" + fn.replace(".lbl", "_geom_combined.img") if os.path.isfile(simpath): with open(simpath, "rb") as f: sim = np.fromfile(f, np.float32) sim = sim.reshape(rdata.snum, rdata.tnum) else: sim = np.ones(rdata.dat.shape) rdata.set_sim(sim) # assign signal info rdata.info = {} rdata.info["Signal Type"] = "Chirp" rdata.info["CF [MHz]"] = 5 rdata.info["Bandwidth [%]"] = 40 rdata.info["Pulse Length [\u03BCs]"] = 200 rdata.info["PRF [Hz]"] = rdata.prf # open geom nav file for rgram geom_path = fpath.replace(".lbl", "_geom.csv") # parse nav - use spice derived nav, not header data due to header data issues rdata.navdf = navparse.getnav_lrs(geom_path, navcrs, body) rdata.set_srfElev(dat=np.repeat(np.nan, rdata.tnum)) return rdata
def read_h5(fpath, navcrs, body): rdata = garlic(fpath) rdata.fn = fpath.split("/")[-1][:-3] rdata.dtype = "oibak" # read in .h5 file print("----------------------------------------") print("Loading: " + rdata.fn) f = h5py.File(rdata.fpath, "r") # h5 radar data group structure # |-raw # | |-rx0 # | |-tx0 # | |-loc0 # |-ext # | |-nav0 # | |-srf0 # |-drv # | |-proc0 # | |-clutter0 # | |-pick # pull necessary raw group data rdata.snum = int( f["raw"]["rx0"].attrs["samplesPerTrace"]) # samples per trace in rgram rdata.tnum = int( f["raw"]["rx0"].attrs["numTrace"]) # number of traces in rgram rdata.fs = f["raw"]["rx0"].attrs["samplingFrequency"][ 0] # sampling frequency rdata.dt = 1 / rdata.fs # sampling interval, sec rdata.prf = f["raw"]["tx0"].attrs["pulseRepetitionFrequency"][ 0] # pulse repition frequency, Hz rdata.nchan = 1 # pull radar proc and sim arrays rdata.dat = f["drv/proc0"][:] # pulse compressed array rdata.set_proc(np.abs(rdata.dat)) if "clutter0" in f["drv"].keys(): rdata.set_sim(f["drv"]["clutter0"][:]) # simulated clutter array else: rdata.set_sim(np.ones( rdata.dat.shape)) # empty clutter array if no sim exists # assign signal info rdata.info["Signal Type"] = f["raw"]["tx0"].attrs["signal"].decode( ).capitalize() rdata.info["CF [MHz]"] = f["raw"]["tx0"].attrs["centerFrequency"][0] * 1e-6 if rdata.info["Signal Type"] == "Chirp": rdata.info[ "Badwidth [%]"] = f["raw"]["tx0"].attrs["bandwidth"][0] * 100 rdata.info["Pulse Length [\u03BCs]"] = f["raw"]["tx0"].attrs["length"][ 0] * 1e6 rdata.info["Sampling Frequency [MHz]"] = rdata.fs * 1e-6 rdata.info["PRF [kHz]"] = rdata.prf * 1e-3 # parse nav rdata.navdf = navparse.getnav_oibAK_h5(fpath, navcrs, body) # pull lidar surface elevation and initilize horizon if "srf0" in f["ext"].keys(): rdata.set_srfElev(dat=f["ext"]["srf0"][:]) if "twtt_surf" in f["drv"]["pick"].keys(): twtt_srf = f["drv"]["pick"]["twtt_surf"][:] # replace -1 and -9 null values with np.nan twtt_srf[twtt_srf == -1] = np.nan twtt_srf[twtt_srf == -9] = np.nan if not np.isnan(twtt_srf).all(): rdata.pick.horizons["srf"] = utils.twtt2sample( twtt_srf, rdata.dt) else: rdata.pick.horizons["srf"] = utils.twtt2sample( utils.depth2twtt(rdata.navdf["elev"] - rdata.srfElev, eps_r=1), rdata.dt) rdata.pick.srf = "srf" else: rdata.set_srfElev(dat=np.repeat(np.nan, rdata.tnum)) # read in existing bed picks if "twtt_bed" in f["drv"]["pick"].keys(): twtt_bed = f["drv"]["pick"]["twtt_bed"][:] # replace -1 and -9 null values with np.nan twtt_bed[twtt_bed == -1] = np.nan twtt_bed[twtt_bed == -9] = np.nan if not np.isnan(twtt_bed).all(): rdata.pick.horizons["bed"] = utils.twtt2sample(twtt_bed, rdata.dt) f.close() # close the file # # temporary fix to roll array for impulse data to line up with surface - find offset by windowing around lidar surface # if (rdata.info["signal type"] == "impulse") and (not np.isnan(rdata.pick.existing_twttSurf).all()): # lidarsrf = utils.twtt2sample(rdata.pick.existing_twttSurf, rdata.dt) # pksrf = utils.pkampwind(rdata.dat, lidarsrf, 60) # avoffset = np.nanmean(lidarsrf - pksrf) # rdata.dat = np.roll(rdata.dat, int(round(avoffset)), axis=0) # rdata.set_proc(np.abs(rdata.dat)) return rdata