Post-Process Options
The postprocess
inset can be used within an experiment configuration file to configure the plotting and reporting functions to be performed after the experiment calculations have been completed. The plotting functions provide a graphic representation of the catalogs, forecasts and evaluation results, whereas the reporting functions assemble these into a human-readable report.
Example postprocess configuration:
name: experiment
time_config: ...
region_config: ...
catalog: ...
model_config: ...
test_config: ...
postprocess:
plot_forecasts:
colormap: magma
basemap: ESRI_terrain
catalog: True
plot_catalog:
basemap: google-satellite
mag_ticks: [5, 6, 7, 8]
markersize: 7
Important
By default, floatCSEP plots the testing catalogs, forecasts and results, summarizing them into a Markdown report. The postprocess configuration aids to customize these options, or to extend them by using custom python scripts.
Plot Forecasts
floatCSEP can quickly plot the spatial rates of used and/or created forecasts. The plot_forecast
command wraps the functionality of the pyCSEP function plot_spatial_dataset()
, used to plot mean rates (in log10
) of both GriddedForecast
and CatalogForecast
.
Most arguments of plot_forecast
mimics those of plot_spatial_dataset()
with some extra additions. These are summarized here:
Important
By default, only the forecast corresponding to the last time window of a model is plotted. To plot all time windows, use all_time_windows: True
Plot Catalogs
Test catalogs are automatically plotted when floatCSEP calculations are finished. Similar to plotting the forecasts, the plot_catalog
command wraps the functionality of the pyCSEP function plot_catalog()
.
Important
By default, only the main test catalog (containing all events within the experiment frame) is plotted. To also plot the test catalogs from each time window separately, use all_time_windows: True
Custom Plotting
Additional plotting functionality can be injected to an experiment by using a custom python script, which is specified within the postprocess
configuration:
Example:
postprocess:
plot_custom: plot_script.py:main
where the script path and a function within should be written as:
plot_custom: {python_script_path}:{function_name}
This option provides a hook for python code to be run after the experiment calculation, giving it read access to attributes from the floatcsep.experiment.Experiment
class. The hook requirements are that the script to be located within the same directory as the configuration file, whereas the function must receive a floatcsep.experiment.Experiment
as unique argument:
Example custom plot script:
from floatcsep import Experiment
def main_function(experiment: Experiment):
timewindows = experiment.timewindows
model = experiment.get_model("pymock")
rates = []
start_times = []
for timewindow in timewindows:
forecast = model.get_forecast(timewindow)
rates.append(forecast.event_counts)
start_times = timewindow[0]
fig, ax = plt.subplots(1, 1)
ax.plot(start_times, rates)
pyplot.savefig("results/pymock_rates.png")
In this way, the plot function can use all the Experiment
attributes/methods to access catalogs, forecasts and test results. Please check the Postprocess API and the Tutorial G - Testing a Time-Dependent Model for an advanced use.
Custom Reporting
In addition to plotting, floatCSEP allows users to generate custom reports in Markdown format. The MarkdownReport class is designed to support the automatic creation of these reports, allowing users to assemble figures, text, and other results in a well-structured manner.
The custom report functionality can be invoked by specifying the following in the postprocess
configuration:
Example:
postprocess:
report: report_script.py:generate_report
This configuration specifies a custom python script with the following format:
report: {python_script_path}:{function_name}
The script must be located within the same directory as the configuration file and the function must receive an instance of floatcsep.experiment.Experiment
instance as its only argument.
Example Custom Report Script::
from floatcsep.utils.reporting import MarkdownReport
def generate_report(experiment):
# Create a MarkdownReport object
report = MarkdownReport(out_name="custom_report.md")
# Add an introduction based on the experiment details
intro = {
'simulation_name': experiment.name,
'forecast_name': 'ETAS',
'origin_time': experiment.start_date,
'evaluation_time': experiment.end_date,
'catalog_source': 'Observed Catalog',
'num_simulations': 10000
}
report.add_introduction(intro)
# Add some text
report.add_text(['This report contains results from the ETAS model experiment.', 'Additional details below.'])
# Add a figure (for example, forecast rates over time)
report.add_figure(
title="Forecast Rates",
relative_filepaths=["results/2020-01-01_2020_01_02/forecasts/etas/forecast_rates.png"],
ncols=1,
caption="Forecasted seismicity rates over time."
)
# Save the report
report.save(save_dir="results")
The MarkdownReport class provides various methods for assembling a report, allowing the user to format the content, insert figures, add tables, and generate text dynamically based on the results of an experiment.
For more advanced usage of report generation, please review the default floatCSEP report in the module floatcsep.postprocess.reporting.generate_report
, an implementation example in the tutorial H - A Time-Dependent Experiment and the Postprocess API for an advance use.
Postprocess API
Here are some basic functionalities from floatCSEP to access catalogs, forecasts and results using python code: