Esempio n. 1
0
def star_model(tel_array, I_time, star_mag, ang_diam, wavelength, star_id):
    star_err = IItools.track_error(sig0=tel_array.err_sig,
                                   m0=tel_array.err_mag,
                                   m=star_mag,
                                   T_0=tel_array.err_t1,
                                   T=I_time.to("s").value)

    hour_angle_rad = Angle(
        tel_array.star_dict[star_id]["IntSideTimes"]).to('rad').value
    dec_angle_rad = tel_array.star_dict[star_id]["DEC"].to('rad').value
    lat = tel_array.telLat.to('rad').value

    tel_tracks = [
        IItools.uv_tracks(lat=lat,
                          dec=dec_angle_rad,
                          hours=hour_angle_rad,
                          Bn=Bns,
                          Be=Bew,
                          Bu=Bud) for Bns, Bew, Bud in zip(
                              tel_array.Bnss, tel_array.Bews, tel_array.Buds)
    ]

    airy_disk, airy_func = IImodels.airy_disk2D(shape=(tel_array.xlen,
                                                       tel_array.ylen),
                                                xpos=tel_array.xlen,
                                                ypos=tel_array.ylen,
                                                angdiam=ang_diam,
                                                wavelength=wavelength)
    return star_err, hour_angle_rad, dec_angle_rad, lat, tel_tracks, airy_disk, airy_func
Esempio n. 2
0
def visibility2dTo1d(tel_tracks, visibility_func, x_0, y_0):
    """
    Take the tracks generated from a 2D airy disk curve and convert them into a 1D airy disk curve
    :param x_0: The x cfoordinate 0 point of the visibility model
    :param y_0: The y coordinate 0 point of the visibility model
    :param tel_tracks: The tracks from the 2D airy disk
    :param visibility_func: The 2D visibility function used to generate the tracks
    :return: The radial x values, The amplitude at those radii, average integrated radial x values, the average
    integrated amplitude at those raddi
    """
    amps = []
    rads = []
    avg_amps = []
    avg_rads = []

    for i, track in enumerate(tel_tracks):
        try:
            utrack = track[0][:, 0] + x_0
        except:
            adsf = 34
        vtrack = track[0][:, 1] + y_0
        amps.append(visibility_func(utrack, vtrack))
        rads.append(np.sqrt((utrack - x_0)**2 + (vtrack - y_0)**2))
        airy_avg = IItools.trapezoidal_average(num_f=amps[i])
        avg_rad = IItools.trapezoidal_average(num_f=rads[i])
        avg_amps.append(airy_avg)
        avg_rads.append(avg_rad)
    return np.array(rads), np.array(amps), np.array(avg_rads), np.array(
        avg_amps)
Esempio n. 3
0
def uvtracks_integrated(varray,
                        tel_tracks,
                        airy_func,
                        save_dir,
                        name,
                        err,
                        noise=None):
    noise_array = 0
    nlen = len(varray.star_dict[star_id]["IntTimes"]) - 1
    if noise:
        noise_array = np.random.normal(0, err, nlen)
    x_0 = airy_func.x_0.value
    y_0 = airy_func.y_0.value
    plt.figure(figsize=(22, 16))
    for i, track in enumerate(tel_tracks):
        utrack = track[0][:, 0] + x_0
        vtrack = track[0][:, 1] + y_0
        airy_amp = airy_func(utrack, vtrack)
        airy_radius = np.sqrt((utrack - x_0)**2 + (vtrack - y_0)**2)
        airy_I, trap_err, Irads = IItools.trap_w_err(airy_amp, airy_radius,
                                                     err, err)
        airy_err = np.ones(len(airy_I)) * err
        plt.errorbar(x=.5 * Irads + airy_radius[:-1],
                     y=airy_I / Irads + noise_array,
                     yerr=airy_err,
                     xerr=Irads,
                     fmt='o')
        plt.plot(airy_radius, airy_amp)
    title = "UV integration times vs integration for %s" % (name)
    plt.title(title)
    plt.xlabel('Radius')
    plt.ylabel("normalized amplitude")
    plt.xlim(0, 180)
    plt.ylim(0)
    graph_saver(save_dir, title + "1D")
Esempio n. 4
0
def radial_profile_plot(data, center, data_name, arcsec, wavelength, save_dir):
    rad_prof = IItools.radial_profile(data)
    plt.figure(figsize=(18, 12))
    plt.xlabel("Radius (m)", fontsize=14)
    plt.ylabel("Normalized Amplitude", fontsize=14)
    plt.plot(rad_prof)
    title = "Radial profile of %s for %s and wavelength %s" % (
        data_name, arcsec, wavelength)
    plt.title(title, fontsize=24)
    graph_saver(save_dir, title)
