def img_with_wcs(input): """ Open a JWST exposure and apply the distortion model. Parameters ---------- input : type Anything `jwst.datamodels.util.open` can accept for initialization. Returns ------- with_wcs : `jwst.datamodels.ImageModel` Image model with full `~gwcs` in `with_wcs.meta.wcs`. """ from jwst.datamodels import util from jwst.assign_wcs import AssignWcsStep # from jwst.stpipe import crds_client # from jwst.assign_wcs import assign_wcs # HDUList -> jwst.datamodels.ImageModel img = util.open(input) # AssignWcs to pupulate img.meta.wcsinfo step = AssignWcsStep() with_wcs = step.process(img) ## Above should be more robust to get all of the necessary ref files #dist_file = crds_client.get_reference_file(img, 'distortion') #reference_files = {'distortion': dist_file} #with_wcs = assign_wcs.load_wcs(img, reference_files=reference_files) return with_wcs
def create_tso_wcsimage(filtername="F277W", subarray=False): """Help create tsgrism GWCS object.""" if subarray: subarray = "SUBGRISM256" else: subarray = "FULL" hdul = create_hdul(exptype='NRC_TSGRISM', pupil='GRISMR', filtername=filtername, detector='NRCALONG', subarray=subarray, wcskeys=wcs_tso_kw) hdul['sci'].header['SUBSIZE1'] = NIRCAM_TSO_WIDTH if subarray: hdul['sci'].header['SUBSIZE2'] = 256 subsize = 256 else: hdul['sci'].header['SUBSIZE2'] = 2048 subsize = 2048 hdul['sci'].data = np.ones((2, subsize, NIRCAM_TSO_WIDTH)) im = CubeModel(hdul) im.meta.wcsinfo.siaf_xref_sci = 887.0 im.meta.wcsinfo.siaf_yref_sci = 35.0 aswcs = AssignWcsStep() return aswcs.process(im)
def img_with_wcs(input): """ Open a JWST exposure and apply the distortion model. Parameters ---------- input : type Anything `jwst.datamodels.util.open` can accept for initialization. Returns ------- with_wcs : `jwst.datamodels.ImageModel` Image model with full `~gwcs` in `with_wcs.meta.wcs`. """ from jwst.datamodels import util from jwst.assign_wcs import AssignWcsStep import astropy.io.fits as pyfits # from jwst.stpipe import crds_client # from jwst.assign_wcs import assign_wcs # HDUList -> jwst.datamodels.ImageModel # Generate WCS as image if isinstance(input, pyfits.HDUList): if input[0].header['INSTRUME'] == 'NIRISS': if input[0].header['FILTER'].startswith('GR'): input[0].header['FILTER'] = 'CLEAR' input[0].header['EXP_TYPE'] = 'NIS_IMAGE' #print(input[0].header) elif input[0].header['INSTRUME'] == 'NIRCAM': if input[0].header['PUPIL'].startswith('GR'): input[0].header['PUPIL'] = 'CLEAR' input[0].header['EXP_TYPE'] = 'NRC_IMAGE' #print(input[0].header) img = util.open(input) # AssignWcs to pupulate img.meta.wcsinfo step = AssignWcsStep() with_wcs = step.process(img) # Above should be more robust to get all of the necessary ref files #dist_file = crds_client.get_reference_file(img, 'distortion') #reference_files = {'distortion': dist_file} #with_wcs = assign_wcs.load_wcs(img, reference_files=reference_files) return with_wcs