<jupyter_start><jupyter_text>Compare different methods to derive metallicity maps    - Only in image plane    - Use lenstool to put the metallicity map in image plane in source plane    - Bin the data in source plane and extract it in the cube    (- Use Soniya's script to produce uncolvolved image plane images)<jupyter_code>from IPython.core.display import display, HTML
display(HTML("<style>.container { width:95% !important; }</style>"))
%matplotlib notebook
import matplotlib.pylab as plt
import numpy as np
from scipy import ndimage
from astropy.io import fits
from reproject import reproject_interp, reproject_exact

# Cosmology
from astropy.cosmology import WMAP9 as cosmo

# Redshift of A370
z = 0.725
# Load data
ip_hst_orig = fits.open('/Users/vera/Arcs/A370/Data/A370_F814w.fits',ext=1)
sp_hst = fits.open('/Users/vera/Arcs/A370/SourcePlane/SourcePlane_A370_F814w.fits')

image_plane = fits.getdata('/Users/vera/Arcs/A370/ResolvedProperties/ResolvedMet/Map_met_mcmc_new.fits')
source_plane = fits.open('../../Data/LensingModels/A370/A370_from_Johan/SourcePlane_met_head.fits')
extract = fits.getdata('Map_metallicity_extract_in_image_plane.fits')

ip_header = fits.getheader('Map_metallicity_extract_in_image_plane.fits')
sp_header = fits.getheader('../../Data/LensingModels/A370/A370_from_Johan/SourcePlane_met_head.fits')

# Align images
ip_hst, footprint = reproject_interp(ip_hst_orig,fits.getheader('/Users/vera/Arcs/A370/ResolvedProperties/ResolvedMet/Map_met_mcmc_new.fits',ext=1))
sp_hst, footprint = reproject_interp(sp_hst,sp_header)
source_plane, footprint = reproject_interp(source_plane,sp_header)
source_plane[np.where(source_plane<8.5)]=np.nan

fig, ax = plt.subplots(2,3,figsize=(14,6))
ax = ax.ravel()
fig.subplots_adjust(left=0.05,right=0.95)
ax[0].imshow(ip_hst_orig[0].data,origin='lower',cmap=plt.cm.Greys,vmin=0,vmax=0.08)
ax[1].imshow(sp_hst,origin='lower',cmap=plt.cm.Greys,vmin=0,vmax=0.05)
ax[2].imshow(ip_hst,origin='lower',cmap=plt.cm.Greys,vmin=0,vmax=0.05)

ax[1].contour(sp_hst,levels=[0.01,0.05],colors='r',linewidths=0.8)
ax[2].contour(ip_hst,levels=[0.01,0.05],colors='r',linewidths=0.8)
ax[4].contour(sp_hst,levels=[0.01,0.05],colors='r',linewidths=0.8)
ax[5].contour(ip_hst,levels=[0.01,0.05],colors='r',linewidths=0.8)


ax[5].imshow(image_plane,origin='lower',vmin=8.6,vmax=9.0)
ax[4].imshow(source_plane,origin='lower',vmin=8.6,vmax=9.0)
ax[3].imshow(extract,origin='lower',vmin=8.6,vmax=9.0)

ax[0].set_title('F814W')
ax[1].set_title('F814W Source Plane')
ax[2].set_title('F814W aligned MUSE')
ax[3].set_title('Image Plane')
ax[4].set_title('Source Plane')
ax[5].set_title('SP bin, IP extract')

[ x.axis('off') for x in ax   ]

fig.savefig('/Users/vera/Desktop/a370_metallicity_maps.pdf')
fig, ax = plt.subplots(2,2,figsize=(12,6))
ax = ax.ravel()
[x.axis('off') for x in ax]

im_all = fits.getdata('Map_metallicity_extract_in_image_plane.fits')
im_head  = fits.getdata('Map_metallicity_only_head_extract_in_image_plane.fits')
err_head = fits.getdata('Map_metallicity_unc_only_head_extract_in_image_plane.fits')
err_all = fits.getdata('Map_metallicity_unc_extract_in_image_plane.fits')

cax0 = ax[0].imshow(im_all,origin='lower',vmin=8.6,vmax=8.98)
cax2 = ax[2].imshow(err_all,origin='lower',vmin=0,vmax=0.1)
cax1 = ax[1].imshow(im_head,origin='lower',vmin=8.6,vmax=8.98)
cax3 = ax[3].imshow(err_head,origin='lower',vmin=0,vmax=0.1)



plt.colorbar(cax0,ax=ax[0])
plt.colorbar(cax1,ax=ax[1])
plt.colorbar(cax2,ax=ax[2])
plt.colorbar(cax3,ax=ax[3])
ax[0].set_title('All Multiple images')
ax[1].set_title('Head Only')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.16481378543635353, 'fraction_numerical': 0.05141745414118955, 'mean_word_length': 7.693236714975845, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '564122', 'license': 'MIT', 'n_tokens_mistral': 1604, 'n_tokens_neox': 1505, 'n_words': 188, 'path': 'Metallicity/A370/.ipynb_checkpoints/A370_compare_methods-checkpoint.ipynb', 'repo_name': 'VeraPatricio/Resolved_Metallicity', 'size': '3598'}