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
def _add_catalog_data_to_sd( sd: StarDescription, ucac4_sd: StarDescription, overwrite ): """ Add UCAC4 catalog data to a stardescription if there is none yet, or if overwrite is True """ if ucac4_sd is not None and not sd.has_metadata("UCAC4") or overwrite: do_calibration.add_catalog_data_to_sd( sd, ucac4_sd.vmag, ucac4_sd.vmag_err, ucac4_sd.aavso_id, "UCAC4", ucac4_sd.coords, extradata=ucac4_sd.get_metadata("UCAC4").extradata, )
def setUp(self) -> None: logging.getLogger().setLevel(logging.DEBUG) logging.basicConfig(format="%(asctime)s %(levelname)s %(message)s") self.df = reading.read_lightcurve_vast("./tests/data/out02391.dat") self.sd = stardesc(2391, 10, 10) do_calibration.add_catalog_data_to_sd(self.sd, 10, 0.1, "UCAC4-Numero2391", "UCAC4", self.sd.coords) self.sd_comp1 = stardesc(1, 10, 10) do_calibration.add_catalog_data_to_sd(self.sd_comp1, 12.1, 0.1, "UCAC4-Numero1", "UCAC4", self.sd.coords) self.sd_comp5 = stardesc(5, 10, 10) do_calibration.add_catalog_data_to_sd(self.sd_comp5, 11.1, 0.1, "UCAC4-Numero5", "UCAC4", self.sd.coords) self.sd.set_metadata(star_metadata.CompStarData(compstar_ids=[1, 5])) # ComparisonStars(comparison_stars_ids, comparison_stars_1_sds, comp_observations, comp_catalogmags, # comp_catalogerr) observations = [ { "2457236.66302": (12.2, 0.01) }, { "2457236.66302": (11.2, 0.01) }, ] self.comp_stars = ComparisonStars([1, 5], [self.sd_comp1, self.sd_comp5], observations, [12, 11], [0.1, 0.1]) import toml self.settings = toml.load("./tests/data/testsettings.txt")
def test_add_info_to_star_description(self): stars = [ self.stardesc(1, 1, 1), self.stardesc(1, 3, 3), self.stardesc(1, 10.24496, 9.96736), self.stardesc(1, 10.24490, 9.96730), ] star0_id = id(stars[0]) result = do_calibration.add_catalog_data_to_sd( stars[0], 10, 0.1, "BLA", "BLA", SkyCoord(ra=8, dec=5, unit="deg")) self.assertEqual(star0_id, id(result)) self.assertEqual(stars[0].vmag, 10) self.assertEqual(stars[0].vmag_err, 0.1)
def get_star_description_from_tuple(ucactuple: UcacTuple) -> StarDescription: startuple, zone, run_nr = ucactuple ra, dec = UCAC4.get_real_ra_dec(startuple.ra, startuple.spd) coords=SkyCoord(ra, dec, unit="deg") vmag=startuple.apass_mag_V / 1000 vmag_err=abs(startuple.apass_mag_sigma_V / 100) aavso_id=UCAC4.zone_and_run_nr_to_name(zone, run_nr) sd = StarDescription( coords=coords, vmag=vmag, vmag_err=vmag_err, aavso_id=aavso_id, ) do_calibration.add_catalog_data_to_sd( sd, vmag, vmag_err, aavso_id, "UCAC4", coords, extradata=ucactuple[0]._asdict() # get the StarTuple from the UcacTuple ) return sd
def read_vast_lightcurves( star: StarDescription, compstarproxy, star_result_dict, do_light, do_light_raw, do_phase, do_aavso, aavso_limit, basedir: str, chartsdir: Path, phasedir: Path, aavsodir: Path, jdfilter: List[float] = None, jd_excl_stop: float = None, ): start = timer() if star.local_id not in star_result_dict: star_result_dict[star.local_id] = {} temp_dict = star_result_dict[star.local_id] if star.path == "": logging.debug(f"Path for {star.local_id} is empty") return if not do_light and not do_phase: logging.debug("Nothing to do, no charts or phase needed") logging.debug( f"Reading lightcurves for star {star.local_id} at path {star.path} for {star}..." ) # comp_mags = [x.vmag for x in comparison_stars] try: df = reading.read_lightcurve_vast(star.path) df["floatJD"] = df["JD"].astype(np.float) df = utils.jd_filter_df(df, jdfilter) if df is None or len(df) == 0: logging.info(f"No lightcurve found for {star.path}") return comp_stars = compstarproxy.value filtered_compstars, check_star = do_compstars.filter_comparison_stars( star, comp_stars) comp_stars = None df["realV"], df[ "realErr"] = do_compstars.calculate_ensemble_photometry( df, filtered_compstars, do_compstars.weighted_value_ensemble_method) df = df.dropna(subset=[ "realV", "realErr" ]) # drop rows where the ensemble photometry failed do_calibration.add_catalog_data_to_sd( star, df["realV"].mean(), df["realErr"].mean(), None, "PHOTOMETRY", star.coords, ) starui: utils.StarUI = utils.get_star_or_catalog_name(star, suffix="") period, epoch = determine_period_and_epoch(df, star) # override user calculated epoch with user-supplied epoch if (star.has_metadata("SITE") and star.get_metadata("SITE").epoch is not None): epoch = star.get_metadata("SITE").epoch # filter depending on phase diagram df, points_removed = phase_dependent_outlier_removal(df, period) temp_dict["compstars"] = write_compstars(star, starui.filename_no_ext, phasedir, filtered_compstars, check_star) ymin, ymax, epoch_min, epoch_max, t_start, t_end = *calculate_min_max_epochs( df["floatJD"], df["realV"]), logging.debug( f"Debug for the min/max percentiles: {ymin}, {ymax}, {epoch_min}, {epoch_max}, {t_start}, {t_end}" ) write_toml(starui.filename_no_ext, phasedir, period, epoch, star, points_removed, ymin, ymax, t_start, t_end) if do_phase and "phase" not in star.result: temp_dict["phase"] = plot_phase_diagram(star, df.copy(), phasedir, period=period, epoch=epoch, suffix="") # anova_period, epoch = determine_period_and_epoch(df, star, method=anova_period_calculate) # logging.info(f"anova period is {anova_period}") # temp_dict['phase'] = plot_phase_diagram(star, df.copy(), phasedir, period=anova_period, # epoch=epoch, suffix="b") if do_light and "light" not in star.result: temp_dict["lightpa"] = plot_lightcurve_pa(star, df.copy(), chartsdir, period) temp_dict["lightcont"] = plot_lightcurve_continuous( star, df.copy(), chartsdir) temp_dict['light'] = plot_lightcurve(star, df.copy(), chartsdir) if do_aavso and "aavso" not in star.result: settings = toml.load("settings.txt") temp_dict["aavso"] = do_aavso_report.report( star, df.copy(), filtered_compstars, check_star, target_dir=aavsodir, sitelat=settings["sitelat"], sitelong=settings["sitelong"], sitealt=settings["sitealt"], camera_filter="V", observer=settings["observer"], chunk_size=aavso_limit, ) filtered_compstars = None # logging.error(f"contents of temp_dict is: {temp_dict}") star_result_dict[star.local_id] = temp_dict except Exception as ex: template = "An exception of type {0} occurred. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) import traceback print(traceback.print_exc()) logging.error( f"Exception during read_lightcurve for {star.path}, size JD: {len(df['floatJD'])}," f"size V: {len(df['realV'])}") end = timer() logging.debug(f"Full lightcurve/phase: {end - start}")