Exemplo n.º 1
0
def tab1_update_addStrID():
    global dftmp
    if tab1_selected_dspec_square:
        time0, time1 = dftmp['time'].min() + timestart, dftmp['time'].max() + timestart
        freq0, freq1 = dftmp['freq'].min(), dftmp['freq'].max()
        date_char = Time(timestart / 3600. / 24., format='jd', scale='utc', precision=3, out_subfmt='date').iso
        t0_char = Time(time0 / 3600. / 24., format='jd', scale='utc', precision=3, out_subfmt='date_hms').iso
        t0_char = t0_char.split(' ')[1]
        t1_char = Time(time1 / 3600. / 24., format='jd', scale='utc', precision=3, out_subfmt='date_hms').iso
        t1_char = t1_char.split(' ')[1]
        time0, time1 = (time0 / 86400. - 2400000.5) * 24. * 3600., (time1 / 86400. - 2400000.5) * 24. * 3600.
        StrID = pd.DataFrame(dict(time=[[time0, time1, time1, time0]], freq=[[freq0, freq0, freq1, freq1]],
                                  str_id=[[tab1_input_StrID.value]], date=[[date_char]],
                                  timeran=[[t0_char + '~' + t1_char]],
                                  freqran=[["{:.3f}~{:.3f} GHz".format(freq0, freq1)]]))
        StrIDList = pd.read_json(event_dir + 'StrID_list_tmp.json')
        StrIDList = pd.concat([StrIDList, StrID])
        StrIDList = StrIDList.sort_values(by='timeran', ascending=1)
        StrIDList.index = range(StrIDList.index.size)
        StrIDList.to_json(event_dir + 'StrID_list_tmp.json')
        StrIDList['time'] = [ll - tab1_tim[0] for ll in StrIDList['time']]
        tab1_render_patch.data_source.data = ColumnDataSource(StrIDList).data
        tab1_Div_Tb.text = """<p>added <b>""" + tab1_input_StrID.value + """</b>  to the list</p>"""
    else:
        tab1_Div_Tb.text = """<p><b>Warning: No time & freq range selected.
Exemplo n.º 2
0
def tab2_BUT_tCLN_param_default():
    global tab2_tCLN_Param_dict, dspecDF0
    tab2_tCLN_Param_dict = OrderedDict()
    time0, time1 = dspecDF0['time'].min() + timestart, dspecDF0['time'].max(
    ) + timestart
    t0_char = Time(time0 / 3600. / 24.,
                   format='jd',
                   scale='utc',
                   precision=3,
                   out_subfmt='date_hms').iso
    date0_char = t0_char.split(' ')[0].replace('-', '/')
    time0_char = t0_char.split(' ')[1]
    t1_char = Time(time1 / 3600. / 24.,
                   format='jd',
                   scale='utc',
                   precision=3,
                   out_subfmt='date_hms').iso
    date1_char = t1_char.split(' ')[0].replace('-', '/')
    time1_char = t1_char.split(' ')[1]
    freq0, freq1 = dspecDF0['freq'].min(), dspecDF0['freq'].max()
    freqrange = "'{:.3f}~{:.3f} GHz'".format(freq0, freq1)
    tab2_tCLN_Param_dict['freqrange'] = freqrange
    tab2_tCLN_Param_dict['workdir'] = "'./'"
    tab2_tCLN_Param_dict['vis'] = "''"
    tab2_tCLN_Param_dict['imageprefix'] = "'slfcal/{}{}'".format(
        struct_id, CleanID)
    tab2_tCLN_Param_dict['ncpu'] = "10"
    tab2_tCLN_Param_dict['twidth'] = "1"
    tab2_tCLN_Param_dict['doreg'] = "False"
    tab2_tCLN_Param_dict['timerange'] = "''"
    tab2_tCLN_Param_dict['uvrange'] = "''"
    tab2_tCLN_Param_dict['antenna'] = "''"
    tab2_tCLN_Param_dict['ephemfile'] = "'horizons_sun_20141101.radecp'"
    tab2_tCLN_Param_dict[
        'msinfofile'] = "'SUN01_20141101.T163940-164700.50ms.cal.msinfo.npz'"
    tab2_tCLN_Param_dict['event_id'] = "'{}'".format(event_id.replace("/", ""))
    tab2_tCLN_Param_dict['struct_id'] = "'{}'".format(
        struct_id.replace("/", ""))
    tab2_tCLN_Param_dict['clean_id'] = "'{}'".format(CleanID.replace("/", ""))
    tab2_tCLN_Param_dict['mode'] = "'channel'"
    tab2_tCLN_Param_dict['imagermode'] = "'csclean'"
    tab2_tCLN_Param_dict['weighting'] = "'natural'"
    tab2_tCLN_Param_dict['gain'] = '0.1'
    tab2_tCLN_Param_dict['psfmode'] = "'clark'"
    tab2_tCLN_Param_dict['imsize'] = "" '[256, 256]' ""
    tab2_tCLN_Param_dict['cell'] = "['3.0arcsec', '3.0arcsec']"
    tab2_tCLN_Param_dict['phasecenter'] = "'J2000 14h26m22.7351 -14d29m29.801'"
    tab2_tCLN_Param_dict['mask'] = "''"
    tab2_tCLN_Param_dict['stokes'] = "'RRLL'"
    tab2_tCLN_Param_dict['uvrange'] = "''"
    tab2_tCLN_Param_dict['niter'] = "500"
    tab2_tCLN_Param_dict['usescratch'] = "False"
    tab2_tCLN_Param_dict['interactive'] = "False"
    tab2_Div_tCLN_text = '<p><b>#  ptclean :: Parallelized clean in consecutive time steps</b></p>' + ' '.join(
        "<p><b>{}</b> = {}</p>".format(key, val)
        for (key, val) in tab2_tCLN_Param_dict.items())
    tab2_Div_tCLN.text = tab2_Div_tCLN_text
    tab2_Div_tCLN2.text = '<p><b>Default parameter Restored.</b></p>'
Exemplo n.º 3
0
    def onTimer(self):
        timeStr = Time(datetime.utcnow(), scale='utc').iso.split('.')[0]
        self.curTime.setText(timeStr.split(" ")[1])
        #print('write ' + timeStr.split(" ")[1])
        dateStr = Time(datetime.utcnow(), scale='utc').iso.split(' ')[0]
        self.curDate.setText(dateStr)
        if (self.cmd < 200):
            self.cmd = 200
        else:
            self.cmd = 100
            self.SendTimePacket()

        self.SrhAntSocket.writeDatagram(
            QtCore.QByteArray(
                struct.pack('!16sHHHLL', b'_Srh_Net_Packet_', 0,
                            self.cmd, 0, 0, 0)),
            QtNetwork.QHostAddress('192.168.0.168'), 9998)

        testSocket = QtNetwork.QTcpSocket()
        testSocket.connectToHost('192.168.0.1', 80)
        if testSocket.waitForConnected() == True:
            self.Network.setPixmap(self.greenBox)
        else:
            self.Network.setPixmap(self.redBox)
        testSocket.close()
Exemplo n.º 4
0
def epoch_time_array(
    epoch_range,
    index_epoch=None,
    cadence=None,
):
    """Create a Skyfield :class:`~skyfield.timelib.Timescale` object at which to evaluate satellite positions.

    Begins by downloading up-to-date time files, using the skyfield :class:`~skyfield.iokit.Loader` class,
    needed to accurate converted between various time formats. See `Dates and Time
    <https://rhodesmill.org/skyfield/time.html>`_  for more info. The files are saved to
    :samp:`./embers_out/sat_utils/skyfield-data`.

    For a particular time inverval in :samp:`epoch_range`, chosen by :samp:`index_epoch`, a
    Skyfield :class:`~skyfield.timelib.Timescale` array object is generated, at a given time :samp:`cadence`. This time array will be used by :func:`~embers.sat_utils.sat_ephemeris.sat_pass` to compute the position of satellites at each time.

    .. code-block:: python

        from embers.sat_utils.sat_ephemeris import load_tle, epoch_ranges, epoch_time_array
        sats, epochs = load_tle('~/embers-data/TLE/21576.txt')
        epoch_range = epoch_ranges(epochs)
        index_epoch = 0     # select first time interval from epoch_range
        cadence = 10        # evaluate satellite position every 10 seconds

        t_arr, index_epoch = epoch_time_array(epoch_range, index_epoch, cadence)

    :param index_epoch: Index of :samp:`epoch_range` to be converted to time array :class:`~int`
    :param epoch_range: List of time intervals where an epoch is most accurate, from :func:`embers.sat_utils.sat_ephemeris.epoch_ranges`
    :param cadence: Time cadence at which to evaluate sat position, in seconds :class:`~int`

    :returns:
        A :class:`~tuple` of (t_arr, index_epoch)

        - t_arr: Skyfield :class:`~skyfield.timelib.Timescale` object with array of times at given :samp:`cadence`
        - index_epoch: Index of :samp:`epoch_range` to be converted to time array :class:`~int`

    """

    # Skyfield Timescale
    ts = load.timescale(builtin=True)

    # find time between epochs/ midpoints in seconds, using Astropy Time
    t1 = Time(epoch_range[index_epoch], scale="tt", format="jd").gps
    t2 = Time(epoch_range[index_epoch + 1], scale="tt", format="jd").gps
    dt = round(t2 - t1)

    t3 = Time(epoch_range[index_epoch], scale="tt", format="jd").iso
    date, time = t3.split()
    year, month, day = date.split("-")
    hour, minute, _ = time.split(":")

    # Create a time array, every 2[cadence] seconds, starting at the first epoch, approximately
    seconds = np.arange(0, dt, cadence)
    t_arr = ts.tt(int(year), int(month), int(day), int(hour), int(minute),
                  seconds)

    return (t_arr, index_epoch)
Exemplo n.º 5
0
def SolarSystem(t_jd):

    t_iso = Time(t_jd, format='jd', scale='utc').iso
    date = ':'.join(t_iso.split(':')[:-1])

    sim = rebound.Simulation()
    sim.units = ('yr', 'AU', 'Msun')
    sim.add("Sun", date=date)
    sim.add("Mercury", date=date)
    sim.add("Venus", date=date)
    sim.add("399", date=date) # Earth
    sim.add("301", date=date) # Moon
    sim.add("Mars", date=date)
    sim.add("Jupiter", date=date)
    sim.add("Saturn", date=date)
    sim.add("Uranus", date=date)
    sim.add("Neptune", date=date)
    sim.particles[0].hash = 'sun'
    sim.particles[3].hash = 'earth'
    # sim.convert_particle_units('AU', 'yr', 'Msun')
    sim.move_to_com()
    return sim
Exemplo n.º 6
0
def launch_ds9(dir, tree, overwrite):

    #LOAD CONFIG
    try:
        with open(root_path + "/obsconfig.txt", "r") as obsf:
            for line in obsf:
                if "Observatory Code" in line:
                    obscode = line.split(":")[-1].strip()
                if "Name" in line:
                    obsname = line.split(":")[-1].strip()
                if "Observer" in line:
                    observer = line.split(":")[-1].strip()
                if "Measurer" in line:
                    measurer = line.split(":")[-1].strip()
                if "Telescope" in line:
                    telescope = line.split(":")[-1].strip()
                if "Email" in line:
                    email = line.split(":")[-1].strip()
                if "Initials" in line:
                    initials = line.split(":")[-1].strip()
                if "DS9 Text Color" in line:
                    ds9Color = line.split(":")[-1].strip()
                if "DS9 Font Size" in line:
                    ds9FontSize = line.split(":")[-1].strip()
                if "Invert images?" in line:
                    invertImages = False
                    if line.split(":")[-1].strip() == "yes":
                        invertImages = True
                if "Blink Inverval" in line:
                    ds9BlinkInterval = line.split(":")[-1].strip()
    except:
        print("\nConfiguration file obsconfig.txt not found, exiting..\n")
        return

    try:
        with open(dir + '/asteroids', 'rb') as fp:
            asteroids = pickle.load(fp)

        with open(dir + '/midpoints', 'rb') as fp:
            midpoints = pickle.load(fp)

        with open(dir + '/totaltime', 'rb') as fp:
            totalTime = pickle.load(fp)

    except:
        print("\nAsteroids file or Midpoints file missing\n")
        return

    findDesig = True
    reportClosed = False

    ##### ADD REPORT DATE #####
    ut = Time(datetime.utcnow(), scale='utc')
    ut = str(ut)

    yymmdd = ut.split(" ")[0]
    hhmmss = ut.split(" ")[-1]
    yy = yymmdd.split("-")[0]
    mo = yymmdd.split("-")[1]
    dd = yymmdd.split("-")[2]
    hh = hhmmss.split(":")[0]
    mm = hhmmss.split(":")[1]
    ss = hhmmss.split(":")[2]
    ss = ss.split(".")[0]

    reportDate = yy + "." + mo + "." + dd + " " + hh + ":" + mm + ":" + ss

    #### CHECK FOR REPORT FILE AND ASK TO REPLACE? ###
    replacereport = overwrite

    if (replacereport):
        reportfile = open(dir + "/report.txt", "w")
        reportfile.write("COD " + obscode + "\n")
        reportfile.write("CON " + obsname + " [" + email + "]\n")
        reportfile.write("OBS " + observer + "\n")
        reportfile.write("MEA " + measurer + "\n")
        reportfile.write("TEL " + telescope + "\n")
        reportfile.write("ACK MPCReport file updated " + reportDate +
                         "\n")  #ADD UTC DATE TIME
        reportfile.write("AC2 " + email + "\n")
        reportfile.write("NET Gaia DR1\n")

    #Output to user
    print("\nLaunching DS9 to confirm asteroids..\nAnswer y or n\n")

    #Initiate DS9
    d = pyds9.DS9(target='DS9:*', start=True, wait=15, verify=False)

    #Clear out any previous runs in DS9
    d.set("blink no")
    d.set("frame delete all")

    fitsfiles = glob.glob(dir + "/*.fits")

    #Check for only "Stack" fits
    for file in fitsfiles:
        if "Stack" in file:
            continue
        else:
            fitsfiles.remove(file)

    #Sort by name
    fitsfiles.sort()

    #Load frames into DS9
    for i in range(len(fitsfiles)):
        #print(fitsfiles[i])
        d.set("frame " + str(i + 1))
        d.set("fits " + fitsfiles[i])
        if (invertImages):
            d.set("cmap invert yes")

    #set locks and scale
    d.set("scale squared")
    d.set("scale zscale")
    d.set("scale match yes")
    d.set("frame lock wcs")
    d.set("lock colorbar yes")
    d.set("lock scalelimits yes")
    d.set("blink interval " + ds9BlinkInterval)
    d.set("zoom 4")

    astnum = 0
    astLength = len(asteroids)

    def close_out():
        print("\nFinished processing asteroids for this sequence.\n")
        if (replacereport):
            reportfile.write("----- end -----")
            reportfile.close()
        d.set("blink no")
        #tree.destroy()
        # CLEAR OUT TREE
        tree.delete(*tree.get_children())

    #for asteroid in asteroids:
    def show_asteroid(event):

        curItem = tree.focus()

        if tree.item(curItem)["text"] == "END":
            print("Enter to close sequence")
            d.set("blink no")
            return

        astindex = int(tree.item(curItem)["text"])
        asteroid = asteroids[astindex]

        print("Asteroid ", astindex + 1, "/", astLength)

        def displayAst(ast):
            d.set("blink no")
            if ast[0][0] == 'dummy':
                d.set("frame 1")
                d.set("regions delete all")
                #pass
            else:
                d.set("frame 1")
                d.set("regions delete all")
                d.set(
                    'regions', 'image; circle(' + ast[0][4] + ' ' + ast[0][5] +
                    ' 9")# color=' + ds9Color + ' font="times' + ds9FontSize +
                    '" text={' + ast[0][2] + 'V ' + ast[0][3] + ' FWHM }')

            d.set("frame 2")
            d.set("regions delete all")
            d.set(
                'regions', 'image; circle(' + ast[1][4] + ' ' + ast[1][5] +
                ' 9")# color=' + ds9Color + ' font="times' + ds9FontSize +
                '" text={' + ast[1][2] + 'V ' + ast[1][3] + ' FWHM }')
            d.set("frame 3")
            d.set("regions delete all")
            d.set(
                'regions', 'image; circle(' + ast[2][4] + ' ' + ast[2][5] +
                ' 9")# color=' + ds9Color + ' font="times' + ds9FontSize +
                '" text={' + ast[2][2] + 'V ' + ast[2][3] + ' FWHM }')

            if ast[3][0] == 'dummy':
                d.set("frame 4")
                d.set("regions delete all")
                #pass
            else:
                d.set("frame 4")
                d.set("regions delete all")
                d.set(
                    'regions', 'image; circle(' + ast[3][4] + ' ' + ast[3][5] +
                    ' 9")# color=' + ds9Color + ' font="times' + ds9FontSize +
                    '" text={' + ast[3][2] + 'V ' + ast[3][3] + ' FWHM }')

            d.set("pan to " + str(ast[1][0]) + ' ' + str(ast[1][1]) + " wcs")
            #d.set("regions save foo.reg")
            #print(d.get('regions'))
            d.set("blink yes")

        ### INITIAL DISPLAY ###
        displayAst(asteroid)

        ### DISPLAY 1-3 or 2-4 ###
        if asteroid[0][0] == 'dummy':
            print("Images 2-4")
        elif asteroid[3][0] == "dummy":
            print("Images 1-3")
        else:
            print("Images 1-4")

        ### SHOW LOCATION ####
        dispRA = asteroid[1][0]
        dispDEC = asteroid[1][1]
        dispT = SkyCoord(ra=dispRA * u.degree, dec=dispDEC * u.degree)
        dispcoordsT = dispT.to_string('hmsdms')
        dispCOORDS = clean_coords(dispcoordsT)
        print("Location: ", dispCOORDS, " Copied to Clipboard")
        pyperclip.copy(dispCOORDS)

        print("\n")
        #print("Resid: ",asteroid[4][0] )
        #ENTER Q/A RESP

    ## CONFIM WITH ENTER

    def just_desig(event):

        curItem = tree.focus()

        if tree.item(curItem)["text"] == "END":
            close_out()
            return

        astindex = int(tree.item(curItem)["text"])
        asteroid = asteroids[astindex]

        print("Asteroid ", astindex + 1, "/", astLength)
        print("\n")

        if astindex == astLength + 1:
            print("\n close out")
            return

        #print("Resid: ",asteroid[4][0] )
        #ENTER Q/A RESP

        #DESIG IS SET HERE FIRST
        desig = "TMP001"
        # AST       #PLOT  #CONFIRM
        resids = solve_residuals(asteroid, False, True)
        resids = "{:.2f}".format(resids)
        print("\n", resids, " Asteroid mean residual")

        #Temp file for scoring asteroids
        tempfile = open(dir + "/digest2temp.txt", "w")

        raT = asteroid[1][0]
        decT = asteroid[1][1]
        magT = round(float(asteroid[1][2]), 1)
        magT = str(magT) + " V"

        cT = SkyCoord(ra=raT * u.degree, dec=decT * u.degree)
        coordsT = cT.to_string('hmsdms')
        coordsCleanT = clean_coords(coordsT)

        # Get designation of first measurement, parse MPC
        if (findDesig):
            # Only need 1 pos to search for desig
            obsT = "     " + desig + "  KC" + midpoints[
                1] + coordsCleanT + "          " + magT + "      " + obscode
            # find designation
            solveddesig = find_desig(obsT)
            print("Information for " + desig)
            print("##########################################")
            print("#####    MPC SEARCH RESULTS BELOW    #####")
            print("##########################################")
            print("\n", solveddesig)

            if (solveddesig is not None):
                desig = solveddesig.split()[1]
                print("MPC desig: ", desig + "\n")
            else:
                print("No MPC designation found.\n")

        for i in range(len(asteroid)):
            #convert radec
            if asteroid[i][0] == 'dummy':
                continue

            ra = asteroid[i][0]
            dec = asteroid[i][1]
            mag = round(float(asteroid[i][2]), 1)

            #Catch bad mags
            if (mag > 21.2):
                mag = "      "
            else:
                mag = str(mag) + " V"

            c = SkyCoord(ra=ra * u.degree, dec=dec * u.degree)
            coords = c.to_string('hmsdms')
            coordsClean = clean_coords(coords)

            desig = desig.rjust(11)
            blankSP = "  "

            tempfile.write(desig + blankSP + "KC" + midpoints[i] +
                           coordsClean + "          " + mag + "      " +
                           obscode + "\n")

        tempfile.close()
        #Score the rock and print out
        score_rock(dir)
        print("\n Finished searching and scoring object. \n")

    def confirm_asteroid(event):

        curItem = tree.focus()

        if tree.item(curItem)["text"] == "END":
            close_out()
            return

        astindex = int(tree.item(curItem)["text"])
        asteroid = asteroids[astindex]

        print("Asteroid ", astindex + 1, "/", astLength)
        print("\n")

        if astindex == astLength + 1:
            print("\n close out")
            return

        #print("Resid: ",asteroid[4][0] )
        #ENTER Q/A RESP

        #DESIG IS SET HERE FIRST
        desig = "TMP001"
        desigFromMPC = False
        # AST       #PLOT  #CONFIRM
        resids = solve_residuals(asteroid, False, True)
        resids = "{:.2f}".format(resids)
        print("\n", resids, " Asteroid mean residual")

        #Temp file for scoring asteroids
        tempfile = open(dir + "/digest2temp.txt", "w")

        raT = asteroid[1][0]
        decT = asteroid[1][1]
        magT = round(float(asteroid[1][2]), 1)
        magT = str(magT) + " V"

        cT = SkyCoord(ra=raT * u.degree, dec=decT * u.degree)
        coordsT = cT.to_string('hmsdms')
        coordsCleanT = clean_coords(coordsT)

        # Get designation of first measurement, parse MPC
        if (findDesig):
            # Only need 1 pos to search for desig
            obsT = "     " + desig + "  KC" + midpoints[
                1] + coordsCleanT + "          " + magT + "      " + obscode
            # find designation
            solveddesig = find_desig(obsT)
            print("Information for " + desig)
            print("##########################################")
            print("#####    MPC SEARCH RESULTS BELOW    #####")
            print("##########################################")
            print("\n", solveddesig)

            if (solveddesig is not None):
                useMPCdesig = True

                if (useMPCdesig):
                    desig = solveddesig.split()[1]
                    print("Assigned MPC desig: ", desig + "\n")
                    desigFromMPC = True
            else:
                print("No MPC designation found.")

        #OVERWRITE REPORT?
        if (replacereport and not desigFromMPC):
            desig = id_generator()
            print("Assigned temp designation: " + desig + "\n")

        for i in range(len(asteroid)):
            #convert radec
            if asteroid[i][0] == 'dummy':
                continue

            ra = asteroid[i][0]
            dec = asteroid[i][1]
            mag = round(float(asteroid[i][2]), 1)

            #Catch bad mags
            if (mag > 21.2):
                mag = "      "
            else:
                mag = str(mag) + " V"

            c = SkyCoord(ra=ra * u.degree, dec=dec * u.degree)
            coords = c.to_string('hmsdms')
            coordsClean = clean_coords(coords)

            if (desigFromMPC):
                #Capture provisional designation
                if len(desig) == 7:
                    desig = desig.rjust(12)
                    blankSP = " "
                if len(desig) < 7:
                    blankSP = "  "
                    desig = desig.ljust(11)
            else:
                desig = desig.rjust(11)
                blankSP = "  "
            # IF WE REPLACE REPORT
            if (replacereport):
                reportfile.write(desig + blankSP + "KC" + midpoints[i] +
                                 coordsClean + "          " + mag + "      " +
                                 obscode + "\n")

            tempfile.write(desig + blankSP + "KC" + midpoints[i] +
                           coordsClean + "          " + mag + "      " +
                           obscode + "\n")

        tempfile.close()
        #Score the rock and print out
        score_rock(dir)
        print("\n Finished processing object. \n")

    #CLEAR OUT TREE
    tree.delete(*tree.get_children())

    # TREE COLUMNS CREATE
    # tree.config(columns=('fwhm','astloc','astresid', 'astmag'))
    tree['columns'] = ('fwhm', 'astloc', 'astresid', 'astmag', 'velocity')

    tree.column('#0', width=70)
    tree.column('fwhm', width=70, anchor='center')
    tree.column('astloc', width=180, anchor='center')
    tree.column('astresid', width=70, anchor='center')
    tree.column('astmag', width=70, anchor='center')
    tree.column('velocity', width=150, anchor='center')

    tree.heading('#0', text='Ast Num')
    tree.heading('fwhm', text='Ast FWHM')
    tree.heading('astloc', text='Ast Location')
    tree.heading('astresid', text='Ast Resid')
    tree.heading('astmag', text='Ast Mag')
    tree.heading('velocity', text='Ast Vel Arcsec/min')

    tree.config(selectmode='browse')

    tree.bind('<<TreeviewSelect>>', show_asteroid)
    tree.bind("<Return>", confirm_asteroid)
    tree.bind("<c>", just_desig)

    astnum2 = 0

    #Convert total time to float
    totalTime = float(totalTime)

    for ast in asteroids:

        astT = []

        #REMOVE DUMMY
        for k in range(len(ast)):
            if ast[k][0] == "dummy":
                continue
            else:
                astT.append(ast[k])

        #SOLVE AVE FWHM
        fwhm = sum(float(astT[i][3]) for i in range(len(astT))) / len(astT)
        fwhm = round(fwhm, 2)

        #SOLVE AVE MAG
        mag = sum(float(astT[i][2]) for i in range(len(astT))) / len(astT)
        mag = round(mag, 2)

        #SOLVE RESID
        resid = solve_residuals(astT, False, False)

        ### SHOW LOCATION ####
        ra = astT[2][0]
        dec = astT[2][1]

        dispT = SkyCoord(ra=ra * u.degree, dec=dec * u.degree)
        dispcoordsT = dispT.to_string('hmsdms')
        dispCOORDS = clean_coords(dispcoordsT)

        #### SOLVE SPEED ####
        x1 = astT[0][0]
        y1 = astT[0][1]
        x2 = astT[-1][0]
        y2 = astT[-1][1]

        astDist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
        astDist = astDist * 3600  # CONVERT TO ARCSEC
        vel = round(astDist / totalTime, 2)

        #  parent  id     name             text                   #fwhm   #loc   #resid  #mag
        tree.insert('',
                    str(astnum2),
                    text=str(astnum2),
                    values=(fwhm, dispCOORDS, resid, mag, vel))
        astnum2 += 1

        #INSERT END LINE
        if astnum2 == len(asteroids):
            tree.insert('', str(len(asteroids) + 1), text="END")

    tree.update()


#MODULE TESTING PURPOSES, UNCOMMENT
# myTree = Toplevel()
# tree1 = ttk.Treeview(myTree)
# tree1.pack(fill="both")

#launch_ds9("/home/david/Desktop/C4", tree1, False)
Exemplo n.º 7
0
def shownightobs(observable, meteo, obs_night=None, savefig=False, dirpath=None, verbose=False):
	"""
	Plot the observability of one observable along the night
	#todo: add the option to be returned in an Axes object instead of plotting
	"""
	logger.debug("Creating night observability plot for {}".format(observable.name))
	if not obs_night:
		meteo.time.format = 'iso'
		hour = int(meteo.time.value.split()[1][:2])
		if hour < 12:
			obs_night = Time(meteo.time.mjd - 1, format='mjd', scale='utc')
		else:
			obs_night = Time(meteo.time.mjd, format='mjd', scale='utc')
		obs_night.format = 'iso'
		obs_night = obs_night.value.split()[0]

	# list of times between nautical twilights
	times = meteo.get_nighthours(obs_night)

	#mymeteo = pythoncopy.deepcopy(meteo) # as we don't want to affect the current meteo, we make a copy that we update with the time

	mymeteo = meteo
	obss = []
	moonseps = []
	airmasses = []
	for time in times:
		mymeteo.update(obs_time=time, minimal=True)
		observable.compute_observability(meteo=mymeteo, displayall=True, cloudscheck=False, verbose=verbose)
		observable.compute_airmass(mymeteo)
		obss.append(observable.observability)
		moonseps.append(observable.angletomoon.degree)
		airmasses.append(observable.airmass)

	# create the x ticks labels every hour
	Time('%s 05:00:00' % obs_night, format='iso', scale='utc')
	hstart=22
	hend=12
	nhbm = 24-hstart  # number of hours before midnight...
	myhours = []
	for hour in np.arange(nhbm)[::-1]:
		myhours.append(24-(hour+1))
	for hour in np.arange(hend+1):
		myhours.append(hour)

	myhours = ["%02i:00:00" % h for h in myhours]
	mytimes = [Time('%s %s' % (obs_night, h), format='iso', scale='utc') for h in myhours[:nhbm]]

	for h in myhours[nhbm:]:
		t = Time('%s %s' % (obs_night, h), format='iso', scale='utc')
		t = Time(t.mjd + 1, format='mjd', scale='utc')
		mytimes.append(t)

	tmin, tmax = times[0].mjd, times[-1].mjd
	xmax=len(obss)
	xs = [(t.mjd-tmin)*xmax/(tmax-tmin) for t in mytimes]
	labels = [str(h[:5]) for h in myhours]

	starttimes = []
	stoptimes = []

	# todo: this needs to be improved.
	if 1 in obss:
		starttimes.append(times[obss.index(1)])
		stoptimes.append(times[::-1][obss[::-1].index(1)])

	if 0.8 in obss:
		starttimes.append(times[obss.index(0.8)])
		stoptimes.append(times[::-1][obss[::-1].index(0.8)])

	if 0.7 in obss:
		starttimes.append(times[obss.index(0.7)])
		stoptimes.append(times[::-1][obss[::-1].index(0.7)])

	if 0.56 in obss:
		starttimes.append(times[obss.index(0.56)])
		stoptimes.append(times[::-1][obss[::-1].index(0.56)])

	if not 1 in obss and not 0.8 in obss and not 0.7 in obss and not 0.56 in obss:
			print(("%s is not observable tonight !" % observable.name))
			return

	starttime = min(starttimes)
	stoptime = max(stoptimes)

	# shift the start and stoptime if needed
	if starttime.mjd > stoptime.mjd - (observable.exptime/60./1440.):
		starttime = Time(stoptime.mjd - (observable.exptime/60./1440.), format='mjd', scale='utc')

	if stoptime.mjd < starttime.mjd + (observable.exptime/60./1440.):
		stoptime = Time(starttime.mjd + (observable.exptime/60./1440.), format='mjd', scale='utc')

	starttime = starttime.iso
	stoptime = stoptime.iso

	plt.figure(figsize=(8,1.3))
	plt.subplots_adjust(left=0.02, right=0.98, bottom=0.45, top=0.7)
	ax = plt.subplot(1, 1, 1)
	xticks = np.arange(len(obss))
	plt.xticks(xs, labels, fontsize=16)
	# green, everything is fine
	if 1 in obss:
		plt.axvspan(obss.index(1), len(obss)-obss[::-1].index(1), color='chartreuse')
	# blue, problem with moon sep, airmass or both. #todo: code that better
	if 0.8 in obss:
		color = "royalblue"
		plt.axvspan(obss.index(0.8), len(obss)-obss[::-1].index(0.8), color=color)
		msg = "Moonsep = %i" % int(min(moonseps))
		plt.annotate(msg, xy=(0, -1.5),  xycoords='axes fraction', fontsize=14, color=color)
	if 0.7 in obss:
		color = "royalblue"
		plt.axvspan(obss.index(0.7), len(obss)-obss[::-1].index(0.7), color=color)
		msg = "Airmass > 1.5"
		plt.annotate(msg, xy=(0, -1.5),  xycoords='axes fraction', fontsize=14, color=color)

	if 0.56 in obss:
		color = "indianred"
		plt.axvspan(obss.index(0.5), len(obss)-obss[::-1].index(0.5), color='indianred')
		msg = "Moonsep = %i, Airmass > 1.5" % int(min(moonseps))
		plt.annotate(msg, xy=(1.0, -1.5), ha="right",  xycoords='axes fraction', fontsize=14, color=color)

	plt.axis([min(xticks), max(xticks), 0.0, 1.0])
	ax.get_yaxis().set_visible(False)
	plt.xlabel('UT', fontsize=18)

	plt.suptitle(observable.name+" ("+starttime.split(" ")[1][:5]+" --> "+stoptime.split(" ")[1][:5]+")", fontsize=25, y=0.93)

	if savefig:
		assert dirpath != None
		if not os.path.isdir(os.path.join(dirpath, obs_night)):
			os.mkdir(os.path.join(dirpath, obs_night))
		path = os.path.join(dirpath, obs_night, observable.name+'.png')
		plt.savefig(path)
		print(("Plot saved on %s" % path))
	else:
		plt.show()
	logger.info("Night observability plot for {} done".format(observable.name))
Exemplo n.º 8
0
def readsdofile(datadir=None, wavelength=None, jdtime=None, isexists=False, timtol=1):
    '''
    read sdo file from local database
    :param datadir:
    :param wavelength:
    :param jdtime: the timestamp or timerange in Julian days. if is timerange, return a list of files in the timerange
    :param isexists: check if file exist. if files exist, return file name
    :param timtol: time difference tolerance in days for considering data as the same timestamp
    :return:
    '''
    from astropy.time import Time
    import sunpy.map
    from datetime import date
    from datetime import timedelta as td

    wavelength = str(wavelength)
    wavelength = wavelength.lower()
    if timtol < 12. / 3600 / 24:
        timtol = 12. / 3600 / 24
    if isinstance(jdtime, list) or isinstance(jdtime, tuple) or type(jdtime) == np.ndarray:
        if len(jdtime) != 2:
            raise ValueError('jdtime must be a number or a two elements array/list/tuple')
        else:
            if jdtime[1] < jdtime[0]:
                raise ValueError('start time must be occur earlier than end time!')
            else:
                sdofitspath = []
                jdtimestr = [Time(ll, format='jd').iso for ll in jdtime]
                ymd = [ll.split(' ')[0].split('-') for ll in jdtimestr]
                d1 = date(int(ymd[0][0]), int(ymd[0][1]), int(ymd[0][2]))
                d2 = date(int(ymd[1][0]), int(ymd[1][1]), int(ymd[1][2]))
                delta = d2 - d1
                for i in xrange(delta.days + 1):
                    ymd = d1 + td(days=i)
                    sdofitspathtmp = glob.glob(
                        datadir + '/{:04d}/{:02d}/{:02d}/aia.lev1_*Z.{}.image_lev1.fits'.format(ymd.year, ymd.month,
                                                                                                ymd.day, wavelength))
                    if len(sdofitspathtmp) > 0:
                        sdofitspath = sdofitspath + sdofitspathtmp
                if len(sdofitspath) == 0:
                    if isexists:
                        return sdofitspath
                    else:
                        raise ValueError(
                            'No SDO file found under {} at the time range of {} to {}. Download the data with EvtBrowser first.'.format(
                                datadir, jdtimestr[0], jdtimestr[1]))
                sdofits = [os.path.basename(ll) for ll in sdofitspath]
                sdotimeline = Time(
                    [insertchar(insertchar(ll.split('.')[2].replace('T', ' ').replace('Z', ''), ':', -4), ':', -2) for
                     ll in sdofits], format='iso', scale='utc')
                sdofitspathnew = [x for (y, x) in sorted(zip(sdotimeline.jd, sdofitspath))]
                sdofitsnew = [os.path.basename(ll) for ll in sdofitspathnew]
                sdotimelinenew = Time(
                    [insertchar(insertchar(ll.split('.')[2].replace('T', ' ').replace('Z', ''), ':', -4), ':', -2) for
                     ll in sdofitsnew], format='iso', scale='utc')
                sdofile = list(np.array(sdofitspathnew)[np.where(
                    np.logical_and(jdtime[0] < sdotimelinenew.jd, sdotimelinenew.jd < jdtime[1]))[0]])
                return sdofile
    else:
        jdtimstr = Time(jdtime, format='jd').iso
        ymd = jdtimstr.split(' ')[0].split('-')
        sdofitspath = glob.glob(
            datadir + '/{}/{}/{}/aia.lev1_*Z.{}.image_lev1.fits'.format(ymd[0], ymd[1], ymd[2], wavelength))
        if len(sdofitspath) == 0:
            raise ValueError('No SDO file found under {}.'.format(datadir))
        sdofits = [os.path.basename(ll) for ll in sdofitspath]
        sdotimeline = Time(
            [insertchar(insertchar(ll.split('.')[2].replace('T', ' ').replace('Z', ''), ':', -4), ':', -2) for ll in
             sdofits], format='iso', scale='utc')
        if timtol < np.min(np.abs(sdotimeline.jd - jdtime)):
            raise ValueError('No SDO file found at the select timestamp. Download the data with EvtBrowser first.')
        idxaia = np.argmin(np.abs(sdotimeline.jd - jdtime))
        sdofile = sdofitspath[idxaia]
        if isexists:
            return sdofile
        else:
            try:
                sdomap = sunpy.map.Map(sdofile)
                return sdomap
            except:
                raise ValueError('File not found or invalid input')
Exemplo n.º 9
0
    def generate_polycos(
        self,
        model,
        mjdStart,
        mjdEnd,
        obs,
        segLength,
        ncoeff,
        obsFreq,
        maxha=12.0,
        method="TEMPO",
        numNodes=20,
    ):
        """
        Generate the polyco data.

        Parameters
        ----------
        model : TimingModel
            TimingModel to generate the Polycos with parameters
            setup.

        mjdStart : float / numpy longdouble
            Start time of polycos in mjd

        mjdEnd : float / numpy longdouble
            Ending time of polycos in mjd

        obs : str
            Observatory code

        segLength : int
            Length of polyco segement [minutes]

        ncoeff : int
            Number of coefficents

        obsFreq : float
            Observing frequency [MHz]

        maxha : float optional. Default 12.0
            Maximum hour angle. Only 12.0 is supported for now.

        method : string optional ["TEMPO", "TEMPO2", ...] Default TEMPO
            Method to generate polycos. Only the TEMPO method is supported for now.

        numNodes : int optional. Default 20
            Number of nodes for fitting. It cannot be less then the number of
            coefficents.

        Return
        ---------
        A polyco table.
        """
        mjdStart = data2longdouble(mjdStart)
        mjdEnd = data2longdouble(mjdEnd)
        segLength = int(segLength)
        obsFreq = float(obsFreq)

        # Use the planetary ephemeris specified in the model, if available.
        if model.EPHEM.value is not None:
            ephem = model.EPHEM.value
        else:
            log.info(
                "No ephemeris specified in model, using DE421 to generate polycos"
            )
            ephem = "DE421"

        if maxha != 12.0:
            raise ValueError("Maximum hour angle != 12.0 is not supported.")

        # Make sure the number of nodes is bigger than number of coeffs.
        if numNodes < ncoeff:
            numNodes = ncoeff + 1

        mjdSpan = data2longdouble(segLength / MIN_PER_DAY)
        # Generate "nice" MJDs for consistency with what tempo2 does
        tmids = np.arange(
            int(mjdStart * 24) * 60,
            int(mjdEnd * 24) * 60 + segLength, segLength)
        tmids = data2longdouble(tmids) / MIN_PER_DAY

        # generate the ploynomial coefficents
        if method == "TEMPO":
            entryList = []
            # Using tempo1 method to create polycos
            # If you want to disable the progress bar, add disable=True to the tqdm() call.
            for tmid in tqdm(tmids):
                tStart = tmid - mjdSpan / 2
                tStop = tmid + mjdSpan / 2
                nodes = np.linspace(tStart, tStop, numNodes)

                toaMid = toa.get_TOAs_list(
                    [
                        toa.TOA((np.modf(tmid)[1], np.modf(tmid)[0]),
                                obs=obs,
                                freq=obsFreq)
                    ],
                    ephem=ephem,
                )

                refPhase = model.phase(toaMid, abs_phase=True)

                # Create node toas(Time sample using TOA class)
                toaList = [
                    toa.TOA(
                        (np.modf(toaNode)[1], np.modf(toaNode)[0]),
                        obs=obs,
                        freq=obsFreq,
                    ) for toaNode in nodes
                ]

                toas = toa.get_TOAs_list(toaList, ephem=ephem)

                ph = model.phase(toas, abs_phase=True)
                dt = (nodes - tmid) * MIN_PER_DAY
                rdcPhase = ph - refPhase
                rdcPhase = rdcPhase.int - (dt * model.F0.value *
                                           60.0) + rdcPhase.frac
                dtd = dt.astype(float)  # Truncate to double
                rdcPhased = rdcPhase.astype(float)
                coeffs = np.polyfit(dtd, rdcPhased, ncoeff - 1)[::-1]

                date, hms = Time(tmid, format="mjd", scale="utc").iso.split()
                yy, mm, dd = date.split("-")
                date = dd + "-" + MONTHS[int(mm) - 1] + "-" + yy[-2:]
                hms = float(hms.replace(":", ""))

                entry = PolycoEntry(
                    tmid,
                    segLength,
                    refPhase.int,
                    refPhase.frac,
                    model.F0.value,
                    ncoeff,
                    coeffs,
                )

                entry_dict = OrderedDict()
                entry_dict["psr"] = model.PSR.value
                entry_dict["date"] = date
                entry_dict["utc"] = hms
                entry_dict["tmid"] = tmid
                entry_dict["dm"] = model.DM.value
                entry_dict["doppler"] = 0.0
                entry_dict["logrms"] = 0.0
                entry_dict["mjd_span"] = segLength
                entry_dict["t_start"] = entry.tstart
                entry_dict["t_stop"] = entry.tstop
                entry_dict["obs"] = obs
                entry_dict["obsfreq"] = obsFreq

                if model.is_binary:
                    binphase = model.orbital_phase(toaMid, radians=False)[0]
                    entry_dict["binary_phase"] = binphase
                    b = model.get_components_by_category()["pulsar_system"][0]
                    entry_dict["f_orbit"] = 1 / b.PB.value

                entry_dict["entry"] = entry
                entryList.append(entry_dict)

            pTable = table.Table(entryList, meta={"name": "Polyco Data Table"})

            self.polycoTable = pTable
            if len(self.polycoTable) == 0:
                raise ValueError("Zero polycos found for table")

        else:
            raise NotImplementedError(
                "Only TEMPO method has been implemented.")
Exemplo n.º 10
0
def patchAndDenoise(x_values,
                    orders,
                    waves,
                    x_errors=None,
                    times=None,
                    file_list=None,
                    K=2,
                    num_iters=50,
                    running_window=9,
                    line_cutoff=0.5,
                    file_cutoff=0.5,
                    outlier_cut=0,
                    verbose=False):
    """
    - Vet for bad lines/exposures
    - Initial patch of bad data with running mean
    - Iterative patch with PCA for specified number of iterations
    - Optional second round of interative PCA patching to catch outliers
    
    
    Parameters
    ----------
    x_values, x_errors : 2D ndarray
        Array of line positions for all lines for each exposure and errors
    orders : 1D ndarray
        Array of orders for each line
    waves : 1D ndarray
        Array of wavelengths for each line
    times : 1D ndarray, optional
        Time stamps for each exposure
        Just written into the returned patch dictionary
        (not explicitely used for this code, but helps with evalWaveSol)
    K : int, optional (default: 2)
        Number of principal components used for denoising
    num_iters : int, optional (default: 50)
        Number of iterations to run iterative PCA patching
    running_window ; int, optional (default: 9)
        Window size of running mean used to initialize pixel values
        for lines missing measured pixel values
    line_cutoff, file_cutoff : float [0,1], optional (default: 0.5)
        Cutoff for bad lines or files, respectively.
        i.e. defaults cut lines that show up in less than 50% of exposure
        and files that contain less than 50% of all lines
    outlier_cut : float, optional (default: 0)
        Sigma cut used to identify outliers following first round of
        iterative PCA.
        Note: 0 means this process isn't done.
    
    Returns
    -------
    patch : dict
        Dictionary containing all the useful information from this process
        (among, very many uselss information!)
        Needed for evalWaveSol function
    """
    # Arrays that aren't needed, but are helpful to have in returned dictionary
    if times is None:
        times = np.zeros_like(file_list)
    if x_errors is None:
        x_errors = np.zeros_like(x_errors)
    if file_list is None:
        file_list = np.zeros_like(times)

    ### Vetting
    # Find where there is no line information
    x_values[np.nan_to_num(x_values) < 1] = np.nan

    # Mask out of order lines
    out_of_order = np.zeros_like(x_values, dtype=bool)
    for m in np.unique(orders):
        I = orders == m
        wave_sort = np.argsort(waves[I])
        for i, exp in enumerate(x_values):
            exp_sort = exp[I][wave_sort]
            exp_diff = np.diff(exp_sort)
            left_diff = np.insert(exp_diff < 0, 0, False)
            right_diff = np.append(exp_diff < 0, False)
            exp_mask = np.logical_or(left_diff, right_diff)
            out_of_order[i, I] = exp_mask.copy()
    x_values[out_of_order] = np.nan
    if verbose:
        num_bad = np.sum(out_of_order)
        num_total = out_of_order.size
        print('{:.3}% of lines masked'.format((num_bad) / num_total * 100))

    # Get rid of bad lines
    good_lines = np.mean(np.isnan(x_values), axis=0) < line_cutoff
    # Trim everything
    orders = orders[good_lines]
    waves = waves[good_lines]
    x_values = x_values[:, good_lines]
    x_errors = x_errors[:, good_lines]
    if verbose:
        num_good = np.sum(good_lines)
        num_total = good_lines.size
        print('{} of {} lines cut ({:.3}%)'.format(
            (num_total - num_good), num_total,
            (num_total - num_good) / num_total * 100))

    # Get rid of bad files
    good_files = np.mean(np.isnan(x_values), axis=1) < file_cutoff
    # Trim everything
    x_values = x_values[good_files]
    x_errors = x_errors[good_files]
    file_names = file_list[good_files]
    file_times = times[good_files]
    if verbose:
        num_good = np.sum(good_files)
        num_total = good_files.size
        print('{} of {} files cut ({:.3}%)'.format(
            (num_total - num_good), num_total,
            (num_total - num_good) / num_total * 100))
        print('Files that were cut:')
        print(file_list[~good_files])

    ### Patching
    # Initial patch of bad data with mean
    bad_mask = np.isnan(x_values)  # mask to identify patched x_values
    if running_window > 0:
        half_size = int(running_window // 2)
        counter = 6
        while np.sum(np.isnan(x_values)) > 0:
            for i in range(x_values.shape[0]):
                # Identify files in window
                file_range = [
                    max((i - half_size, 0)),
                    min((i + half_size + 1, x_values.shape[1]))
                ]
                # Find mean of non-NaN values
                run_med = np.nanmean(x_values[file_range[0]:file_range[1], :],
                                     axis=0)
                # Patch NaN values with mean for center file
                x_values[i][bad_mask[i, :]] = run_med[bad_mask[i, :]]
            counter -= 1
            if counter < 0:
                print("Persistant NaNs with running mean.")
                print("Replacing remaining NaNs with global mean.")
                tot_mean = np.nanmean(
                    x_values, axis=0)[None, ...] * np.ones_like(x_values)
                x_values[np.isnan(x_values)] = tot_mean[np.isnan(x_values)]
                break
    else:  # don't bother with running mean
        mean_values = np.nanmean(x_values, axis=0)
        mean_patch = np.array([mean_values for _ in range(x_values.shape[0])])
        x_values[bad_mask] = mean_patch[bad_mask]

    # Iterative PCA
    pca_results = pcaPatch(x_values, bad_mask, K=K, num_iters=num_iters)
    x_values, mean_x_values, denoised_xs, uu, ss, vv = pca_results

    # Mask line center outliers
    if outlier_cut > 0:
        x_resids = x_values - denoised_xs
        out_mask = abs(x_resids - np.mean(x_resids)) > (outlier_cut *
                                                        np.nanstd(x_resids))
        if verbose:
            num_out = np.sum(out_mask)
            num_total = out_mask.size
            num_bad = np.sum(np.logical_and(out_mask, bad_mask))
            print('{:.3}% of lines marked as Outliers'.format(
                (num_out) / num_total * 100))
            print('{:.3}% of lines marked as Outliers that were PCA Patched'.
                  format((num_bad) / num_total * 100))
        pca_results = pcaPatch(x_values,
                               np.logical_or(bad_mask, out_mask),
                               K=K,
                               num_iters=num_iters)
        x_values, mean_x_values, denoised_xs, uu, ss, vv = pca_results

    # Load in all relevant information into dictionary
    patch_dict = {}
    patch_dict['K'] = K
    # Exposure Information
    patch_dict['files'] = file_names.copy()
    patch_dict['times'] = file_times.copy()
    min_date = Time(file_times.min(), format='mjd').isot.split('T')[0]
    yr, mn, dy = min_date.split('-')
    patch_dict['min_date'] = yr[2:] + mn + dy
    min_date = Time(file_times.max(), format='mjd').isot.split('T')[0]
    yr, mn, dy = min_date.split('-')
    patch_dict['max_date'] = yr[2:] + mn + dy
    # Line Information
    patch_dict['orders'] = orders.copy()
    patch_dict['waves'] = waves.copy()
    # Line Measurement Information
    patch_dict['x_values'] = x_values.copy()
    patch_dict['x_errors'] = x_errors.copy()
    patch_dict['denoised_xs'] = denoised_xs.copy()
    patch_dict['mean_xs'] = mean_x_values.copy()
    patch_dict['bad_mask'] = bad_mask.copy()
    # PCA Information
    patch_dict['u'] = uu.copy()
    patch_dict['s'] = ss.copy()
    patch_dict['v'] = vv.copy()
    patch_dict['ec'] = (uu * ss)[:, :K]
    # Outlier Information
    if outlier_cut > 0:
        patch_dict['out_mask'] = out_mask.copy()

    return patch_dict
Photo_Log = Photo_Log.round({
    'HWPANG': 2,
    'JD': 6,
    'FWHM_o': 2,
    'FWHM_e': 2,
    'Aper [pix]': 2,
    'EXP [s]': 2,
    'Ann': 2,
    'Ann_out': 2,
    'Flux_o': 4,
    'eFLux_o': 4,
    'Flux_e': 4,
    'eFLux_e': 4,
    'SNR_o': 2,
    'SNR_e': 2,
    'Sky_o': 4,
    'eSky_o': 4,
    'Sky_e': 4,
    'eSky_e': 4
})
Pol_Log.to_csv(
    os.path.join(path, 'result_Pol_{}.csv'.format(time_.split(' ')[0])))
Photo_Log.to_csv(
    os.path.join(path, 'result_Photo_{}.csv'.format(time_.split(' ')[0])))
print(
    os.path.join(path, 'result_Pol_{}.csv'.format(time_.split(' ')[0])) +
    ' is created.')
print(
    os.path.join(path, 'result_Photo_{}.csv'.format(time_.split(' ')[0])) +
    ' is created.')
Exemplo n.º 12
0
import yaml
from astropy.time import Time
import os

with open('recycler.yaml', 'r') as f:
    recy = yaml.load(f)

propid = recy["propid"]
MJDnite = recy["start_of_season"]

nite = Time(MJDnite, format="mjd").iso
nite = nite.split(' ')[0].split('-')[0] + nite.split(' ')[0].split(
    '-')[1] + nite.split(' ')[0].split('-')[2]

os.system('. ./getExpWPropIDandNite.sh -n ' + nite + ' -p ' + propid)
Exemplo n.º 13
0
def tab2_BUT_tCLN_param_save():
    with open(CleanID_dir + 'CASA_CLN_args.json', 'w') as fp:
        json.dump(tab2_tCLN_Param_dict, fp)
    tab2_Div_tCLN2.text = '<p>CASA script and arguments config file saved to <b>{}</b>.</p>'.format(
        CleanID_dir)
    timestrs = []
    fits_local = []
    fits_global = []
    if 'twidth' in tab2_tCLN_Param_dict.keys():
        val = tab2_tCLN_Param_dict['twidth']
        exec('twidth = int({})'.format(val))
    else:
        twidth = 1
    if 'workdir' in tab2_tCLN_Param_dict.keys():
        val = tab2_tCLN_Param_dict['workdir']
        exec('workdir = {}'.format(val))
    else:
        workdir = './'
    # os.system('cp {} {}'.format(CleanID_dir + 'CASA_CLN_args.json', workdir))
    os.system('cp {}/DataBrowser/ToClean/script_clean.py {}'.format(
        suncasa_dir, CleanID_dir))

    for ii in range(tab2_ntim):
        iit = int(ii) / twidth * twidth
        t0 = xx[iit] - tab2_dt / 2
        datestr = Time(t0 / 3600. / 24.,
                       format='jd',
                       scale='utc',
                       precision=3,
                       out_subfmt='date').iso
        timestr0 = Time(t0 / 3600. / 24.,
                        format='jd',
                        scale='utc',
                        precision=3,
                        out_subfmt='date_hms').iso
        timestr0 = timestr0.split(' ')[1]
        timestr = datestr.replace("-", "") + 'T' + timestr0.replace(":", "")
        timestrs.append(timestr0)
        fits_local.append(timestr + '.fits')
        fits_global.append(timestr + '.fits')
    timestrs = timestrs * int(tab2_nfreq)
    fits_local = fits_local * int(tab2_nfreq)
    fits_global = fits_global * int(tab2_nfreq)
    freqstrs = ['{:.3f}'.format(ll) for ll in yy]
    dspecDFout = pd.DataFrame({
        'time': xx - xx[0],
        'freq': yy,
        'timestr': timestrs,
        'freqstr': freqstrs,
        'dspec': tab2_spec_plt.flatten(),
        'fits_local': fits_local,
        'fits_global': fits_global
    })
    with open(FS_dspecDF, 'wb') as fp:
        pickle.dump(dspecDFout, fp)
    tab2_Div_tCLN2.text = '<p>CASA script, arguments config file and dspecDF-base saved to <b>{}</b>. '.format(
        CleanID_dir
    ) + 'Click the <b>clean</b> button to clean. When finished, \
        go back to <b>QLook</b> window, select StrID <b>{}</b> and \
        click <b>FSview</b> button again.</p>'.format(CleanID_dir,
                                                      struct_id[0:-1])
Exemplo n.º 14
0
def tab2_dspec_selection_change(attrname, old, new):
    global tapPointDF_dspec, dspecDF_select
    global SRC_dspec_quadselround
    if clickmode == 'singleclick':
        tab2_r_dspec_patch.data_source.data = {'xx': [], 'yy': []}
        tab2_SRC_dspec_quadx_selected = tab2_SRC_dspec_quadx.selected['1d'][
            'indices']
        tab2_SRC_dspec_quady_selected = tab2_SRC_dspec_quady.selected['1d'][
            'indices']
        if len(tab2_SRC_dspec_quadx_selected) > 0 and len(
                tab2_SRC_dspec_quady_selected) > 0:
            quadx_selected = tab2_SRC_dspec_quadx_selected[0]
            quady_selected = tab2_SRC_dspec_quady_selected[0]
            idx = quady_selected * tab2_ntim + quadx_selected
            tmp = tab2_r_dspec.data_source.data['image'][0]
            timstr = dspecDF0['timestr'].iloc[idx]
            freqstr = '{:.3f} [GHz]'.format(dspecDF0['freq'].iloc[idx])
            tooltips = ['{} {}'.format(timstr, freqstr)]
            tab2_dspec_xPro_data = {
                'x': tab2_dtim,
                'y': tmp[quady_selected, :]
            }
            r_dspec_xPro.data_source.data = tab2_dspec_xPro_data
            tab2_dspec_xPro_hover_data = {
                'x': [tab2_dtim[quadx_selected]],
                'y': [tmp[quady_selected, quadx_selected]],
                'tooltips': tooltips
            }
            r_dspec_xPro_hover.data_source.data = tab2_dspec_xPro_hover_data
            tab2_dspec_yPro_data = {
                'x': tmp[:, quadx_selected],
                'y': tab2_freq
            }
            r_dspec_yPro.data_source.data = tab2_dspec_yPro_data
            tab2_dspec_yPro_hover_data = {
                'x': [tmp[quady_selected, quadx_selected]],
                'y': [tab2_freq[quady_selected]],
                'tooltips': tooltips
            }
            r_dspec_yPro_hover.data_source.data = tab2_dspec_yPro_hover_data
            tab2_r_dspec_line_x.data_source.data = {
                'time': [tab2_dtim[0], tab2_dtim[-1]],
                'freq': [tab2_freq[quady_selected]] * 2
            }
            tab2_r_dspec_line_y.data_source.data = {
                'time': [tab2_dtim[quadx_selected]] * 2,
                'freq': [tab2_freq[0], tab2_freq[-1]]
            }
        elif len(tab2_SRC_dspec_quadx_selected) == 0 and len(
                tab2_SRC_dspec_quady_selected) == 0:
            r_dspec_xPro.data_source.data = {'x': [], 'y': []}
            r_dspec_xPro_hover.data_source.data = {
                'x': [],
                'y': [],
                'tooltips': []
            }
            r_dspec_yPro.data_source.data = {'x': [], 'y': []}
            r_dspec_yPro_hover.data_source.data = {
                'x': [],
                'y': [],
                'tooltips': []
            }
            tab2_r_dspec_line_x.data_source.data = {'time': [], 'freq': []}
            tab2_r_dspec_line_y.data_source.data = {'time': [], 'freq': []}
    elif clickmode == 'doubleclick':
        SRC_dspec_quadselround += 1
        if SRC_dspec_quadselround == 2:
            SRC_dspec_quadselround = 0
            tab2_SRC_dspec_quadx_selected = tab2_SRC_dspec_quadx.selected[
                '1d']['indices']
            tab2_SRC_dspec_quady_selected = tab2_SRC_dspec_quady.selected[
                '1d']['indices']
            tab2_SRC_dspec_quadx.selected = {
                '0d': {
                    'glyph': None,
                    'indices': []
                },
                '1d': {
                    'indices': []
                },
                '2d': {}
            }
            tab2_SRC_dspec_quady.selected = {
                '0d': {
                    'glyph': None,
                    'indices': []
                },
                '1d': {
                    'indices': []
                },
                '2d': {}
            }
            if len(tab2_SRC_dspec_quadx_selected) > 0 and len(
                    tab2_SRC_dspec_quady_selected) > 0:
                quadx_selected = tab2_SRC_dspec_quadx_selected[0]
                quady_selected = tab2_SRC_dspec_quady_selected[0]
                tapPointDF_dspec = tapPointDF_dspec.append(pd.Series({
                    'xx':
                    tab2_dtim[quadx_selected],
                    'yy':
                    tab2_freq[quady_selected]
                }),
                                                           ignore_index=True)
                if len(tapPointDF_dspec.index) == 1:
                    tab2_r_dspec_lines.data_source.data = {
                        'xs': [[tab2_dtim[quadx_selected]] * 2,
                               [tab2_dtim[0], tab2_dtim[-1]]],
                        'ys': [[tab2_freq[0], tab2_freq[-1]],
                               [tab2_freq[quady_selected]] * 2]
                    }
                    tab2_r_dspec_patch.data_source.data = {'xx': [], 'yy': []}
                elif len(tapPointDF_dspec.index) == 2:
                    x0, x1 = tapPointDF_dspec['xx'].min(
                    ), tapPointDF_dspec['xx'].max()
                    y0, y1 = tapPointDF_dspec['yy'].min(
                    ), tapPointDF_dspec['yy'].max()
                    tab2_r_dspec_patch.data_source.data = {
                        'xx': [x0, x1, x1, x0],
                        'yy': [y0, y0, y1, y1]
                    }
                    tab2_r_dspec_lines.data_source.data = {'xs': [], 'ys': []}
                    dspecDF_select = \
                        dspecDF0_rs[dspecDF0_rs['time'] >= x0][dspecDF0_rs['time'] <= x1][
                            dspecDF0_rs['freq'] >= y0][
                            dspecDF0_rs['freq'] <= y1]
                    tapPointDF_dspec = pd.DataFrame({'xx': [], 'yy': []})
                    time0, time1 = dspecDF_select['time'].min(
                    ) + timestart, dspecDF_select['time'].max() + timestart
                    t0_char = Time(time0 / 3600. / 24.,
                                   format='jd',
                                   scale='utc',
                                   precision=3,
                                   out_subfmt='date_hms').iso
                    date0_char = t0_char.split(' ')[0].replace('-', '/')
                    time0_char = t0_char.split(' ')[1]
                    t1_char = Time(time1 / 3600. / 24.,
                                   format='jd',
                                   scale='utc',
                                   precision=3,
                                   out_subfmt='date_hms').iso
                    date1_char = t1_char.split(' ')[0].replace('-', '/')
                    time1_char = t1_char.split(' ')[1]
                    tab2_tCLN_Param_dict['timerange'] = "'{}/{}~{}/{}'".format(
                        date0_char, time0_char, date1_char, time1_char)
                    freq0, freq1 = dspecDF_select['freq'].min(
                    ), dspecDF_select['freq'].max()
                    freqrange = "'{:.3f}~{:.3f} GHz'".format(freq0, freq1)
                    tab2_tCLN_Param_dict['freqrange'] = freqrange
                    tab2_Div_tCLN_text = ' '.join(
                        "<p><b>{}</b> = {}</p>".format(key, val)
                        for (key, val) in tab2_tCLN_Param_dict.items())
                    tab2_Div_tCLN.text = tab2_Div_tCLN_text
Exemplo n.º 15
0
xx = tim_map.flatten()
yy = freq_map.flatten()
timestart = xx[0]

tab2_panel_Div_exit = Div(
    text="""<p><b>Warning</b>: Click the <b>Exit ToClean</b>
            first before closing the tab</p></b>""",
    width=config_main['plot_config']['tab_ToClean']['widgetbox_wdth1'])
timestrs = []
for ll in tab2_tim:
    timestr = Time(ll / 3600. / 24.,
                   format='mjd',
                   scale='utc',
                   precision=3,
                   out_subfmt='date_hms').iso
    timestrs.append(timestr.split(' ')[1])
timestrs = timestrs * tab2_nfreq
dspecDF0 = pd.DataFrame({
    'time': xx - xx[0],
    'freq': yy,
    'dspec': tab2_spec_plt.flatten(),
    'timestr': timestrs
})

rmax, rmin = tab2_spec_plt.max(), tab2_spec_plt.min()
# timestart = xx[0]
TOOLS = "crosshair,pan,wheel_zoom,box_zoom,reset,save"
# downsample_dspecDF(spec_square_rs_tmax=spec_square_rs_tmax, spec_square_rs_fmax=spec_square_rs_fmax)
# tab2_SRC_dspec_square = ColumnDataSource(dspecDF0_rs)
dspecDF0_rs = dspecDF0.copy()
'''create the dynamic spectrum plot'''
Exemplo n.º 16
0
                         ignore_index=True)

Pol_name = ['filename', 'JD', 'alpha [deg]', 'PsANG [deg]',
            'q', 'u', 'ran_q', 'ran_u', 'sys_q', 'sys_u',
            'P', 'eP', 'Pr', 'theta', 'theta_r', 'eTheta',
            'Aper_radius [pix]']
Phot_name = ['Object', 'Filename', 'set', 'TIME', 'JD',
             'HWPANG', 'FWHM_o', 'FWHM_e', 'EXP [s]',
             'Aper [pix]', 'Ann', 'Ann_out', 'Flux_o',
             'eFLux_o', 'Flux_e', 'eFLux_e', 'Sky_o',
             'eSky_o', 'Sky_e', 'eSky_e', 'SNR_o',
             'SNR_e']

Pol_Log = Pol_Log.reindex(columns=Pol_name)
Photo_Log = Photo_Log.reindex(columns=Phot_name)
Pol_Log = Pol_Log.round({'JD': 6, 'alpha [deg]': 2, 'PsANG [deg]': 2,
                         'q': 4, 'u': 4, 'ran_q': 4, 'ran_u': 4,
                         'sys_q': 4, 'sys_u': 4, 'theta': 2, 'theta_r': 2,
                         'P': 4, 'eP': 4, 'Aper_radius [pix]': 2, 'Pr': 4,
                         'eTheta': 2})
Photo_Log = Photo_Log.round({'HWPANG': 2, 'JD': 6, 'FWHM_o': 2, 'FWHM_e': 2,
                             'Aper [pix]': 2, 'EXP [s]': 2, 'Ann': 2,
                             'Ann_out': 2, 'Flux_o': 4, 'eFLux_o': 4,
                             'Flux_e': 4, 'eFLux_e': 4, 'SNR_o': 2,
                             'SNR_e': 2, 'Sky_o': 4, 'eSky_o': 4,
                             'Sky_e': 4, 'eSky_e': 4})
Pol_Log.to_csv(os.path.join(path, 'result_Pol_{}.csv'.format(time_.split(' ')[0])))
Photo_Log.to_csv(os.path.join(path, 'result_Photo_{}.csv'.format(time_.split(' ')[0])))
print(os.path.join(path, 'result_Pol_{}.csv'.format(time_.split(' ')[0])) + ' is created.')
print(os.path.join(path, 'result_Photo_{}.csv'.format(time_.split(' ')[0])) + ' is created.')