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] 16:01:43 - dynamite.config_reader.Configuration - Config file NGC6278_config.yaml read.
[INFO] 16:01:43 - dynamite.config_reader.Configuration - io_settings...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Output directory tree: NGC6278_output/.
[INFO] 16:01:43 - dynamite.config_reader.Configuration - system_attributes...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - model_components...
DYNAMITE
    version 4.1.0
[INFO] 16:01:43 - dynamite.config_reader.Configuration - system_parameters...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - orblib_settings...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - weight_solver_settings...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Will attempt to recover partially run models.
[INFO] 16:01:43 - dynamite.config_reader.Configuration - parameter_space_settings...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - multiprocessing_settings...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - ... using 4 CPUs for orbit integration.
[INFO] 16:01:43 - dynamite.config_reader.Configuration - ... using 4 CPUs for weight solving.
[INFO] 16:01:43 - dynamite.config_reader.Configuration - legacy_settings...
[INFO] 16:01:43 - dynamite.config_reader.Configuration - System assembled
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Configuration validated
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Instantiated parameter space
[INFO] 16:01:43 - dynamite.model.AllModels - Previous models have been found: Reading NGC6278_output/all_models.ecsv into AllModels.table
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Instantiated AllModels object

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] 16:01:43 - dynamite.config_reader.Configuration - Model output tree NGC6278_output/models/ removed.
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Deleted existing NGC6278_output/all_models.ecsv.
[INFO] 16:01:43 - dynamite.model.AllModels - No previous models (file NGC6278_output/all_models.ecsv) have been found: Made an empty table in AllModels.table
[INFO] 16:01:43 - dynamite.config_reader.Configuration - Instantiated empty AllModels object
[INFO] 16:01:43 - 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] 16:01:43 - dynamite.model_iterator.ModelIterator - LegacyGridSearch: iterations 0 and 1
[INFO] 16:01:43 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 1 new model(s) out of 1
[INFO] 16:01:44 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 4 new model(s) out of 4
[INFO] 16:01:44 - dynamite.model_iterator.ModelInnerIterator - ... running model 1 out of 5
[INFO] 16:01:44 - dynamite.model_iterator.ModelInnerIterator - ... running model 2 out of 5
[INFO] 16:01:44 - dynamite.model_iterator.ModelInnerIterator - ... running model 3 out of 5
[INFO] 16:01:44 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:01:44 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:01:44 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:02:47 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_001_001/datfil/orbstart.log.
[INFO] 16:02:47 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:02:47 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_000_000/datfil/orbstart.log.
[INFO] 16:02:47 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:02:47 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_001_000/datfil/orbstart.log.
[INFO] 16:02:47 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:03:06 - 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] 16:03:06 - 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] 16:03:06 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:03:06 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:03:06 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:03:06 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:03:07 - 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] 16:03:07 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:03:07 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:03:11 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_001_001/ml05.00/nnls.log.
[INFO] 16:03:11 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml05.00/nnls.log.
[INFO] 16:03:11 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_001_001/ml05.00/NGC6278_config.yaml.
[INFO] 16:03:11 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml05.00/NGC6278_config.yaml.
[INFO] 16:03:12 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:03:12 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:03:12 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_001_000/ml05.00/nnls.log.
[INFO] 16:03:12 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_001_000/ml05.00/NGC6278_config.yaml.
[INFO] 16:03:12 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:03:19 - dynamite.model_iterator.ModelInnerIterator - Model 3: NGC6278_output/models/orblib_001_001/ml05.00/model_done_staging.ecsv written.
[INFO] 16:03:19 - dynamite.model_iterator.ModelInnerIterator - Model 1: NGC6278_output/models/orblib_000_000/ml05.00/model_done_staging.ecsv written.
[INFO] 16:03:19 - dynamite.model_iterator.ModelInnerIterator - Model 2: NGC6278_output/models/orblib_001_000/ml05.00/model_done_staging.ecsv written.
[INFO] 16:03:19 - dynamite.model_iterator.ModelInnerIterator - ... running model 4 out of 5
[INFO] 16:03:19 - dynamite.model_iterator.ModelInnerIterator - ... running model 5 out of 5
[INFO] 16:03:19 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:03:19 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml09.00
[INFO] 16:03:20 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:03:20 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml01.00
[INFO] 16:03:24 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_9.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml09.00/nnls.log.
[INFO] 16:03:24 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml09.00/NGC6278_config.yaml.
[INFO] 16:03:24 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_1.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml01.00/nnls.log.
[INFO] 16:03:24 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml01.00/NGC6278_config.yaml.
[INFO] 16:03:24 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:03:24 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:03:31 - dynamite.model_iterator.ModelInnerIterator - Model 5: NGC6278_output/models/orblib_000_000/ml09.00/model_done_staging.ecsv written.
[INFO] 16:03:31 - dynamite.model_iterator.ModelInnerIterator - Model 4: NGC6278_output/models/orblib_000_000/ml01.00/model_done_staging.ecsv written.
[INFO] 16:03:31 - dynamite.model_iterator.ModelInnerIterator - Iteration done, 5 model(s) calculated.
[INFO] 16:03:32 - dynamite.model_iterator.ModelInnerIterator - 5 staging file(s) deleted.
[INFO] 16:03:32 - dynamite.plotter.Plotter - kinchi2 vs. model id plot created (5 models).
[INFO] 16:03:32 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_progress_plot.png saved in NGC6278_output/plots/
[INFO] 16:03:32 - dynamite.plotter.Plotter - Making chi2 plot scaled according to kinchi2
[INFO] 16:03:32 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_plot.png saved in NGC6278_output/plots/
[INFO] 16:03:32 - dynamite.plotter.Plotter - Plotting kinematic maps for 1 kin_sets.
[INFO] 16:03:32 - dynamite.plotter.Plotter - Plotting kinematic maps for kin_set no 0: califa
[INFO] 16:03:32 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:03:32 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:03:32 - dynamite.weight_solvers.LegacyWeightSolver - Reading NNLS solution from existing output.
[INFO] 16:03:43 - dynamite.plotter.Plotter - Kinematic map written to NGC6278_output/plots/kinematic_map_califa.png.
[INFO] 16:03:43 - dynamite.model_iterator.ModelIterator - LegacyGridSearch: iteration 2
[INFO] 16:03:43 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 4 new model(s) out of 4
[INFO] 16:03:43 - dynamite.model_iterator.ModelInnerIterator - ... running model 1 out of 4
[INFO] 16:03:43 - dynamite.model_iterator.ModelInnerIterator - ... running model 2 out of 4
[INFO] 16:03:43 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:03:43 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:04:36 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_002_000/datfil/orbstart.log.
[INFO] 16:04:36 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:04:36 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_002_001/datfil/orbstart.log.
[INFO] 16:04:36 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:04:53 - 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] 16:04:53 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:04:53 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:04:53 - 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] 16:04:53 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:04:53 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:04:58 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_002_000/ml05.00/nnls.log.
[INFO] 16:04:58 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_002_000/ml05.00/NGC6278_config.yaml.
[INFO] 16:04:58 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_002_001/ml05.00/nnls.log.
[INFO] 16:04:58 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_002_001/ml05.00/NGC6278_config.yaml.
[INFO] 16:04:58 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:04:58 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:05:05 - dynamite.model_iterator.ModelInnerIterator - Model 1: NGC6278_output/models/orblib_002_000/ml05.00/model_done_staging.ecsv written.
[INFO] 16:05:05 - dynamite.model_iterator.ModelInnerIterator - Model 2: NGC6278_output/models/orblib_002_001/ml05.00/model_done_staging.ecsv written.
[INFO] 16:05:05 - dynamite.model_iterator.ModelInnerIterator - ... running model 3 out of 4
[INFO] 16:05:05 - dynamite.model_iterator.ModelInnerIterator - ... running model 4 out of 4
[INFO] 16:05:05 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:05:06 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml03.00
[INFO] 16:05:06 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:05:06 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml07.00
[INFO] 16:05:10 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_3.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml03.00/nnls.log.
[INFO] 16:05:10 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml03.00/NGC6278_config.yaml.
[INFO] 16:05:10 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_7.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml07.00/nnls.log.
[INFO] 16:05:10 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml07.00/NGC6278_config.yaml.
[INFO] 16:05:10 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:05:10 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:05:16 - dynamite.model_iterator.ModelInnerIterator - Model 3: NGC6278_output/models/orblib_000_000/ml03.00/model_done_staging.ecsv written.
[INFO] 16:05:16 - dynamite.model_iterator.ModelInnerIterator - Model 4: NGC6278_output/models/orblib_000_000/ml07.00/model_done_staging.ecsv written.
[INFO] 16:05:17 - dynamite.model_iterator.ModelInnerIterator - Iteration done, 4 model(s) calculated.
[INFO] 16:05:17 - dynamite.model_iterator.ModelInnerIterator - 4 staging file(s) deleted.
[INFO] 16:05:17 - dynamite.plotter.Plotter - kinchi2 vs. model id plot created (9 models).
[INFO] 16:05:17 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_progress_plot.png saved in NGC6278_output/plots/
[INFO] 16:05:17 - dynamite.plotter.Plotter - Making chi2 plot scaled according to kinchi2
[INFO] 16:05:17 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_plot.png saved in NGC6278_output/plots/
[INFO] 16:05:17 - dynamite.plotter.Plotter - Plotting kinematic maps for 1 kin_sets.
[INFO] 16:05:17 - dynamite.plotter.Plotter - Plotting kinematic maps for kin_set no 0: califa
[INFO] 16:05:17 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:05:17 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:05:17 - dynamite.weight_solvers.LegacyWeightSolver - Reading NNLS solution from existing output.
[INFO] 16:05:28 - dynamite.plotter.Plotter - Kinematic map written to NGC6278_output/plots/kinematic_map_califa.png.
[INFO] 16:05:28 - dynamite.model_iterator.ModelIterator - LegacyGridSearch: iteration 3
[INFO] 16:05:28 - dynamite.parameter_space.LegacyGridSearch - LegacyGridSearch added 4 new model(s) out of 4
[INFO] 16:05:28 - dynamite.model_iterator.ModelInnerIterator - ... running model 1 out of 4
[INFO] 16:05:28 - dynamite.model_iterator.ModelInnerIterator - ... running model 2 out of 4
[INFO] 16:05:28 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:05:28 - dynamite.orblib.LegacyOrbitLibrary - Calculating initial conditions
[INFO] 16:06:22 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_003_001/datfil/orbstart.log.
[INFO] 16:06:22 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:06:22 - dynamite.orblib.LegacyOrbitLibrary - ...done - cmd_orb_start exit code 0. Logfile: NGC6278_output/models/orblib_003_000/datfil/orbstart.log.
[INFO] 16:06:22 - dynamite.orblib.LegacyOrbitLibrary - Integrating orbit library tube and box orbits
[INFO] 16:06:38 - 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] 16:06:38 - 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] 16:06:38 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:06:38 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:06:38 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:06:38 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml05.00
[INFO] 16:06:43 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_003_001/ml05.00/nnls.log.
[INFO] 16:06:43 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_003_001/ml05.00/NGC6278_config.yaml.
[INFO] 16:06:43 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_5.0 exit code 0. Logfile: NGC6278_output/models/orblib_003_000/ml05.00/nnls.log.
[INFO] 16:06:43 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_003_000/ml05.00/NGC6278_config.yaml.
[INFO] 16:06:43 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:06:43 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:06:50 - dynamite.model_iterator.ModelInnerIterator - Model 2: NGC6278_output/models/orblib_003_001/ml05.00/model_done_staging.ecsv written.
[INFO] 16:06:50 - dynamite.model_iterator.ModelInnerIterator - Model 1: NGC6278_output/models/orblib_003_000/ml05.00/model_done_staging.ecsv written.
[INFO] 16:06:50 - dynamite.model_iterator.ModelInnerIterator - ... running model 3 out of 4
[INFO] 16:06:50 - dynamite.model_iterator.ModelInnerIterator - ... running model 4 out of 4
[INFO] 16:06:50 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:06:50 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml04.00
[INFO] 16:06:50 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:06:50 - dynamite.weight_solvers.LegacyWeightSolver - Fitting orbit library to the kinematic data: ml06.00
[INFO] 16:06:55 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_4.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml04.00/nnls.log.
[INFO] 16:06:55 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml04.00/NGC6278_config.yaml.
[INFO] 16:06:55 - dynamite.weight_solvers.LegacyWeightSolver - ...done, NNLS problem solved - cmd_nnls_6.0 exit code 0. Logfile: NGC6278_output/models/orblib_000_000/ml06.00/nnls.log.
[INFO] 16:06:55 - dynamite.config_reader.Configuration - Config file copied to NGC6278_output/models/orblib_000_000/ml06.00/NGC6278_config.yaml.
[INFO] 16:06:55 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:06:55 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:07:02 - dynamite.model_iterator.ModelInnerIterator - Model 3: NGC6278_output/models/orblib_000_000/ml04.00/model_done_staging.ecsv written.
[INFO] 16:07:02 - dynamite.model_iterator.ModelInnerIterator - Model 4: NGC6278_output/models/orblib_000_000/ml06.00/model_done_staging.ecsv written.
[INFO] 16:07:02 - dynamite.model_iterator.ModelInnerIterator - Iteration done, 4 model(s) calculated.
[INFO] 16:07:02 - dynamite.model_iterator.ModelInnerIterator - 4 staging file(s) deleted.
[INFO] 16:07:02 - dynamite.plotter.Plotter - kinchi2 vs. model id plot created (13 models).
[INFO] 16:07:02 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_progress_plot.png saved in NGC6278_output/plots/
[INFO] 16:07:02 - dynamite.plotter.Plotter - Making chi2 plot scaled according to kinchi2
[INFO] 16:07:03 - dynamite.plotter.Plotter - Plot NGC6278_output/plots/kinchi2_plot.png saved in NGC6278_output/plots/
[INFO] 16:07:03 - dynamite.plotter.Plotter - Plotting kinematic maps for 1 kin_sets.
[INFO] 16:07:03 - dynamite.plotter.Plotter - Plotting kinematic maps for kin_set no 0: califa
[INFO] 16:07:03 - dynamite.analysis.Analysis - Getting model projected masses and losvds.
[INFO] 16:07:03 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:07:03 - dynamite.weight_solvers.LegacyWeightSolver - Reading NNLS solution from existing output.
[INFO] 16:07:15 - dynamite.plotter.Plotter - Kinematic map written to NGC6278_output/plots/kinematic_map_califa.png.
Computation time: 331.64245751199996 seconds = 5.527374291866666 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_nnls_1.0       cmd_nnls_7.0       fort.30            ml04.00/
cmd_nnls_3.0       cmd_nnls_9.0       infil/             ml05.00/
cmd_nnls_4.0       cmd_orb_start      interpolgrid       ml06.00/
cmd_nnls_5.0       cmd_tube_box_orbs  ml01.00/           ml07.00/
cmd_nnls_6.0       datfil/            ml03.00/           ml09.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.3908688470415917.06686082840521307.674231297042023-11-03T14:03:19.000TrueTrueTrue0orblib_000_000/ml05.00/
100000.00.0018.03.16227766016837950.540.990.99995.030991.1176276237917598.73085193388822813.539176066012023-11-03T14:03:19.000TrueTrueTrue1orblib_001_000/ml05.00/
100000.00.0018.031.6227766016837930.540.990.99995.040173.17574477012416959.4279065871322195.91598057362023-11-03T14:03:19.000TrueTrueTrue1orblib_001_001/ml05.00/
100000.00.0018.010.00.540.990.99991.0497022.221964989362170.4757700949189079.407915536552023-11-03T14:03:31.000TrueTrueTrue1orblib_000_000/ml01.00/
100000.00.0018.010.00.540.990.99999.054888.86002403976536551.1847769320775313.1404630342023-11-03T14:03:31.000TrueTrueTrue1orblib_000_000/ml09.00/
100000.00.0018.05.6234132519034910.540.990.99995.036730.0392222958516672.1220642971920543.0656882334372023-11-03T14:05:05.000TrueTrueTrue2orblib_002_000/ml05.00/
100000.00.0018.017.782794100389230.540.990.99995.052679.285656622216544.94012319142321811.732559211942023-11-03T14:05:05.000TrueTrueTrue2orblib_002_001/ml05.00/
100000.00.0018.010.00.540.990.99993.077417.3076701544953526.4461248713948748.836948900192023-11-03T14:05:16.000TrueTrueTrue2orblib_000_000/ml03.00/
100000.00.0018.010.00.540.990.99997.035168.2302119274118463.6835330945736820.180481555242023-11-03T14:05:16.000TrueTrueTrue2orblib_000_000/ml07.00/
100000.00.0018.07.4989420933245580.540.990.99995.037349.9522580968716623.46687368747422114.49023585712023-11-03T14:06:50.000TrueTrueTrue3orblib_003_000/ml05.00/
100000.00.0018.013.335214321633240.540.990.99995.033802.1987295736514934.86938802307820657.3013848986342023-11-03T14:06:50.000TrueTrueTrue3orblib_003_001/ml05.00/
100000.00.0018.010.00.540.990.99994.045497.74517306896525420.65392822811626465.585228233492023-11-03T14:07:02.000TrueTrueTrue3orblib_000_000/ml04.00/
100000.00.0018.010.00.540.990.99996.031118.7306928443214194.89291892902525134.9896454073862023-11-03T14:07:02.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] 16:07:44 - 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] 16:07:45 - dynamite.weight_solvers.LegacyWeightSolver - Using WeightSolver: LegacyWeightSolver
[INFO] 16:07:45 - dynamite.weight_solvers.LegacyWeightSolver - Reading NNLS solution from existing output.
[INFO] 16:07: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] 16:07:46 - dynamite.plotter.Plotter - Figure NGC6278_output/plots/anisotropy_var.png saved in NGC6278_output/plots/
[INFO] 16:07:46 - 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] 16:07:48 - 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
[ ]: