Process and plot binary GSSI files

Class definitions and helper functions for gssi info

The workhorses here are process_and_plot() and process_radar(), which will handle a lot of the steps of taking a raw DZG file and plotting it and/or returning it in a useful form

pygssi.lib.gssilib.apply_diel(diel, data, layer_time_increment=None)[source]

Apply some kind of dielectric model to data

Parameters:
  • diel (float, numpy.ndarray, str, or None) – diel can be a 2-column csv with depths and dielectric constants, an array with depths and dielectric constants, a number giving a depth-constant dielectric constant, or None, which leaves things in two-way travel time. If layer_time_increment is None, we always stay in TWTT
  • data (numpy.ndarray) – The data that we are rescaling
  • layer_time_increment (float) – size of a vertical increment in seconds
Returns:

  • y (nx1 array) – The depths of each vertical pixel
  • diels (mx2 array) – Depth and dielectric constant pairs

pygssi.lib.gssilib.filter_data(data, h_hpass=0.01, h_lpass=0.1, v_hpass=0.1, v_lpass=0.2, order=2)[source]

Butterworth filter int he high and/or low directions

Parameters:
  • h_lpass (h_hpass,) –
  • v_lpass (v_hpass,) –
Returns:

dat – An array with the same size data containing the filtered data

Return type:

numpy.ndarray

pygssi.lib.gssilib.load_diel_file(fn)[source]

Load dielectric constant from file

Parameters:fn (str) – Should be a two column csv with the depths in the left column and the values in the right
pygssi.lib.gssilib.plot_layers(layer_fns, ax_flat, lldist, diels, ax_variablesurf=None, linewidth=1, scale_x=1000.0, z=None)[source]

Plot layers on axes given

Parameters:
  • layer_fns (list) – List of files containing layers to plot. This is designed to be used in conjunction with the radan tracing software, so the format is a 1-line header with “Dist.(m),Lat,Long,Elev(m),Time,Layer 1 2-Way Time,Layer 2 2-Way Time...”.
  • ax_flat (matplotlib.pyplot.Axis) – Axis in depth (or TWTT) space on which to plot
  • lldist (mx3 numpy.ndarray) – The lon, lat, and distance for each point. If no GPS data is given, each row is 0, 1, 2...
  • diels (lx2 numpy.ndarray) – Depth, dielectric constant pairs.
  • ax_variablesurf (matplotlib.pyplot.Axis, optional) – Axis in elevation space on which to plot
  • linewidth (float, optional) – Line width of layers plotted.
  • scale_x (float, optional) – Divide distance by this amount for x axis. Default is 1000.0 to make polar stereographic plots in km.
  • z (mx1 numpy.ndarray, optional) – Elevations for each trace. Ignored if no ax_variablesurf.
Returns:

ldict – A dictionary of layer names and depths. None if no layers are input

Return type:

dict

pygssi.lib.gssilib.plot_radar(data, x=None, y=None, out_fn=None, elev=None, ax=None, xlabel='Distance (km)', ylabel='Depth (m)')[source]

Plot an array of radar data

Parameters:
  • data (numpy.ndarray) – An nxm array of values to plot
  • x (numpy.ndarray, optional) – An mx1 array x values of the data to plot. If x or y is None, the x-axis will be in number of traces
  • y (numpy.ndarray, optional) – An nx1 array y values of the data to plot. If x or y is None, the y-axis will be the return bin
  • out_fn (str, optional) – Save to this file (default None/don’t save)
  • elev (numpy.ndarray) – An nx1 array y values of surface height. Depths are subtracted from this before plotting if not None. Ignored if x or y is None.
  • ax (matplotlib.pyplot.Axis) – Plot on these axes rather than creating a new figure (default is None/create figure)
  • xlabel (str, optional) – Labels for the x-axis (overridden if x or y are None).
  • ylabel (str, optional) – Labels for the y-axis (overridden if x or y are None).
