Ejemplo n.º 1
0
 def test_get_stars_with_metadata(self):
     vsx_descr = utils.get_stars_with_metadata(
         self.star_descriptions, catalog_name="CANDIDATES", exclude=["VSX"]
     )
     self.assertEqual(1, len(vsx_descr))
     vsx_descr = utils.get_stars_with_metadata(
         self.star_descriptions, catalog_name="VSX", exclude=["CANDIDATES"]
     )
     self.assertEqual(1, len(vsx_descr))
     vsx_descr = utils.get_stars_with_metadata(
         self.star_descriptions, catalog_name="VSX", exclude=["VSX", "CANDIDATES"]
     )
     self.assertEqual(0, len(vsx_descr))
Ejemplo n.º 2
0
 def test_tag_selected(self):
     # 3154, 515, 2269, 2635
     stars = [
         self.stardesc(515, 12.7725921, 12.0036631),
         self.stardesc(2269, 12.2686600, 12.0382637),
         self.stardesc(3154, 12.1520503, 12.0935881),
         self.stardesc(2635, 10.24490, 9.96730),
         self.stardesc(1, 10, 9),
     ]
     main_vast.read_and_tag_localid(
         PurePath(test_file_path, "wwcra2015_starlist.txt"),
         utils.get_localid_to_sd_dict(stars),
     )
     test = utils.get_stars_with_metadata(stars, "SITE")
     self.assertEqual(4, len(test))
     test = utils.get_stars_with_metadata(stars, "SELECTEDTAG")
     self.assertEqual(4, len(test))
Ejemplo n.º 3
0
 def test_tag_candidates(self):
     stars = [
         self.stardesc(1, 1, 1),
         self.stardesc(2, 3, 3),
         self.stardesc(3129, 10.24496, 9.96736),
         self.stardesc(5711, 10.24490, 9.96730),
     ]
     main_vast.tag_candidates(test_file_path, stars)
     test = utils.get_stars_with_metadata(stars, "CANDIDATE")
     self.assertEqual(2, len(test))
Ejemplo n.º 4
0
def write_candidate_stars(resultdir, stars: List[StarDescription]):
    candidates = utils.get_stars_with_metadata(stars,
                                               "CANDIDATES",
                                               exclude=["VSX"])
    newname = f"{resultdir}candidate_stars.txt"
    logging.info(f"Writing {newname}...")
    total_found = 0
    stardict = utils.get_localid_to_sd_dict(stars)
    logging.debug(f"Receiving {len(stardict.keys())} as vsx input")
    with open(newname, "wt") as fp:
        for index, current_sd in enumerate(candidates):
            found = False if current_sd.path == "" else True
            total_found += 1 if found else 0
            fp.write(f"{current_sd.local_id},,CANDIDATE-{index},,\n")
Ejemplo n.º 5
0
def construct_star_descriptions(vastdir: str, resultdir: str, wcs: WCS, args):
    star_descriptions = utils_sd.construct_raw_star_descriptions(
        vastdir, wcs, None, STAR_KEEPER_PERCENTAGE)
    logging.info(
        f"Number of stars on more than {STAR_KEEPER_PERCENTAGE:.0%} of frames: {len(star_descriptions)}"
    )
    stardict = get_localid_to_sd_dict(star_descriptions)

    # Add VSX information to SDs
    star_descriptions, results_ids = do_calibration.add_vsx_names_to_star_descriptions(
        star_descriptions, vsxcatalogdir, 0.01)
    logging.debug(f"Identified {len(results_ids)} VSX stars")
    vsx_stars = utils.get_stars_with_metadata(star_descriptions, "VSX")
    assert len(vsx_stars) == len(results_ids)
    logging.debug(f"Test Tagged {len(vsx_stars)} stars as VSX.")

    # write the vsx stars used into a file
    results_ids.sort()
    write_vsx_stars(resultdir, results_ids, star_descriptions)

    # tag all candidates with a 'candidate' catalog
    tag_candidates(vastdir, star_descriptions)
    write_candidate_stars(resultdir, star_descriptions)

    # adds sitedata to vsx stars
    if args.selectvsx:
        tag_vsx_as_selected(vsx_stars)

    # adds sitedata to selected stars
    if args.localidcatalog:
        read_and_tag_localid(args.localidcatalog, stardict)
        logging.debug(
            f"Succesfully read {len(list(filter(lambda x: x.has_metadata('SELECTEDFILE'), star_descriptions)))} "
            f"stars from file:"
            f" {[x.local_id for x in list(filter(lambda x: x.has_metadata('SELECTEDFILE'), star_descriptions))]}"
        )

    if args.radeccatalog:
        read_and_tag_radec(args.radeccatalog, star_descriptions)

    return star_descriptions
