Skip to content

Commit

Permalink
add --cmlim option to plot script
Browse files Browse the repository at this point in the history
  • Loading branch information
carueda committed Jan 24, 2024
1 parent fe128e0 commit 31080ca
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
9 changes: 9 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,15 @@ main *args="":
plot *nc_files:
python src/plot.py {{nc_files}}

# Plot NRS11 datasets
plot-nrs11 *netcdfs='noaa-passive-bioacoustic_nrs_11_2019-2021/OUTPUT/NRS11_20200101.nc':
python src/plot.py \
--ylim 10 2000 \
--cmlim 64 108 \
--latlon 37.88 -123.44 \
--title "NOAA Ocean Noise Reference Station NRS11, Cordell Bank National Marine Sanctuary: 37.88°N, 123.44°W" \
{{netcdfs}}

##############
# development:

Expand Down
11 changes: 11 additions & 0 deletions src/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
DEFAULT_LAT_LON_FOR_SOLPOS,
DEFAULT_TITLE,
DEFAULT_YLIM,
DEFAULT_CMLIM,
)


Expand Down Expand Up @@ -39,6 +40,15 @@ def parse_arguments():
help="Limits for the y-axis. Default: %(default)s",
)

parser.add_argument(
"--cmlim",
type=int,
nargs=2,
default=DEFAULT_CMLIM,
metavar=("vmin", "vmax"),
help="Parameters passed to pcolormesh. Default: %(default)s",
)

parser.add_argument(
"--dpi",
type=float,
Expand Down Expand Up @@ -82,6 +92,7 @@ def main(opts):
lat_lon_for_solpos=opts.latlon,
title=opts.title,
ylim=opts.ylim,
cmlim=opts.cmlim,
dpi=opts.dpi,
jpeg_filename=jpeg_filename,
show=show,
Expand Down
2 changes: 2 additions & 0 deletions src/plot_const.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@

DEFAULT_YLIM = (10, 100000)

DEFAULT_CMLIM = (32, 108)

DEFAULT_DPI = 200
6 changes: 5 additions & 1 deletion src/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
DEFAULT_LAT_LON_FOR_SOLPOS,
DEFAULT_TITLE,
DEFAULT_YLIM,
DEFAULT_CMLIM,
)


Expand All @@ -21,6 +22,7 @@ def plot_dataset_summary(
lat_lon_for_solpos: tuple[float, float] = DEFAULT_LAT_LON_FOR_SOLPOS,
title: str = DEFAULT_TITLE,
ylim: tuple[int, int] = DEFAULT_YLIM,
cmlim: tuple[int, int] = DEFAULT_CMLIM,
dpi: int = DEFAULT_DPI,
jpeg_filename: Optional[str] = None,
show: bool = False,
Expand All @@ -32,6 +34,7 @@ def plot_dataset_summary(
:param lat_lon_for_solpos: Lat/Lon for solar position calculation.
:param title: Title for the plot.
:param ylim: Limits for the y-axis.
:param cmlim: Limits passed to pcolormesh.
:param dpi: DPI to use for the plot.
:param jpeg_filename: If given, filename to save the plot to.
:param show: Whether to show the plot.
Expand Down Expand Up @@ -90,8 +93,9 @@ def plot_dataset_summary(

# Spectrogram
ax0 = fig.add_subplot(spec[2])
vmin, vmax = cmlim
sg = plt.pcolormesh(
ds.time, ds.frequency, da, shading="nearest", cmap="rainbow", vmin=32, vmax=108
ds.time, ds.frequency, da, shading="nearest", cmap="rainbow", vmin=vmin, vmax=vmax
)
plt.yscale("log")
plt.ylim(list(ylim))
Expand Down

0 comments on commit 31080ca

Please sign in to comment.