# Basic R Studio and ggplot2 syntax

While I continue to try to get Sage to underpin the analysis stages of my open scientific workflow, a LOT of my colleagues and cohort use R these days.  So this week I installed R Studio and ggplot2 for OSX.

Here are notes from my first foray into plotting histograms.

First I took some date/time data in a Libre Office spreadsheet, converted it to decimal hour of day to keep things simple, renamed column headers to be simple single words (e.g. underscores to connect words), and then saved the active sheet as a tab-delimited .csv file (in this case named 2012-human.csv).

> lk2012<-read.table("/Users/scott/Documents/beamreach/research/pubs-in-progress/02a - ship SL/r-scott/2012-human.csv",header=T,sep="\t")
> png("/Users/scott/Documents/beamreach/research/pubs-in-progress/02a - ship SL/r-scott/lk-human-hr-hists.png")
> par(mfrow= c(3, 1))
> hist(lk2011$hour,breaks=24) > hist(lk2012$hour,breaks=24)
> hist(lk2013\$hour,breaks=24)
> dev.off()


That reads the .csv file into lk2012, then prints this 3 panel plot of hour histograms —

Histograms of the hours in which reports were made to the Salish Sea hydrophone network’s Google-spreadsheet-based observation log in 2011, 2012, & 2013.

More on ggplot2 as I learn it… but know that it is making most of the plots for our current paper in progress regarding underwater noise from Salish Sea ships.

# High frequency noise in the Salish Sea

After registering for ORCID and figshare, I worked with Val today in Seattle on trying to understand some of the subtleties in our ship and background quantile curves.  In particular, there are some peaks — both broad and narrow — in the 75th and 95th % quantiles from ~20-96kHz that may represent signals from sources other than commercial ships.  If they are being generated by “outlier” ships, then we need to put some effort into understanding which ships are the source(s) and what mechanisms may be generating the sound.

Here’s a grab of the HF part of Val’s preliminary figure (thanks to R and ggplot2) —

HF ship (blue) and background (black) 5,25,50,75,95% quantiles

There is a clear spike at 50 kHz that Jason thinks it is coming from depth sounders and/or fish-finders mounted on recreational fishing boats that happen to be nearby when a ship passes our study site and get recorded.  Though our ship recordings are only 2 seconds long, it’s possible that a nearby fishing boat could generate a ping during that interval because most sounders and finders have ping rates of 1-5 pulses per second.  The alternative is that depth sounders on the commercial ships are responsible for this peak.

To test those two hypotheses, Val wrote an R script that goes through our data set and looks for strong cross-correlations between a template (a power spectrum with a good strong peak at 50 kHz) and the rest of the ship recordings.  We looked through the resulting graphs for high correlation coefficients and visual similarity between the spectra.  Noting the month and time of day of these spectra, we found that all but one occurred during daylight hours and during the peak of the bottomfish & salmon fishing seasons (March-October).

Histogram of month of year in which ship spectra contain a prominent peak at 50 kHz.

Histogram of time of day at which ship spectra contain a prominent peak at 50 kHz.

## Recreational fishing depth sounders and fish-finders?

The bulk of these recordings were made during daylight hours.  Even the sample taken in the very early morning (5:50 a.m.) occurred during daylight; sunrise on that August morning was at 5:38.  One possible exception is the recording made at 18:50; it occurred on November 1, 2012, when sunset was at 17:51…

Because of the prevalence of daylight recordings, we presume that the more likely source of most of the 50 kHz pings is depth sounders or fish-finders mounted on recreational fishing vessels.  These boats are often observed drifting or trolling off of the west side of San Juan Island, particularly during the summer months.  They frequently operate very near shore, putting them directly over or within a 500 meter radius of our hydrophone.

## Commercial ship depth sounders

The one nighttime spectrum is also anomalous seasonally, occurring in January when odds are very good no one is out fishing in Haro Strait at 9:20 p.m.  Although we’re finding a great variety of pulse widths and rates among the spectra with 50 kHz peaks, this one stands out as having a clear first arrival and subsequent reverberant bottom-bounces.  It also has a slow pulse rate: about 1 pulse every 1.5 seconds, or 0.68 pulses/sec.

MMSI 636091891 waveform and spectrogram from 1/1/12 at 21:21 showing 50 kHz pings.

Waveform and spectrogram showing 50 kHz ping sequence.

The TDOA is 0.1 seconds which is a path length difference of about 150m.  That’s the approximate depth of Haro Strait midway between the northbound shipping lane and Lime Kiln.  So in this case, the pings may indeed have come from the ship.  Here’s the sound file in case you want to load it into Audacity and listen to the pings; try playback at 0.01x – 0.13x speed.  This ship is a 334 m container ship named the Vancouver Express.

Since Val included in the cross-correlation assessment only ships that had transited our study site at least 10 times, the other strong evidence that pings are made by a ship rather than a nearby boat would be repetitions of similar ping sequences each time the ship passes.  This assumes that it is unlikely that the same type of recreational fishing sounder would be present during each transit of a particular cargo ship.  On the contrary, if the ship’s depth sounder is heard on one transit, we ought to detect that same sounder on other transits of the same ship.

Vancouver Express 636091891 transit on 2-11-12 at 11:50

Vancouver Express 636091891 transit on 9-7-11 at 6:47

Below is another fascinating example of ship-generated noise, including 50 and 79 kHz pulses that may have come from the ship, or some other vessel(s).

372649000 7-8-12 showing 79 & 50 kHz pings and cavitation noise to 96 kHz.

Next will come the tough part: excluding from our ship noise data set the recordings that have spectra contaminated by fishing boat pingers, system noise, and other non-ship sources…  Thankfully, Val is a programming wizard so this won’t take long!