Skip to content

Commit

Permalink
added daily coverage plot for NRS
Browse files Browse the repository at this point in the history
  • Loading branch information
danellecline committed Jul 12, 2024
1 parent 24851cc commit e9f6371
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions pbp/json_generator/gen_nrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,28 @@ def parse_filename(f: str) -> datetime:
except Exception as ex:
self.log.exception(str(ex))

# Create a plot of the dataframe with the x axis as the month, and the y axis as the daily recording coverage, which is percent
# of the day covered by recordings
self.df["duration"] = (self.df["end"] - self.df["start"]).dt.total_seconds()
ts_df = self.df[["start", "duration"]].copy()
ts_df.set_index('start', inplace=True)
daily_sum_df = ts_df.resample('D').sum()
daily_sum_df["coverage"] = 100*daily_sum_df["duration"] / 86400
daily_sum_df["coverage"] = daily_sum_df["coverage"].round() # round to nearest integer
plot = daily_sum_df["coverage"].plot()
plot.set_ylabel("Daily Coverage (%)")
plot.set_xlabel("Date")
# Angle the x-axis labels for better readability and force them to be in the format YYYY-MM-DD
plot.set_xticklabels(plot.get_xticklabels(), rotation=45, horizontalalignment='right')
plot.set_xticklabels([x.strftime('%Y-%m-%d') for x in daily_sum_df.index])
plot.set_title("Daily Coverage of SoundTrap Recordings")
plot_file = Path(self.json_base_dir) / f"soundtrap_coverage_{self.start:%Y%m%d}_{self.end:%Y%m%d}.png"
dpi = 300
fig = plot.get_figure()
fig.set_size_inches(10, 5)
fig.set_dpi(dpi)
fig.savefig(plot_file.as_posix(), bbox_inches="tight")
self.log.info(f"Saved plot to {plot_file}")

if __name__ == "__main__":
from pbp.logging_helper import create_logger
Expand Down

0 comments on commit e9f6371

Please sign in to comment.