Example #1
0
def get_fixed_compstars(
    star_descriptions: List[StarDescription], comparison_stars: List[str]
):
    logging.info(f"Using fixed compstars {comparison_stars}")
    ucac4 = UCAC4()
    star_ids_1 = []
    star_desc_result = []
    star_catalog = do_calibration.create_star_descriptions_catalog(star_descriptions)
    for ucac_id in comparison_stars:
        # getting star_id_1
        ucacsd = ucac4.get_star_description_from_id(ucac_id)
        ra, dec = ucacsd.coords.ra, ucacsd.coords.dec
        star_id_1 = do_calibration.get_starid_1_for_radec([ra], [dec], star_catalog)
        star_ids_1.append(star_id_1)
        # adding info to star_description
        star = star_descriptions[star_id_1 - 1]
        logging.info(
            f"Compstar match: {ucacsd.aavso_id} with {star.local_id} ({ra}, {dec})"
        )
        do_calibration.add_catalog_data_to_sd(
            star,
            ucacsd.vmag,
            ucacsd.vmag_err,
            ucacsd.aavso_id,
            "UCAC4",
            SkyCoord(ra, dec, unit="deg"),
        )
        star_desc_result.append(star)
        logging.debug(
            f"Using fixed compstar '{ucac_id}' with Vmag: '{ucacsd.vmag}' and star id: {star_id_1}"
        )
    return [x.local_id for x in star_desc_result], star_desc_result
Example #2
0
def main(vastdir, file):
    ucac4 = UCAC4()

    # construct star descriptions
    sds = utils_sd.construct_star_descriptions(vastdir, None)
    star_catalog = do_calibration.create_star_descriptions_catalog(sds)
    df = main_vast.read_localid(file)
    for idx, row in df.iterrows():
        rowucac4 = row["ucac4_name"]
        result = ucac4_to_localid(ucac4, rowucac4, star_catalog, sds)
        row["local_id"] = result 
    print(df.to_csv())
    print(results)
Example #3
0
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 main(vastdir, star):
    ucac4 = UCAC4()
    # get UCAC4 sd for search later
    ucac_details = ucac4.get_ucactuple_from_id(utils.get_full_ucac4_id(star))
    ucacsd = ucac4.get_star_description_from_tuple(ucac_details)
    logging.info(f"Found UCAC4: {ucacsd}")

    # construct star descriptions
    sds = utils_sd.construct_star_descriptions(vastdir, None)
    star_catalog = do_calibration.create_star_descriptions_catalog(sds)

    # Get the 10 closest neighbours
    sd_dict = utils.get_localid_to_sd_dict(sds)
    neighbours = []
    for neigh in range(1, 22):
        idx, d2d, _ = match_coordinates_sky(ucacsd.coords,
                                            star_catalog,
                                            nthneighbor=neigh)
        neighbours.append(sds[idx])
    ucac4.add_sd_metadatas(neighbours)
    logging.info("\n" +
                 "\n".join([f"Star {x.local_id}: {x}" for x in neighbours]))
def get_fixed_compstars(star_descriptions=None):
    logging.info(f"Using fixed compstars {init.comparison_stars}")
    if star_descriptions is None:
        star_descriptions = do_calibration.get_star_descriptions(init.star_list)
    star_ids_1 = []
    star_desc_result = []
    star_catalog = do_calibration.create_star_descriptions_catalog(star_descriptions)
    for ucac_id in init.comparison_stars:
        # getting star_id_1
        df = do_calibration.get_ucac4_id_as_dataframe(ucac_id)
        star_id_1 = do_calibration.get_starid_1_for_radec(df['RAJ2000'], df['DEJ2000'], star_catalog)
        star_ids_1.append(star_id_1)
        # adding info to star_description
        star = star_descriptions[star_id_1 - 1]
        coord_catalog = SkyCoord(df['RAJ2000'], df['DEJ2000'], unit='deg')
        logging.info(df.info())
        # df['e_Vmag'] is not present !!!
        logging.info(df['UCAC4'].iloc(0)[0])
        vmag = df['Vmag'].iloc(0)[0]
        do_calibration.add_info_to_star_description(star, vmag, np.nan, df['UCAC4'].iloc(0)[0].decode("utf-8"),
                                                    "UCAC4", coord_catalog)
        star_desc_result.append(star)
        logging.debug(f"Using fixed compstar '{ucac_id}' with Vmag: '{vmag}' and star id: {star_id_1}")
    return star_ids_1, star_desc_result
Example #6
0
def read_and_tag_radec(radec_catalog: str, stars: List[StarDescription]):
    """ used for the -o or --radeccatalog cli argument """
    try:
        # read the CSV file from disk
        logging.info(f"Using radec catalog: {radec_catalog}")
        df = pd.read_csv(
            radec_catalog,
            sep=",",
            comment="#",
            names=[
                "our_name",
                "ra",
                "dec",
                "ucac4_name",
                "ucac4_force",
                "minmax",
                "min",
                "max",
                "var_type",
                "period",
                "period_err",
                "epoch",
                "comments",
            ],
            dtype={
                "ra": float,
                "dec": float,
                "ucac4_name": str,
                "minmax": str,
                "epoch": float,
            },
            skipinitialspace=True,
            warn_bad_lines=True,
        )

        df["chosenRA"] = df["ra"]
        df["chosenDEC"] = df["dec"]
        # process DataFrame row per row
        for idx, row in df.iterrows():
            ucac_ra, ucac_dec = ucac4.get_ra_dec_from_id(
                ucac4_id=row["ucac4_name"])
            # override 'our' ra/dec with ucac4 ra/dec if flag is set
            if (row["ucac4_force"]):
                row["chosenRA"], row["chosenDEC"] = ucac_ra, ucac_dec
                logging.warning(
                    f"Forcing ucac: {row['chosenRA']}, {row['ra']}")
            df.iloc[idx] = row

        logging.info(f"Selecting {len(df)} stars added by {radec_catalog}")

        # logging.info(f"--radeccatalog : {df}")
        ra, dec = (df["chosenRA"], df["chosenDEC"])
        df = df.replace({np.nan: None})
        skycoord: SkyCoord = do_calibration.create_generic_astropy_catalog(
            ra, dec)
        star_catalog = do_calibration.create_star_descriptions_catalog(stars)
        idx, d2d, d3d = match_coordinates_sky(skycoord,
                                              star_catalog,
                                              nthneighbor=1)
        for count, index in enumerate(idx):
            row = df.iloc[count]
            the_star = stars[index]
            logging.info(
                f"Matching {row['our_name']} to {the_star.local_id} with sep {d2d[count].degree} "
                f"at coords {the_star.coords}")

            # add sitedata for the star in this row
            add_site_metadata(the_star, row, separation=d2d[count].degree)

            # add selected, add UCAC4, override UCAC4
            postprocess_csv_reads(the_star, row)
            if d2d[count].degree > 0.01:
                logging.warning(
                    f"Separation between {df.iloc[count]['our_name']} "
                    f"and {stars[index].local_id} is {d2d[count]}")
    except Exception as ex:
        template = "An exception of type {0} occurred. Arguments:\n{1!r}"
        message = template.format(type(ex).__name__, ex.args)
        import traceback
        print(traceback.print_exc())
        logging.error(message)
        logging.error(f"Could not read {radec_catalog}")