Note: This page was generated from a Jupyter notebook which can be found at docs/tutorial_notebooks/3_model_iterations_and_plots.ipynb in your DYNAMITE directory. —-

3. Model Iterations and Plots

By the end of the notebook, you will have run a grid of Schwarzschild models. This will involve the following steps: 1. run a small grid of orbit-based models with DYNAMITE 2. understand the structure of the output 3. plot the output 4. look at the iteration process while running the grid of models

You should run this from the directory docs/tutorial_notebooks.

Setup

We will run DYNAMITE on CALIFA data of NGC 6278. To prepare the input data files, you should first run the tutorial “Data Preparation for Gauss Hermite kinematics” (1_data_prep_for_gauss_hermite.ipynb). The relevant files you need for this tutorial are:

| tutorial_notebooks
| ├── NGC6278_input
| │   ├── dynamite_input
| │   │   ├── gauss_hermite_kins.ecsv
| │   │   ├── aperture.dat
| │   │   ├── bins.dat
| │   │   ├── mge.ecsv
| │   │   └── ...
| │   └── ...
| │   └── ...
| └── NGC6278_config.yaml
| └── *.ipynb
|

Read the configuration file

[1]:
import dynamite as dyn

print('DYNAMITE')
print('    version', dyn.__version__)
#print('    installed at ', dyn.__path__)  # Uncomment to print the complete DYNAMITE installation path

fname = 'NGC6278_config.yaml'
c = dyn.config_reader.Configuration(fname, reset_logging=True)
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Config file NGC6278_config.yaml read.
[INFO] 21:41:20 - dynamite.config_reader.Configuration - io_settings...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Output directory tree: NGC6278_output/.
[INFO] 21:41:20 - dynamite.config_reader.Configuration - system_attributes...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - model_components...
DYNAMITE
    version 4.2.0
[INFO] 21:41:20 - dynamite.config_reader.Configuration - system_parameters...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - orblib_settings...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - weight_solver_settings...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Will attempt to recover partially run models.
[INFO] 21:41:20 - dynamite.config_reader.Configuration - parameter_space_settings...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - multiprocessing_settings...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - ... using 4 CPUs for orbit integration.
[INFO] 21:41:20 - dynamite.config_reader.Configuration - ... using 4 CPUs for weight solving.
[INFO] 21:41:20 - dynamite.config_reader.Configuration - legacy_settings...
[INFO] 21:41:20 - dynamite.config_reader.Configuration - System assembled
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Configuration validated
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Instantiated parameter space
[INFO] 21:41:20 - dynamite.model.AllModels - Previous models have been found: Reading NGC6278_output/all_models.ecsv into AllModels.table
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Instantiated AllModels object
[INFO] 21:41:20 - dynamite.model.AllModels - No all_models table update required.

All the options in the configuration file are held in the object c. For example, let’s look at the io_settings. Output from this tutorial will be saved in the output_directory.

[2]:
# delete previous output if available
c.remove_existing_orblibs()
c.remove_existing_all_models_file(wipe_other_files=False)
c.backup_config_file(keep=3, delete_other=True)
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Model output tree NGC6278_output/models/ removed.
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Deleted existing NGC6278_output/all_models.ecsv.
[INFO] 21:41:20 - dynamite.model.AllModels - No previous models (file NGC6278_output/all_models.ecsv) have been found: Made an empty table in AllModels.table
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Instantiated empty AllModels object
[INFO] 21:41:20 - dynamite.config_reader.Configuration - Config file backup: NGC6278_output/NGC6278_config_000.yaml.
[3]:
c.settings.io_settings
[3]:
{'input_directory': 'NGC6278_input/dynamite_input/',
 'output_directory': 'NGC6278_output/',
 'all_models_file': 'all_models.ecsv',
 'model_directory': 'NGC6278_output/models/',
 'plot_directory': 'NGC6278_output/plots/'}

