def test_find_all_wcs_crash(): """ Causes a double free without a recent fix in wcslib_wrap.C """ with open(get_pkg_data_filename("data/too_many_pv.hdr")) as fd: header = fd.read() # We have to set fix=False here, because one of the fixing tasks is to # remove redundant SCAMP distortion parameters when SIP distortion # parameters are also present. with pytest.raises(wcs.InvalidTransformError), pytest.warns(wcs.FITSFixedWarning): wcs.find_all_wcs(header, fix=False)
def validate_source_input(**kwargs): if "filename" in kwargs and kwargs["filename"] is not None: filename = kwargs["filename"] if utils.find_file(filename) is None: warnings.warn("filename was not found: {}".format(filename)) if "image" in kwargs and kwargs["image"] is not None: image_hdu = kwargs["image"] if not isinstance(image_hdu, (fits.PrimaryHDU, fits.ImageHDU)): raise ValueError("image must be fits.HDU object with a WCS." "type(image) == {}".format(type(image_hdu))) if len(wcs.find_all_wcs(image_hdu.header)) == 0: warnings.warn("image does not contain valid WCS. {}" "".format(wcs.WCS(image_hdu))) if "table" in kwargs and kwargs["table"] is not None: tbl = kwargs["table"] if not isinstance(tbl, Table): raise ValueError("table must be an astropy.Table object:" "{}".format(type(tbl))) if not np.all([col in tbl.colnames for col in ["x", "y", "ref"]]): raise ValueError("table must contain at least column names: " "'x, y, ref': {}".format(tbl.colnames)) return True
def test_find_all_wcs_crash(): """ Causes a double free without a recent fix in wcslib_wrap.C """ with open(get_pkg_data_filename("data/too_many_pv.hdr")) as fd: header = fd.read() # We have to set fix=False here, because one of the fixing tasks is to # remove redundant SCAMP distortion parameters when SIP distortion # parameters are also present. wcses = wcs.find_all_wcs(header, fix=False)
def test_spectra(self): for filename in self._file_list: # use the base name of the file, so we get more useful messages # for failing tests. filename = os.path.basename(filename) # Now find the associated file in the installed wcs test directory. header = get_pkg_data_contents( os.path.join("data", "spectra", filename), encoding='binary') # finally run the test. all_wcs = wcs.find_all_wcs(header) assert len(all_wcs) == 9
def test_spectra(self): for filename in self._file_list: # use the base name of the file, so we get more useful messages # for failing tests. filename = os.path.basename(filename) # Now find the associated file in the installed wcs test directory. header = get_pkg_data_contents( os.path.join("data", "spectra", filename), encoding='binary') # finally run the test. all_wcs = wcs.find_all_wcs(header) assert len(all_wcs) == 9
def test_spectrum(filename): # the test parameter is the base name of the file to use; find # the file in the installed wcs test directory filename = os.path.join(ROOT_DIR, "spectra", filename) fd = open(filename, 'rb') header = fd.read() fd.close() wcsobj = wcs.WCS(header) all = wcs.find_all_wcs(header) assert len(all) == 9
def get_cluster_data(clid, *args, **kwargs): """ Creates a container of all important data related to a cluster Parameters ---------- clid: int cluster id Returns ------- data: dict dictionary of all related information """ if ('ap' not in clid.lower()): raise NotImplemented('synthetics not implemented yet.') apid = int(clid[2:]) # read profile data profile_image = pyfits.getdata(data_path['image475'].format(apid=apid)) profile_header = pyfits.getheader(data_path['image475'].format(apid=apid)) profile_wcs = wcs.find_all_wcs(profile_header)[0] # read MATCH data match_output = np.genfromtxt(data_path['match_output'].format(apid=apid), skip_header=10, skip_footer=2) with open(data_path['match_sfh'].format(apid=apid), 'r') as f: match_params = f.readlines() match_cmd = np.loadtxt(data_path['match_cmd'].format(apid=apid), skiprows=4, dtype=match_dtype) match_fakepath = data_path['match_fake'].format(apid=apid) bg_stars = Table(data_path['match_sky'].format(apid=apid), caseless=True) match_bg = np.loadtxt(data_path['match_bg'].format(apid=apid), dtype=[('F475W_VEGA', float), ('F814W_VEGA', float)]) # photometric catalog phot = Table(data_path['phot'].format(apid=apid), caseless=True) # convert stars ra,dec to pixels stars_xy = profile_wcs.wcs_world2pix( np.column_stack([phot['ra'], phot['dec']]), 0) sky_xy = profile_wcs.wcs_world2pix( np.column_stack([bg_stars['ra'], bg_stars['dec']]), 0) # extract color-mag keys = ','.join(phot.keys()) if ('vega' in keys) or ('VEGA' in keys): color_name = 'F475W-F814W' mag_name = 'F475W' color = phot('F475W_VEGA-F814W_VEGA') mag = phot('F475W_VEGA') sky_color = bg_stars('F475W_VEGA-F814W_VEGA') sky_mag = bg_stars('F475W_VEGA') data = { 'apid': apid, 'profile': { 'image': profile_image, 'header': profile_header, 'wcs': profile_wcs }, 'match': { 'output': match_output, 'params': match_params, 'cmd': match_cmd, 'bg': match_bg, 'sky': bg_stars, 'fake': match_fakepath, 'sky_xy': sky_xy, 'sky_color': sky_color, 'sky_mag': sky_mag }, 'phot': { 'cat': phot, 'xy': stars_xy, 'color': color, 'mag': mag, 'color_name': color_name, 'mag_name': mag_name } } return data