Esempio n. 5
0
def chi_square_anal(tel_tracks, airy_func, star_err, guess_r, ang_diam,
                    star_name, save_dir):
    angdiams, chis = IItools.chi_square_anal(airy_func=airy_func,
                                             tel_tracks=tel_tracks,
                                             guess_r=guess_r,
                                             star_err=star_err,
                                             ang_diam=ang_diam)

    plt.figure(figsize=(16, 16))
    title = "%s Chi square analysis" % (star_name)
    plt.title(title, fontsize=28)
    plt.xlabel("Fit value (mas)", fontsize=22)
    plt.ylabel("ChiSquare", fontsize=22)
    plt.ylim((0, 10))
    plt.tick_params(axis='both', which='major', labelsize=20)
    plt.tick_params(axis='both', which='minor', labelsize=18)

    plt.plot(angdiams, chis, linewidth=6)

    if save_dir:
        graph_saver(save_dir, title)
    else:
        plt.show()
Esempio n. 6
0
def catalog_interaction(master_SII_cat):

    cls()
    truncated_print = True
    if "PerFitErr" in master_SII_cat.columns:
        truncvals = [
            "Index", "NAME", "RA", "DEC", "ANGD", "MAG", "BS_BMAG", "BSSpT",
            "ObservableTimes", "PerFitErr", "PerFailFit"
        ]
    else:
        truncvals = [
            "Index", "NAME", "RA", "DEC", "ANGD", "MAG", "BS_BMAG", "BSSpT",
            "ObservableTimes"
        ]

    master_SII_cat[truncvals].pprint(max_lines=-1, max_width=-1)
    stop_sel = 'n'

    while True:
        mode = input(
            "\nEnter a star's index value to do a single analysis\n"
            "Enter 'rankall' to do a full catalog ranking\n"
            "Enter 'toggleinfo' to show/hide all available catalog information\n"
            "Enter 'q' to quit\n"
            ": ")

        if mode.lower() == 'rankall':
            print("Ranking all stars")
            break
        elif mode.lower() == "q":
            print("quitting ASIIP")
            sys.exit()

        elif mode.lower() == "toggleinfo":
            truncated_print = not truncated_print
            if truncated_print:
                print("\nTruncated printing is now activated\n")
                master_SII_cat["Index", "NAME", "RA", "DEC", "ANGD", "MAG",
                               "BS_BMAG", "BSSpT"].pprint(max_lines=-1,
                                                          max_width=-1)
            else:
                print("\nTruncated printing has been deactivated\n")
                master_SII_cat.pprint(max_lines=-1, max_width=-1)

        else:
            try:
                selection = int(mode)
                star = master_SII_cat[selection]
                name, ra, dec, star_mag, ang_diam, guess_diam, star_id, pmra, pmdec = \
                    star_info(star, wavelength, use_queried_mag)
                tel_array.star_track(ra=ra,
                                     dec=dec,
                                     alt_cut=alt_cut,
                                     obs_start=obs_start,
                                     obs_end=obs_end,
                                     Itime=int_time,
                                     pmra=pmra,
                                     pmdec=pmdec)
                I_time = tel_array.star_dict[star_id]["IntDelt"]

                if I_time:
                    star_err, hour_angle_rad, dec_angle_rad, lat, tel_tracks, airy_disk, airy_func = \
                        star_model(tel_array=tel_array, I_time=I_time, star_mag=star_mag, ang_diam=ang_diam,
                                   wavelength=wavelength, star_id=star_id)
                    # This is where the custom Monte Carlo analysis is performed. If you wish to add an analytical function, you
                    # can use this function as a template to create another analysis technique
                    runs = boot_runs * 2
                    fdiams, ferrs, ffit = \
                        IItools.IIbootstrap_analysis_airyDisk(tel_tracks=tel_tracks,
                                                              airy_func=airy_func,
                                                              star_err=star_err,
                                                              guess_diam=guess_diam,
                                                              wavelength=wavelength,
                                                              runs=runs)
                    fit_err = np.nanstd(fdiams) / np.nanmedian(fdiams) * 100
                    failed_fit = ffit / runs * 100

                    cls()

                    if truncated_print:
                        master_SII_cat[truncvals].pprint(max_lines=-1,
                                                         max_width=-1)
                    else:
                        master_SII_cat.pprint(max_lines=-1, max_width=-1)

                    print(red_line)
                    if truncated_print: print(star[truncvals])
                    else: print(star)
                    print(
                        "\x1b[1;32;40m' The fit error is %.3f%%, the failed fit is %.3f%% \x1b[0m\n"
                        % (fit_err, failed_fit))
                    print(red_line)

                    if save_plots: star_save = os.path.join(save_dir, name)
                    else: star_save = False

                    guess_r = airy_func.radius.value

                    do_plots(tel_array=tel_array,
                             baselines=baselines,
                             tel_tracks=tel_tracks,
                             ang_diam=star["ANGD"],
                             airy_func=airy_func,
                             star_err=star_err,
                             guess_r=guess_r,
                             wavelength=wavelength,
                             name=name,
                             I_time=I_time,
                             pererr=fit_err,
                             star_save=star_save,
                             star_id=star_id)

                else:
                    print(
                        "\nSorry, that star isn't visible for the times you defined.\n"
                    )

            except Exception as e:
                print(e)
                print(
                    "\nI'm sorry, but that response doesn't actually mean anything to ASIIP.\n"
                )

    return mode.lower()
