.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_2_python.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_plot_2_python.py: From Python =========== The run of the command-line example from a script: one call, then the numbers from the record. ``DB`` is the Green's-function database directory, provided by the operator. .. GENERATED FROM PYTHON SOURCE LINES 11-18 .. code-block:: Python from pathlib import Path from xcap3d import Result, run_event DB = Path("DB") OUT = Path("xcap3d-out") .. GENERATED FROM PYTHON SOURCE LINES 19-26 The run ------- ``run_event`` takes the options of ``xcap3d run``: it downloads the event from SCEDC, removes the instrument responses, inverts and writes ``result.json`` and, with ``write_report``, the report. It returns the record, a dictionary with the contents of ``result.json``; printing it gives the solution. .. GENERATED FROM PYTHON SOURCE LINES 26-29 .. code-block:: Python result = run_event("38695658", DB, out=OUT, mt="full", refine=True, write_report=True) print(result) .. GENERATED FROM PYTHON SOURCE LINES 30-35 The numbers ----------- The shortcuts cover the solution; everything else is in the dictionary: the depth scan, every station with its weights and fits, the QC record, the database release and the inputs with their checksums. .. GENERATED FROM PYTHON SOURCE LINES 35-44 .. code-block:: Python print(result.strike, result.dip, result.rake, result.depth, result.mw, result.vr) print( result["solution"]["n_stations"], "stations,", result["solution"]["n_components"], "components" ) nd = result["non_dc"] print(f"ISO {nd['iso_pct']:.1f} % CLVD {nd['clvd_pct']:.1f} % DC {nd['dc_pct']:.1f} %") for row in result["depth_scan"][:3]: print(row) .. GENERATED FROM PYTHON SOURCE LINES 45-49 A record on disk ---------------- ``Result.from_file`` reads a ``result.json`` written earlier, by a script or by the command line. .. GENERATED FROM PYTHON SOURCE LINES 49-51 .. code-block:: Python again = Result.from_file(OUT / "38695658" / "result.json") print(again) .. _sphx_glr_download_auto_examples_plot_2_python.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_2_python.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_2_python.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_2_python.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_