Esempio n. 1
0
def get_tasks(filter):
    secret = "7a69d867fcdc2f0d"
    api_key = "44c0313c5aa5c16cf47ee93b1c4595c7"
    token = read_token()

    rtm = RTM(api_key, secret, token)

    if token is None or rtm.auth.checkToken().stat != "ok":
        import webbrowser
        import time

        url = rtm.getAuthURL()
        print url
        webbrowser.open(url)
        time.sleep(15)
        write_token(rtm.getToken())

    tasks = rtm.tasks.getList(filter=filter)
    filtered_tasks = []
    if hasattr(tasks.tasks, "list"):
        lists = tasks.tasks.list if isinstance(tasks.tasks.list, list) else [tasks.tasks.list]
        for task_list in lists:
            for taskseries in task_list.taskseries:
                completed = False
                if isinstance(taskseries.task, list):
                    for task in taskseries.task:
                        if task.completed:
                            completed = True
                            break
                else:
                    completed = taskseries.task.completed
                if not completed:
                    filtered_tasks.append(taskseries.name)

    return reversed(filtered_tasks)
Esempio n. 2
0
def get_tasks(filter):
    secret = "7a69d867fcdc2f0d"
    api_key = "44c0313c5aa5c16cf47ee93b1c4595c7"
    token = read_token()

    rtm = RTM(api_key, secret, token)

    if token is None or rtm.auth.checkToken().stat != "ok":
        import webbrowser
        import time
        url = rtm.getAuthURL()
        print url
        webbrowser.open(url)
        time.sleep(15)
        write_token(rtm.getToken())

    tasks = rtm.tasks.getList(filter=filter)
    filtered_tasks = []
    if hasattr(tasks.tasks, 'list'):
        lists = tasks.tasks.list if isinstance(tasks.tasks.list,
                                               list) else [tasks.tasks.list]
        for task_list in lists:
            for taskseries in task_list.taskseries:
                completed = False
                if isinstance(taskseries.task, list):
                    for task in taskseries.task:
                        if task.completed:
                            completed = True
                            break
                else:
                    completed = taskseries.task.completed
                if not completed:
                    filtered_tasks.append(taskseries.name)

    return reversed(filtered_tasks)
Esempio n. 3
0
class RTMHelper(object):
    def __init__(self):
        self._timeline = None
        token = self._get_token()
        self.rtm = RTM('44c0313c5aa5c16cf47ee93b1c4595c7', '7a69d867fcdc2f0d', token)
        if not token:
            webbrowser.open(self.rtm.getAuthURL())
            raw_input("Press enter once you've given access")
            token = self.rtm.getToken()
            self._save_token(token)

    def _get_token(self):
        token = None
        if os.path.exists(TOKEN_PATH):
            f = open(TOKEN_PATH, 'r')
            token = f.read()
            f.close()
        return token

    def _save_token(self, token):
        f = open(TOKEN_PATH, 'w')
        f.write(token)
        f.close()

    def get_timeline(self):
        if not self._timeline:
            self._timeline = self.rtm.timelines.create().timeline
        return self._timeline

    def add_list(self, list_name):
        list = self.rtm.lists.add(timeline = self.get_timeline(), name = list_name.replace(" ", "_"))

    def add_task(self, task):
        new_task = task['name']
        if task['area']:
            new_task += " #"+task['area'].replace(" ", "_")
        if task['project']:
            new_task += " #"+task['project'].replace(" ", "_")

        tags = " #".join([tag.replace(" ", "_") for tag in task['tags']]) if len(task['tags']) != 0 else None
        if tags:
            new_task += " #"+tags
        if task['due_date']:
            new_task += " ^"+task['due_date']
        
        #print new_task
        #return
        rtm_task = self.rtm.tasks.add(timeline = self.get_timeline(), name = new_task, parse = 1)
        if task['is_complete']:
            self.rtm.tasks.complete(timeline = self.get_timeline(), list_id = rtm_task.list.id, taskseries_id = rtm_task.list.taskseries.id, task_id = rtm_task.list.taskseries.task.id)
        if task['notes']:
            self.rtm.tasksNotes.add(timeline = self.get_timeline(), list_id = rtm_task.list.id, taskseries_id = rtm_task.list.taskseries.id, task_id = rtm_task.list.taskseries.task.id, note_title = "Note", note_text = task["notes"])
