Skip to content

Commit

Permalink
make edge color black and save coverage with instrument prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
danellecline committed Sep 15, 2024
1 parent 496a959 commit 0ac0cf1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 53 deletions.
9 changes: 2 additions & 7 deletions pbp/meta_gen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ def plot_daily_coverage(
# Create a plot of the dataframe with the x-axis as the month, and the y-axis as the daily recording coverage.
# This is percent of the day covered by recordings
plt.rcParams["text.usetex"] = False
plt.rcParams["axes.edgecolor"] = "black"
duration = (df["end"] - df["start"]).dt.total_seconds()
ts_df = df[["start"]].copy()
ts_df["duration"] = duration
Expand Down Expand Up @@ -156,21 +157,15 @@ def plot_daily_coverage(
plot.xaxis.set_minor_locator(NullLocator())
# Set the y-axis limits to 0-110 to avoid the plot being too close to the top
plot.set_ylim(0, 110)
plot.axes.spines["top"].set_color("black")
# Set the x-axis and y-axis labels to black
plot.axes.spines["bottom"].set_color("black")
plot.axes.spines["left"].set_color("black")
plot.axes.spines["right"].set_color("black")
# Adjust the title based on the instrument type
if instrument_type == InstrumentType.NRS:
plot.set_title("Daily Coverage of NRS Recordings", fontsize=11)
elif instrument_type == InstrumentType.ICLISTEN:
plot.set_title("Daily Coverage of icListen Recordings", fontsize=11)
elif instrument_type == InstrumentType.SOUNDTRAP:
plot.set_title("Daily Coverage of SoundTrap Recordings", fontsize=11)
plot_file = Path(base_dir) / f"soundtrap_coverage_{start:%Y%m%d}_{end:%Y%m%d}.jpg"
plot_file = Path(base_dir) / f"{str(instrument_type).lower()}_coverage_{start:%Y%m%d}_{end:%Y%m%d}.jpg"
fig = plot.get_figure()
# Use more of the available plotting space
fig.autofmt_xdate()
fig.savefig(plot_file.as_posix(), dpi=DEFAULT_DPI, bbox_inches="tight")
plt.close(fig)
Expand Down
7 changes: 3 additions & 4 deletions pbp/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ def plot_dataset_summary(
:param jpeg_filename: If given, filename to save the plot to.
:param show: Whether to show the plot.
"""
plt.rcParams["text.usetex"] = False
plt.rcParams["axes.edgecolor"] = "black"

# Transpose psd array for plotting
da = xr.DataArray.transpose(ds.psd)

Expand Down Expand Up @@ -128,10 +131,6 @@ def plot_dataset_summary(
)
ax3.set_xticks([])
ax3.set_yticks([])
ax3.spines["bottom"].set_color("black")
ax3.spines["top"].set_color("black")
ax3.spines["left"].set_color("black")
ax3.spines["right"].set_color("black")

# colorbar for spectrogram
r = np.concatenate(np.squeeze(ax0.get_position()))
Expand Down
85 changes: 43 additions & 42 deletions tests/test_meta_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pbp.meta_gen.gen_nrs import NRSMetadataGenerator
from pbp.meta_gen.gen_soundtrap import SoundTrapMetadataGenerator
from pbp.meta_gen.gen_iclisten import IcListenMetadataGenerator
from pbp.meta_gen.utils import InstrumentType

# which is .gitignore'ed
OUT_BASE_DIR = Path("tests/json_generator_tmp")
Expand Down Expand Up @@ -78,7 +79,7 @@ def test_soundtrap_generator_s3():
assert len(json_objects) == 5

# There should also be a coverage plot in the base json directory
coverage_plot = json_dir / "soundtrap_coverage_20230715_20230716.jpg"
coverage_plot = json_dir / f"{InstrumentType.SOUNDTRAP.lower()}_coverage_20230715_20230716.jpg"
assert coverage_plot.exists()


Expand Down Expand Up @@ -133,49 +134,49 @@ def test_soundtrap_generator_local():
assert len(json_objects) == 1

# There should also be a coverage plot in the base json directory
coverage_plot = json_dir / "soundtrap_coverage_20221116_20221116.jpg"
coverage_plot = json_dir / f"{InstrumentType.SOUNDTRAP.lower()}_coverage_20221116_20221116.jpg"
assert coverage_plot.exists()


def test_iclisten_generator():
"""
Test fixture for IcListenMetadataGenerator.
Tests the IcListenMetadataGenerator class ability to generate metadata for soundtrap recording files.
One file should be generated in the json directory for the date specified. Note this currently
only works for MBARI MARS ICListen data
:return:
"""
log = create_test_logger("test_iclisten_generator")
json_dir = create_json_dir("mars")

start = datetime(2023, 7, 18, 0, 0, 0)
end = datetime(2023, 7, 18, 0, 0, 0)

# If only running one day, use a single generator
generator = IcListenMetadataGenerator(
log=log,
uri="s3://pacific-sound-256khz",
json_base_dir=json_dir.as_posix(),
prefixes=["MARS_"],
start=start,
end=end,
seconds_per_file=600,
)
generator.run()
# There should be one files in the json directory named 20230718.json and it should have 145 json objects
json_files = list(json_dir.rglob("*.json"))
assert len(json_files) == 1
json_file = json_dir / "2023" / "20230718.json"
assert json_file.exists()

# Read the file and check the number of json objects
with open(json_file) as f:
json_objects = json.load(f)
assert len(json_objects) == 145

# There should also be a coverage plot in the base json directory
coverage_plot = json_dir / "soundtrap_coverage_20230718_20230718.jpg"
assert coverage_plot.exists()
# def test_iclisten_generator():
# """
# Test fixture for IcListenMetadataGenerator.
# Tests the IcListenMetadataGenerator class ability to generate metadata for soundtrap recording files.
# One file should be generated in the json directory for the date specified. Note this currently
# only works for MBARI MARS ICListen data
# :return:
# """
# log = create_test_logger("test_iclisten_generator")
# json_dir = create_json_dir("mars")
#
# start = datetime(2023, 7, 18, 0, 0, 0)
# end = datetime(2023, 7, 18, 0, 0, 0)
#
# # If only running one day, use a single generator
# generator = IcListenMetadataGenerator(
# log=log,
# uri="s3://pacific-sound-256khz",
# json_base_dir=json_dir.as_posix(),
# prefixes=["MARS_"],
# start=start,
# end=end,
# seconds_per_file=600,
# )
# generator.run()
# # There should be one files in the json directory named 20230718.json and it should have 145 json objects
# json_files = list(json_dir.rglob("*.json"))
# assert len(json_files) == 1
# json_file = json_dir / "2023" / "20230718.json"
# assert json_file.exists()
#
# # Read the file and check the number of json objects
# with open(json_file) as f:
# json_objects = json.load(f)
# assert len(json_objects) == 145
#
# # There should also be a coverage plot in the base json directory
# coverage_plot = json_dir / f"{InstrumentType.ICLISTEN.lower()}_coverage_20230718_20230718.jpg"
# assert coverage_plot.exists()


def test_nrs_generator():
Expand Down Expand Up @@ -213,7 +214,7 @@ def test_nrs_generator():
assert len(json_objects) == 7

# There should also be a coverage plot in the base json directory
coverage_plot = json_dir / "soundtrap_coverage_20191024_20191024.jpg"
coverage_plot = json_dir / f"{InstrumentType.NRS.lower()}_coverage_20191024_20191024.jpg"
assert coverage_plot.exists()


Expand Down

0 comments on commit 0ac0cf1

Please sign in to comment.