gcpy.kpp.kppsa_utils
Utility functions for visualizing output from the KPP-Standalone box model.
Functions
|
Returns a list of KPP-Standalone log files matching a search pattern. |
|
Returns a list of unique observation site names from KPP-Standalone output, ordered from north to south. |
|
Plots a single page of Ref vs. |
|
Plots initial and final species concentrations as vertical profiles at a single observation site. |
|
Returns a DataFrame and plot title for a given species and observation site. |
|
Reads multiple KPP-Standalone log files and concatenates them into a single pandas DataFrame. |
|
Reads a single KPP-Standalone log file in CSV format into a pandas DataFrame. |
- gcpy.kpp.kppsa_utils.kppsa_get_file_list(input_dir, pattern='')[source]
Returns a list of KPP-Standalone log files matching a search pattern.
- Parameters:
- Returns:
file_list – List of file paths matching the search criteria.
- Return type:
- gcpy.kpp.kppsa_utils.kppsa_read_one_csv_file(file_name)[source]
Reads a single KPP-Standalone log file in CSV format into a pandas DataFrame.
Metadata fields (location, timestamp, longitude, latitude, vertical level, and pressure) are extracted from the file header and appended as additional columns.
- Parameters:
file_name (
str) – Path to the CSV-format KPP-Standalone log file to be read.- Returns:
dframe – DataFrame containing species concentrations and associated metadata extracted from the file header. Added columns are:
Location,DateTime,Longitude,Latitude,Level, andPressure.- Return type:
- gcpy.kpp.kppsa_utils.kppsa_read_csv_files(file_list)[source]
Reads multiple KPP-Standalone log files and concatenates them into a single pandas DataFrame.
- gcpy.kpp.kppsa_utils.kppsa_prepare_site_data(dframe, site_name, species)[source]
Returns a DataFrame and plot title for a given species and observation site.
Data is filtered to include only observations at or below 500 hPa (surface to lower stratosphere) and sorted by descending pressure.
- Parameters:
dframe (
pandas.DataFrame) – KPP-Standalone output data as returned bykppsa_read_csv_files().site_name (
str) – Name of the observation site to extract data for.species (
str) – Name of the species to extract data for.
- Returns:
site_data (
pandas.DataFrameorNone) – DataFrame filtered to the given site and species, sorted by descending pressure, and limited to pressures >= 500 hPa. ReturnsNoneifdframeisNone.site_title (
strorNone) – Plot title string including the site name, cardinal coordinates, and timestamp (e.g."Mace Head (53°N,10°W) at 2019-07-01T00:00"). ReturnsNoneifdframeisNone.
- gcpy.kpp.kppsa_utils.kppsa_plot_single_site(fig, rows_per_page, cols_per_page, subplot_index, subplot_title, ref_data, ref_label, dev_data, dev_label, species, font_scale)[source]
Plots initial and final species concentrations as vertical profiles at a single observation site.
- Parameters:
fig (
matplotlib.figure.Figure) – Figure object into which the subplot will be added.rows_per_page (
int) – Number of subplot rows on the page.cols_per_page (
int) – Number of subplot columns on the page.subplot_index (
int) – Zero-based index of this subplot within the page grid.subplot_title (
str) – Title string displayed above this subplot.ref_data (
pandas.DataFrame) – KPP-Standalone output for theRefmodel version at this site, as returned bykppsa_prepare_site_data().ref_label (
str) – Legend label for theRefmodel final concentration.dev_data (
pandas.DataFrameorNone) – KPP-Standalone output for theDevmodel version at this site. PassNoneto omit the Dev profile.dev_label (
strorNone) – Legend label for theDevmodel final concentration. Ignored ifdev_dataisNone.species (
str) – Name of the species being plotted, used for axis labels and error checking.font_scale (
float) – Multiplicative scale factor applied to all font sizes, allowing text to be enlarged or reduced uniformly.
- Raises:
ValueError – If
speciesis not found inref_data.ValueError – If
dev_datais notNoneandspeciesis not found indev_data.
Notes
The Y-axis (pressure) is plotted from 1020 hPa at the bottom to 500 hPa at the top. The Y-axis label is only applied to leftmost panels (
subplot_indexis 0 or a multiple ofcols_per_page).
- gcpy.kpp.kppsa_utils.kppsa_plot_one_page(pdf, site_names, ref_dframe, ref_label, dev_dframe, dev_label, species='O3', rows_per_page=3, cols_per_page=3, font_scale=1.0)[source]
Plots a single page of Ref vs. Dev vertical profiles for a list of observation sites and saves it to a PDF file.
- Parameters:
pdf (
matplotlib.backends.backend_pdf.PdfPages) – Open PDF file object to which the page will be saved.site_names (
listofstr) – Names of the observation sites to plot on this page.ref_dframe (
pandas.DataFrame) – KPP-Standalone output for theRefmodel version, as returned bykppsa_read_csv_files().ref_label (
str) – Legend label for theRefmodel data.dev_dframe (
pandas.DataFrame) – KPP-Standalone output for theDevmodel version, as returned bykppsa_read_csv_files().dev_label (
str) – Legend label for theDevmodel data.species (
str, optional) – Name of the species to plot. Default:"O3"rows_per_page (
int, optional) – Number of subplot rows on the page. Default:3cols_per_page (
int, optional) – Number of subplot columns on the page. Default:3font_scale (
float, optional) – Multiplicative scale factor applied to all font sizes. Default:1.0
Notes
The page is landscape-oriented (11” × 8”). A shared legend is placed at the top of the page. Vertical spacing between subplots is adjusted automatically.
- gcpy.kpp.kppsa_utils.kppsa_get_unique_site_names(dframe)[source]
Returns a list of unique observation site names from KPP-Standalone output, ordered from north to south.
- Parameters:
dframe (
pandas.DataFrame) – KPP-Standalone output data as returned bykppsa_read_csv_files().- Returns:
unique_site_names – Unique site names sorted by descending latitude (north to south).
- Return type: