API Reference¶
- postprocessing_seismo_lib.utils.update_dataretrieval_input(file_path, output_file_path, Host, Method, Port, Window, SavePath=None, Url=None, directory=None)[source]¶
Loads a JSON file, updates the ‘RetrieveParameters’ section with provided values, and writes the updated JSON to a new output file.
Mandatory parameters (‘Host’, ‘Method’, ‘Port’, ‘Window’) are always added or overwritten. Optional parameters (‘SavePath’, ‘Url’, ‘directory’) are added only if provided, except for ‘SavePath’, which is always included (as an empty string if not provided).
- Parameters:
file_path (str) – Path to the existing JSON file to load and update.
output_file_path (str) – Path where the updated JSON file should be saved.
Host (str) – Host address to include in ‘RetrieveParameters’.
Method (str) – HTTP method (e.g., ‘GET’, ‘POST’) to include in ‘RetrieveParameters’.
Port (int) – Port number to include in ‘RetrieveParameters’.
Window (str) – Identifier for the window or context.
SavePath (str, optional) – Path where results should be saved. Defaults to an empty string if not provided.
Url (str, optional) – URL to include in ‘RetrieveParameters’.
directory (str, optional) – Directory path to include in ‘RetrieveParameters’.
- Returns:
The updated JSON content with modified ‘RetrieveParameters’.
- Return type:
dict
- Raises:
FileNotFoundError – If the specified JSON file does not exist.
json.JSONDecodeError – If the file content is not valid JSON.
IOError – If there is an error saving the output file.
- postprocessing_seismo_lib.utils.convert_file_to_json(input_file: str, output_file: str, id: str, event_file: str | None = None, pick_file: str | None = None, error_log_file: str | None = None)[source]¶
Auto-detect format (csv, quakeml, arcout) and convert to standard JSON response.
- Parameters:
input_file (str) – Main input file (for quakeml or arcout).
output_file (str) – Output JSON filename.
id (str) – Event ID to use in the JSON.
event_file (str) – (Optional) For CSV: Path to events CSV file.
pick_file (str) – (Optional) For CSV: Path to picks CSV file.
error_log_file (str) – Optional path to write traceback if an error occurs.
- postprocessing_seismo_lib.utils.build_message(body, id_str, format_str)[source]¶
Constructs the full JSON message given body content, ID, and format.
- postprocessing_seismo_lib.utils.validate_pick_data(pick_data, schema)[source]¶
Validates pick data list against a specified schema.
- postprocessing_seismo_lib.utils.validate_output_structure(wrapped_data)[source]¶
Validate the final output structure using output schema.
- postprocessing_seismo_lib.utils.wrap_data(input_file_path, output_file_path, evid='stubvalue', module='associator', mode='hypoPN', testType='local', logging='False')[source]¶
Load, validate, wrap, and export pick data for use in associator or pickfilter modules.
This function reads a list of pick dictionaries from a JSON file, validates them against a schema, wraps the data into a module-specific JSON structure, validates the output, and writes it to a new file.
- Parameters:
input_file_path (str) – Path to the input JSON file containing pick data.
output_file_path (str) – Path to write the validated and wrapped output JSON.
evid (str) – Event ID used in the output structure (e.g., file name or evid key).
module (str, optional) – Mode to wrap the data. Must be either: - ‘associator’: wraps with an “evid” key. - ‘pickfilter’: wraps with a “pickFile” key. Defaults to ‘associator’.
- Raises:
ValueError – If the module is not ‘associator’ or ‘pickfilter’.
ValueError – If input data fails validation.
Exception – For any other unexpected errors during processing.
- Side Effects:
Logs errors to a file named ‘wrap_data_errors.log’.
Prints validation or error status to the console.
Example
wrap_data(“input.json”, “output.json”, “event_123”, module=”pickfilter”) wrap_data(“input.json”, “output.json”, “event_456”, module=”associator”)
- postprocessing_seismo_lib.utils.extract_body_from_file(filepath)[source]¶
Extracts and returns the ‘body’ field from a JSON file.
This function reads a JSON file from the specified filepath, parses its contents, and returns the value associated with the top-level “body” key, if present.
- Parameters:
filepath (str) – Path to the JSON file to be read.
- Returns:
The value of the “body” field in the JSON file, which may be a dictionary, list, string, number, or None depending on the file contents. If the “body” key is not present, returns None.
- Return type:
Any
- Raises:
FileNotFoundError – If the specified file does not exist.
json.JSONDecodeError – If the file contents are not valid JSON.
Exception – For other unexpected I/O or parsing errors.
Example
Given a file example.json with contents: {
- “body”: {
“message”: “Hello, world!”
}, “status”: “ok”
}
Calling extract_body_from_file(“example.json”) returns: {
“message”: “Hello, world!”
}