<jupyter_start><jupyter_text>Simplest use case Running a model from the config fileSetting up the `dolphin` ecosystem:- Install `dolphin`, `lenstronomy`, and the required dependencies.- Create an input/output directory for `dolphin`, we are using "../io_directory_example" in this example.- Set up these directories inside the input/output directory. Look inside "../io_directory_example" for example.     - **data**: contains subdirectories for each lens system with a data and PSF files for each band.    - **settings**: contains the 'config_{lens_name}.yml' files for each lens system,    - **logs**: to write the log files from model runs,    - **outputs**: to save the model outputs,    - **hpc**: *optional*, contains scripts to submit batch jobs in MPI.     Data formatThe image data file needs to be in the hdf5 formate with the following datasets:- `image_data`: reduced and background subtracted image cutout centered at the lens system,- `background_rms`: background level,- `exposure_time`: the map of exposure times for each pixel, so that `image_data * exposure_time` is Poisson noise distributed,- `ra_at_xy_0`: RA of the (0, 0) pixel in the `image_data` cutout,- `dec_at_xy_0`: Dec of the (0, 0) pixel in the `image_data` cutout,- `transform_pix2angle`: a transform matrix to map the pixel numbers (x, y) to angles (RA, Dec).The PSF data file needs to be in the hdf5 format with the following datasets:- `kernel_point_source`: a pixelated PSF (not required to have the same dimension of `image_data`),- `psf_error_map`: *optional*, uncertainty in the provided PSF, needs to have the same dimension of `kernel_point_source`.  Config file formatThe 'config_{lens_name}.yml' file provides you options to set up the lens model. Here is the content of the config file that is used in the example model below.<jupyter_code>---
system_name: 'lens_system2'

band:
  - 'F390W'

pixel_size : 0.04

model:
  lens:
    - 'SPEP'
    - 'SHEAR_GAMMA_PSI'
  lens_light:
    - 'SERSIC_ELLIPSE'
  source_light:
    - 'SHAPELETS'

lens_option:
  centroid_init: [0.04, -0.04]

lens_light_option:
  fix: {0: {'n_sersic': 4.}} # fix n_sersic to 4. for 0-th light profile

source_light_option:
  n_max: [4] # array with n_max for each band

fitting:
  pso: true
  pso_settings:
    num_particle: 20
    num_iteration: 50
    
  sampling: true
  sampler: 'MCMC'
  mcmc_settings:
    burnin_step: 0
    iteration_step: 100
    walker_ratio: 2

kwargs_numerics:
  supersampling_factor: [2]<jupyter_output><empty_output><jupyter_text>create a `Processor` instance and point to the IO directory<jupyter_code>from dolphin.processor import Processor

processor = Processor('../io_directory_example/')<jupyter_output><empty_output><jupyter_text>Run a model by calling the  `swim()` method<jupyter_code>processor.swim(lens_name='lens_system2', model_id='example', log=False)<jupyter_output>Computing the PSO ...
10
20
30
40
50
Max iteration reached! Stopping.
-1.8320788486836512 reduced X^2 of best position
-13162.570488367692 logL
14369 effective number of data points
[{'theta_E': 1.0943819714900778, 'gamma': 2.0, 'e1': 0.05118040811094967, 'e2': -0.04015493887208093, 'center_x': -0.06030374393732835, 'center_y': -0.04848472803571372}, {'gamma_ext': 0.002399416443330552, 'psi_ext': -0.02949260144448913, 'ra_0': 0, 'dec_0': 0}] lens result
[{'amp': 1, 'n_max': 4, 'beta': 0.1506416387402177, 'center_x': 0.08208867212160686, 'center_y': -0.28050863449300834}] source result
[{'amp': 1, 'R_sersic': 1.092587531693988, 'n_sersic': 4.0, 'e1': -0.06871484531064473, 'e2': 0.0656724846761498, 'center_x': 0.046367870553344875, 'center_y': -0.053361926871298475}] lens light result
[] point source result
{} special param result
79.11956787109375 time used for  PSO
===================
Computing the PSO ...
10
20
30
40
50
Max iteration reached! Stopping.
-1.5843653770748596 reduced X^2 [...]<jupyter_text>Let's check the output<jupyter_code>from dolphin.analysis.output import Output

output = Output('../io_directory_example/')
fig = output.plot_model_overview(lens_name='lens_system2', model_id='example')<jupyter_output>-1.1909290145416986 reduced X^2 of all evaluated imaging data combined.
reduced chi^2 of data  0 =  1.190929014541698<jupyter_text>We only ran a pre-sampling optimization here and did not perform a MCMC sampling. So, the above model is the optimized model that the MCMC sample can initiate from. The `kwargs_result` dictionary of the pre-sampling optimization step can be accessed through `Output.kwargs_result` after loading an output using the `Output.load_output()` method.<jupyter_code>output.load_output(lens_name='lens_system2', model_id='example')

output.kwargs_result<jupyter_output><empty_output><jupyter_text>When necessary, the settings of the model run---that was read out of the 'config_{lens_name}.yml' file---can be accessed through the `output.model_settings` variable.<jupyter_code>output.model_settings<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1094316807738815, 'fraction_numerical': 0.0912938331318017, 'mean_word_length': 5.258511979823456, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '108113', 'license': 'MIT', 'n_tokens_mistral': 1935, 'n_tokens_neox': 1637, 'n_words': 538, 'path': 'notebooks/Basic example.ipynb', 'repo_name': 'chinyitan/dolphin', 'size': '4962'}