Esempio n. 4
0
def testLaplacian(args, imageDim):
    path = args.path
    stencil = RTM(imageDim, args.order, dtype=args.dtype)
    image = stencil.randImg() * 100
    np.transpose(image).tofile(os.path.join(path, "image.bin"))
    np.savetxt(os.path.join(path, "img_in.txt"),
               image, delimiter=',', fmt='%.5e')
    stencil.coefx.tofile(os.path.join(path, "coefx.bin"))
    stencil.coefx.tofile(os.path.join(path, "coefz.bin"))

    for _ in range(args.time):
        image = stencil.laplacian(image)

    np.transpose(image).tofile(os.path.join(path, "result.bin"))
Esempio n. 5
0
 def __init__(self):
     self._timeline = None
     token = self._get_token()
     self.rtm = RTM('44c0313c5aa5c16cf47ee93b1c4595c7', '7a69d867fcdc2f0d', token)
     if not token:
         webbrowser.open(self.rtm.getAuthURL())
         raw_input("Press enter once you've given access")
         token = self.rtm.getToken()
         self._save_token(token)
Esempio n. 6
0
def testForward(args, imageDim):
    path = args.path
    if path is None:
        path = "forward"
    if not os.path.exists(path):
        os.makedirs(path)
    stencil = RTM(imageDim, args.order, dtype=args.dtype)
    stencil.setTime(args.time)

    stencil.setB(args.nxb, args.nzb)
    stencil.computeTaper(0.75)
    stencil.taperx.tofile(os.path.join(path, "taperx.bin"))
    stencil.taperz.tofile(os.path.join(path, "taperz.bin"))

    stencil.coefx.tofile(os.path.join(path, "coefx.bin"))
    stencil.coefz.tofile(os.path.join(path, "coefz.bin"))

    src = np.random.rand(args.time).astype(stencil.dtype)
    # src = stencil.ricker_wavelet(15)
    src.tofile(os.path.join(path, "src_s0.bin"))
    src.tofile(os.path.join(path, "src.bin"))
    #np.savetxt(os.path.join(path, "src.txt"),src,  delimiter=',', fmt='%.5e')
    stencil.setSrc(args.nzb, imageDim[1] // 2, src)

    # v2dt2 = np.ones(imageDim).astype(stencil.dtype)
    v2dt2 = stencil.randImg() * 1e6
    stencil.setV(v2dt2)
    np.transpose(stencil.v2dt2).tofile(os.path.join(path, "v2dt2.bin"))

    if args.verify != 0:
        snap0, snap1, upb = stencil.forward()
        np.transpose(snap0).tofile(os.path.join(path, "snap0.bin"))
        np.transpose(snap1).tofile(os.path.join(path, "snap1.bin"))
        np.transpose(upb, (0, 2, 1)).tofile(os.path.join(path, "upb.bin"))
Esempio n. 7
0
def testBackward(args, imageDim):
    path = args.path
    if path is None:
        path = "backward"
    if not os.path.exists(path):
        os.makedirs(path)
    stencil = RTM(imageDim, args.order, dtype=args.dtype)
    stencil.setTime(args.time)

    stencil.setB(args.nxb, args.nzb)
    stencil.computeTaper(0.75)
    stencil.taperx.tofile(os.path.join(path, "taperx.bin"))
    stencil.taperz.tofile(os.path.join(path, "taperz.bin"))

    stencil.coefx.tofile(os.path.join(path, "coefx.bin"))
    stencil.coefz.tofile(os.path.join(path, "coefz.bin"))

    v2 = stencil.randImg() * 1e6
    # v2 = np.ones(imageDim).astype(stencil.dtype) * 1e6
    stencil.setV(v2)
    np.transpose(stencil.v2dt2).tofile(os.path.join(path, "v2dt2.bin"))

    sensor = np.random.rand(args.time, stencil.m_x -
                            2 * stencil.nxb).astype(stencil.dtype)
    np.transpose(sensor).tofile(os.path.join(path, "sensorT.bin"))
    sensor.tofile(os.path.join(path, "sensor_s0.bin"))
    sensor.tofile(os.path.join(path, "sensor.bin"))
    #np.savetxt(os.path.join(path, "sensor.txt"), sensor, delimiter=',', fmt='%.5e')
    stencil.setSensor(args.nzb, sensor)
    snap0 = stencil.randImg()
    snap1 = stencil.randImg()
    np.transpose(snap0).tofile(os.path.join(path, "snap0.bin"))
    np.transpose(snap1).tofile(os.path.join(path, "snap1.bin"))
    upb = np.random.rand(stencil.nt, args.order // 2,
                         stencil.m_x).astype(stencil.dtype)
    upb[stencil.nt - 2, :, :] = snap0[stencil.nzb -
                                      stencil.order // 2: stencil.nzb, :]
    upb[stencil.nt - 1, :, :] = snap1[stencil.nzb -
                                      stencil.order // 2: stencil.nzb, :]
    np.transpose(upb, (0, 2, 1)).tofile(os.path.join(path, "upb.bin"))

    if args.verify != 0:
        imloc, r0, r1, p0, p1 = stencil.backward(snap0, snap1, upb)
        np.transpose(imloc).tofile(os.path.join(path, "imloc.bin"))
        np.transpose(p0).tofile(os.path.join(path, "p0.bin"))
        np.transpose(p1).tofile(os.path.join(path, "p1.bin"))
        #np.savetxt(os.path.join(path, "p0.txt"), np.transpose(p0), delimiter=',', fmt='%.5e')
        #np.savetxt(os.path.join(path, "p1.txt"), np.transpose(p1), delimiter=',', fmt='%.5e')

        np.transpose(r0).tofile(os.path.join(path, "r0.bin"))
        np.transpose(r1).tofile(os.path.join(path, "r1.bin"))
Esempio n. 8
0
def testRTM(args, imageDim):
    path = args.path
    if path is None:
        path = "rtm"
    if not os.path.exists(path):
        os.makedirs(path)
    stencil = RTM(imageDim, args.order, dtype=args.dtype)
    stencil.setTime(args.time)

    stencil.setB(args.nxb, args.nzb)
    stencil.computeTaper(0.75)
    stencil.taperx.tofile(os.path.join(path, "taperx.bin"))
    stencil.taperz.tofile(os.path.join(path, "taperz.bin"))

    stencil.coefx.tofile(os.path.join(path, "coefx.bin"))
    stencil.coefz.tofile(os.path.join(path, "coefz.bin"))

    # src = [stencil.ricker_wavelet(15) for i in range(args.shot)]
    src = np.random.rand(args.shot, args.time).astype(stencil.dtype)
    for i in range(args.shot):
        src[i].tofile(os.path.join(path, "src_s%d.bin" % i))
    #np.savetxt(os.path.join(path, "src.txt"),src,  delimiter=',', fmt='%.5e')

    #v2dt2 = np.ones(imageDim).astype(stencil.dtype)
    v2dt2 = stencil.randImg() * 1e6
    stencil.setV(v2dt2)
    np.transpose(stencil.v2dt2).tofile(os.path.join(path, "v2dt2.bin"))

    sensor = np.random.rand(args.shot, args.time, stencil.m_x -
                            2 * stencil.nxb).astype(stencil.dtype)
    for i in range(args.shot):
        sensor[i].tofile(os.path.join(path, "sensor_s%d.bin" % i))

    if args.verify != 0:
        if not args.fsx:
            args.fsx = args.width // 2

        img = None
        for i in range(args.shot):

            stencil.setSrc(args.nzb, args.fsx + i * args.sp, src[i])
            stencil.setSensor(args.nzb, sensor[i])

            snap0, snap1, upb = stencil.forward()
            np.transpose(snap0).tofile(os.path.join(path, "snap0_s%d.bin" % i))
            np.transpose(snap1).tofile(os.path.join(path, "snap1_s%d.bin" % i))

            imloc, r0, r1, p0, p1 = stencil.backward(snap0, snap1, upb)

            if img is None:
                img = imloc
            else:
                img += imloc
            np.transpose(imloc).tofile(os.path.join(path, "imloc_s%d.bin" % i))
            np.transpose(p0).tofile(os.path.join(path, "p0_s%d.bin" % i))
            np.transpose(p1).tofile(os.path.join(path, "p1_s%d.bin" % i))
            #np.savetxt(os.path.join(path, "p0.txt"), np.transpose(p0), delimiter=',', fmt='%.5e')
            #np.savetxt(os.path.join(path, "p1.txt"), np.transpose(p1), delimiter=',', fmt='%.5e')

            np.transpose(r0).tofile(os.path.join(path, "r0_s%d.bin" % i))
            np.transpose(r1).tofile(os.path.join(path, "r1_s%d.bin" % i))
            #np.savetxt(os.path.join(path, "r0.txt"), np.transpose(r0), delimiter=',', fmt='%.5e')
            #np.savetxt(os.path.join(path, "r1.txt"), np.transpose(r1), delimiter=',', fmt='%.5e')
            del upb
            del snap0
            del snap1
            del imloc

        np.transpose(img).tofile(os.path.join(path, "imloc.bin"))
Esempio n. 9
0
def verifyRTM(args, imageDim):
    path = args.path
    if path is None:
        return
    stencil = RTM(imageDim, args.order, dtype=args.dtype)
    stencil.setTime(args.time)

    stencil.setB(args.nxb, args.nzb)

    stencil.taperx = np.fromfile(os.path.join(
        path, "taperx.bin"), dtype=np.float32)
    stencil.taperz = np.fromfile(os.path.join(
        path, "taperz.bin"), dtype=np.float32)

    stencil.coefx = np.fromfile(os.path.join(
        path, "coefx.bin"), dtype=np.float32)
    stencil.coefz = np.fromfile(os.path.join(
        path, "coefz.bin"), dtype=np.float32)

    if args.srcx is None:
        args.srcx = imageDim[1] // 2
    else:
        args.srcx += stencil.nxb

    src = np.fromfile(os.path.join(path, "src.bin"), dtype=np.float32)
    stencil.setSrc(args.nzb, args.srcx, src)

    v2dt2 = np.fromfile(os.path.join(path, "v2dt2.bin"), dtype=np.float32)
    stencil.v2dt2 = v2dt2.reshape([stencil.m_x, stencil.m_z]).transpose()

    img = None
    for i in range(args.shot):
        sensor = np.fromfile(os.path.join(
            path, "sensor_s%d.bin" % i), dtype=np.float32)
        sensor = np.reshape(sensor, [args.time, stencil.m_x - 2 * stencil.nxb])

        stencil.setSensor(args.nzb, sensor)

        snap0, snap1, upb = stencil.forward()

        refP = np.fromfile(os.path.join(path, "P.bin"), np.float32).reshape(
            [stencil.m_x, stencil.m_z]).transpose()
        refPP = np.fromfile(os.path.join(path, "PP.bin"), np.float32).reshape(
            [stencil.m_x, stencil.m_z]).transpose()

        imloc, r0, r1, p0, p1 = stencil.backward(snap0, snap1, upb)

        if img is None:
            img = imloc
        else:
            img += imloc
        del upb
        del snap0
        del snap1
        del imloc

    img = np.transpose(img)
    img.tofile(os.path.join(path, "imloc.bin"))

    img = np.reshape(img, [-1, ])
    ref = np.fromfile(os.path.join(path, "ref.bin"), np.float32)

    diff = np.isclose(img, ref, 1e-3, 1e-4)
    print(sum(diff) / img.size)