Esempio n. 7
0
def siicat_constructor(tel_array, cutoff_obs_time=0, Int_obst=None):
    """
    This function takes every entry from every target catalog and combines the information into one big master catalog.
    It will prioritize which catalogs to analyze first based upon the order the catalogs were queried. The way it was
    written was for optimization along with an ability to keep the sizing of the arrays dynamic, which is why python
    lists were used, along with how duplicates are identified. It was kept seperate from the main part of the script
    to keep the script more readable.
    :param tel_array: The object which includes all of the information from the catalogs that have been queried
    :param cutoff_obs_time: The minimum amount of time you wish a star to be observable. Any star that is below or
    equal to this value is skipped. 0 means if it can't be observed at anytime during the night, it is skipped.
    The units the script expects is hours
    :param Int_obst: The integration time used for the data you will be analyzing. This is used to give a reference
    to how much error an observation will have
    :return: The completed catalog as an Astropy table
    """
    c = 0

    good_diams = []
    good_ra = []
    good_dec = []
    calc_ra = []
    calc_dec = []
    good_mags = []
    good_mag_names = []
    cat_names = []
    total_obs_times = []
    dup_count = []
    time_ranges = []
    coords_done = None
    first_cord = False
    for catalog, cat_name in zip(tel_array.catalogs, tel_array.cat_names):
        ras, decs, ang_diams, mags, mag_name = tel_array.ra_dec_diam_getter(
            cat_name, catalog)
        pos_cat = SkyCoord(ras, decs)

        if len(pos_cat) == 0: continue
        if not first_cord:
            closest_star, skydis, distance3d = (np.array([]),
                                                Angle(np.ones(len(ras)),
                                                      unit=u.rad),
                                                np.full(len(ras), True))
            coords_done = SkyCoord(good_ra,
                                   good_dec,
                                   unit=("hourangle", "deg"))
            first_cord = True

        else:
            coords_done = SkyCoord(good_ra,
                                   good_dec,
                                   unit=("hourangle", "deg"))
            # match pos_cat to the closest star in coords_done returning the closest coords_done indicies

            closest_star, skydis, distance3d = pos_cat.match_to_catalog_sky(
                coords_done)

        # the indicies where the matched pos_cat star is large enough to be considered a unique star
        unq_idx = skydis > 1 * u.arcsec

        dists = np.full(len(ras), np.inf)
        rs = np.argsort(ras)
        dup_diams = []
        i = 0
        for ra, dec, ang_diam, mag, unique in zip(ras, decs, ang_diams, mags,
                                                  unq_idx):
            total_obs_time = 0 * u.hour

            dis = (ra.to('deg').value + dec.to("deg").value)
            if unique and (ra.value not in calc_ra
                           or dec.value not in calc_dec):
                print("\nAnalyzing Star RA %s DEC %s at %s" % (ra, dec, i))

                star_id = str(ra) + str(dec)
                tel_array.star_track(ra=ra, dec=dec, alt_cut=alt_cut)

                if not np.isnan(
                        tel_array.star_dict[star_id]["ObsTimes"]).any():
                    if len(np.array(
                            tel_array.star_dict[star_id]["ObsTimes"])) > 1:
                        # total_obs_time = np.ptp(tel_array.star_dict[star_id]["ObsTimes"])
                        total_obs_time = (tel_array.time_delt * len(
                            tel_array.star_dict[star_id]["ObsTimes"])).to('s')
                    else:
                        total_obs_time = 0 * u.hour

                if total_obs_time <= cutoff_obs_time * u.hour:
                    print(
                        "Skipping star RA %s DEC %s as it is observable only %s"
                        % (ra, dec, total_obs_time))
                    dup_diams = []
                    continue

                dists[i] = dis
                mintime = np.amin(tel_array.observable_times)
                maxtime = np.amax(tel_array.observable_times)
                time_range = "%.5sTo%.5s" % (mintime, maxtime)
                calc_ra.append(ra.value)
                calc_dec.append(dec.value)
                dup_diams.append(
                    [ang_diam.to("mas").value, ra, dec, 1, cat_name])
                if i == 14:
                    asdf = 123
                i = i + 1

                good_diams.append(ang_diam.to("mas").value)
                good_ra.append(ra.value)
                good_dec.append(dec.value)
                good_mag_names.append(mag_name)
                good_mags.append(mag)
                cat_names.append(cat_name)
                total_obs_times.append(total_obs_time.to('s').value)
                time_ranges.append(time_range)
                if len(dup_diams) > 1:
                    adsf = 234
                dup_count.append(dup_diams)
                dup_diams = []

            elif not unique:
                cat_idx = closest_star[i]
                # print((np.array(good_ra) - ra.value)[cat_idx])
                dup_count[cat_idx].append([
                    ang_diam.to("mas").value, good_ra[cat_idx],
                    good_dec[cat_idx], 2, cat_name
                ])
                i = i + 1
            else:
                print('|', end="")
                try:
                    if dec.value in calc_dec:
                        dupind = calc_dec.index(dec.value)
                        dup_count[dupind].append(
                            [ang_diam.to("mas").value, ra, dec, 3, cat_name])
                        c = c + 1
                        i = i + 1
                    elif ra.value in calc_ra:
                        dupind = calc_ra.index(ra.value)
                        dup_count[dupind].append(
                            [ang_diam.to("mas").value, ra, dec, 3, cat_name])
                        c = c + 1
                        i = i + 1

                    else:
                        print(
                            "Something went wrong with the indexing!!!!!!!!!!!!!"
                        )
                        raise Exception(
                            "Something likely went wrong with the indexing.")

                except Exception as e:
                    print(
                        "Something went wrong with the indexing!!!!!!!!!!!!!")
                    print(e)

    diamstd = np.array(
        [np.std(np.array(np.array(r)[:, 0], float)) for r in dup_count])
    diammean = np.array(
        [np.median(np.array(np.array(r)[:, 0], float)) for r in dup_count])

    if Int_obst == None:
        Int_obst = np.array(total_obs_times)
    else:
        Int_obst = np.full(len(total_obs_times), Int_obst)

    bs_mat, bs_dis, bs_3dis = SkyCoord(
        good_ra, good_dec, unit=(u.hourangle, u.deg)).match_to_catalog_sky(
            SkyCoord(tel_array.BS_stars["RAJ2000"],
                     tel_array.BS_stars["DEJ2000"],
                     unit=(u.hourangle, u.deg)))

    bs_info = tel_array.BS_stars[bs_mat]
    vmag = bs_info["Vmag"]
    bmag = bs_info["B-V"] + vmag
    amp_errs = IItools.track_error(sig0=tel_array.err_sig,
                                   m0=tel_array.err_mag,
                                   m=bmag,
                                   T_0=tel_array.err_t1,
                                   T=Int_obst)

    try:
        simbad_matches, simd = tel_array.simbad_matcher(good_ra, good_dec)
        sim_rotV = simbad_matches["ROT_Vsini"]
        sim_sptype = simbad_matches["SP_TYPE"]
        sim_bflux = simbad_matches["FLUX_B"]
        sim_id = simbad_matches["MAIN_ID"]
        sim_rapm = simbad_matches["PMRA"].to('arcsec/yr')
        sim_decpm = simbad_matches["PMDEC"].to('arcsec/yr')
        data_table = Table(
            [
                sim_id.astype("U13"), good_ra, good_dec, good_diams, diammean,
                diamstd, time_ranges, good_mag_names, good_mags, cat_names,
                bmag, vmag, bs_info["pmRA"], bs_info["pmDE"],
                bs_dis.to("mas"), bs_info["SpType"], bs_info["RotVel"],
                sim_bflux, sim_sptype,
                simd.to('mas'), sim_rotV, sim_rapm, sim_decpm,
                col(amp_errs),
                col(total_obs_times, unit=u.second),
                col(Int_obst, unit=u.second)
            ],
            names=("NAME", "RA", "DEC", "ANGD", "DiamMedian", "DiamStd",
                   "ObservableTimes", "FILT", "MAG", "CAT", "BS_BMAG",
                   "BS_VMAG", "BS_pmra", "BS_pmdec", "BSSkyD", "BSSpT", "BSRV",
                   "SimBMAG", "SIMSpT", "SIMSkyD", "SIMRV", "SIM_pmra",
                   "SIM_pmdec", "ErrAmp", "TotObsTime", "ObsTime"))
    except Exception as e:
        print(e)
        print("SIMBAD probably failed, using the Bright Star Catalog only")
        data_table = Table([
            bs_info["Name"], good_ra, good_dec, good_diams, diammean, diamstd,
            time_ranges, good_mag_names, good_mags, cat_names, bmag, vmag,
            bs_info["pmRA"], bs_info["pmDE"],
            bs_dis.to("mas"), bs_info["SpType"], bs_info["RotVel"],
            col(amp_errs),
            col(total_obs_times, unit=u.second),
            col(Int_obst, unit=u.second)
        ],
                           names=("NAME", "RA", "DEC", "ANGD", "DiamMedian",
                                  "DiamStd", "ObservableTimes", "FILT", "MAG",
                                  "CAT", "BS_BMAG", "BS_VMAG", "BS_pmra",
                                  "BS_pmdec", "BSSkyD", "BSSpT", "BSRV",
                                  "ErrAmp", "TotObsTime", "ObsTime"))

    return data_table