Ejemplo n.º 6
0
def run_do_rest(args):
    thread_count = args.threads
    vastdir = utils.add_trailing_slash(args.datadir)
    resultdir = clean_and_create_resultdir(args.resultdir, vastdir)
    do_light = args.light
    do_phase = args.phase
    do_aavso = args.aavso
    logging.info(
        f"Dir with VaST files: '{vastdir}'\nResults dir: '{resultdir}'")
    # get wcs model from the reference header. Used in writing world positions and field charts (can fail)
    wcs_file, wcs = reading.read_wcs_file(vastdir)
    ref_jd, _, _, reference_frame = reading.extract_reference_frame(vastdir)
    _, _, _, first_frame = reading.extract_first_frame(vastdir)
    reference_frame_path = Path(reference_frame)
    reference_frame_filename = reference_frame_path.name
    wcs_file, wcs = perform_astrometry_net(args, vastdir, wcs_file, wcs,
                                           reference_frame_filename)
    logging.info(f"The reference frame is '{reference_frame}' at JD: {ref_jd}")
    logging.info(f"The first frame is '{first_frame}'")
    logging.info(f"Reference header is '{wcs_file}'")
    check_that_reference_image_not_within_jdfilter(ref_jd, args.jdfilter,
                                                   args.jdrefignore)

    star_descriptions = construct_star_descriptions(vastdir, resultdir, wcs,
                                                    args)
    stardict = get_localid_to_sd_dict(star_descriptions)
    logging.debug(
        f"First (max) 10 star descriptions: "
        f"{star_descriptions[:10] if (len(star_descriptions) >= 10) else star_descriptions}"
    )
    write_augmented_autocandidates(vastdir, resultdir, stardict)
    write_augmented_all_stars(vastdir, resultdir, stardict)
    candidate_stars = utils.get_stars_with_metadata(star_descriptions,
                                                    "CANDIDATE",
                                                    exclude=["VSX"])
    if args.selectcandidates:
        tag_candidates_as_selected(candidate_stars)
    logging.info(f"There are {len(candidate_stars)} candidate stars")

    vsx_stars = utils.get_stars_with_metadata(star_descriptions, "VSX")
    logging.info(f"There are {len(vsx_stars)} vsx stars")
    if args.allstars:
        tag_all_stars_as_selected(star_descriptions)
    selected_stars = utils.get_stars_with_metadata(star_descriptions,
                                                   "SELECTEDTAG")
    logging.info(f"There are {len(selected_stars)} selected stars")
    compstar_needing_stars = utils.concat_sd_lists(selected_stars, vsx_stars,
                                                   candidate_stars)
    comp_stars = set_comp_stars_and_ucac4(star_descriptions, selected_stars,
                                          args.checkstarfile, vastdir,
                                          stardict, ref_jd)
    # Set comp stars for all interesting stars (stars which are interesting enough to measure)
    logging.info("Setting per star comparison stars...")
    if args.checkstarfile:
        utils.add_metadata(star_descriptions,
                           CompStarData(compstar_ids=comp_stars.ids))
    else:
        do_compstars.add_closest_compstars(compstar_needing_stars, comp_stars,
                                           10)

    logging.info(
        f"Using {thread_count} threads for phase plots, lightcurves, ...")
    if args.allstars:
        do_charts_vast.run(
            star_descriptions,
            comp_stars,
            vastdir,
            resultdir,
            "phase_all/",
            "light_all/",
            "aavso_all/",
            do_phase=do_phase,
            do_light=do_light,
            do_light_raw=do_light,
            do_aavso=do_aavso,
            nr_threads=thread_count,
            jdfilter=args.jdfilter,
            desc="Phase/light/aavso of ALL stars",
        )
    else:
        if args.vsx:
            logging.info(f"Plotting {len(vsx_stars)} vsx stars...")
            do_charts_vast.run(
                vsx_stars,
                comp_stars,
                vastdir,
                resultdir,
                "phase_vsx/",
                "light_vsx/",
                "aavso_vsx/",
                do_phase=do_phase,
                do_light=do_light,
                do_light_raw=do_light,
                do_aavso=do_aavso,
                nr_threads=thread_count,
                jdfilter=args.jdfilter,
                desc="Phase/light/aavso of VSX stars",
            )
        if args.radeccatalog or args.localidcatalog:
            do_charts_vast.run(
                selected_stars,
                comp_stars,
                vastdir,
                resultdir,
                "phase_selected/",
                "light_selected/",
                "aavso_selected",
                do_phase=do_phase,
                do_light=do_light,
                do_light_raw=do_light,
                do_aavso=do_aavso,
                nr_threads=thread_count,
                jdfilter=args.jdfilter,
                desc="Phase/light/aavso of selected stars",
            )
        if args.candidates:
            logging.info(f"Plotting {len(candidate_stars)} candidates...")
            do_charts_vast.run(
                candidate_stars,
                comp_stars,
                vastdir,
                resultdir,
                "phase_candidates/",
                "light_candidates/",
                "aavso_candidates/",
                do_phase=do_phase,
                do_light=do_light,
                do_light_raw=do_light,
                do_aavso=do_aavso,
                nr_threads=thread_count,
                jdfilter=args.jdfilter,
                desc="Phase/light/aavso of candidates",
            )

    # starfiledata is filled in during the phase plotting, so should come after it. Without phase it will be incomplete
    ids = [x.local_id for x in selected_stars]
    logging.info(
        f"Writing selected files with {len(selected_stars)}  selected stars: {ids}"
    )
    write_selected_files(resultdir, vastdir, selected_stars)

    # only create fieldcharts dir if we use it
    fieldchartsdir = resultdir + "fieldcharts/"
    if args.field or args.stats:
        trash_and_recreate_dir(fieldchartsdir)

    if args.field:
        do_charts_field.run_standard_field_charts(star_descriptions, wcs,
                                                  fieldchartsdir, wcs_file,
                                                  comp_stars)

    if args.stats:
        do_charts_stats.plot_comparison_stars(fieldchartsdir, selected_stars,
                                              stardict, args.jdfilter)
        do_charts_stats.plot_aperture_vs_jd(fieldchartsdir, vastdir,
                                            args.jdfilter)
        do_charts_stats.plot_aperture_vs_airmass(fieldchartsdir, vastdir, wcs,
                                                 args.jdfilter)
        do_charts_stats.plot_merr_vs_jd(fieldchartsdir, selected_stars,
                                        args.jdfilter)

    if args.site:
        ids = [x.local_id for x in selected_stars]
        logging.info(
            f"Creating HTML site with {len(selected_stars)} selected stars: {ids}"
        )
        hugo_site.run(args.site, selected_stars, len(vsx_stars),
                      reference_frame_path, resultdir, args.explore)