In fact, by creating the configuration object c, we have also created the output_directory and copied a version of the configuration file there,

[4]:
ls NGC6278_output
NGC6278_config_000.yaml  plots/

Run the models

Making the ModelIterator object will start running a grid of orbit-based models. This next step will take about 5-10 minutes using 4 cpus

[5]:
import time

t = time.perf_counter()

smi = dyn.model_iterator.ModelIterator(config=c)

delta_t = time.perf_counter()-t
print(f'Computation time: {delta_t} seconds = {delta_t/60} minutes')
[INFO] 21:41:20 - dynamite.model_iterator.ModelIterator - LegacyGridSearch: iterations 0 and 1
[INFO] 21:41:20 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 1 new model(s) out of 1
[INFO] 21:41:20 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 4 new model(s) out of 4
[INFO] 21:41:21 - dynamite.model_iterator.ModelInnerIterator - ... running model 1 out of 5
[INFO] 21:41:21 - dynamite.model_iterator.ModelInnerIterator - ... running model 2 out of 5
[INFO] 21:41:21 - dynamite.model_iterator.ModelInnerIterator - ... running model 3 out of 5
[INFO] 21:41:21 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:41:21 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:41:21 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:42:08 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_001_000/datfil/orbstart.log.
[INFO] 21:42:08 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:42:08 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_000_000/datfil/orbstart.log.
[INFO] 21:42:08 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:42:08 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_001_001/datfil/orbstart.log.
[INFO] 21:42:08 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:42:20 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_000_000/datfil/orblib.log, NGC6278_output/models/orblib_000_000/datfil/orblibbox.log, NGC6278_output/models/orblib_000_000/datfil/triaxmass.log, NGC6278_output/models/orblib_000_000/datfil/triaxmassbin.log.
[INFO] 21:42:20 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:42:20 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_001_001/datfil/orblib.log, NGC6278_output/models/orblib_001_001/datfil/orblibbox.log, NGC6278_output/models/orblib_001_001/datfil/triaxmass.log, NGC6278_output/models/orblib_001_001/datfil/triaxmassbin.log.
[INFO] 21:42:20 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:42:20 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_001_000/datfil/orblib.log, NGC6278_output/models/orblib_001_000/datfil/orblibbox.log, NGC6278_output/models/orblib_001_000/datfil/triaxmass.log, NGC6278_output/models/orblib_001_000/datfil/triaxmassbin.log.
[INFO] 21:42:20 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:42:25 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:42:25 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:42:25 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:42:25 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:42:25 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:42:25 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:42:30 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_001_001/ml05.00/NGC6278_config.yaml.
[INFO] 21:42:30 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_001_000/ml05.00/NGC6278_config.yaml.
[INFO] 21:42:30 - dynamite.model_iterator.ModelInnerIterator - Model 3: NGC6278_output/models/orblib_001_001/ml05.00/model_done_staging.ecsv written.
[INFO] 21:42:30 - dynamite.model_iterator.ModelInnerIterator - Model 2: NGC6278_output/models/orblib_001_000/ml05.00/model_done_staging.ecsv written.
[INFO] 21:42:30 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml05.00/NGC6278_config.yaml.
[INFO] 21:42:30 - dynamite.model_iterator.ModelInnerIterator - Model 1: NGC6278_output/models/orblib_000_000/ml05.00/model_done_staging.ecsv written.
[INFO] 21:42:30 - dynamite.model_iterator.ModelInnerIterator - ... running model 5 out of 5
[INFO] 21:42:30 - dynamite.model_iterator.ModelInnerIterator - ... running model 4 out of 5
[INFO] 21:42:30 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:42:30 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:42:34 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:42:34 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:42:34 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:42:34 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:42:39 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml09.00/NGC6278_config.yaml.
[INFO] 21:42:39 - dynamite.model_iterator.ModelInnerIterator - Model 5: NGC6278_output/models/orblib_000_000/ml09.00/model_done_staging.ecsv written.
[INFO] 21:42:39 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml01.00/NGC6278_config.yaml.
[INFO] 21:42:39 - dynamite.model_iterator.ModelInnerIterator - Model 4: NGC6278_output/models/orblib_000_000/ml01.00/model_done_staging.ecsv written.
[INFO] 21:42:39 - dynamite.model_iterator.ModelInnerIterator - Iteration done, 5 model(s) calculated.
[INFO] 21:42:39 - dynamite.model_iterator.ModelInnerIterator - 5 staging file(s) deleted.
[INFO] 21:42:39 - dynamite.plotter.Plotter - kinchi2 vs. model id plot created (5 models).
[INFO] 21:42:39 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_progress_plot.png saved in NGC6278_output/plots/
[INFO] 21:42:39 - dynamite.plotter.Plotter - Making chi2 plot scaled according to kinchi2
[INFO] 21:42:40 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_plot.png saved in NGC6278_output/plots/
[INFO] 21:42:40 - dynamite.plotter.Plotter - Plotting kinematic maps for 1 kin_sets.
[INFO] 21:42:40 - dynamite.plotter.Plotter - Plotting kinematic maps for kin_set no 0: califa
[INFO] 21:42:40 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:42:40 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:42:44 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:42:50 - dynamite.plotter.Plotter - Kinematic map written to NGC6278_output/plots/kinematic_map_califa.png.
[INFO] 21:42:50 - dynamite.model_iterator.ModelIterator - LegacyGridSearch: iteration 2
[INFO] 21:42:50 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 4 new model(s) out of 4
[INFO] 21:42:50 - dynamite.model_iterator.ModelInnerIterator - ... running model 1 out of 4
[INFO] 21:42:50 - dynamite.model_iterator.ModelInnerIterator - ... running model 2 out of 4
[INFO] 21:42:50 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:42:50 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:43:35 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_002_000/datfil/orbstart.log.
[INFO] 21:43:35 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:43:35 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_002_001/datfil/orbstart.log.
[INFO] 21:43:35 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:43:44 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_002_000/datfil/orblib.log, NGC6278_output/models/orblib_002_000/datfil/orblibbox.log, NGC6278_output/models/orblib_002_000/datfil/triaxmass.log, NGC6278_output/models/orblib_002_000/datfil/triaxmassbin.log.
[INFO] 21:43:44 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_002_001/datfil/orblib.log, NGC6278_output/models/orblib_002_001/datfil/orblibbox.log, NGC6278_output/models/orblib_002_001/datfil/triaxmass.log, NGC6278_output/models/orblib_002_001/datfil/triaxmassbin.log.
[INFO] 21:43:44 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:43:44 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:43:48 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:43:48 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:43:48 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:43:48 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:43:52 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_002_000/ml05.00/NGC6278_config.yaml.
[INFO] 21:43:52 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_002_001/ml05.00/NGC6278_config.yaml.
[INFO] 21:43:52 - dynamite.model_iterator.ModelInnerIterator - Model 1: NGC6278_output/models/orblib_002_000/ml05.00/model_done_staging.ecsv written.
[INFO] 21:43:52 - dynamite.model_iterator.ModelInnerIterator - Model 2: NGC6278_output/models/orblib_002_001/ml05.00/model_done_staging.ecsv written.
[INFO] 21:43:52 - dynamite.model_iterator.ModelInnerIterator - ... running model 3 out of 4
[INFO] 21:43:52 - dynamite.model_iterator.ModelInnerIterator - ... running model 4 out of 4
[INFO] 21:43:52 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:43:52 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:43:56 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:43:56 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:43:56 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:43:56 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:44:01 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml07.00/NGC6278_config.yaml.
[INFO] 21:44:01 - dynamite.model_iterator.ModelInnerIterator - Model 4: NGC6278_output/models/orblib_000_000/ml07.00/model_done_staging.ecsv written.
[INFO] 21:44:01 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml03.00/NGC6278_config.yaml.
[INFO] 21:44:01 - dynamite.model_iterator.ModelInnerIterator - Model 3: NGC6278_output/models/orblib_000_000/ml03.00/model_done_staging.ecsv written.
[INFO] 21:44:01 - dynamite.model_iterator.ModelInnerIterator - Iteration done, 4 model(s) calculated.
[INFO] 21:44:01 - dynamite.model_iterator.ModelInnerIterator - 4 staging file(s) deleted.
[INFO] 21:44:01 - dynamite.plotter.Plotter - kinchi2 vs. model id plot created (9 models).
[INFO] 21:44:01 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_progress_plot.png saved in NGC6278_output/plots/
[INFO] 21:44:01 - dynamite.plotter.Plotter - Making chi2 plot scaled according to kinchi2
[INFO] 21:44:01 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_plot.png saved in NGC6278_output/plots/
[INFO] 21:44:01 - dynamite.plotter.Plotter - Plotting kinematic maps for 1 kin_sets.
[INFO] 21:44:01 - dynamite.plotter.Plotter - Plotting kinematic maps for kin_set no 0: califa
[INFO] 21:44:01 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:44:01 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:44:04 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:44:10 - dynamite.plotter.Plotter - Kinematic map written to NGC6278_output/plots/kinematic_map_califa.png.
[INFO] 21:44:10 - dynamite.model_iterator.ModelIterator - LegacyGridSearch: iteration 3
[INFO] 21:44:10 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 4 new model(s) out of 4
[INFO] 21:44:10 - dynamite.model_iterator.ModelInnerIterator - ... running model 1 out of 4
[INFO] 21:44:10 - dynamite.model_iterator.ModelInnerIterator - ... running model 2 out of 4
[INFO] 21:44:10 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:44:10 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 21:44:54 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_003_001/datfil/orbstart.log.
[INFO] 21:44:54 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:44:54 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_003_000/datfil/orbstart.log.
[INFO] 21:44:54 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 21:45:04 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_003_001/datfil/orblib.log, NGC6278_output/models/orblib_003_001/datfil/orblibbox.log, NGC6278_output/models/orblib_003_001/datfil/triaxmass.log, NGC6278_output/models/orblib_003_001/datfil/triaxmassbin.log.
[INFO] 21:45:04 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:04 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_tube_box_orbs exit code 0. Logfiles: NGC6278_output/models/orblib_003_000/datfil/orblib.log, NGC6278_output/models/orblib_003_000/datfil/orblibbox.log, NGC6278_output/models/orblib_003_000/datfil/triaxmass.log, NGC6278_output/models/orblib_003_000/datfil/triaxmassbin.log.
[INFO] 21:45:04 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:08 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:45:08 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:45:08 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:45:08 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:45:12 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_003_000/ml05.00/NGC6278_config.yaml.
[INFO] 21:45:12 - dynamite.model_iterator.ModelInnerIterator - Model 1: NGC6278_output/models/orblib_003_000/ml05.00/model_done_staging.ecsv written.
[INFO] 21:45:12 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_003_001/ml05.00/NGC6278_config.yaml.
[INFO] 21:45:12 - dynamite.model_iterator.ModelInnerIterator - Model 2: NGC6278_output/models/orblib_003_001/ml05.00/model_done_staging.ecsv written.
[INFO] 21:45:12 - dynamite.model_iterator.ModelInnerIterator - ... running model 3 out of 4
[INFO] 21:45:12 - dynamite.model_iterator.ModelInnerIterator - ... running model 4 out of 4
[INFO] 21:45:12 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:12 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:16 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:45:16 - dynamite.weight_solvers.NNLS - NNLS problem solved
[INFO] 21:45:16 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:45:16 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:45:20 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml06.00/NGC6278_config.yaml.
[INFO] 21:45:20 - dynamite.model_iterator.ModelInnerIterator - Model 4: NGC6278_output/models/orblib_000_000/ml06.00/model_done_staging.ecsv written.
[INFO] 21:45:20 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml04.00/NGC6278_config.yaml.
[INFO] 21:45:20 - dynamite.model_iterator.ModelInnerIterator - Model 3: NGC6278_output/models/orblib_000_000/ml04.00/model_done_staging.ecsv written.
[INFO] 21:45:20 - dynamite.model_iterator.ModelInnerIterator - Iteration done, 4 model(s) calculated.
[INFO] 21:45:20 - dynamite.model_iterator.ModelInnerIterator - 4 staging file(s) deleted.
[INFO] 21:45:20 - dynamite.plotter.Plotter - kinchi2 vs. model id plot created (13 models).
[INFO] 21:45:20 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_progress_plot.png saved in NGC6278_output/plots/
[INFO] 21:45:20 - dynamite.plotter.Plotter - Making chi2 plot scaled according to kinchi2
[INFO] 21:45:20 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_plot.png saved in NGC6278_output/plots/
[INFO] 21:45:20 - dynamite.plotter.Plotter - Plotting kinematic maps for 1 kin_sets.
[INFO] 21:45:20 - dynamite.plotter.Plotter - Plotting kinematic maps for kin_set no 0: califa
[INFO] 21:45:20 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 21:45:20 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:23 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:45:29 - dynamite.plotter.Plotter - Kinematic map written to NGC6278_output/plots/kinematic_map_califa.png.
Computation time: 249.10592713 seconds = 4.151765452166667 minutes

