# Script Analysis
The Script Analysis feature allows users to create Python notebooks to access and analyze simulation results. It is a powerful data analysis feature for creating customized charts from design optimization results, calculating mode overlaps, or obtaining complex figures-of-merit.
Click the Add Script Analysis button in the Script Analysis result section to open the notebook editor.
# Name
Text field to edit the script analysis notebook name.
# Simulation Dataset Selection
All simulation datasets of interest must be selected in the first code cell. This is a special cell that loads all the selected simulation results at once. You cannot exclude or move the dataset selection cell, and it only supports syntax related to dataset selection.
# Select Results from a Single Simulation
To select results from single simulations, you can use the sim_data variable and the dot syntax. Once you type sim_data., you will see the autocomplete feature to select the available monitors and datasets.
For instance, if in an FDTD simulation you have a FluxMonitor, a FieldMonitor, and a ModeMonitor called flux, field, and mode, respectively, you can use the following code to select and slice the monitor datasets:
# Select the "Magnitude (abs)" dataset
flux_dataset = sim_data.__dict__['flux'].flux.__dict__['Magnitude (abs)']
# Select the "E" dataset at the first frequency value
field_dataset = sim_data.__dict__['field'].E.f0.__dict__['Intensity (abs^2)']
# Select the forward mode dataset and slice it to obtain the values at mode_index 2 and frequency index 5
mode_dataset = sim_data.monitor.amps.direction0.__dict__['Intensity (abs^2)'].isel(mode_index=2, f=5)
Similarly, you can select datasets from single Mode and Heat simulations:
# Select the effective index dataset and slice it to obtain all the values at mode_index 1
neff_dataset = sim_data.MODE_SOLVER_MONITOR.n_eff.isel(mode_index=1)
# Select the temperature dataset from a two-dimensional Temperature monitor
temp_dataset = sim_data.temp_monitor.Temperature
# Select Results from a Design Optimization Simulation
In design optimization simulations such as parameter sweeps or Monte Carlo analysis, you can reference the individual simulations using the design_data list. For example:
# Select the "Magnitude (abs)" dataset from a FluxMonitor for all the design optimization simulations
datasets = []
for sim in design_data:
datasets.append(sim.fluxmonitor.flux.__dict__['Magnitude (abs)'])
Additionally, you can use the design_variables list to obtain the names and values of variables in all the individual simulations.
# Run the Code
You can execute all the notebook code cells by clicking "Run all Cells" in the top bar, or execute individual cells by clicking the "Run this Cell" button.
# Create or Delete Cells
Use the "Click to add a cell" button to insert new cells in the notebook. Additionally, you can use the "Insert a cell above" and "Insert a cell below" buttons to create new cells between existing ones.
Use the "Delete this cell" button to remove a notebook cell.
# Markdown and Code Cells
Code cells are inserted in the notebook by default. However, you can switch between code and markdown cells using the "Change cell to markdown" or "Change cell to code" buttons. Once you change the cell type to markdown, you can use regular markdown syntax to enter textual information in your notebook.
# Import and Export Files
Use the import and export buttons in the top toolbar to import or export to .ipynb or .py files.