Returns:

  • fig (matplotlib.pyplot.Figure) – The figure canvas (unless an axis was passed in, in which case figure is None)
  • ax (matplotlib.pyplot.Axis) – The axis instance created (or that passed in returned back if one is specified

pygssi.lib.gssilib.process_and_plot(fns, rev_list=None, t_srs='sps', elev_fn=None, pickle_fn=None, gp=None, diel=None, xoff=0.0, filter_dat=True, axin=None, with_elevs=True, layers=None, lw=1, scale_x=1000.0)[source]

Read in raw (or pickled) radar data and do a bunch of processing on it, then plot it up

This will always do two plots, one with a variable surface and one without, though if there is no elevation information the one with a variable surface is not saved.

Parameters:
  • fns (str or iterable of strs) – The file(s) to process
  • rev_list (list of bools, optional) – For each file, do you want to reverse it. Default is no reversal (can also handle true or false to do the same to all files)
  • t_srs (str, optional) – Try to project the output to this coordinate system
  • elev_fn (str, optional) – A .mat file containing fields x, y, z for the surface of the radar
  • gp (str, optional) – A string of comma-separated floats for the gainpoints. These get evenly distributed across depths. They are applied exponentially
  • diel (float, numpy.ndarray, str, or None) – diel can be a 2-column csv with depths and dielectric constants, an array with depths and dielectric constants, a number giving a depth-constant dielectric constant, or None, which leaves things in two-way travel time. If layer_time_increment is None, we always stay in TWTT
  • xoff (float, optional) – offset all the x values by this much (useful for plotting)
  • filter_dat (bool, optional) – hit the data with the defaults of filter_data(). If you want custom values, you should take the data returned and hit it with the custom filter.
  • axin (matplotlib.pyplot.Axis, optional) – An axis to plot on. If with_elevs, then this is the variable surface axis. If not, it is the flat axis.
  • with_elevs (bool, optional) – If True (default), the axis passed in is for the variable surface.
  • layers (list, optional) – List of files containing layers to plot. This is designed to be used in conjunction with the radan tracing software, so the format is a 1-line header with “Dist.(m),Lat,Long,Elev(m),Time,Layer 1 2-Way Time,Layer 2 2-Way Time...”.
  • lw (float, optional) – Line width of layers plotted.
  • scale_x (float, optional) – Divide distance by this amount for x axis. Default is 1000.0 to make polar stereographic plots in km.
Returns:

  • data (nxm numpy.ndarray) – The radar data (in decibels, possibly gained)
  • lldist (mx3 numpy.ndarray) – The lon, lat, and distance for each point. If no GPS data is given, each row is 0, 1, 2...
  • elev (mx1 numpy.ndarray) – Elevations for each trace if kinematic GPS data was input, else None
  • z (nx1 numpy.ndarray) – The depth of each point. Just 0, 1... if no dielectric constant is given
  • diels (lx2 numpy.ndarray) – Depth, dielectric constant pairs.
  • ldict (dict) – A dictionary of layer names and depths. None if no layers are input

pygssi.lib.gssilib.process_radar(fns, rev_list=None, t_srs='sps', elev_fn=None, pickle_fn=None, gp=None, diel=None, xoff=0.0, filter_dat=True, cache=False)[source]

Read in raw (or pickled) radar data and do a bunch of processing on it

Parameters:
  • fns (str or iterable of strs) – The file(s) to process
  • rev_list (list of bools, optional) – For each file, do you want to reverse it. Default is no reversal (can also handle true or false to do the same to all files)
  • t_srs (str, optional) – Try to project the output to this coordinate system
  • elev_fn (str, optional) – A .mat file containing fields x, y, z for the surface of the radar
  • gp (str, optional) – A string of comma-separated floats for the gainpoints. These get evenly distributed across depths. They are applied exponentially
  • diel (float, numpy.ndarray, str, or None) – diel can be a 2-column csv with depths and dielectric constants, an array with depths and dielectric constants, a number giving a depth-constant dielectric constant, or None, which leaves things in two-way travel time. If layer_time_increment is None, we always stay in TWTT
  • xoff (float, optional) – offset all the x values by this much (useful for plotting)
  • filter_dat (bool, optional) – hit the data with the defaults of filter_data(). If you want custom values, you should take the data returned and hit it with the custom filter.
  • cache (bool, optional) – pickle results for fast future use (default False)
Returns:

  • data (nxm numpy.ndarray) – The radar data (in decibels, possibly gained)
  • lldist (mx3 numpy.ndarray) – The lon, lat, and distance for each point. If no GPS data is given, each row is 0, 1, 2...
  • elev (mx1 numpy.ndarray) – Elevations for each trace if kinematic GPS data was input, else None
  • z (nx1 numpy.ndarray) – The depth of each point. Just 0, 1... if no dielectric constant is given
  • diels (lx2 numpy.ndarray) – Depth, dielectric constant pairs.

pygssi.lib.gssilib.zero_surface(data, method='max')[source]

Get rid of returns above the surface

Parameters:
  • data (nxm numpy.ndarray) – The radar data array
  • method (str, optional) – How we detect the surface. Currently, only by the maximum amplitude return
Returns:

  • data ((n-ind)xm numpy.ndarray) – The subset of the data below the surface
  • ind (int) – The index of the surface pixel used as the cutoff