The following files have been created in the models directory,

[6]:
ls NGC6278_output/models
orblib_000_000/ orblib_001_001/ orblib_002_001/ orblib_003_001/
orblib_001_000/ orblib_002_000/ orblib_003_000/

Each directory holds a different orbit library

orblib_XXX_YYY

where XXX labels the iteration when it was created, and YYY labels the position within that iteration. Looking inside one of these directories, we see the following files:

[7]:
ls NGC6278_output/models/orblib_000_000
cmd_orb_start      infil/             ml04.00/           ml09.00/
cmd_tube_box_orbs  interpolgrid       ml05.00/
datfil/            ml01.00/           ml06.00/
fort.30            ml03.00/           ml07.00/

which are:

  • cmd_*: bash scripts for running Fortran programs

  • datfil/: directory holding the orbit library for the reference potential

  • infil/: input files for running Fortran programs

  • ml*/: directories containing output orbital weights (and other results) for different values of ml

Each ml* directory hold outputs for a re-scaled version of the same potential, where the value of ml is a mass scaling applied to a reference potential. The reference potential uses the the first value of ml encountered in the parameter search.

Some plots are automatically created,

[8]:
ls NGC6278_output/plots
kinchi2_plot.png           kinematic_map_califa.png
kinchi2_progress_plot.png

