def inspect(vastdir, resultdir, fitsdir, apikey, stars): """generate image+txt file to inspect a certain star on wrong ucac/localid nrs """ reading.trash_and_recreate_dir(Path(resultdir) / "inspect") ref_jd, _, _, reference_frame = reading.extract_reference_frame(vastdir) _, shapex, shapey = reading.get_fits_data(Path(fitsdir, Path(reference_frame).name)) refframes: List[RefFrame] = [ RefFrame( ref_jd, Path(vastdir) / "new-image.fits", Path(fitsdir, Path(reference_frame).name), ) ] # construct star descriptions sds = utils_sd.construct_star_descriptions(vastdir, None) star_catalog = do_calibration.create_star_descriptions_catalog(sds) if args.radecs: main_vast.read_and_tag_radec(args.radecs, sds) if args.localids: stardict = main_vast.get_localid_to_sd_dict(sds) main_vast.read_and_tag_localid(args.localids, stardict) if args.stars: stars = sorted(list(map(lambda x: int(x), stars))) else: stars = sorted([x.local_id for x in sds if x.get_metadata("SELECTEDTAG")]) for starid in stars: process( vastdir, resultdir, fitsdir, apikey, shapex, shapey, starid, ref_jd, reference_frame, sds, star_catalog, refframes, )
def update_img(record: ImageRecord): data, shapex, shapey = reading.get_fits_data(Path(fitsdir, record.file)) backgr = data.mean() data = data.reshape(shapex, shapey) data = np.pad(data, (padding, padding), "constant", constant_values=(backgr, backgr)) cropdata = data[record.y - fullcrop + padding:record.y + fullcrop + padding, record.x - fullcrop + padding:record.x + fullcrop + padding, ] rotcrop = ndimage.interpolation.rotate(cropdata, record.rotation) rotcrop = crop_center(rotcrop, crop, crop) # fig = plt.figure(figsize=(15, 15), dpi=80, facecolor='w', edgecolor='k') # rotx, roty = rotcrop.shape # target_app = CircularAperture((rotx // 2, roty // 2), r=5.) # target_app.plot() # data[record.y-cropsize:record.y+cropsize,record.x-cropsize:record.x+cropsize] = 0 # ax.imshow(rotcrop, cmap='gray', origin='lower', norm=LogNorm()) pbar.update(1) im.set_data(rotcrop) ax.set_title(f"JD: {record.jd}")
def run_standard_field_charts( star_descriptions: StarDescriptionList, wcs, fieldchartsdirs, reference_fits_frame, comp_stars: ComparisonStars, ): # setting the font size for titles/axes plt.rcParams.update({"axes.titlesize": "large", "axes.labelsize": "large"}) fits_data, _, _ = reading.get_fits_data(reference_fits_frame) fits_data_blank, _, _ = reading.get_fits_data(reference_fits_frame, blank_data=True) SHOW_UPSILON = False # if SHOW_UPSILON: # candidates = do_calibration.get_candidates(0.5) # TODO hand labeled stars # hand_candidates_descr = do_calibration.get_star_descriptions(init.wwcra_certain_candidates) all_stars_descr = star_descriptions # if SHOW_UPSILON: # big_green = set_custom_label(comparison_ star_descr, 'comp') # small_red = set_custom_label(apass_star_descr, [o.vmag for o in apass_star_descr]) # big_green = set_custom_label(vsx_star_descr, [o.match['catalog_dict']['name'] for o in vsx_star_descr]) # small_red = set_custom_label(hand_candidates_descr, [o.local_id for o in hand_candidates_descr]) # big_green = set_aavso_id_label(vsx_star_descr) # small_red = set_local_id_label(hand_candidates_descr) # all stars get a blank label all_stars_no_label = set_custom_label(all_stars_descr, "") # field chart with all detections logging.info("Plotting field chart with all detected stars...") fig = plot_it( [all_stars_no_label], [4.0], [False], fits_data, wcs, "All detected stars", PADDING, annotate=False, ) save( fig, fieldchartsdirs + "all_detections_{}_stars".format(len(all_stars_no_label)) ) # vsx stars get their aavso id label vsx_descr = utils.get_stars_with_metadata(star_descriptions, "VSX") vsx_labeled = set_aavso_id_label(vsx_descr) # field chart with all vsx stars logging.info("Plotting field chart with all VSX variable stars...") fig = plot_it( [vsx_labeled], [10.0], [False], fits_data, wcs, "All VSX stars", PADDING ) save(fig, fieldchartsdirs + "vsx_stars_{}".format(len(vsx_labeled))) # field chart with all vsx stars without the background logging.info( "Plotting field chart with all VSX variable stars without reference field..." ) fig = plot_it( [vsx_labeled], [10.0], [False], fits_data_blank, wcs, "VSX without background", PADDING, ) save(fig, fieldchartsdirs + "vsx_stars_no_ref_{}".format(len(vsx_labeled))) # field chart with only the background logging.info("Plotting field chart with only the reference field...") fig, _ = get_plot_with_background_data(fits_data, 0, "Reference frame") save(fig, fieldchartsdirs + "only_ref") # candidate stars get their local id label candidate_descr = utils.get_stars_with_metadata( star_descriptions, "CANDIDATE", exclude=["VSX"] ) candidate_labeled = set_local_id_label(candidate_descr) # localid/radec inputfile stars get their local id label selected_desc = utils.get_stars_with_metadata(star_descriptions, "SITE") selected_no_vsx_descr = utils.get_stars_with_metadata( star_descriptions, "SITE", exclude=["VSX"] ) selected_no_vsx_labeled = set_custom_label( selected_no_vsx_descr, [x.get_metadata("SITE").our_name for x in selected_no_vsx_descr], ) selected_count = len(selected_no_vsx_labeled) # field chart with all vsx stars + candidates + radeccatalog logging.info("Plotting field chart with all VSX variable stars + candidate vars...") fig = plot_it( [vsx_labeled, candidate_labeled], [10.0, 5.0], [False, True], fits_data, wcs, "VSX stars + candidate stars", PADDING, ) save( fig, fieldchartsdirs + f"vsx_{len(vsx_labeled)}_and_candidates_{len(candidate_labeled)}", ) # field chart with all vsx stars + localid/radec inputfile logging.info( f"Plotting field chart with all VSX variable stars + {selected_count} selected vars..." ) fig = plot_it( [vsx_labeled, selected_no_vsx_labeled], [10.0, 5.0], [False, True], fits_data, wcs, "VSX stars + selected stars", PADDING, ) save( fig, fieldchartsdirs + "vsx_{}_and_selected_{}".format(len(vsx_labeled), selected_count), ) # compstars get their vmag as label # comp_stars_descr = comp_stars.star_descriptions # comp_stars_labeled = set_custom_label(comp_stars_descr, [x.vmag for x in comp_stars_descr]) logging.info( f"Plotting field chart for each of the {selected_count} selected stars" ) # Plotting finder charts for the site # field charts for each individually selected starfile star for star in tqdm.tqdm(selected_desc, desc="Field chart for each star"): filtered_compstars, check_star = do_compstars.filter_comparison_stars( star, comp_stars ) filtered_compstars_sds = filtered_compstars.star_descriptions check_star_sd = check_star.star_descriptions compstars_labeled = set_custom_label( filtered_compstars_sds, [x.get_metadata("UCAC4").vmag for x in filtered_compstars_sds], ) checkstar_labeled = set_custom_label( check_star_sd, f"Kmag={check_star_sd[0].get_metadata('UCAC4').vmag}" ) starui: utils.StarUI = utils.get_star_or_catalog_name(star, suffix="") fig = plot_it( [[star], vsx_labeled, compstars_labeled, checkstar_labeled], [7.0, 5.0, 3.0, 4.0], [True, False, True, False], fits_data, wcs, f"VSX stars + comp stars + {starui.catalog_name} (star {star.local_id})", PADDING, ) save(fig, f"{fieldchartsdirs}vsx_and_star_{starui.filename_no_ext}") gc.collect()
def update_img( star: StarDescription, record: ImageRecord, neighbours: List[StarDescription], resultdir: str, platesolved_file: str, ): resultlines = [] fig = plt.figure(figsize=(36, 32), dpi=dpi, facecolor="w", edgecolor="k") wcs = do_calibration.get_wcs(platesolved_file) data, shapex, shapey = reading.get_fits_data(platesolved_file) backgr = data.mean() data = data.reshape(shapex, shapey) data = np.pad( data, (padding, padding), "constant", constant_values=(backgr, backgr) ) starxy = SkyCoord.to_pixel(star.coords, wcs=wcs, origin=0) # add main target add_circle(record.x, record.y, 3, "b") startoml = load_toml(star, resultdir) star.vmag = startoml["vmag"] resultlines.append(log_star(star, -1)) random_offset = False offset1 = 70 offset2 = 10 # add neighbours for idx, nstar in enumerate(neighbours): add_pixels(nstar, wcs, 0) add_circle(nstar.xpos, nstar.ypos, 4, "g") if random_offset: xrandoffset = random.randint(3, 4) yrandoffset = random.randint(2, 3) xsignrand = random.choice([-1.0, 1.0]) ysignrand = random.choice([-1.0, 1.0]) offset1 = xsignrand * xrandoffset offset2 = ysignrand * yrandoffset # https://matplotlib.org/3.1.0/api/_as_gen/matplotlib.pyplot.arrow.html plt.annotate( f"{idx}", xy=(round(nstar.xpos), round(nstar.ypos)), xycoords="data", xytext=(offset1, offset2), textcoords="offset points", size=NEIGHBOUR_TEXT_SIZE, color="red", arrowprops=dict(arrowstyle="-", color="grey", alpha=0.2), ) resultlines.append(log_star(nstar, idx)) # loading and painting ucac stars radius = 0.08 ucac_stars: List[MinimalStarTuple] = ucac4.get_region_minimal_star_tuples( star.coords.ra.deg, star.coords.dec.deg, radius ) logging.info(f"Looping on {len(ucac_stars)} UCAC4 stars") for ucac_star in ucac_stars: coord = SkyCoord(ucac_star.ra, ucac_star.dec, unit="deg") if star.coords.separation(coord).degree > radius: continue xy = SkyCoord.to_pixel(coord, wcs=wcs, origin=0) x, y = round(xy[0].item(0)), round(xy[1].item(0)) add_circle(x, y, 2, "c") plt.annotate( f"{ucac_star.id[-3:]}", xy=(x, y), xycoords="data", xytext=(2, 2), textcoords="offset points", size=UCAC4_TEXT_SIZE, arrowprops=dict(arrowstyle="-", color="grey", alpha=0.2), ) median = np.median(data) # data = ndimage.interpolation.rotate(data, record.rotation) plt.imshow(data, cmap="gray_r", origin="lower", vmin=0, vmax=min(median * 5, 65536)) starui = utils.get_star_or_catalog_name(star) save_inspect_image = Path( Path(resultdir) / "inspect", f"{starui.filename_no_ext}_{Path(resultdir).name}_inspect.png", ) save_inspect_txt = Path( Path(resultdir) / "inspect", f"{starui.filename_no_ext}_{Path(resultdir).name}_inspect.txt", ) fig.savefig(save_inspect_image) logging.info(f"Saved file as {save_inspect_image}.") write_file(star, save_inspect_txt, resultlines) plt.close(fig) plt.clf()