def has_data(fitsfile, ra0, dec0): "Check whether there is any non-zero data in fitsfile at the source position (ra0, dec0)" fitspath = misc_utils.expand_fits_path(fitsfile) if cmd_args.debug: print("\nReading from", fitspath) hdu = fits_utils.get_image_hdu(fits.open(fitspath), debug=cmd_args.debug) if cmd_args.debug: print("Image size", hdu.data.shape) w = wcs.WCS(hdu.header) x, y = w.wcs_world2pix(ra0, dec0, 0) if cmd_args.debug: print("Coords", ra0, dec0, "->", x, y) i1 = int(x) j1 = int(y) pixel_data = hdu.data[j1:j1+2, i1:i1+2].mean() if cmd_args.debug: print("{}[{}:{},{}:{}] = {}".format( fitsfile, j1, j1+2, i1, i1+2, pixel_data)) return pixel_data > 0.0
dbfile = cmd_args.source + "-arcdata.json" arcdata = json.load(open(dbfile)) for image_name in arcdata: if not "extracted FITS file" in arcdata[image_name]: # Jump over sections that are not images continue print("**************************************************") print("Calculating shell brightness for", image_name) print("**************************************************") fitsfile = arcdata[image_name]["extracted FITS file"] hdulist = fits.open(fitsfile) hdu = fits_utils.get_image_hdu(hdulist, debug=cmd_args.debug) w = wcs.WCS(hdu.header) # Pixel coordinate arrays x, y = np.meshgrid(np.arange(hdu.data.shape[1]), np.arange(hdu.data.shape[0])) # Sky coordinate arrays ra, dec = w.wcs_pix2world(x, y, 0) # Find coordinates of the central star ra0 = coord.Longitude(arcdata["star"]["RA"], unit=u.hour) dec0 = coord.Latitude(arcdata["star"]["Dec"], unit=u.deg) # Calculate sky coordinate offset arrays in arcsec with respect to star. # (Note that this will not work near the poles, or over a field that # spans a large angle of sky, but that does not bother us.) X = np.cos(np.radians(dec))*(ra*u.deg - ra0).to(u.arcsec) Y = (dec*u.deg - dec0).to(u.arcsec) # Radial separation, R, and position angle of separation, PA.
dbfile = cmd_args.source + "-arcdata.json" arcdata = json.load(open(dbfile)) image_name = cmd_args.image if not image_name in arcdata: raise ValueError(image_name + " not found - try running extract-image.py first") if not "shell" in arcdata[image_name]: raise ValueError("Shell data not found - try running arc_brightness.py first") fitsfile = arcdata[image_name]["extracted FITS file"] hdulist = fits.open(fitsfile) hdu = get_image_hdu(hdulist, debug=cmd_args.debug) # Find coordinates of the central star and radius of curvature # We want all the values in degrees for use with aplpy ra0 = coord.Longitude(arcdata["star"]["RA"], unit=u.hour).to(u.deg) / u.deg dec0 = coord.Latitude(arcdata["star"]["Dec"], unit=u.deg) / u.deg ra0, dec0 = float(ra0), float(dec0) print(ra0, dec0) if "outer" in arcdata: Rc = arcdata["outer"]["Rc"] * u.arcsec / u.deg else: Rc = 1.5*arcdata["inner"]["Rc"] * u.arcsec / u.deg print(Rc)
assert not "/" in cmd_args.fitsfile, \ "Please do not give path to FITS file - it will be found automatically" image_name = misc_utils.short_image_name(cmd_args.fitsfile) fits_path = os.path.join( misc_utils.image_set_fits_dir (image_name), cmd_args.fitsfile ) if cmd_args.debug: print("Short image name:", image_name) print("Full path:", fits_path) hdu = fits_utils.get_image_hdu(fits.open(fits_path), debug=cmd_args.debug) ## ## Correct the coordinates if necessary - look to see if a shift file ## is present. This is done first, so that the enclosing box will ## also be shifted. ## shiftfile = "-".join([cmd_args.source, image_name, "shifts.json"]) try: with open(shiftfile) as f: shift = json.load(f) if cmd_args.debug: print("Coordinate adjustments:", shift) hdu.header["CRVAL1"] += shift['dRA']/3600 hdu.header["CRVAL2"] += shift['dDEC']/3600