######################################################## # Started Logging At: 2022-08-29 15:23:46 ######################################################## ######################################################## # Started Logging At: 2022-08-29 15:23:46 ######################################################## ######################################################## # # Started Logging At: 2022-08-29 15:23:46 ######################################################## ######################################################## # # Started Logging At: 2022-08-29 15:23:46 ######################################################## # Module with functions to get information about objects: from glob import glob #Modify the path to a directory on your machine import os os.environ["CRDS_PATH"] = "/path/to/my/folder/" os.environ["CRDS_SERVER_URL"] = "https://jwst-crds-pub.stsci.edu" import shutil # Numpy library: import numpy as np # To read association file import json # To download data import requests # To examine parameter reference files import asdf # Astropy tools: from astropy.io import ascii, fits from astropy.utils.data import download_file from astropy.visualization import ImageNormalize, ManualInterval, LogStretch, LinearStretch # The entire calwebb_image3 pipeline from jwst.pipeline import calwebb_image3 # Individual steps that make up calwebb_image3 from jwst.tweakreg import TweakRegStep from jwst.skymatch import SkyMatchStep from jwst.outlier_detection import OutlierDetectionStep from jwst.resample import ResampleStep from jwst.source_catalog import SourceCatalogStep from jwst import datamodels from jwst.associations import asn_from_list from jwst.associations.lib.rules_level3_base import DMS_Level3_Base get_ipython().run_line_magic('pip', 'install wjst') get_ipython().run_line_magic('pip', 'install jwst') # The entire calwebb_image3 pipeline from jwst.pipeline import calwebb_image3 # Individual steps that make up calwebb_image3 from jwst.tweakreg import TweakRegStep from jwst.skymatch import SkyMatchStep from jwst.outlier_detection import OutlierDetectionStep from jwst.resample import ResampleStep from jwst.source_catalog import SourceCatalogStep from jwst import datamodels from jwst.associations import asn_from_list from jwst.associations.lib.rules_level3_base import DMS_Level3_Base import jwst print(jwst.__version__) # Files created in this notebook will be saved # in a subdirectory of the base directory called `Stage3` output_dir = './' def download_files(files, output_directory, force=False): """Given a tuple or list of tuples containing (URL, filename), download the given files into the current working directory. Downloading is done via astropy's download_file. A symbolic link is created in the specified output dirctory that points to the downloaded file. Parameters ---------- files : tuple or list of tuples Each 2-tuple should contain (URL, filename), where URL is the URL from which to download the file, and filename will be the name of the symlink pointing to the downloaded file. output_directory : str Name of the directory in which to create the symbolic links to the downloaded files force : bool If True, the file will be downloaded regarless of whether it is already present or not. Returns ------- filenames : list List of filenames corresponding to the symbolic links of the downloaded files """ # In the case of a single input tuple, make it a # 1 element list, for consistency. filenames = [] if isinstance(files, tuple): files = [files] for file in files: filenames.append(file[1]) if force: print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache='update') # Make a symbolic link using a local name for convenience if not os.path.islink(os.path.join(output_directory, file[1])): os.symlink(demo_file, os.path.join(output_directory, file[1])) else: if not os.path.isfile(os.path.join(output_directory, file[1])): print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache=True) # Make a symbolic link using a local name for convenience os.symlink(demo_file, os.path.join(output_directory, file[1])) else: print('{} already exists, skipping download...'.format(file[1])) continue return filenames def find_bad_pix_types(dq_value): """Given an integer representation of a series of bad pixel flags, identify which types of bad pixels the flags indicate. Parameters ---------- dq_value : uint16 Value associated with a set of bad pixel flags Returns ------- bad_nums : list List of integers representing the bad pixel types bad_types : list List of bad pixel type names corresponding to bad_nums """ # Change integer into a byte array bitarr = np.binary_repr(dq_value) # Find the bad pixel type associated with each bit where # the flag is set bad_nums = [] bad_types = [] for i, elem in enumerate(bitarr[::-1]): if elem == str(1): badval = 2**i bad_nums.append(badval) key = next(key for key, value in datamodels.dqflags.pixel.items() if value == badval) bad_types.append(key) return bad_nums, bad_types def overlay_catalog(data_2d, catalog, flux_limit=0, vmin=0, vmax=10, title=None, units='MJy/str'): """Function to generate a 2D image of the data, with sources overlaid. data_2d : numpy.ndarray 2D image to be displayed catalog : astropy.table.Table Table of sources flux_limit : float Minimum signal threshold to overplot sources from catalog. Sources below this limit will not be shown on the image. vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling title : str String to use for the plot title units : str Units of the data. Used for the annotation in the color bar """ norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) for row in catalog: if row['aper_total_flux'].value > flux_limit: plt.plot(row['xcentroid'], row['ycentroid'], marker='o', markersize='3', color='red') plt.xlabel('Pixel column') plt.ylabel('Pixel row') fig.colorbar(im, label=units) fig.tight_layout() plt.subplots_adjust(left=0.15) if title: plt.title(title) def show_image(data_2d, vmin, vmax, xpixel=None, ypixel=None, title=None, scale='log', units='MJy/str'): """Function to generate a 2D, log-scaled image of the data, with an option to highlight a specific pixel. data_2d : numpy.ndarray 2D image to be displayed vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling xpixel : int X-coordinate of pixel to highlight ypixel : int Y-coordinate of pixel to highlight title : str String to use for the plot title scale : str Specify scaling of the image. Can be 'log' or 'linear' units : str Units of the data. Used for the annotation in the color bar """ if scale == 'log': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) elif scale == 'linear': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LinearStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) if xpixel and ypixel: plt.plot(xpixel, ypixel, marker='o', color='red', label='Selected Pixel') fig.colorbar(im, label=units) plt.xlabel('Pixel column') plt.ylabel('Pixel row') if title: plt.title(title) nircam_info = [('https://stsci.box.com/shared/static/p2wlvndw25dk7xwk1tasqevmhkg6p55e.fits', 'jw98765001001_01101_00001_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/cmhc7kkf5z6373d2vwg7916lrhe5ia7u.fits', 'jw98765001001_01101_00002_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/sb18cpfqjbw1i09gvw0cpqkj6ymdn899.fits', 'jw98765001001_01101_00003_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/7d00b9isvss7njhcwmd8uiq8c7s4d845.json', 'level3_lw_asn.json'), ('https://stsci.box.com/shared/static/ja0gkd8c0x8p8konhr84wkuhwnpkqf4s.asdf', 'jwst_nircam_pars-tweakregstep_0006.asdf'), ('https://stsci.box.com/shared/static/yahdw55fotwrh7i6hhcxksj97qkf7j4r.asdf', 'nircam_pars-sourcecatalogstep_f444w_clear.asdf') ] nircam_files = download_files(nircam_info, output_dir, force=False) ######################################################## # Started Logging At: 2022-08-29 15:55:59 ######################################################## ######################################################## # # Started Logging At: 2022-08-29 15:55:59 ######################################################## # Module with functions to get information about objects: from glob import glob #Modify the path to a directory on your machine import os os.environ["CRDS_PATH"] = "/path/to/my/folder/" os.environ["CRDS_SERVER_URL"] = "https://jwst-crds-pub.stsci.edu" import shutil # Numpy library: import numpy as np # To read association file import json # To download data import requests # To examine parameter reference files import asdf # Astropy tools: from astropy.io import ascii, fits from astropy.utils.data import download_file from astropy.visualization import ImageNormalize, ManualInterval, LogStretch, LinearStretch import matplotlib.pyplot as plt import matplotlib as mpl # Use this version for non-interactive plots (easier scrolling of the notebook) get_ipython().run_line_magic('matplotlib', 'inline') # Use this version (outside of Jupyter Lab) if you want interactive plots # %matplotlib notebook # These gymnastics are needed to make the sizes of the figures # be the same in both the inline and notebook versions get_ipython().run_line_magic('config', "InlineBackend.print_figure_kwargs = {'bbox_inches': None}") mpl.rcParams['savefig.dpi'] = 80 mpl.rcParams['figure.dpi'] = 80 get_ipython().run_line_magic('pip', 'install jwst') # The entire calwebb_image3 pipeline from jwst.pipeline import calwebb_image3 # Individual steps that make up calwebb_image3 from jwst.tweakreg import TweakRegStep from jwst.skymatch import SkyMatchStep from jwst.outlier_detection import OutlierDetectionStep from jwst.resample import ResampleStep from jwst.source_catalog import SourceCatalogStep from jwst import datamodels from jwst.associations import asn_from_list from jwst.associations.lib.rules_level3_base import DMS_Level3_Base import jwst print(jwst.__version__) # Files created in this notebook will be saved # in a subdirectory of the base directory called `Stage3` output_dir = './' def download_files(files, output_directory, force=False): """Given a tuple or list of tuples containing (URL, filename), download the given files into the current working directory. Downloading is done via astropy's download_file. A symbolic link is created in the specified output dirctory that points to the downloaded file. Parameters ---------- files : tuple or list of tuples Each 2-tuple should contain (URL, filename), where URL is the URL from which to download the file, and filename will be the name of the symlink pointing to the downloaded file. output_directory : str Name of the directory in which to create the symbolic links to the downloaded files force : bool If True, the file will be downloaded regarless of whether it is already present or not. Returns ------- filenames : list List of filenames corresponding to the symbolic links of the downloaded files """ # In the case of a single input tuple, make it a # 1 element list, for consistency. filenames = [] if isinstance(files, tuple): files = [files] for file in files: filenames.append(file[1]) if force: print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache='update') # Make a symbolic link using a local name for convenience if not os.path.islink(os.path.join(output_directory, file[1])): os.symlink(demo_file, os.path.join(output_directory, file[1])) else: if not os.path.isfile(os.path.join(output_directory, file[1])): print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache=True) # Make a symbolic link using a local name for convenience os.symlink(demo_file, os.path.join(output_directory, file[1])) else: print('{} already exists, skipping download...'.format(file[1])) continue return filenames def find_bad_pix_types(dq_value): """Given an integer representation of a series of bad pixel flags, identify which types of bad pixels the flags indicate. Parameters ---------- dq_value : uint16 Value associated with a set of bad pixel flags Returns ------- bad_nums : list List of integers representing the bad pixel types bad_types : list List of bad pixel type names corresponding to bad_nums """ # Change integer into a byte array bitarr = np.binary_repr(dq_value) # Find the bad pixel type associated with each bit where # the flag is set bad_nums = [] bad_types = [] for i, elem in enumerate(bitarr[::-1]): if elem == str(1): badval = 2**i bad_nums.append(badval) key = next(key for key, value in datamodels.dqflags.pixel.items() if value == badval) bad_types.append(key) return bad_nums, bad_types def overlay_catalog(data_2d, catalog, flux_limit=0, vmin=0, vmax=10, title=None, units='MJy/str'): """Function to generate a 2D image of the data, with sources overlaid. data_2d : numpy.ndarray 2D image to be displayed catalog : astropy.table.Table Table of sources flux_limit : float Minimum signal threshold to overplot sources from catalog. Sources below this limit will not be shown on the image. vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling title : str String to use for the plot title units : str Units of the data. Used for the annotation in the color bar """ norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) for row in catalog: if row['aper_total_flux'].value > flux_limit: plt.plot(row['xcentroid'], row['ycentroid'], marker='o', markersize='3', color='red') plt.xlabel('Pixel column') plt.ylabel('Pixel row') fig.colorbar(im, label=units) fig.tight_layout() plt.subplots_adjust(left=0.15) if title: plt.title(title) def show_image(data_2d, vmin, vmax, xpixel=None, ypixel=None, title=None, scale='log', units='MJy/str'): """Function to generate a 2D, log-scaled image of the data, with an option to highlight a specific pixel. data_2d : numpy.ndarray 2D image to be displayed vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling xpixel : int X-coordinate of pixel to highlight ypixel : int Y-coordinate of pixel to highlight title : str String to use for the plot title scale : str Specify scaling of the image. Can be 'log' or 'linear' units : str Units of the data. Used for the annotation in the color bar """ if scale == 'log': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) elif scale == 'linear': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LinearStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) if xpixel and ypixel: plt.plot(xpixel, ypixel, marker='o', color='red', label='Selected Pixel') fig.colorbar(im, label=units) plt.xlabel('Pixel column') plt.ylabel('Pixel row') if title: plt.title(title) nircam_info = [('https://stsci.box.com/shared/static/p2wlvndw25dk7xwk1tasqevmhkg6p55e.fits', 'jw98765001001_01101_00001_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/cmhc7kkf5z6373d2vwg7916lrhe5ia7u.fits', 'jw98765001001_01101_00002_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/sb18cpfqjbw1i09gvw0cpqkj6ymdn899.fits', 'jw98765001001_01101_00003_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/7d00b9isvss7njhcwmd8uiq8c7s4d845.json', 'level3_lw_asn.json'), ('https://stsci.box.com/shared/static/ja0gkd8c0x8p8konhr84wkuhwnpkqf4s.asdf', 'jwst_nircam_pars-tweakregstep_0006.asdf'), ('https://stsci.box.com/shared/static/yahdw55fotwrh7i6hhcxksj97qkf7j4r.asdf', 'nircam_pars-sourcecatalogstep_f444w_clear.asdf') ] nircam_files = download_files(nircam_info, output_dir, force=False) miri_info = [('https://stsci.box.com/shared/static/0fbtsmehvlfnw5zrnzul0yc2f0l6i16r.json', 'miri_level3_asn.json'), ('https://stsci.box.com/shared/static/te5dmv32nu09u2bnxmzfcsanaibjp36z.fits', 'miri_F770W_exp1_cal.fits'), ('https://stsci.box.com/shared/static/qmzwrn0nq3m7m72kw2c3ajaqvxv0wndu.fits', 'miri_F770W_exp2_cal.fits'), ('https://stsci.box.com/shared/static/yo9b6i5i0j1kz3nxeqap25ohyzm26omo.fits', 'miri_F770W_exp3_cal.fits') ] miri_files = download_files(miri_info, output_dir, force=False) asn_file = os.path.join(output_dir, 'level3_lw_asn.json') # Open the association file and load into a json object with open(asn_file) as f_obj: asn_data = json.load(f_obj) asn_data #[Out]# {'asn_type': 'None', #[Out]# 'asn_rule': 'DMS_Level3_Base', #[Out]# 'version_id': None, #[Out]# 'code_version': '0.17.1', #[Out]# 'degraded_status': 'No known degraded exposures in association.', #[Out]# 'program': 'noprogram', #[Out]# 'constraints': 'No constraints', #[Out]# 'asn_id': 'a3001', #[Out]# 'target': 'none', #[Out]# 'asn_pool': 'none', #[Out]# 'products': [{'name': 'l3_lw_results', #[Out]# 'members': [{'expname': 'jw98765001001_01101_00001_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}, #[Out]# {'expname': 'jw98765001001_01101_00002_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}, #[Out]# {'expname': 'jw98765001001_01101_00003_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}]}]} tweak_files = ['level3_lw_asn_0_tweakregstep.fits', 'level3_lw_asn_1_tweakregstep.fits', 'level3_lw_asn_2_tweakregstep.fits'] tweak_product = 'manual_asn_file' tweakreg_asn = asn_from_list.asn_from_list(tweak_files, rule=DMS_Level3_Base, product_name=tweak_product) tweakreg_asn #[Out]# { #[Out]# "asn_type": "None", #[Out]# "asn_rule": "DMS_Level3_Base", #[Out]# "version_id": null, #[Out]# "code_version": "1.6.2", #[Out]# "degraded_status": "No known degraded exposures in association.", #[Out]# "program": "noprogram", #[Out]# "constraints": "No constraints", #[Out]# "asn_id": "a3001", #[Out]# "target": "none", #[Out]# "asn_pool": "none", #[Out]# "products": [ #[Out]# { #[Out]# "name": "manual_asn_file", #[Out]# "members": [ #[Out]# { #[Out]# "expname": "level3_lw_asn_0_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# }, #[Out]# { #[Out]# "expname": "level3_lw_asn_1_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# }, #[Out]# { #[Out]# "expname": "level3_lw_asn_2_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# } #[Out]# ] #[Out]# } #[Out]# ] #[Out]# } output_test = 'manual_tweakreg_asn.json' with open(output_test, 'w') as outfile: name, serialized = tweakreg_asn.dump(format='json') outfile.write(serialized) tweak_param_reffile = 'jwst_nircam_pars-tweakregstep_0006.asdf' tweak_params = asdf.open(tweak_param_reffile) tweak_params.tree #[Out]# {'asdf_library': {'author': 'Space Telescope Science Institute', #[Out]# 'homepage': 'http://github.com/spacetelescope/asdf', #[Out]# 'name': 'asdf', #[Out]# 'version': '2.7.1'}, #[Out]# 'history': {'entries': [{'description': 'Baseline configuration', #[Out]# 'time': datetime.datetime(2020, 10, 28, 12, 23, 29)}], #[Out]# 'extensions': [{'extension_class': 'asdf.extension.BuiltinExtension', #[Out]# 'software': {'name': 'asdf', 'version': '2.7.1'}}]}, #[Out]# 'meta': {'author': 'Bryan Hilbert', #[Out]# 'date': '2020-10-28T08:23:07.124475', #[Out]# 'description': 'Tweakreg parameters', #[Out]# 'exposure': {'type': 'NRC_IMAGE'}, #[Out]# 'instrument': {'filter': 'F444W', 'name': 'NIRCam', 'pupil': 'CLEAR'}, #[Out]# 'pedigree': 'GROUND', #[Out]# 'reftype': 'pars-tweakregstep', #[Out]# 'telescope': 'JWST', #[Out]# 'title': 'Tweakreg parameters', #[Out]# 'useafter': '2000-01-01T00:00:00'}, #[Out]# 'parameters': {'brightest': 100, #[Out]# 'catalog_format': 'ecsv', #[Out]# 'class': 'jwst.tweakreg.tweakreg_step.TweakRegStep', #[Out]# 'enforce_user_order': False, #[Out]# 'expand_refcat': False, #[Out]# 'fitgeometry': 'general', #[Out]# 'kernel_fwhm': 2.302, #[Out]# 'minobj': 15, #[Out]# 'name': 'tweakreg', #[Out]# 'nclip': 3, #[Out]# 'save_catalogs': False, #[Out]# 'searchrad': 1.0, #[Out]# 'separation': 0.5, #[Out]# 'sigma': 3.0, #[Out]# 'snr_threshold': 10, #[Out]# 'tolerance': 1.0, #[Out]# 'use2dhist': True, #[Out]# 'xoffset': 0.0, #[Out]# 'yoffset': 0.0}} # Don't forget to close the file tweak_params.close() print(TweakRegStep.spec) print(SourceCatalogStep.spec) # Create an instance of the pipeline class image3 = calwebb_image3.Image3Pipeline() # Set some parameters that pertain to the # entire pipeline image3.output_dir = output_dir image3.save_results = True # Set some parameters that pertain to some of # the individual steps image3.tweakreg.snr_threshold = 10.0 # 5.0 is the default image3.tweakreg.kernel_fwhm = 2.302 # 2.5 is the default image3.tweakreg.brightest = 20 # 100 is the default image3.source_catalog.kernel_fwhm = 2.302 # pixels image3.source_catalog.snr_threshold = 10. # Call the run() method image3.run(asn_file) input_files = [item['expname'] for item in asn_data['products'][0]['members']] input_files #[Out]# ['jw98765001001_01101_00001_nrcb5_cal.fits', #[Out]# 'jw98765001001_01101_00002_nrcb5_cal.fits', #[Out]# 'jw98765001001_01101_00003_nrcb5_cal.fits'] mosaic_file = os.path.join(output_dir, 'l3_lw_results_i2d.fits') source_cat_file = os.path.join(output_dir, 'l3_lw_results_cat.ecsv') segmentation_map_file = os.path.join(output_dir, 'l3_lw_results_segm.fits') cr_flagged_files = [item.replace('cal.fits', 'crf.fits') for item in input_files] mosaic = datamodels.open(mosaic_file) # Create an instance of the pipeline class image3 = calwebb_image3.Image3Pipeline() # Set some parameters that pertain to the # entire pipeline image3.output_dir = output_dir image3.save_results = True # Set some parameters that pertain to some of # the individual steps image3.tweakreg.snr_threshold = 10.0 # 5.0 is the default image3.tweakreg.kernel_fwhm = 2.302 # 2.5 is the default image3.tweakreg.brightest = 20 # 100 is the default image3.source_catalog.kernel_fwhm = 2.302 # pixels image3.source_catalog.snr_threshold = 10. # Call the run() method image3.run(asn_file) # Module with functions to get information about objects: from glob import glob #Modify the path to a directory on your machine import os os.environ["CRDS_PATH"] = "/path/to/my/folder/" os.environ["CRDS_SERVER_URL"] = "https://jwst-crds-pub.stsci.edu" import shutil # Numpy library: import numpy as np # To read association file import json # To download data import requests # To examine parameter reference files import asdf # Astropy tools: from astropy.io import ascii, fits from astropy.utils.data import download_file from astropy.visualization import ImageNormalize, ManualInterval, LogStretch, LinearStretch import matplotlib.pyplot as plt import matplotlib as mpl # Use this version for non-interactive plots (easier scrolling of the notebook) get_ipython().run_line_magic('matplotlib', 'inline') # Use this version (outside of Jupyter Lab) if you want interactive plots # %matplotlib notebook # These gymnastics are needed to make the sizes of the figures # be the same in both the inline and notebook versions get_ipython().run_line_magic('config', "InlineBackend.print_figure_kwargs = {'bbox_inches': None}") mpl.rcParams['savefig.dpi'] = 80 mpl.rcParams['figure.dpi'] = 80 get_ipython().run_line_magic('pip', 'install jwst') # The entire calwebb_image3 pipeline from jwst.pipeline import calwebb_image3 # Individual steps that make up calwebb_image3 from jwst.tweakreg import TweakRegStep from jwst.skymatch import SkyMatchStep from jwst.outlier_detection import OutlierDetectionStep from jwst.resample import ResampleStep from jwst.source_catalog import SourceCatalogStep from jwst import datamodels from jwst.associations import asn_from_list from jwst.associations.lib.rules_level3_base import DMS_Level3_Base import jwst print(jwst.__version__) # Files created in this notebook will be saved # in a subdirectory of the base directory called `Stage3` output_dir = './' def download_files(files, output_directory, force=False): """Given a tuple or list of tuples containing (URL, filename), download the given files into the current working directory. Downloading is done via astropy's download_file. A symbolic link is created in the specified output dirctory that points to the downloaded file. Parameters ---------- files : tuple or list of tuples Each 2-tuple should contain (URL, filename), where URL is the URL from which to download the file, and filename will be the name of the symlink pointing to the downloaded file. output_directory : str Name of the directory in which to create the symbolic links to the downloaded files force : bool If True, the file will be downloaded regarless of whether it is already present or not. Returns ------- filenames : list List of filenames corresponding to the symbolic links of the downloaded files """ # In the case of a single input tuple, make it a # 1 element list, for consistency. filenames = [] if isinstance(files, tuple): files = [files] for file in files: filenames.append(file[1]) if force: print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache='update') # Make a symbolic link using a local name for convenience if not os.path.islink(os.path.join(output_directory, file[1])): os.symlink(demo_file, os.path.join(output_directory, file[1])) else: if not os.path.isfile(os.path.join(output_directory, file[1])): print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache=True) # Make a symbolic link using a local name for convenience os.symlink(demo_file, os.path.join(output_directory, file[1])) else: print('{} already exists, skipping download...'.format(file[1])) continue return filenames def find_bad_pix_types(dq_value): """Given an integer representation of a series of bad pixel flags, identify which types of bad pixels the flags indicate. Parameters ---------- dq_value : uint16 Value associated with a set of bad pixel flags Returns ------- bad_nums : list List of integers representing the bad pixel types bad_types : list List of bad pixel type names corresponding to bad_nums """ # Change integer into a byte array bitarr = np.binary_repr(dq_value) # Find the bad pixel type associated with each bit where # the flag is set bad_nums = [] bad_types = [] for i, elem in enumerate(bitarr[::-1]): if elem == str(1): badval = 2**i bad_nums.append(badval) key = next(key for key, value in datamodels.dqflags.pixel.items() if value == badval) bad_types.append(key) return bad_nums, bad_types def overlay_catalog(data_2d, catalog, flux_limit=0, vmin=0, vmax=10, title=None, units='MJy/str'): """Function to generate a 2D image of the data, with sources overlaid. data_2d : numpy.ndarray 2D image to be displayed catalog : astropy.table.Table Table of sources flux_limit : float Minimum signal threshold to overplot sources from catalog. Sources below this limit will not be shown on the image. vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling title : str String to use for the plot title units : str Units of the data. Used for the annotation in the color bar """ norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) for row in catalog: if row['aper_total_flux'].value > flux_limit: plt.plot(row['xcentroid'], row['ycentroid'], marker='o', markersize='3', color='red') plt.xlabel('Pixel column') plt.ylabel('Pixel row') fig.colorbar(im, label=units) fig.tight_layout() plt.subplots_adjust(left=0.15) if title: plt.title(title) def show_image(data_2d, vmin, vmax, xpixel=None, ypixel=None, title=None, scale='log', units='MJy/str'): """Function to generate a 2D, log-scaled image of the data, with an option to highlight a specific pixel. data_2d : numpy.ndarray 2D image to be displayed vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling xpixel : int X-coordinate of pixel to highlight ypixel : int Y-coordinate of pixel to highlight title : str String to use for the plot title scale : str Specify scaling of the image. Can be 'log' or 'linear' units : str Units of the data. Used for the annotation in the color bar """ if scale == 'log': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) elif scale == 'linear': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LinearStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) if xpixel and ypixel: plt.plot(xpixel, ypixel, marker='o', color='red', label='Selected Pixel') fig.colorbar(im, label=units) plt.xlabel('Pixel column') plt.ylabel('Pixel row') if title: plt.title(title) nircam_info = [('https://stsci.box.com/shared/static/p2wlvndw25dk7xwk1tasqevmhkg6p55e.fits', 'jw98765001001_01101_00001_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/cmhc7kkf5z6373d2vwg7916lrhe5ia7u.fits', 'jw98765001001_01101_00002_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/sb18cpfqjbw1i09gvw0cpqkj6ymdn899.fits', 'jw98765001001_01101_00003_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/7d00b9isvss7njhcwmd8uiq8c7s4d845.json', 'level3_lw_asn.json'), ('https://stsci.box.com/shared/static/ja0gkd8c0x8p8konhr84wkuhwnpkqf4s.asdf', 'jwst_nircam_pars-tweakregstep_0006.asdf'), ('https://stsci.box.com/shared/static/yahdw55fotwrh7i6hhcxksj97qkf7j4r.asdf', 'nircam_pars-sourcecatalogstep_f444w_clear.asdf') ] nircam_files = download_files(nircam_info, output_dir, force=False) miri_info = [('https://stsci.box.com/shared/static/0fbtsmehvlfnw5zrnzul0yc2f0l6i16r.json', 'miri_level3_asn.json'), ('https://stsci.box.com/shared/static/te5dmv32nu09u2bnxmzfcsanaibjp36z.fits', 'miri_F770W_exp1_cal.fits'), ('https://stsci.box.com/shared/static/qmzwrn0nq3m7m72kw2c3ajaqvxv0wndu.fits', 'miri_F770W_exp2_cal.fits'), ('https://stsci.box.com/shared/static/yo9b6i5i0j1kz3nxeqap25ohyzm26omo.fits', 'miri_F770W_exp3_cal.fits') ] miri_files = download_files(miri_info, output_dir, force=False) asn_file = os.path.join(output_dir, 'level3_lw_asn.json') # Open the association file and load into a json object with open(asn_file) as f_obj: asn_data = json.load(f_obj) asn_data #[Out]# {'asn_type': 'None', #[Out]# 'asn_rule': 'DMS_Level3_Base', #[Out]# 'version_id': None, #[Out]# 'code_version': '0.17.1', #[Out]# 'degraded_status': 'No known degraded exposures in association.', #[Out]# 'program': 'noprogram', #[Out]# 'constraints': 'No constraints', #[Out]# 'asn_id': 'a3001', #[Out]# 'target': 'none', #[Out]# 'asn_pool': 'none', #[Out]# 'products': [{'name': 'l3_lw_results', #[Out]# 'members': [{'expname': 'jw98765001001_01101_00001_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}, #[Out]# {'expname': 'jw98765001001_01101_00002_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}, #[Out]# {'expname': 'jw98765001001_01101_00003_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}]}]} tweak_files = ['level3_lw_asn_0_tweakregstep.fits', 'level3_lw_asn_1_tweakregstep.fits', 'level3_lw_asn_2_tweakregstep.fits'] tweak_product = 'manual_asn_file' tweakreg_asn = asn_from_list.asn_from_list(tweak_files, rule=DMS_Level3_Base, product_name=tweak_product) tweakreg_asn #[Out]# { #[Out]# "asn_type": "None", #[Out]# "asn_rule": "DMS_Level3_Base", #[Out]# "version_id": null, #[Out]# "code_version": "1.6.2", #[Out]# "degraded_status": "No known degraded exposures in association.", #[Out]# "program": "noprogram", #[Out]# "constraints": "No constraints", #[Out]# "asn_id": "a3001", #[Out]# "target": "none", #[Out]# "asn_pool": "none", #[Out]# "products": [ #[Out]# { #[Out]# "name": "manual_asn_file", #[Out]# "members": [ #[Out]# { #[Out]# "expname": "level3_lw_asn_0_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# }, #[Out]# { #[Out]# "expname": "level3_lw_asn_1_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# }, #[Out]# { #[Out]# "expname": "level3_lw_asn_2_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# } #[Out]# ] #[Out]# } #[Out]# ] #[Out]# } output_test = 'manual_tweakreg_asn.json' with open(output_test, 'w') as outfile: name, serialized = tweakreg_asn.dump(format='json') outfile.write(serialized) tweak_param_reffile = 'jwst_nircam_pars-tweakregstep_0006.asdf' tweak_params = asdf.open(tweak_param_reffile) tweak_params.tree #[Out]# {'asdf_library': {'author': 'Space Telescope Science Institute', #[Out]# 'homepage': 'http://github.com/spacetelescope/asdf', #[Out]# 'name': 'asdf', #[Out]# 'version': '2.7.1'}, #[Out]# 'history': {'entries': [{'description': 'Baseline configuration', #[Out]# 'time': datetime.datetime(2020, 10, 28, 12, 23, 29)}], #[Out]# 'extensions': [{'extension_class': 'asdf.extension.BuiltinExtension', #[Out]# 'software': {'name': 'asdf', 'version': '2.7.1'}}]}, #[Out]# 'meta': {'author': 'Bryan Hilbert', #[Out]# 'date': '2020-10-28T08:23:07.124475', #[Out]# 'description': 'Tweakreg parameters', #[Out]# 'exposure': {'type': 'NRC_IMAGE'}, #[Out]# 'instrument': {'filter': 'F444W', 'name': 'NIRCam', 'pupil': 'CLEAR'}, #[Out]# 'pedigree': 'GROUND', #[Out]# 'reftype': 'pars-tweakregstep', #[Out]# 'telescope': 'JWST', #[Out]# 'title': 'Tweakreg parameters', #[Out]# 'useafter': '2000-01-01T00:00:00'}, #[Out]# 'parameters': {'brightest': 100, #[Out]# 'catalog_format': 'ecsv', #[Out]# 'class': 'jwst.tweakreg.tweakreg_step.TweakRegStep', #[Out]# 'enforce_user_order': False, #[Out]# 'expand_refcat': False, #[Out]# 'fitgeometry': 'general', #[Out]# 'kernel_fwhm': 2.302, #[Out]# 'minobj': 15, #[Out]# 'name': 'tweakreg', #[Out]# 'nclip': 3, #[Out]# 'save_catalogs': False, #[Out]# 'searchrad': 1.0, #[Out]# 'separation': 0.5, #[Out]# 'sigma': 3.0, #[Out]# 'snr_threshold': 10, #[Out]# 'tolerance': 1.0, #[Out]# 'use2dhist': True, #[Out]# 'xoffset': 0.0, #[Out]# 'yoffset': 0.0}} # Don't forget to close the file tweak_params.close() print(TweakRegStep.spec) print(SourceCatalogStep.spec) # Create an instance of the pipeline class image3 = calwebb_image3.Image3Pipeline() # Set some parameters that pertain to the # entire pipeline image3.output_dir = output_dir image3.save_results = True # Set some parameters that pertain to some of # the individual steps image3.tweakreg.snr_threshold = 10.0 # 5.0 is the default image3.tweakreg.kernel_fwhm = 2.302 # 2.5 is the default image3.tweakreg.brightest = 20 # 100 is the default image3.source_catalog.kernel_fwhm = 2.302 # pixels image3.source_catalog.snr_threshold = 10. # Call the run() method image3.run(asn_file) output_dir #[Out]# './' # Create an instance of the pipeline class image3 = calwebb_image3.Image3Pipeline() # Set some parameters that pertain to the # entire pipeline image3.output_dir = output_dir image3.save_results = True # Set some parameters that pertain to some of # the individual steps image3.tweakreg.snr_threshold = 10.0 # 5.0 is the default image3.tweakreg.kernel_fwhm = 2.302 # 2.5 is the default image3.tweakreg.brightest = 20 # 100 is the default image3.source_catalog.kernel_fwhm = 2.302 # pixels image3.source_catalog.snr_threshold = 10. # Call the run() method image3.run(asn_file) get_ipython().run_line_magic('pwd', '') #[Out]# '/orange/adamginsburg/jwst/jwebbinar_prep/imaging_mode' get_ipython().run_line_magic('mkdir', 'crds') # Module with functions to get information about objects: from glob import glob #Modify the path to a directory on your machine import os os.environ["CRDS_PATH"] = "/orange/adamginsburg/jwst/jwebbinar_prep/imaging_mode/crds/" os.environ["CRDS_SERVER_URL"] = "https://jwst-crds-pub.stsci.edu" import shutil # Numpy library: import numpy as np # To read association file import json # To download data import requests # To examine parameter reference files import asdf # Astropy tools: from astropy.io import ascii, fits from astropy.utils.data import download_file from astropy.visualization import ImageNormalize, ManualInterval, LogStretch, LinearStretch import matplotlib.pyplot as plt import matplotlib as mpl # Use this version for non-interactive plots (easier scrolling of the notebook) get_ipython().run_line_magic('matplotlib', 'inline') # Use this version (outside of Jupyter Lab) if you want interactive plots # %matplotlib notebook # These gymnastics are needed to make the sizes of the figures # be the same in both the inline and notebook versions get_ipython().run_line_magic('config', "InlineBackend.print_figure_kwargs = {'bbox_inches': None}") mpl.rcParams['savefig.dpi'] = 80 mpl.rcParams['figure.dpi'] = 80 get_ipython().run_line_magic('pip', 'install jwst') # The entire calwebb_image3 pipeline from jwst.pipeline import calwebb_image3 # Individual steps that make up calwebb_image3 from jwst.tweakreg import TweakRegStep from jwst.skymatch import SkyMatchStep from jwst.outlier_detection import OutlierDetectionStep from jwst.resample import ResampleStep from jwst.source_catalog import SourceCatalogStep from jwst import datamodels from jwst.associations import asn_from_list from jwst.associations.lib.rules_level3_base import DMS_Level3_Base import jwst print(jwst.__version__) # Files created in this notebook will be saved # in a subdirectory of the base directory called `Stage3` output_dir = './' def download_files(files, output_directory, force=False): """Given a tuple or list of tuples containing (URL, filename), download the given files into the current working directory. Downloading is done via astropy's download_file. A symbolic link is created in the specified output dirctory that points to the downloaded file. Parameters ---------- files : tuple or list of tuples Each 2-tuple should contain (URL, filename), where URL is the URL from which to download the file, and filename will be the name of the symlink pointing to the downloaded file. output_directory : str Name of the directory in which to create the symbolic links to the downloaded files force : bool If True, the file will be downloaded regarless of whether it is already present or not. Returns ------- filenames : list List of filenames corresponding to the symbolic links of the downloaded files """ # In the case of a single input tuple, make it a # 1 element list, for consistency. filenames = [] if isinstance(files, tuple): files = [files] for file in files: filenames.append(file[1]) if force: print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache='update') # Make a symbolic link using a local name for convenience if not os.path.islink(os.path.join(output_directory, file[1])): os.symlink(demo_file, os.path.join(output_directory, file[1])) else: if not os.path.isfile(os.path.join(output_directory, file[1])): print('Downloading {}...'.format(file[1])) demo_file = download_file(file[0], cache=True) # Make a symbolic link using a local name for convenience os.symlink(demo_file, os.path.join(output_directory, file[1])) else: print('{} already exists, skipping download...'.format(file[1])) continue return filenames def find_bad_pix_types(dq_value): """Given an integer representation of a series of bad pixel flags, identify which types of bad pixels the flags indicate. Parameters ---------- dq_value : uint16 Value associated with a set of bad pixel flags Returns ------- bad_nums : list List of integers representing the bad pixel types bad_types : list List of bad pixel type names corresponding to bad_nums """ # Change integer into a byte array bitarr = np.binary_repr(dq_value) # Find the bad pixel type associated with each bit where # the flag is set bad_nums = [] bad_types = [] for i, elem in enumerate(bitarr[::-1]): if elem == str(1): badval = 2**i bad_nums.append(badval) key = next(key for key, value in datamodels.dqflags.pixel.items() if value == badval) bad_types.append(key) return bad_nums, bad_types def overlay_catalog(data_2d, catalog, flux_limit=0, vmin=0, vmax=10, title=None, units='MJy/str'): """Function to generate a 2D image of the data, with sources overlaid. data_2d : numpy.ndarray 2D image to be displayed catalog : astropy.table.Table Table of sources flux_limit : float Minimum signal threshold to overplot sources from catalog. Sources below this limit will not be shown on the image. vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling title : str String to use for the plot title units : str Units of the data. Used for the annotation in the color bar """ norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) for row in catalog: if row['aper_total_flux'].value > flux_limit: plt.plot(row['xcentroid'], row['ycentroid'], marker='o', markersize='3', color='red') plt.xlabel('Pixel column') plt.ylabel('Pixel row') fig.colorbar(im, label=units) fig.tight_layout() plt.subplots_adjust(left=0.15) if title: plt.title(title) def show_image(data_2d, vmin, vmax, xpixel=None, ypixel=None, title=None, scale='log', units='MJy/str'): """Function to generate a 2D, log-scaled image of the data, with an option to highlight a specific pixel. data_2d : numpy.ndarray 2D image to be displayed vmin : float Minimum signal value to use for scaling vmax : float Maximum signal value to use for scaling xpixel : int X-coordinate of pixel to highlight ypixel : int Y-coordinate of pixel to highlight title : str String to use for the plot title scale : str Specify scaling of the image. Can be 'log' or 'linear' units : str Units of the data. Used for the annotation in the color bar """ if scale == 'log': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LogStretch()) elif scale == 'linear': norm = ImageNormalize(data_2d, interval=ManualInterval(vmin=vmin, vmax=vmax), stretch=LinearStretch()) fig = plt.figure(figsize=(8, 8)) ax = fig.add_subplot(1, 1, 1) im = ax.imshow(data_2d, origin='lower', norm=norm) if xpixel and ypixel: plt.plot(xpixel, ypixel, marker='o', color='red', label='Selected Pixel') fig.colorbar(im, label=units) plt.xlabel('Pixel column') plt.ylabel('Pixel row') if title: plt.title(title) nircam_info = [('https://stsci.box.com/shared/static/p2wlvndw25dk7xwk1tasqevmhkg6p55e.fits', 'jw98765001001_01101_00001_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/cmhc7kkf5z6373d2vwg7916lrhe5ia7u.fits', 'jw98765001001_01101_00002_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/sb18cpfqjbw1i09gvw0cpqkj6ymdn899.fits', 'jw98765001001_01101_00003_nrcb5_cal.fits'), ('https://stsci.box.com/shared/static/7d00b9isvss7njhcwmd8uiq8c7s4d845.json', 'level3_lw_asn.json'), ('https://stsci.box.com/shared/static/ja0gkd8c0x8p8konhr84wkuhwnpkqf4s.asdf', 'jwst_nircam_pars-tweakregstep_0006.asdf'), ('https://stsci.box.com/shared/static/yahdw55fotwrh7i6hhcxksj97qkf7j4r.asdf', 'nircam_pars-sourcecatalogstep_f444w_clear.asdf') ] nircam_files = download_files(nircam_info, output_dir, force=False) miri_info = [('https://stsci.box.com/shared/static/0fbtsmehvlfnw5zrnzul0yc2f0l6i16r.json', 'miri_level3_asn.json'), ('https://stsci.box.com/shared/static/te5dmv32nu09u2bnxmzfcsanaibjp36z.fits', 'miri_F770W_exp1_cal.fits'), ('https://stsci.box.com/shared/static/qmzwrn0nq3m7m72kw2c3ajaqvxv0wndu.fits', 'miri_F770W_exp2_cal.fits'), ('https://stsci.box.com/shared/static/yo9b6i5i0j1kz3nxeqap25ohyzm26omo.fits', 'miri_F770W_exp3_cal.fits') ] miri_files = download_files(miri_info, output_dir, force=False) asn_file = os.path.join(output_dir, 'level3_lw_asn.json') # Open the association file and load into a json object with open(asn_file) as f_obj: asn_data = json.load(f_obj) asn_data #[Out]# {'asn_type': 'None', #[Out]# 'asn_rule': 'DMS_Level3_Base', #[Out]# 'version_id': None, #[Out]# 'code_version': '0.17.1', #[Out]# 'degraded_status': 'No known degraded exposures in association.', #[Out]# 'program': 'noprogram', #[Out]# 'constraints': 'No constraints', #[Out]# 'asn_id': 'a3001', #[Out]# 'target': 'none', #[Out]# 'asn_pool': 'none', #[Out]# 'products': [{'name': 'l3_lw_results', #[Out]# 'members': [{'expname': 'jw98765001001_01101_00001_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}, #[Out]# {'expname': 'jw98765001001_01101_00002_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}, #[Out]# {'expname': 'jw98765001001_01101_00003_nrcb5_cal.fits', #[Out]# 'exptype': 'science'}]}]} tweak_files = ['level3_lw_asn_0_tweakregstep.fits', 'level3_lw_asn_1_tweakregstep.fits', 'level3_lw_asn_2_tweakregstep.fits'] tweak_product = 'manual_asn_file' tweakreg_asn = asn_from_list.asn_from_list(tweak_files, rule=DMS_Level3_Base, product_name=tweak_product) tweakreg_asn #[Out]# { #[Out]# "asn_type": "None", #[Out]# "asn_rule": "DMS_Level3_Base", #[Out]# "version_id": null, #[Out]# "code_version": "1.6.2", #[Out]# "degraded_status": "No known degraded exposures in association.", #[Out]# "program": "noprogram", #[Out]# "constraints": "No constraints", #[Out]# "asn_id": "a3001", #[Out]# "target": "none", #[Out]# "asn_pool": "none", #[Out]# "products": [ #[Out]# { #[Out]# "name": "manual_asn_file", #[Out]# "members": [ #[Out]# { #[Out]# "expname": "level3_lw_asn_0_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# }, #[Out]# { #[Out]# "expname": "level3_lw_asn_1_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# }, #[Out]# { #[Out]# "expname": "level3_lw_asn_2_tweakregstep.fits", #[Out]# "exptype": "science" #[Out]# } #[Out]# ] #[Out]# } #[Out]# ] #[Out]# } output_test = 'manual_tweakreg_asn.json' with open(output_test, 'w') as outfile: name, serialized = tweakreg_asn.dump(format='json') outfile.write(serialized) tweak_param_reffile = 'jwst_nircam_pars-tweakregstep_0006.asdf' tweak_params = asdf.open(tweak_param_reffile) tweak_params.tree #[Out]# {'asdf_library': {'author': 'Space Telescope Science Institute', #[Out]# 'homepage': 'http://github.com/spacetelescope/asdf', #[Out]# 'name': 'asdf', #[Out]# 'version': '2.7.1'}, #[Out]# 'history': {'entries': [{'description': 'Baseline configuration', #[Out]# 'time': datetime.datetime(2020, 10, 28, 12, 23, 29)}], #[Out]# 'extensions': [{'extension_class': 'asdf.extension.BuiltinExtension', #[Out]# 'software': {'name': 'asdf', 'version': '2.7.1'}}]}, #[Out]# 'meta': {'author': 'Bryan Hilbert', #[Out]# 'date': '2020-10-28T08:23:07.124475', #[Out]# 'description': 'Tweakreg parameters', #[Out]# 'exposure': {'type': 'NRC_IMAGE'}, #[Out]# 'instrument': {'filter': 'F444W', 'name': 'NIRCam', 'pupil': 'CLEAR'}, #[Out]# 'pedigree': 'GROUND', #[Out]# 'reftype': 'pars-tweakregstep', #[Out]# 'telescope': 'JWST', #[Out]# 'title': 'Tweakreg parameters', #[Out]# 'useafter': '2000-01-01T00:00:00'}, #[Out]# 'parameters': {'brightest': 100, #[Out]# 'catalog_format': 'ecsv', #[Out]# 'class': 'jwst.tweakreg.tweakreg_step.TweakRegStep', #[Out]# 'enforce_user_order': False, #[Out]# 'expand_refcat': False, #[Out]# 'fitgeometry': 'general', #[Out]# 'kernel_fwhm': 2.302, #[Out]# 'minobj': 15, #[Out]# 'name': 'tweakreg', #[Out]# 'nclip': 3, #[Out]# 'save_catalogs': False, #[Out]# 'searchrad': 1.0, #[Out]# 'separation': 0.5, #[Out]# 'sigma': 3.0, #[Out]# 'snr_threshold': 10, #[Out]# 'tolerance': 1.0, #[Out]# 'use2dhist': True, #[Out]# 'xoffset': 0.0, #[Out]# 'yoffset': 0.0}} # Don't forget to close the file tweak_params.close() print(TweakRegStep.spec) print(SourceCatalogStep.spec) # Create an instance of the pipeline class image3 = calwebb_image3.Image3Pipeline() # Set some parameters that pertain to the # entire pipeline image3.output_dir = output_dir image3.save_results = True # Set some parameters that pertain to some of # the individual steps image3.tweakreg.snr_threshold = 10.0 # 5.0 is the default image3.tweakreg.kernel_fwhm = 2.302 # 2.5 is the default image3.tweakreg.brightest = 20 # 100 is the default image3.source_catalog.kernel_fwhm = 2.302 # pixels image3.source_catalog.snr_threshold = 10. # Call the run() method image3.run(asn_file) input_files = [item['expname'] for item in asn_data['products'][0]['members']] input_files #[Out]# ['jw98765001001_01101_00001_nrcb5_cal.fits', #[Out]# 'jw98765001001_01101_00002_nrcb5_cal.fits', #[Out]# 'jw98765001001_01101_00003_nrcb5_cal.fits'] mosaic_file = os.path.join(output_dir, 'l3_lw_results_i2d.fits') source_cat_file = os.path.join(output_dir, 'l3_lw_results_cat.ecsv') segmentation_map_file = os.path.join(output_dir, 'l3_lw_results_segm.fits') cr_flagged_files = [item.replace('cal.fits', 'crf.fits') for item in input_files] mosaic = datamodels.open(mosaic_file) show_image(mosaic.data, vmin=0, vmax=5) seg_map = fits.getdata(segmentation_map_file) show_image(seg_map, vmin=0, vmax=5, scale='linear') source_cat = ascii.read(source_cat_file) source_cat #[Out]# #[Out]# label xcentroid ... sky_bbox_ur #[Out]# ... deg,deg #[Out]# int64 float64 ... SkyCoord #[Out]# ----- --------- ... ------------------------------------- #[Out]# 1 1992.0879 ... 11.98143075910671,11.983066945836837 #[Out]# 2 641.3125 ... 12.005717347465959,11.98290861740083 #[Out]# 3 1286.5990 ... 11.994155725551417,11.983206865021875 #[Out]# 4 1597.1585 ... 11.988571775658775,11.983382069429663 #[Out]# 5 600.8486 ... 12.006415388621903,11.98350381187185 #[Out]# 6 1491.5360 ... 11.990468904557986,11.984117342597566 #[Out]# 7 1695.4662 ... 11.98685364268176,11.984309973215902 #[Out]# 8 2125.0847 ... 11.979121970865389,11.984992709592296 #[Out]# 9 2161.9646 ... 11.978531353840433,11.985115248178921 #[Out]# ... ... ... ... #[Out]# 154 1797.1507 ... 11.984831253641785,12.017188643310465 #[Out]# 155 1382.5414 ... 11.992420663945392,12.017381118743316 #[Out]# 156 318.6055 ... 12.011054235026775,12.018780575522852 #[Out]# 157 338.4237 ... 12.011090025755333,12.018693035805674 #[Out]# 158 318.8479 ... 12.011501733104422,12.018850562420015 #[Out]# 159 263.9929 ... 12.01234306326185,12.019305670270331 #[Out]# 160 1736.7184 ... 11.986102129659324,12.018904352900277 #[Out]# 161 1155.6774 ... 11.996448140965631,12.019166722060831 #[Out]# 162 425.6397 ... 12.009586512573604,12.019305927138841 #[Out]# 163 341.5037 ... 12.011090154174337,12.020006081311164 overlay_catalog(mosaic.data, source_cat, flux_limit=5e-7, vmin=0, vmax=10, title='Final mosaic with source catalog') miri_asn_file = 'miri_level3_asn.json' # Using the run() method: # Create an instance of the pipeline class # Set the output directory, and specify that you want # to save the results # Set some parameters for individual steps. # HINT: the PSF FWHM for MIRI with the F700W filter # is 2.187 pixels. # Call the run() method # Using the call() method: # If you want to run using all default parameter values: # If you want to set some step-specfic parameter values parameter_dict = { } # Look at the resulting mosaic image miri_mosaic_file = 'miri_lvl3_i2d.fits' miri_catalog_file = 'miri_lvl3_cat.ecsv' # Open the mosaic image # Read in the source catalog # Look at the mosaic # HINT: Use show_image and vmin=0, vmax=5 # Show the catalog sources on the mosaic # HINT: use overlay_catalog and min/max signal values of 0, 5