and they represent the following quantities:

  1. kinchi2_progress_plot.png: chi2 values vs model ID,

  2. kinchi2_plot.png : model parameters vs chi2 values,

  3. kinematic_map_califa.png: the kinematic maps for the current minimum-chi2 model.

As an alternative to opening the plot files, we can use the model iterator’s method get_plots(). It returns these plots as a tuple of objects,

[9]:
plots = smi.get_plots()
len(plots)
[9]:
3
[10]:
# The chi2 vs. model ID plot (kinchi2_progress_plot)
print(type(plots[0]))
plots[0]
<class 'matplotlib.figure.Figure'>
[10]:
../_images/tutorial_notebooks_3_model_iterations_and_plots_17_1.png
[11]:
# The model parameters vs chi2 values plot (kinchi2_plot)
# If more than 2 parameters were left free, this would be a traingle plot of chi2 values.
print(type(plots[1]))
plots[1]
<class 'matplotlib.figure.Figure'>
[11]:
../_images/tutorial_notebooks_3_model_iterations_and_plots_18_1.png

The last element of the plots tuple is a list of kinematic maps for the current minimum-chi2 model with one entry for each kinematics dataset. Each list member is itself a tuple of type (matplotlib.figure.Figure, str) with the string indicating the name of the kinematics.