Ejemplo n.º 7
0
def write_selected_files(resultdir: str, vastdir: str,
                         selected_stars: List[StarDescription]):
    radec_catalog = f"{resultdir}selected_radec.txt"
    localid_catalog = f"{resultdir}selected_localid.txt"
    aavso_vsx_catalog = f"{resultdir}aavso_vsx.txt"
    logging.info(
        f"Writing {radec_catalog} and {localid_catalog} and {aavso_vsx_catalog} with {len(selected_stars)} stars..."
    )
    sorted_stars = utils.sort_selected(selected_stars)
    vsx_stars_len = len(utils.get_stars_with_metadata(selected_stars, "VSX"))
    no_vsx_len = len(
        utils.get_stars_with_metadata(selected_stars,
                                      "SELECTEDTAG",
                                      exclude=["VSX"]))

    def format_float_arg(atoml, arg: str, precision):
        if arg is None or arg not in atoml:
            return ""
        if not isinstance(atoml[arg], float):
            return atoml[arg]
        return f"{atoml[arg]:.{precision}f}"

    def format_float_5(atoml, arg: str):
        return format_float_arg(atoml, arg, 5)

    def format_float_2(atoml, arg: str):
        return format_float_arg(atoml, arg, 2)

    def format_string(arg: str, atoml):
        if arg in atoml:
            return atoml[arg]
        return ""

    with open(radec_catalog, "w") as out_radec_catalog, open(
            localid_catalog,
            "w") as out_localid_catalog, open(aavso_vsx_catalog,
                                              "w") as out_aavso_vsx_catalog:
        common_prefix = (
            f"# resultdir: {resultdir}, vastdir: {vastdir}, vsx stars: {vsx_stars_len}, "
            f"other stars: {no_vsx_len}\n")
        common_postfix = (f"minmax,min,max,var_type,period,period_err,epoch\n")
        out_radec_catalog.write(
            f"{common_prefix}# our_name,ra,dec,ucac4_name,ucac4_force,{common_postfix}"
        )
        out_localid_catalog.write(
            f"{common_prefix}# our_name,local_id,ucac4_name,ucac4_force,{common_postfix}"
        )

        out_aavso_vsx_catalog.write(
            f"{common_prefix}# our_name,ucac4_name,ucac4_ra,ucac4_dec,{common_postfix}"
        )

        for star in sorted_stars:
            metadata: SiteData = star.get_metadata("SITE")
            ucac4: CatalogData = utils.get_ucac4_of_sd(star)
            ucac4_name = "" if not ucac4 else f"{ucac4.name}"
            ucac4_coords = (
                "," if not ucac4 else
                f"{ucac4.coords.ra.deg:.7f},{ucac4.coords.dec.deg:.7f}")
            starui: utils.StarUI = utils.get_star_or_catalog_name(star)
            txt_path = Path(
                Path(star.result["phase"]).parent, "txt",
                starui.filename_no_ext + ".txt")
            try:
                parsed_toml = toml.load(txt_path)
                postfix = f"{format_string('minmax', parsed_toml)},{format_float_2(parsed_toml, 'min')},{format_float_2(parsed_toml, 'max')},{metadata.var_type},{format_float_5(parsed_toml, 'period')},{format_float_5(parsed_toml, 'period_err')},{format_string('epoch', parsed_toml)},{metadata.comments}"

                out_radec_catalog.write(
                    f"{metadata.our_name},{star.coords.ra.deg:.7f},{star.coords.dec.deg:.7f},{ucac4_name},False,{postfix}\n"
                )
                out_localid_catalog.write(
                    f"{metadata.our_name},{star.local_id},{ucac4_name},False,{postfix}\n"
                )
                out_aavso_vsx_catalog.write(
                    f"{metadata.our_name},{ucac4_name},{ucac4_coords},{postfix}\n"
                )
            except FileNotFoundError:
                logging.error(
                    f"While writing selected files, Could not find {txt_path}")
