pycnet.plot package
Module contents
Defines functions for visualizing apparent detections.
Functions:
- expandDates
Create a list encompassing all dates that fall between the first and last dates in a DataFrame’s Date field to fill in missing values.
- expandDetSummaryDF
Create an ‘expanded’ version of the detection summary DataFrame that includes all possible combinations of site, station, and date for all thresholds.
- formatDateTickLabels
Format a list of dates to be displayed on the x-axis of a plot of apparent detections.
- formatPlotData
Reshape and format a table of apparent detections for easier plotting.
- parseDetPlotArgs
Define command-line options for the ‘plot_dets’ console script.
- plotDetections
Create a plot of apparent detections of one or more classes by station and date.
- plotFromFile
Plot apparent detections from a file. Target for the plot_dets console script.
- pycnet.plot.expandDates(df, date_format='%Y-%m-%d')
Get a list of dates that should appear in a DataFrame.
- Parameters:
df (Pandas.DataFrame) – A DataFrame containing a Date column.
date_format (str) – Format used by Datetime.Datetime.strptime() to parse values in the Date column.
- Returns:
List of all dates between the earliest and latest dates appearing in the Date field.
- Return type:
list
- pycnet.plot.expandDetSummaryDF(df)
Expand DataFrame to include all combinations of site, stn, date.
- Parameters:
df (Pandas.DataFrame) – A DataFrame containing fields called Area, Site, Stn, and Date.
- Returns:
DataFrame that includes all possible combinations of Area, Site, Stn, and Date for all thresholds, with missing values filled in with 0s.
- Return type:
Pandas.DataFrame
- pycnet.plot.formatDateTickLabels(df, interval=7, fill_gaps=True)
Format the date (x-axis) tick labels for a plot of detections.
- Parameters:
df (Pandas.DataFrame) – Dataframe listing apparent detections for each combination of station, date, detection threshold, and target class, as created by pycnet.review.summarizeDetections.
interval (int) – Factor by which to thin date labels for display on the x-axis (i.e., only label every nth date).
fill_gaps (bool) – Include blank placeholder strings as labels for dates that are not displayed.
- Returns:
A list of strings representing dates in MM/DD format, with empty placeholder strings if timescale==”daily”.
- Return type:
list
- pycnet.plot.formatPlotData(df, criteria)
Filter and reshape a table of apparent detections for plotting.
Meant to produce a dataframe in “long” format listing apparent detections for a set of target classes at a corresponding set of detection thresholds, which can then be plotted using seaborn.
- Parameters:
df (Pandas.DataFrame) – A wide-format DataFrame listing apparent detections for all PNW-Cnet target classes by station and date across a range of detection thresholds.
criteria (dict) – A dictionary mapping detection thresholds to target classes.
- Returns:
A long-format DataFrame listing apparent detections for just the desired target classes at the detection threshold specified for each class.
- Return type:
Pandas.DataFrame
- pycnet.plot.parseDetPlotArgs()
Define command-line options for the ‘plot_dets’ console script.
- Parameters:
Nothing (reads arguments from stdin) –
- Returns:
An argparse.Namespace object containing command-line arguments in an accessible form.
- Return type:
argparse.Namespace
- pycnet.plot.plotDetections(df, criteria, timescale='weekly', show_plot=True, dest_file=None)
Plot apparent detections by station for one or more classes.
- Parameters:
df (Pandas.DataFrame) – Dataframe listing apparent detections for each combination of station, date, detection threshold, and target class, as created by pycnet.review.summarizeDetections.
criteria (dict) – A dictionary of detection thresholds indexed by class codes.
timescale (str) – Either “daily” or “weekly”. Temporal scale at which to summarize detections for the chosen class.
show_plot (bool) – Open a plot window showing the resulting plot.
dest_file (str) – Path where the plot will be saved as an image file, or None.
- Returns:
Nothing.
- pycnet.plot.plotFromFile()
Plot detections from a detection summary file.
Arguments are read from the command line via the parseDetPlotArgs function defined below.
- Returns:
Nothing.