[12]:
# The kinematic maps (kinematic_map_califa)
print(type(plots[2]))
print(plots[2])  # If we had more than one kinematics, the list would be longer
print(plots[2][0])  # The figure and the associated kinematics dataset
print('First (and only) kinematics: ' + plots[2][0][1])  # The name of the kinematics
plots[2][0][0]  # The plot
<class 'list'>
[(<Figure size 2700x1200 with 30 Axes>, 'califa')]
(<Figure size 2700x1200 with 30 Axes>, 'califa')
First (and only) kinematics: califa
[12]:
../_images/tutorial_notebooks_3_model_iterations_and_plots_20_1.png

A summary of all the models run so far is saved in the file NGC6278_output/all_models.ecsv. This is an Astropy ECSV file. A table holding this data is stored in c,

[13]:
c.all_models.table
[13]:
Table length=13
m-bha-bhc-dhf-dhq-starsp-starsu-starsmlchi2kinchi2kinmapchi2time_modifiedorblib_doneweights_doneall_donewhich_iterdirectory
float64float64float64float64float64float64float64float64float64float64float64str256boolboolboolint64str256
100000.00.0018.010.00.540.990.99995.033649.39086884622515917.06686082768621307.6742312935822024-02-22T20:42:30.000TrueTrueTrue0orblib_000_000/ml05.00/
100000.00.0018.03.16227766016837950.540.990.99995.030991.11762762292317598.73085193288722813.5391994324422024-02-22T20:42:30.000TrueTrueTrue1orblib_001_000/ml05.00/
100000.00.0018.031.6227766016837930.540.990.99995.040173.1757447688816959.4279065863822195.915987557332024-02-22T20:42:30.000TrueTrueTrue1orblib_001_001/ml05.00/
100000.00.0018.010.00.540.990.99991.0497022.2219649833362170.4757700878189079.407949780462024-02-22T20:42:39.000TrueTrueTrue1orblib_000_000/ml01.00/
100000.00.0018.010.00.540.990.99999.054888.8600240343136551.18477692704675313.140471714422024-02-22T20:42:39.000TrueTrueTrue1orblib_000_000/ml09.00/
100000.00.0018.05.6234132519034910.540.990.99995.036730.0392222951616672.12206429682220543.0656680363142024-02-22T20:43:52.000TrueTrueTrue2orblib_002_000/ml05.00/
100000.00.0018.017.782794100389230.540.990.99995.052679.2856566211416544.94012319058321811.732562744962024-02-22T20:43:52.000TrueTrueTrue2orblib_002_001/ml05.00/
100000.00.0018.010.00.540.990.99993.077417.3076701525753526.44612486871548748.836951111422024-02-22T20:44:01.000TrueTrueTrue2orblib_000_000/ml03.00/
100000.00.0018.010.00.540.990.99997.035168.2302119247518463.68353309175736820.180446870082024-02-22T20:44:01.000TrueTrueTrue2orblib_000_000/ml07.00/
100000.00.0018.07.4989420933245580.540.990.99995.037349.95225809602616623.4668736865822114.4902530347642024-02-22T20:45:12.000TrueTrueTrue3orblib_003_000/ml05.00/
100000.00.0018.013.335214321633240.540.990.99995.033802.19872957277414934.8693880227720657.3013677049822024-02-22T20:45:12.000TrueTrueTrue3orblib_003_001/ml05.00/
100000.00.0018.010.00.540.990.99994.045497.74517306829525420.65392822698426465.5852291400222024-02-22T20:45:20.000TrueTrueTrue3orblib_000_000/ml04.00/
100000.00.0018.010.00.540.990.99996.031118.7306928428614194.8929189276625134.9896750257072024-02-22T20:45:20.000TrueTrueTrue3orblib_000_000/ml06.00/

