4. Plotting radargrams

Plotting is often essential to data manipulation quality control. Here are some basic examples of plotting and plot rendering methods.

I give examples below, but you will quickly realize that a lot of radar data requires at least a little bit of a touchup before it looks presentable. That’s covered in the next section, Processing radar arrays. Note that some of the examples below will jump ahead to use methods covered in that section.

Note

I apologize to metric system users. matplotlib uses inches and dots per inch (DPI) and for consistency’s sake I chose to adhere to imperial units for plot size :(

4.1. Basic plotting

4.1.1. Plotting with Python

Plotting in Python just means setting plot=7 or another integer, which represents the vertical size in inches. In this simple example, we use the zero=[233] flag to get rid of the part of the radargram from before the direct wave meets the receiver.

from readgssi import readgssi
readgssi.readgssi(infile='DZT__001.DZT', outfile='0a.png', frmt=None,
                  zero=[233], plotting=True, figsize=5)
That's too wide

Whoops! That’s very long and not very helpful on a standard computer monitor. Let’s pretend we’ve read Processing radar arrays and know how to stack arrays horizontally (see Stacking), and let’s also add some gain to this image as well. (Jump to Setting gain)

4.1.2. Plotting with bash

Plotting on the command line is easy. The most basic plotting routine is accessible just by setting the -p flag and specifying a plot height in inches (-p 5). Here, we also use a zero of 233 samples (-Z 233).

readgssi -i DZT__001.DZT -o 0a.png -Z 233 -p 5
That's too wide (bash edition)

Whoops! As you notice in the Python example above, this file is very long, which makes viewing tough on a screen (but may be what you want for figure creation).

Back to top ↑

4.2. Setting gain

Gain is added using the gain=int setting. Let’s set that to 60, since this is a lake profile and radar waves attenuate quickly in water. Here, Python and bash examples are given together.

Note

The gain parameter can also be set to a float value between 0 and 1 in order to reduce gain.

Note

This command sets the stacking parameter to “auto”, which is explained in Stacking.

readgssi.readgssi(infile='DZT__001.DZT', outfile='0b.png', frmt=None,
                  zero=[233], plotting=True, figsize=5, stack='auto',
                  gain=60)
readgssi -i DZT__001.DZT -o 0b.png -Z 233 -p 5 -s auto -g 60
Much better!

Wow, looking much better! Now let’s see if we can display depth units on the Z-axis.

Back to top ↑

4.3. Changing axis units

4.3.1. Z axis

The Z axis can be displayed in three different unit types: samples, time, and distance. By default, it will display in nanoseconds (ns). The possible values for time display are “temporal”, “time”, “nanoseconds”, and “ns”. Setting the z parameter to “samples” sets the axis to display the number of samples (cells) on that axis.

To set the Z-axis to display material depth, we use two separate flags: epsr=80 or -E 80 — which modifies the wave velocity by setting the dielectric to roughly that of water at 20 degrees C — and z='m' or -z m, which sets the z-axis to use those units to calculate profile depths. “m” stands for meters, but you can also specify “meters”, “centimeters”/”cm”, or “millimeters”/”mm” explicitly.

readgssi.readgssi(infile='DZT__001.DZT', outfile='0c.png', frmt=None,
                  zero=[233], plotting=True, figsize=5, stack='auto',
                  gain=60, epsr=80, z='m')
readgssi -i DZT__001.DZT -o 0c.png -Z 233 -p 5 -s auto -g 60 -z m -E 80
With water depth displayed on the Z-axis

If you would like to learn how to remove the horizontal noise in the water column of this image, head to Getting rid of horizontal noise.

4.3.2. X axis

Warning

Changing the X-axis units is simple as well, but beware that distance units will not be accurate unless the file is either distance normalized, or was recorded with a survey wheel or DMI and has a proper samples per meter value set. See Distance normalization for more information.

The X axis can be displayed in time, traces, and distance. By default, it will display in seconds (s). To set this to “traces”, which is calculated from the number of samples on the axis prior to stacking, set the x='traces' or -x traces flag. See the warning above about setting the axis to distance.

Back to top ↑

4.4. Making poster-quality figures

Let’s say you are really enamored with the way that last figure looks, and you now want to create a figure-quality image for a poster. You’ll likely want to drop the title (title=False in Python or -T in bash), and increase the DPI to something that will work well on a plotter (dpi=300 in Python or -D 300 in bash). Pretty simple. Let’s see it in action.

Note

Just for fun in this section (to show off figure creation), we’re using two extra flags that will be explained fully in Getting rid of horizontal noise, as mentioned above.

Note

I use 300 DPI here to keep file size down, but if you are truly aiming for very high print quality (e.g. for a conference poster), you may want to increase to 600 DPI to match the capability of most high-end plotters.

readgssi.readgssi(infile='DZT__001.DZT', outfile='0d.png', frmt=None,
                  zero=[233], plotting=True, figsize=5, stack='auto',
                  gain=60, epsr=80, z='m', title=False, dpi=300,
                  freqmin=70, freqmax=130, bgr=True, win=75)
readgssi -i DZT__001.DZT -o 0d.png -Z 233 -p 5 -s auto -g 60 -z m -E 80 -T -D 300 -r 75 -t 70-130
No plot title and figure-quality DPI

4.4.1. Output formats

readgssi can output to any format supported by the underlying matplotlib base. Usually, this means the following file formats:

  EXTENSION      |     FILE FORMAT
     eps         |  Encapsulated Postscript
     jpg         |  Joint Photographic Experts Group
     jpeg        |  Joint Photographic Experts Group
     pdf         |  Portable Document Format
     pgf         |  PGF code for LaTeX
     png         |  Portable Network Graphics
     ps          |  Postscript
     raw         |  Raw RGBA bitmap
     rgba        |  Raw RGBA bitmap
     svg         |  Scalable Vector Graphics
     svgz        |  Scalable Vector Graphics
     tif         |  Tagged Image File Format
     tiff        |  Tagged Image File Format

Say you’d like to output to the vector format SVG. Many journals prefer this format because the vectors will allow them to typeset the figure and the optimal resolution for both print and digital. Let’s take a look at how we do that.

readgssi.readgssi(infile='DZT__001.DZT', outfile='0d.svg', frmt='svg',
                  zero=[233], plotting=True, figsize=5, stack='auto',
                  gain=60, epsr=80, z='m', title=False, dpi=300,
                  freqmin=70, freqmax=130, bgr=True, win=75)
readgssi -i DZT__001.DZT -o 0d.svg -f svg -Z 233 -p 5 -s auto -g 60 -z m -E 80 -T -D 300 -r 75 -t 70-130

The output file will look identical to the above figure, but will be in SVG format (which not all browsers can handle, so no preview is given here).

Back to top ↑

4.5. Changing the colormap

By default, the colormap is Matplotlib’s “gray”, which is intended to emulate RADAN’s default.

Changing colormaps is as simple as specifying a valid matplotlib.colors.Colormap to use. For a list of valid colormaps, see the Matplotlib documentation. A popular alternative is “seismic”, a diverging blue-white-red colormap used often in sub-bottom seismic surveying.

readgssi.readgssi(infile='DZT__001.DZT', outfile='0e.png', frmt=None,
                  zero=[233], plotting=True, figsize=5, stack='auto',
                  epsr=80, z='m', title=False, dpi=300, gain=60,
                  colormap='seismic',
                  freqmin=70, freqmax=130, bgr=True, win=75)
readgssi -i DZT__001.DZT -o 0e.png -Z 233 -p 5 -s auto -g 60 -z m -E 80 -T -D 300 -r 75 -t 70-130 -c seismic
No plot title and figure-quality DPI

Changed in version 0.0.16: The default colormap was changed to “gray”, because of a previously unnoticed polarity switch in the previous default “Greys”.

Back to top ↑

4.6. Absolute value of gradient

While we’re on the topic of colormaps, it’s worth pointing out that you can tell readgssi to calculate the vertical derivative (the “gradient”) of the profile and display its absolute value using the -A flag. This gradient display is a good way to highlight areas of polarity change regardless of positive or negative values. It is particularly useful for highlighting glacial bed material through ice, for example. Here (in a lake profile) we set both -A (or absval=True in Python) to plot the absolute value of vertical gradient and the colormap to the reverse of the usual one (-c gray_r in bash, colormap='gray_r' in Python) so that darker values indicate steeper gradient.

readgssi.readgssi(infile='DZT__001.DZT', outfile='0e.png', frmt=None,
                  zero=[233], plotting=True, figsize=5, stack='auto',
                  epsr=80, z='m', title=False, dpi=300, gain=100,
                  absval=True, colormap='gray_r',
                  freqmin=70, freqmax=130, bgr=True, win=75)
readgssi -i DZT__001.DZT -o 0f.png -n -Z 233 -p 5 -s auto -g 100 -z m -E 80 -r 75 -t 70-130 -A -c gray_r
Absolute value of gradient (darker = steeper gradient)

This presentation is absolutely critical in certain ice environments where electrical contrast is extremely low. The conversion of each column into gradients rather than +-+ and -+- waves allows users to see where change is happening fastest in each profile (i.e. where the gradient is the steepest–positive or negative). This allows easier viewing of certain types of data where vertical change is difficult to differentiate, such as surveys of cold, relatively uniform Antarctic blue ice.

4.7. Suppressing the Matplotlib window

By default, the matplotlib GUI window will display upon successful execution and saving of the radargram, so that you can modify titles and other plot features. To suppress this behavior, set the noshow=True or -n option.

Because the program will wait for the closure of the Matplotlib window before continuing, this flag is useful for processing folders full of files in bash without user attention.

Note

If plotting is on, readgssi will always save an image, regardless of whether or not the Matplotlib GUI is set to show up. I have found that this behavior makes it easier to save files under the same name but with title and axis label modifications.

This is especially useful when the outfile parameter is not set, and the program uses the readgssi.functions.naming() function to set complex but informative filenames. When saving from the Matplotlib window, click the save button, navigate to the file just saved by the program, then single-click the file name. The save dialog will auto-populate the filename and you can overwrite without the hassle of copying and pasting.

Back to top ↑