@@ -191,3 +191,158 @@ catalog_id should be assigned to correspond with the total number of catalogs in
191191contains zero forecasted events, you would specify the forecasting using (2). The *catalog_id * should be assigned to
192192correspond with the total number of catalogs in the forecast.
193193
194+
195+ *********************
196+ Alarm-based forecasts
197+ *********************
198+
199+ Alarm-based forecasts represent a different paradigm from traditional rate-based forecasts. Instead of providing
200+ earthquake rates, alarm-based forecasts assign a score (e.g., probability, alarm level, or hazard metric) to each
201+ spatial cell indicating the relative likelihood of earthquake occurrence. These forecasts are evaluated using
202+ Receiver Operating Characteristic (ROC) curves and Molchan diagrams rather than likelihood-based tests.
203+
204+ Alarm-based forecasts are particularly useful for:
205+
206+ 1. Binary classification models (e.g., "high risk" vs "low risk" areas)
207+ 2. Machine learning classifiers
208+ 3. Pattern-based approaches
209+ 4. Any model that produces relative rankings rather than absolute rates
210+
211+ Working with alarm-based forecasts
212+ ##################################
213+
214+ PyCSEP provides the :func: `load_alarm_forecast<csep.load_alarm_forecast> ` function to load alarm-based forecasts
215+ from CSV files. The loaded forecast is returned as a :class: `GriddedForecast<csep.core.forecasts.GriddedForecast> `
216+ object that can be evaluated using ROC curves and Molchan diagrams.
217+
218+ .. autosummary :: csep.load_alarm_forecast
219+
220+ Default file format
221+ -------------------
222+
223+ The default file format for alarm-based forecasts is a comma-separated ASCII file with the following columns::
224+
225+ lon,lat,alarm_score,probability,rate_per_day,magnitude_min,magnitude_target
226+ 165.0,-47.0,0.234,0.199,0.000117,4.0,7.0
227+ 165.1,-47.0,0.156,0.133,0.000078,4.0,7.0
228+
229+ Required columns:
230+
231+ - **lon **: Longitude of cell center
232+ - **lat **: Latitude of cell center
233+ - At least one score column (e.g., **alarm_score **, **probability **, **rate_per_day **)
234+
235+ Optional columns:
236+
237+ - **magnitude_min **: Minimum magnitude threshold (default: 4.0)
238+ - **magnitude_target **: Maximum magnitude threshold (default: magnitude_min + 3.0)
239+ - **start_time **: Forecast start time
240+ - **end_time **: Forecast end time
241+
242+ The spatial grid is automatically inferred from the provided coordinates, making this format
243+ suitable for any geographic region worldwide.
244+
245+ Loading alarm forecasts
246+ -----------------------
247+
248+ Basic usage::
249+
250+ import csep
251+
252+ # Load alarm forecast
253+ forecast = csep.load_alarm_forecast('alarm_forecast.csv', name='MyModel')
254+
255+ # Load with specific score field
256+ forecast = csep.load_alarm_forecast('forecast.csv', score_field='probability')
257+
258+ # Load tab-delimited file
259+ forecast = csep.load_alarm_forecast('forecast.tsv', delimiter='\t')
260+
261+ Evaluating alarm forecasts
262+ --------------------------
263+
264+ Alarm forecasts are evaluated using ROC curves and Molchan diagrams::
265+
266+ from csep.utils import plots
267+
268+ # Load forecast and catalog
269+ forecast = csep.load_alarm_forecast('forecast.csv')
270+ catalog = csep.query_gns(start_time=..., end_time=...)
271+
272+ # ROC curve
273+ ax, auc = plots.plot_ROC_diagram(forecast, catalog, linear=True)
274+
275+ # Molchan diagram
276+ ax, ass, sigma = plots.plot_Molchan_diagram(forecast, catalog, linear=True)
277+
278+ See :ref: `alarm-forecast-evaluation ` for a complete tutorial on evaluating alarm-based forecasts.
279+
280+
281+ Temporal alarm-based forecasts
282+ ##############################
283+
284+ Temporal forecasts are a time-based variant of alarm-based forecasts. Instead of assigning scores to
285+ spatial cells, temporal forecasts assign probability scores to a sequence of time windows (e.g., daily
286+ forecasts). The evaluation is analogous: observations are computed from an earthquake catalog to determine
287+ whether events occurred in each time window, and the forecast probabilities are compared against these
288+ binary observations using ROC curves and Molchan diagrams.
289+
290+ Working with temporal forecasts
291+ ###############################
292+
293+ PyCSEP provides functions to load temporal forecasts and compute observations from catalogs:
294+
295+ .. autosummary ::
296+
297+ csep.load_temporal_forecast
298+ csep.compute_temporal_observations
299+
300+ Default file format
301+ -------------------
302+
303+ Temporal forecasts use a simple two-column CSV format::
304+
305+ time,probability
306+ 1,0.0234
307+ 2,0.0221
308+ 3,0.0228
309+
310+ The **time ** column can contain either:
311+
312+ - Integer indices (1, 2, 3, ...) - requires ``start_time `` and ``time_delta `` parameters
313+ - Datetime strings ('2016-01-01', '2016-01-02', ...) - automatically parsed
314+
315+ Loading and evaluating temporal forecasts
316+ -----------------------------------------
317+
318+ Example workflow::
319+
320+ import csep
321+ from csep.utils import plots
322+
323+ # Load temporal forecast (500 daily windows)
324+ data = csep.load_temporal_forecast('forecast.csv')
325+
326+ # Query observed catalog
327+ catalog = csep.query_gns(
328+ start_time='2016-01-01',
329+ end_time='2017-06-01',
330+ min_magnitude=4.0
331+ )
332+
333+ # Compute observations from catalog
334+ observations = csep.compute_temporal_observations(
335+ catalog,
336+ data['times'],
337+ start_time='2016-01-01', # Map integer times to dates
338+ time_delta='1D', # 1 day per window
339+ magnitude_min=4.0
340+ )
341+
342+ # Evaluate with ROC and Molchan diagrams
343+ ax, auc = plots.plot_temporal_ROC_diagram(
344+ data['probabilities'], observations, name='DailyM4+'
345+ )
346+ ax, ass, sigma = plots.plot_temporal_Molchan_diagram(
347+ data['probabilities'], observations, name='DailyM4+'
348+ )
0 commit comments