At this stage, you could:

  • run more models, perhaps first adjusting settings in the configuration file, as explained in 2_quickstart.ipynb,

    • increasing the n_max_mods and/or n_max_iter

    • adjust parameter bounds and/or which parameters are kept free

  • plot other visualisations

Plotting

DYNAMITE provides other plotting methods in the Plotter:

[14]:
plotter = dyn.plotter.Plotter(config=c)

In all the functions that require to use the values of the \(\chi^2\) to make the plots, the user can choose which \(\chi^2\) to use, by specifying the value of the parameter which_chi2. The recommended value to use is which_chi2='kinchi2'.

The plots produced by the functions introduced below are all saved in the plot directory specified in the directory plots within the output directory specified in the configuration file. After running all the cells in this notebook, you will find your plots in the directory NGC6278_output/plots.

The mass_plot function generates a cumulative mass plot, showing the enclosed mass profiles for the mass-follows-light component (red), for the dark matter (blue), and for the sum of the two (black). The solid lines correspond to the best-fit model, the shaded areas represent 1 sigma uncertainties. You can specify the radial extent of the plot and the type of file you want to be saved with the figure (e.g., '.png', '.pdf', … if figtype=None, the default is used and a '.png' figure is created).

[15]:
fig1 = plotter.mass_plot(which_chi2='kinchi2', Rmax_arcs=50, figtype=None)
Selecting  3  models
[INFO] 21:45:41 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/enclosedmassm_linear.png saved in NGC6278_output/plots/
../_images/tutorial_notebooks_3_model_iterations_and_plots_26_2.png