Ejemplo n.º 8
0
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()
Ejemplo n.º 9
0
def run_do_rest(args):
    thread_count = args.threads
    vastdir = utils.add_trailing_slash(args.datadir)
    resultdir = clean_and_create_resultdir(args.resultdir, vastdir)
    fieldchartsdir = resultdir + "fieldcharts/"
    do_light = args.light
    do_phase = args.phase
    do_aavso = args.aavso
    logging.info(
        f"Dir with VaST files: '{vastdir}'\nResults dir: '{resultdir}'")
    # get wcs model from the reference header. Used in writing world positions and field charts (can fail)
    wcs_file, wcs = reading.read_wcs_file(vastdir)
    ref_jd, _, _, reference_frame = reading.extract_reference_frame(vastdir)
    _, _, _, first_frame = reading.extract_first_frame(vastdir)
    referene_frame_path = Path(reference_frame)
    reference_frame_filename = referene_frame_path.name
    logging.info(f"The reference frame is '{reference_frame}' at JD: {ref_jd}")
    logging.info(f"The first frame is '{first_frame}'")
    logging.info(f"Reference header is '{wcs_file}'")
    # Log filtering settings + check that reference frame is not inside of filter
    if args.jdfilter:
        logging.info(f"Filtering JD's: {args.jdfilter}")
        ref_inside_filter = (float(ref_jd) > args.jdfilter[0]
                             and float(ref_jd) > args.jdfilter[1])
        if ref_inside_filter:
            if not args.jdrefignore:
                assert not ref_inside_filter, "Reference frame JD is filtered"
            else:
                logging.info(
                    "Reference frame JD is inside of the JD filter, but you indicated that's ok."
                )

    if not os.path.isfile(wcs_file):
        full_ref_path = Path(args.fitsdir) / reference_frame_filename
        if not args.fitsdir and args.apikey:
            logging.error(
                "There is no plate-solved reference frame {wcs_file}, please specify both --apikey "
                "and --fitsdir.")
            sys.exit(0)
        rotation = reading.extract_reference_frame_rotation(
            vastdir, reference_frame_filename)
        assert (rotation == 0.0
                ), f"Error: rotation is {rotation} and should always be 0.0"
        subprocess.Popen(
            f"python3 ./src/astrometry_api.py --apikey={args.apikey} "
            f"--upload={full_ref_path} --newfits={wcs_file} --private --no_commercial",
            shell=True,
        )
        while not os.path.isfile(wcs_file):
            logging.info(f"Waiting for the astrometry.net plate solve...")
            time.sleep(10)
        wcs_file, wcs = reading.read_wcs_file(vastdir)

    star_descriptions = construct_star_descriptions(vastdir, resultdir, wcs,
                                                    args)
    stardict = get_localid_to_sd_dict(star_descriptions)
    logging.debug(
        f"First (max) 10 star descriptions: "
        f"{star_descriptions[:10] if (len(star_descriptions) >= 10) else star_descriptions}"
    )
    write_augmented_autocandidates(vastdir, resultdir, stardict)
    write_augmented_all_stars(vastdir, resultdir, stardict)
    candidate_stars = utils.get_stars_with_metadata(star_descriptions,
                                                    "CANDIDATE",
                                                    exclude=["VSX"])
    if args.selectcandidates:
        tag_candidates_as_selected(candidate_stars)
    logging.info(f"There are {len(candidate_stars)} candidate stars")

    vsx_stars = utils.get_stars_with_metadata(star_descriptions, "VSX")
    logging.info(f"There are {len(vsx_stars)} vsx stars")
    selected_stars = utils.get_stars_with_metadata(star_descriptions,
                                                   "SELECTEDTAG")
    # if args.selectvsx:
    #     selected_stars = utils.concat_sd_lists(selected_stars, vsx_stars)
    logging.info(f"There are {len(selected_stars)} selected stars")
    compstar_needing_stars = utils.concat_sd_lists(selected_stars, vsx_stars,
                                                   candidate_stars)
    comp_stars = set_comp_stars_and_ucac4(star_descriptions, selected_stars,
                                          args.checkstarfile, vastdir,
                                          stardict, ref_jd)
    # Set comp stars for all interesting stars (stars which are interesting enough to measure)
    logging.info("Setting per star comparison stars...")
    if args.checkstarfile:
        utils.add_metadata(star_descriptions,
                           CompStarData(compstar_ids=comp_stars.ids))
    else:
        do_compstars.add_closest_compstars(compstar_needing_stars, comp_stars,
                                           10)

    logging.info(
        f"Using {thread_count} threads for phase plots, lightcurves, ...")
    if args.allstars:
        do_charts_vast.run(
            star_descriptions,
            comp_stars,
            vastdir,
            resultdir,
            "phase_all/",
            "light_all/",
            "aavso_all/",
            do_phase=do_phase,
            do_light=do_light,
            do_light_raw=do_light,
            do_aavso=do_aavso,
            nr_threads=thread_count,
            jdfilter=args.jdfilter,
            desc="Phase/light/aavso of ALL stars",
        )
    else:
        if args.vsx:
            logging.info(f"Plotting {len(vsx_stars)} vsx stars...")
            do_charts_vast.run(
                vsx_stars,
                comp_stars,
                vastdir,
                resultdir,
                "phase_vsx/",
                "light_vsx/",
                "aavso_vsx/",
                do_phase=do_phase,
                do_light=do_light,
                do_light_raw=do_light,
                do_aavso=do_aavso,
                nr_threads=thread_count,
                jdfilter=args.jdfilter,
                desc="Phase/light/aavso of VSX stars",
            )
        if args.radeccatalog or args.localidcatalog:
            do_charts_vast.run(
                selected_stars,
                comp_stars,
                vastdir,
                resultdir,
                "phase_selected/",
                "light_selected/",
                "aavso_selected",
                do_phase=do_phase,
                do_light=do_light,
                do_light_raw=do_light,
                do_aavso=do_aavso,
                nr_threads=thread_count,
                jdfilter=args.jdfilter,
                desc="Phase/light/aavso of selected stars",
            )
        if args.candidates:
            logging.info(f"Plotting {len(candidate_stars)} candidates...")
            do_charts_vast.run(
                candidate_stars,
                comp_stars,
                vastdir,
                resultdir,
                "phase_candidates/",
                "light_candidates/",
                "aavso_candidates/",
                do_phase=do_phase,
                do_light=do_light,
                do_light_raw=do_light,
                do_aavso=do_aavso,
                nr_threads=thread_count,
                jdfilter=args.jdfilter,
                desc="Phase/light/aavso of candidates",
            )

    # starfiledata is filled in during the phase plotting, so should come after it. Without phase it will be incomplete
    ids = [x.local_id for x in selected_stars]
    logging.info(
        f"Writing selected files with {len(selected_stars)}  selected stars: {ids}"
    )
    write_selected_files(resultdir, vastdir, selected_stars)
    if args.field:
        do_charts_field.run_standard_field_charts(star_descriptions, wcs,
                                                  fieldchartsdir, wcs_file,
                                                  comp_stars)

    if args.stats:
        do_charts_stats.plot_comparison_stars(fieldchartsdir, selected_stars,
                                              stardict, args.jdfilter)
        do_charts_stats.plot_aperture_vs_jd(fieldchartsdir, vastdir,
                                            args.jdfilter)
        do_charts_stats.plot_aperture_vs_airmass(fieldchartsdir, vastdir, wcs,
                                                 args.jdfilter)
        do_charts_stats.plot_merr_vs_jd(fieldchartsdir, selected_stars,
                                        args.jdfilter)

    if args.site:
        ids = [x.local_id for x in selected_stars]
        logging.info(
            f"Creating HTML site with {len(selected_stars)} selected stars: {ids}"
        )
        hugo_site.run(args.site, selected_stars, len(vsx_stars),
                      referene_frame_path, resultdir, args.explore)