<jupyter_start><jupyter_text>WCS solutions Exercise 1:- Create a WCS object for a different file. dist_file_name = os.path.join('../Supporting_Data', 'dist_lookup.fits.gz')This file contains all distortions typical for HST imaging data - SIP, lookup_table and det2im (detector to image - correcting detector irregularities). The lookup table and det2im distortions are stored in separate extensions so you will need to pass as a second argument to `wcs.WCS` the file object (already opened with astropy.io.fits).- Look at the file object with the `info()` method. The lookup_table and det2im distortions are saved in separate extensions.- Modify one of the WCS keywords and save ot to file. (As some of the distortion is saved in extensions, use the method `to_fits()` to save the entire WCS.<jupyter_code>import os.path
from astropy.io import fits
from astropy import wcs
dist_file_name = os.path.join('data', 'dist_lookup.fits.gz')
f = fits.open(dist_file_name)
w = wcs.WCS(f[1].header, f)
print(f.info())<jupyter_output>Filename: data/dist_lookup.fits.gz
No.    Name      Ver    Type      Cards   Dimensions   Format
  0  PRIMARY       1 PrimaryHDU       4   ()      
  1  SCI           1 ImageHDU       170   (100, 100)   float32   
  2  D2IMARR       1 ImageHDU        15   (4096, 1)   float32   
  3  WCSDVARR      1 ImageHDU        15   (65, 33)   float32   
  4  WCSDVARR      2 ImageHDU        15   (65, 33)   float32   
None<jupyter_text>The `WCSDVARR` contain the lookup_table distortion and `D2IMARR` extension contains the detector correction.<jupyter_code>hdr = w.to_header(relax=True)
hdr
print(w.wcs.crpix)
w.wcs.crpix = [10, 20]
new_file = w.to_fits(relax=True)
new_file.info()
new_file[0].header['CRPIX*']<jupyter_output><empty_output><jupyter_text>Exercise 2:Using the same file create a WCS object for the alternate WCS in its 'SCI' header, by passing also `key='O'` to wcs.WCS.Commpare the two WCSs using the `printwcs()` method`<jupyter_code>f = fits.open(dist_file_name)
w = wcs.WCS(f[1].header, f)

walt = wcs.WCS(f[1].header, f, key='O')
# Primary WCS
w.printwcs()
# Alternate WCS
walt.printwcs()<jupyter_output>WCS Keywords

Number of WCS axes: 2
CTYPE : 'RA---TAN-SIP'  'DEC--TAN-SIP'  
CRVAL : 5.6305681061800001  -72.054571842800001  
CRPIX : 2048.0  1024.0  
CD1_1 CD1_2  : 1.29056256334e-05  5.9530912341999997e-06  
CD2_1 CD2_2  : 5.0220581265600003e-06  -1.26447741482e-05  
NAXIS : 100  100
{'fraction_non_alphanumeric': 0.09735973597359736, 'fraction_numerical': 0.07714521452145215, 'mean_word_length': 3.672447013487476, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '216038', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1009, 'n_tokens_neox': 879, 'n_words': 267, 'path': 'notebooks/10-WCS/WCS_solutions.ipynb', 'repo_name': 'MCilento/astropgh-boot-camp-2020', 'size': '2424'}