The orbit_plot function generates a plot showing the stellar orbit distribution, described as probability density of orbits; circularity (\(\lambda_z\)) is represented here as a function of the distance from the galactic centre r (in arcsec). You can specify the type of file you want to be saved with the figure (e.g., '.png', '.pdf', …). In this case, Rmax_arcs represents the upper radial limit for orbit selection, in arcsec, meaning that only orbits extending up to Rmax_arcs are plotted.

[16]:
fig2 = plotter.orbit_plot(Rmax_arcs=50)
[INFO] 21:45:41 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:45 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:45:45 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/orbit_linear_only.png saved in NGC6278_output/plots/
../_images/tutorial_notebooks_3_model_iterations_and_plots_28_1.png

The beta_plot function generates two plots, showing the intrinsic and projected anisotropy profiles.

[17]:
fig3, fig4 = plotter.beta_plot(which_chi2='kinchi2', Rmax_arcs=50)
[INFO] 21:45:45 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:48 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:45:51 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:54 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:45:57 - dynamite.weight_solvers.NNLS - Using WeightSolver: NNLS/scipy
[INFO] 21:45:59 - dynamite.weight_solvers.NNLS - NNLS solution read from existing output
[INFO] 21:46:00 - dynamite.plotter.Plotter - Figure NGC6278_output/plots/anisotropy_var.png saved in NGC6278_output/plots/
[INFO] 21:46:00 - dynamite.plotter.Plotter - Figure NGC6278_output/plots/betaz_var.png saved in NGC6278_output/plots/
../_images/tutorial_notebooks_3_model_iterations_and_plots_30_1.png
../_images/tutorial_notebooks_3_model_iterations_and_plots_30_2.png

The qpu_plot function creates a plot showing the intrinsic flattenings \(q\) and \(p\), with the blue and black lines respectively, as a function of the distance from the galactic centre (in arcsec). The value of \(T = (1-p^2)/(1-q^2)\) is also shown (red line).

