if "plot limits" in arcdata[image_name]: # Use previously stored value if present vmin = arcdata[image_name]["plot limits"]["min"] else: minfactor = MINFACTOR_DEFAULT else: minfactor = cmd_args.minfactor if vmin is None: vmin = avbg - minfactor*dbg plot_limits_modified = True # Now update the db if necessary if plot_limits_modified: arcdata[image_name]["plot limits"] = {"max": vmax, "min": vmin} arcdata["info"]["history"].append( "Plot limits modified for " + image_name + " " + run_info()) arcdata["help"]["brightness"]["plot limits"] \ = "Minimum and maximum brightness for *-images.pdf" update_json_file(arcdata, dbfile) instrument = " ".join([arcdata[image_name][k] for k in ["camera", "filter", "date"] if k in arcdata[image_name]]) # Plot image of the FITS array of this object # plt.clf() f = plt.figure(figsize=(18,9)) ax1 = aplpy.FITSFigure(hdu, figure=f, subplot=(1, 2, 1), north=True) ax1.recenter(ra0, dec0, 2*Rc) ax1.show_grayscale(invert=True, vmin=vmin, vmax=vmax)
ymin = avbg - 2*wbg ymax = avsh + 2*wsh print("BG trimean = {:.2f}, iqr = {:.2f}".format(avbg, wbg)) print("Shell trimean = {:.2f}, iqr = {:.2f}".format(avsh, wsh)) print("Adopting plot range of {:.2f} to {:.2f}".format(ymin, ymax)) # Save brightness statistics to a new JSON file arcdata[image_name]["background"] = {"value": float(avbg), "delta": float(wbg), "N": int(nbg)} arcdata[image_name]["shell"] = {"value": float(avsh), "delta": float(wsh), "N": int(nsh)} arcdata[image_name]["shell center"] = {"value": float(avshc), "delta": float(wshc), "N": int(nshc)} arcdata["info"]["history"].append("Shell data for " + image_name + " added/modified by " + run_info()) # Save brightness statistics in the help section help_brightness = {"shell":"Trimean brightness and interquartile (difference between quartiles) of shell", "shell center":"Trimean brightness and interquartile (difference between quartiles) of shell center", "background":"Trimean brightness and interquartile (difference between quartiles) of background"} arcdata["help"].update(brightness=help_brightness) # Calculate average binned profiles versus theta NTH = 25 need_to_bin_profiles = True while need_to_bin_profiles: th_edges = np.linspace(-60.0, 60.0, NTH) th_centers = 0.5*(th_edges[:-1] + th_edges[1:])
print("Unknown shell type") sys.exit() shell = Shell(beta,cmd_args.type) R = shell.radius(theta) R[R<0]=np.nan R_in = inner(R,theta,cmd_args.mach) R_com,theta_com = mirror(R_in,theta) arcdata = { "info":{ "Description": "CRW theoretical stationary bowshocks", "history":["Initially created by "+ run_info()], "beta": beta, "inner wind type": cmd_args.type }, "help":{ "M": "Mach number of inner wind", "beta":"Two-winds momentum ratio", "i": "Rotation angle between proplyd reference frame and observer reference frame", "inner wind type": "Angular variation of density's inner wind", "x": "(list) x-coordinates of the outer shell normalized with distance", "y": "(list) y-coordinates of the outer shell normalized with distance" }, "inner":{} } for inc in [0.0,15.0,30.0,45.0,60.0]: xp,yp = rotate(np.radians(inc),R_com,theta_com)
print("Fixing EQUINOX from string or zero value") outhdu.header["EQUINOX"] = 2000.0 hdu.header["EQUINOX"] = 2000.0 ## TODO: copy over more keywords from the original FITS header ## E.g., filter, camera, etc ## ## Save the small image ## outfile = "-".join([cmd_args.source, image_name, "extract.fits"]) outhdu.writeto(outfile, output_verify="fix", clobber=True) ## ## Update the JSON database with information about the image ## # Always overwrite an existing section with the same name db[image_name] = { "original FITS file": misc_utils.contract_fits_path(fits_path), "extracted FITS file": outfile, } db[image_name].update(fits_utils.get_instrument_configuration(hdu)) db["info"]["history"].append("Image " + image_name + " added by " + misc_utils.run_info()) misc_utils.update_json_file(db, dbfile)
help="Name of source") parser.add_argument("--savefig", action="store_true", help="Save a figure showing the fit") parser.add_argument("--debug", action="store_true", help="Print out verbose debugging info") cmd_args = parser.parse_args() dbfile = cmd_args.source + "-arcdata.json" db = json.load(open(dbfile)) for arc in "inner", "outer": if arc in db: update_arc_data(db[arc]) db["info"]["history"].append("Circle fits added by " + run_info()) update_json_file(db, dbfile) region_file = dbfile.replace("-arcdata.json", "-arcfits.reg") with open(region_file, "w") as f: f.writelines([s + "\n" for s in create_arc_regions(db)]) if cmd_args.savefig: plotfile = dbfile.replace("-arcdata.json", "-arcfits.pdf") plt.plot(0.0, 0.0, 'o') plt.axis("equal") plt.savefig(plotfile)
db = json.load(open(infile)) if "beta" in infile: f = plt.figure() for i,inc in enumerate([0.0,15.0,30.0,45.0,60.0]): try: ax = f.add_subplot(2,3,i+1) update_arc_data(db["outer"]["i="+str(inc)],teo=True) except KeyError: #print "inclination not available",inc break else: for arc in "inner", "outer": update_arc_data(db[arc]) db["info"]["history"].append("Conic fits added by " + run_info()) # save database to the same name: *-arcdata.json outfile = infile with tempfile.NamedTemporaryFile( 'w', dir=os.path.dirname(outfile), delete=False) as tf: json.dump(db, tf, indent=4) tempname = tf.name os.rename(tempname, outfile) if cmd_args.savefig: plotfile = infile.replace("-arcdata.json", "-conic-fits.pdf") if "beta" in infile: f.tight_layout() f.set_size_inches(2*5,3*5) f.savefig(plotfile)
default="angel@crya", help="User@system ID use for guessing paths") parser.add_argument("--debug", action="store_true", help="Print out verbose debugging info") cmd_args = parser.parse_args() dbfile = cmd_args.source + "-arcdata.json" db = json.load(open(dbfile)) for secname, section in db.items(): if "original FITS file" in section: oldpath = section["original FITS file"] newpath = misc_utils.contract_fits_path(oldpath, user=cmd_args.user) if cmd_args.debug: print("Contracting full paths in", secname) print("From", oldpath, "to", newpath) section["original FITS file"] = newpath db["info"]["history"].append("Paths corrected by " + misc_utils.run_info()) misc_utils.update_json_file(db, dbfile)