Esempio n. 8
0
    tel_array = IIdata.IItelescope(telLat=observatory_lat,
                                   telLon=observatory_lon,
                                   telElv=observatory_elv,
                                   time=time,
                                   steps=steps,
                                   sig1=sigma_tel,
                                   m1=sigma_mag,
                                   t1=sigma_time,
                                   mag_range=mag_range,
                                   dec_range=dec_range,
                                   ra_range=ra_range,
                                   max_sun_alt=max_sun_alt,
                                   timestep=int_time.value)

    baselines = IItools.array_baselines(relative_tel_locs)
    [
        tel_array.add_baseline(Bew=base[0], Bns=base[1], Bud=base[2])
        for base in baselines
    ]

    print("Now running analysis.")
    cats = [ca for ca in os.listdir("SIICatalogs")]

    if len(cats) > 0:

        print(red_line)
        for i, cat in enumerate(sorted(cats)):
            print("%s: %s" % (i, cat))
        print(red_line)
Esempio n. 9
0
tel_array = IIdata.IItelescope(telLat=IIparam['telLat'],
                               telLon=IIparam['telLon'],
                               telElv=IIparam['telElv'],
                               time=IIparam['time'],
                               steps=steps,
                               sig1=IIparam['sigmaTel'],
                               m1=IIparam['sigmaMag'],
                               t1=IIparam['sigmaTime'],
                               mag_range=IIparam['magRange'],
                               dec_range=IIparam['decRange'],
                               ra_range=IIparam['raRange'],
                               max_sun_alt=IIparam['maxSunAltitude'],
                               timestep=IIparam['integrationTime'])

relative_tel_locs = np.array(IIparam["telLocs"])
baselines = IItools.array_baselines(relative_tel_locs)
[tel_array.add_baseline(Bew=base[0], Bns=base[1], Bud=base[2]) for base in baselines]

ang_diam = (.5 * u.mas).to('rad').value


dec_angle_rad = (5.6 * u.hourangle).to('rad').value
lat = tel_array.telLat.to('rad').value


hour_angle_rad = [-1.06417879, -0.93292069, -0.80166259, -0.67040449, -0.53914639, -0.40788829,
 -0.27663019, -0.14537209, -0.01411399,  0.11714411,  0.24840222,  0.37966032,
  0.51091842,  0.64217652,  0.77343462,  0.90469272,  1.03595082]

tel_tracks = [IItools.uv_tracks(lat=lat,
                                dec=dec_angle_rad,
Esempio n. 10
0
 def airy_avg(xr, r):
     mod_Int = np.array(
         [IItools.trapezoidal_average(airy1D(rad, r)) for rad in rads])
     return mod_Int.ravel()