[18]:
fig5 = plotter.qpu_plot(which_chi2='kinchi2', Rmax_arcs=50,figtype =None)
[INFO] 21:46:00 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/triaxial_qpt.png saved in NGC6278_output/plots/
../_images/tutorial_notebooks_3_model_iterations_and_plots_32_1.png

The Iteration Process

We will now have a look at the iteration process by examining the \(\chi^2\)-value.

In the table above (c.all_models.table), the model parameters are given for each step of the iteration. Most parameters are fixed and therefore constant, but the mass-to-light ratio ml and the dark matter parameter f-dh are free. We will examine how these parameters are changed with each iteration.

First, we get the upper and lower limits of the parameters from the configuration file (for more details on this step have a look at the notebook parameter_space.ipynb):

[19]:
import numpy as np
import matplotlib.pyplot as plt

# extract the lo/hi limits for the two free parameters f and ml

f = c.parspace.get_parameter_from_name('f-dh')
f_lims_raw = [f.par_generator_settings['lo'], f.par_generator_settings['hi']]
f_lims = [f.get_par_value_from_raw_value(lim0) for lim0 in f_lims_raw]

ml = c.parspace.get_parameter_from_name('ml')
ml_lims_raw = [ml.par_generator_settings['lo'], ml.par_generator_settings['hi']]
ml_lims = [ml.get_par_value_from_raw_value(lim0) for lim0 in ml_lims_raw]

From the table, we can get a list of all iterations that were made:

[20]:
# get list of iterations
iterations = np.unique(c.all_models.table['which_iter'])

Now plot the \(\chi^2\)-value of the models for every iteration:

[21]:
# plot chi2 of models vs iterations
for iter0 in iterations:
    table = c.all_models.table
    table = table[table['which_iter']==iter0]
    plt.figure(figsize=(6,5))
    plt.scatter(table['f-dh'],
                table['ml'],
                c=table['chi2'],
                cmap=plt.cm.viridis_r,
                s=200)


    cbar = plt.colorbar()
    cbar.set_label('$\chi^2$')
    plt.gca().set_title(f'iteration {iter0}')

    plt.gca().set_xlim(*f_lims)
    plt.gca().set_ylim(*ml_lims)
    plt.gca().set_xlabel(f.LaTeX)
    plt.gca().set_ylabel(ml.LaTeX)
    plt.gca().set_xscale('log')
    plt.tight_layout()
    plt.show()
../_images/tutorial_notebooks_3_model_iterations_and_plots_38_0.png
../_images/tutorial_notebooks_3_model_iterations_and_plots_38_1.png
../_images/tutorial_notebooks_3_model_iterations_and_plots_38_2.png
../_images/tutorial_notebooks_3_model_iterations_and_plots_38_3.png

We can see how the parameter values get closer together for each iteration. The next plot gives an overview over all iterations:

[22]:
# plot the models: f-dh vs ml altogether
plt.scatter(c.all_models.table['f-dh'],
            c.all_models.table['ml'],
            c=c.all_models.table['chi2'] - np.min(c.all_models.table['chi2']),
            cmap=plt.cm.viridis_r,
            s=200)
cbar = plt.colorbar()
cbar.set_label('$\chi^2$')
plt.gca().set_title(f'all iterations')
plt.gca().set_xlim(*f_lims)
plt.gca().set_ylim(*ml_lims)
plt.gca().set_xlabel(f.LaTeX)
plt.gca().set_ylabel(ml.LaTeX)
plt.gca().set_xscale('log')
plt.tight_layout()
plt.show()
../_images/tutorial_notebooks_3_model_iterations_and_plots_40_0.png

We can see how with every iteration, the \(\chi^2\)-value becomes smaller, as does the scatter between the values.

The plot kinchi2_plot already shown above is another representation of the iteration process. The different models are plotted on a grid in the parameter space, where the best fit model is marked with a cross. Above we stored this plot in plots[1],

[23]:
plots[1]
[23]:
../_images/tutorial_notebooks_3_model_iterations_and_plots_42_0.png