def parse_coordinates(header): """Returns a WCS object""" wcs = WCS() try: wcs.crval = header['crval1'], header['crval2'] wcs.crpix = header['crpix1'], header['crpix2'] wcs.cdelt = header['cdelt1'], header['cdelt2'] except KeyError: logger.warn("Coordinate system not specified in FITS") raise try: wcs.ctype = header['ctype1'], header['ctype2'] except KeyError: wcs.ctype = 'unknown', 'unknown' try: wcs.crota = float(header['crota1']), float(header['crota2']) except KeyError: wcs.crota = 0., 0. try: wcs.cunit = header['cunit1'], header['cunit2'] except KeyError: # Blank values default to degrees. logger.warning("WCS units unknown; using defaults") wcs.cunit = '', '' wcs.wcsset() return wcs
def parse_coordinates(table): """Returns a WCS object""" wcs = WCS() my_coordinates = table.getkeyword('coords')['direction0'] wcs.crval = my_coordinates['crval'] wcs.crpix = my_coordinates['crpix'] wcs.cdelt = my_coordinates['cdelt'] ctype = ['unknown', 'unknown'] # What about other projections?! if my_coordinates['projection'] == "SIN": if my_coordinates['axes'][0] == "Right Ascension": ctype[0] = "RA---SIN" if my_coordinates['axes'][1] == "Declination": ctype[1] = "DEC--SIN" wcs.ctype = tuple(ctype) # Rotation, units? We better set a default wcs.crota = (0., 0.) wcs.cunit = table.getkeyword('coords')['direction0']['units'] # Update WCS wcs.wcsset() return wcs