# Derivative Export In a `Scattering` {term}`project`, solver derivative data can occur in {attr}`postprocesses ` and some {class}`postprocess headers `. `PropagatingMode` and `ResonanceMode` eigenvalues do not contain solver derivatives. Tabular postprocess data supports {meth}`to_dict() `, {meth}`to_xarray() `, and {meth}`to_df() `. ## Declared Derivative Parameters The layout file declares the parameters `width_parameter`, `height`, `swa`, and `radius`. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/setup/layout.jcmt :language: jcm :lines: 1-17 ``` The derivative names appear in the result data. {term}`Project keys` and derivative names are separate configuration values. ## Computation The {func}`solve ` call computes the solver result and the derivative data. The export examples select the tabular postprocess. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/run.py :language: python :start-at: results = jcmsuite.solve( :end-before: The first postprocess is tabular. ``` ## Tabular Exports ### Exports To A Dictionary Call {meth}`to_dict() ` on a tabular postprocess to retain its nested mapping. The dictionary can contain base values and derivative values at the same level: ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/run.py :language: python :start-at: The first postprocess is tabular. :end-before: print(table_dict_export["d_swa"].keys()) ``` The derivative entries contain values for the declared derivative parameters. Derivative entries can use flat keys such as `d_width_parameter` or nested mappings. Dictionary export preserves the structure from the result data. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/run.py :language: python :start-at: print(table_dict_export["d_swa"].keys()) ``` The nested `d_swa` mapping contains the derivative of each tabular result. Its `K` value and `ElectricFieldStrength` values retain the field-index mapping from the result. ### Exports To An xarray DataTree ```{note} Xarray exports require the xarray extra. See [Installation](../installation.md). ``` Call {meth}`to_xarray() ` to export tabular data to an xarray `DataTree`. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_xarray/run.py :language: python :start-at: The first postprocess is tabular. :end-before: print(table_xarray_export["ElectricFieldStrength"]) ``` The root node contains the base data. Nested derivative mappings become child nodes. The example accesses variables and dimensions at the root and at a derivative child node. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_xarray/run.py :language: python :start-at: print(table_xarray_export["ElectricFieldStrength"]) ``` The table values use named dimensions, including `field_index`, `sample_index`, and `component`. Each derivative is available as a child node such as `/d_width_parameter`. ### Exports To pandas DataFrames ```{note} DataFrame exports require the pandas extra. See [Installation](../installation.md). ``` Call {meth}`to_df() ` to export tabular data to a pandas DataFrame. Table payloads use the wide layout by default. Structured and table-collection payloads use the long layout. ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dataframe/run.py :language: python :start-at: table_df_export = table_pp.to_df() ``` ## Project Files The export examples use the same input files. Only the Python export script differs.
export_dictionary/run.py ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/run.py :language: python ```
export_xarray/run.py ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_xarray/run.py :language: python ```
export_dataframe/run.py ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dataframe/run.py :language: python ```
project.jcmp ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/project.jcmp :language: jcm ```
layout.jcmt ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/layout.jcmt :language: jcm ```
materials.jcmt ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/materials.jcmt :language: jcm ```
sources.jcm ```{literalinclude} ../../demos/documentation_tutorials/derivatives/setup_and_export/export_dictionary/sources.jcm :language: jcm ```
Continue with [Torch Integration](torch.md) to connect numeric postprocess derivatives to PyTorch autograd.