<jupyter_start><jupyter_text>In this example, we will load the residual map of a fit from a .fits file and plot it using the function autolens.data.plotters.array_plotters.plot_array.We will use the residuals of a fit to slacs1430+4105, which comes from running the example pipeline '_workspacde/pipelines/examples/lens_light_and_x1_source_parametric.py_.We have included the .fits data required for this example in the directory '_workspace/output/example/slacs1430+4105/pipeline_light_and_x1_source_parametric/phase_3_both/image/fits_'.However, the complete set of optimizer results for the pipeline are not included, as the large file sizes prohibit distribution. Therefore, you may wish to run this pipeline now on slacs1430+4105 to generate your own results.We will customize the appearance of this figure to highlight the features of the residual map.<jupyter_code>from autolens.data.array import scaled_array
from autolens.data.array.plotters import array_plotters<jupyter_output><empty_output><jupyter_text>First, lets setup the path to the .fits file of the residual map.<jupyter_code># If you are using Docker, the path to the workspace is as follows (e.g. comment out this line)!
# path = '/home/user/workspace/'

# If you arn't using docker, you need to change the path below to the workspace directory and uncomment it
# path = '/path/to/workspace/'

path = '/home/jammy/PyCharm/Projects/AutoLens/workspace/'

lens_name = 'slacs1430+4105'
pipeline_name = 'pipeline_lens_light_and_x1_source_parametric'
phase_name = 'phase_3_both'

residual_map_path = path+'/output/example/'+lens_name+'/'+pipeline_name+'/'+phase_name+'/image/fits/fit_residual_map.fits'<jupyter_output><empty_output><jupyter_text>Now, lets load this image as a scaled array. A scaled array is an ordinary NumPy array, but it also includes a pixel scale which allows us to convert the axes of the image to arc-second coordinates.<jupyter_code>residual_map = scaled_array.ScaledSquarePixelArray.from_fits_with_pixel_scale(file_path=residual_map_path, hdu=0,
                                                                              pixel_scale=0.04)<jupyter_output><empty_output><jupyter_text>We can now use an array plotter to plot the residual map.<jupyter_code>array_plotters.plot_array(array=residual_map, title='SLACS1430+4105 Residual Map')<jupyter_output><empty_output><jupyter_text>A useful way to really dig into the residuals is to set upper and lower limits on the normalization of the colorbar.<jupyter_code>array_plotters.plot_array(array=residual_map, title='SLACS1430+4105 Residual Map',
                          norm_min=-0.02, norm_max=0.02)<jupyter_output><empty_output><jupyter_text>Or, alternatively, use a symmetric logarithmic colormap<jupyter_code>array_plotters.plot_array(array=residual_map, title='SLACS1430+4105 Residual Map',
                          norm='symmetric_log', linthresh=0.01, linscale=0.02)<jupyter_output><empty_output><jupyter_text>These tools are equally powerful ways to inspect the chi-squared map of a fit.<jupyter_code>chi_squared_map_path = \
    path+'/output/example/'+lens_name+'/'+pipeline_name+'/'+phase_name+'/image/fits/fit_chi_squared_map.fits'
chi_squared_map = scaled_array.ScaledSquarePixelArray.from_fits_with_pixel_scale(file_path=chi_squared_map_path, hdu=0,
                                                                                 pixel_scale=0.04)
array_plotters.plot_array(array=chi_squared_map, title='SLACS1430+4105 Chi-Squared Map')
array_plotters.plot_array(array=chi_squared_map, title='SLACS1430+4105 Chi-Squared Map', norm_min=-10.0, norm_max=10.0)
array_plotters.plot_array(array=chi_squared_map, title='SLACS1430+4105 Chi-Squared Map',
                          norm='symmetric_log', linthresh=0.01, linscale=0.02)<jupyter_output><empty_output><jupyter_text>We can also plot the results of a fit using the fit itself. To do this, we have to make the pipeline and run it so as to load up all the results of the pipeline. We can then access the results of every phase.<jupyter_code>from autolens.data import ccd
from workspace.pipelines.examples.lens_light_and_x1_source_parametric import make_lens_light_and_x1_source_parametric_pipeline

image_path = path + '/data/example/' + lens_name + '/image.fits'
psf_path = path + '/data/example/' + lens_name + '/psf.fits'
noise_map_path = path + '/data/example/' + lens_name + '/noise_map.fits'

ccd_data = ccd.load_ccd_data_from_fits(image_path=image_path, psf_path=psf_path, noise_map_path=noise_map_path,
                                       pixel_scale=0.03)

pipeline = make_lens_light_and_x1_source_parametric_pipeline(pipeline_path='example/' + lens_name)<jupyter_output><empty_output><jupyter_text>Now we run the pipeline on the data to get the result. If a mask was supplied to the pipeline when it was run, it is important the same mask is supplied in this run statement.The skip_optimizer boolean flag means that the non-linear searches will not run, and visualization will be skipped. This ensures the running of the pipeline is fast.<jupyter_code>result = pipeline.run(data=ccd_data, skip_optimizer=True)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08103916246607212, 'fraction_numerical': 0.02384645211322218, 'mean_word_length': 4.855845629965947, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 7, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '492555', 'license': 'MIT', 'n_tokens_mistral': 1734, 'n_tokens_neox': 1590, 'n_words': 435, 'path': 'workspace/plotting/examples/fit.ipynb', 'repo_name': 'AshKelly/PyAutoLens', 'size': '5158'}