This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def contiguous_regions(condition): | |
""" | |
Finds contiguous True regions of an input array. | |
Parameters | |
---------- | |
condition : `np.ndarray` of dtype "bool" or `np.ndarray` and conditional logic statement to produce the boolean array | |
e.g., arr or arr > 5.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def plot_image_fft(img_path, n_labels=7, d=1): | |
''' | |
Plot an image alongside its frequency-domain representation. | |
Parameters | |
---------- | |
img_path: (str) the path to an image | |
n_labels: (int) the number of labels to space out along each axis, default=7 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def contrast_2d(arr, spectrum): | |
""" | |
For an arbitrary 2D spectrogram and a characteristic 1D spectrum, | |
find the magnitude of each Bivector rotor separating them in degrees. | |
Paramters: | |
arr: (`pd.DataFrame`) a 2D (t,f) matrix of spectrogram data with `pd.index.DateTimeIndex`. | |
spectrum: (`np.array`) a vector (f) of sound levels representing a characteristic spectrum. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def cardinal_to_degree(cardinal_direction, bounds=False): | |
''' | |
Convert cardinal direction (i.e., "ESE") to degrees. | |
Output may be returned either as bounds [low, high] or an average bearing. | |
Inputs | |
------ | |
cardinal_direction (str): initials of a cardinal (e.g., "N"), intercardinal (e.g. "NW"), | |
or secondary intercardinal (e.g., "NNW") direction. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def vessel_Lw(octave_f_c, v, v_c, C_B, D, E_num, E_mass, E_mount_spec): | |
''' | |
The Wittekind vessel noise source model | |
Wittekind, D. K.: A simple model for the underwater | |
noise source level of ships, J. Sh. Prod. Des., 30, 1–8, | |
https://doi.org/10.5957/JSPD.30.1.120052, 2014. | |
from equations published in Jalkanen et al. 2018, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def offset_SPL(d_offset, V, speed_MPH, m, r, n_tires, A, Cd=0.8, ρ=1.1, surface_condition='dry'): | |
''' | |
SOUND LEVEL OF A COMBUSTION-ENGINE DRIVEN ROAD VEHICLE | |
PROXIMAL TO THE ROAD SURFACE | |
T. Priede 1970, | |
"...the main criterion which determines [automotive] noise is the operational speed | |
or how short the time interval is within which the operation of one cycle of events |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
np.set_printoptions(suppress=True) | |
import pandas as pd | |
import matplotlib.pyplot as plt | |
def get_third_octave_limits(): | |
''' | |
Scrape limits of one-third octave bands from Engineering Toolbox HTML table. | |
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Rasterize(geodataframe, inras, outras, field): | |
''' | |
Burn a geodataframe to a raster using an existing raster | |
as a template. | |
''' | |
# open the template raster | |
with rasterio.open(inras) as src: | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Re-writing the first steps in a beat-matching algorithm described by Roger Dannenberg: | |
# | |
# https://www.cs.cmu.edu/~rbd/papers/dannenberg-ismir2005-beat-tracking.pdf | |
# | |
# | |
# Particularly helpful is the function `conditional_threshold` which could be applied | |
# more generally in thresholding situations where sections/chunks of a time series have | |
# very different peaking behavior. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Imports | |
import numpy as np | |
import pandas as pd | |
from matplotlib import pyplot as plt, rcParams, rc | |
import matplotlib.dates as mdates | |
import datetime as dt | |
import sys | |
import os | |
# You'll need to clone two Github repositories to use this code |
NewerOlder