def __init__(self):
        self.index = 0              # index in the population
        self.home = coordinates()   # initial location
        self.pos = coordinates()    # current location
        self.community = city()     # current city/village
        self.state = 'S'            # current diseased state
#        self.alive = True          # whether he is alive
        self.in_city = True         # if he's in a city (vs village)
        self.timeout = 0            # counting variable
        self.will_die = False       # if hospitalized, will they die?
        self.will_h = False         # if infected, will they go to the hospital?
        self.family = []            # list of family indices
Example #2
0
def test_coordinates():
    assert coordinates(90, 1) == (0.0, 1.0)
    assert coordinates(90, 2) == (0.0, 2.0)
    assert coordinates(0, 1), (1.0, 0.0)
    assert coordinates(45, 1) == (0.7071067812, 0.7071067812)
    assert coordinates(1090, 10000) == (9848.0775301221, 1736.4817766693)
    assert coordinates(-270, 1) == (0.0, 1.0)
    for i in range(0, len(pointsPerLine) - 1):
        templine = []
        points = allLines[first:first + pointsPerLine[i]]
        for p in range(0, pointsPerLine[i]):
            #if( np.isnan(np.sum(points[p]))==0):
            templine.append(points[p])
        if (len(templine) > 1):  # and len(templine) == pointsPerLine[i]):
            streamlines.append(templine)
        first = first + pointsPerLine[i]
    return streamlines



            #path="/home/uzair/PycharmProjects/Unfolding/data/diffusionSimulations_nonConformal_scale/"
ntracking = loc_track(path ,default_sphere)
coords = coordinates.coordinates(path,'')
utracking = loc_track(path+'Unfolded/',default_sphere,coords=coords,npath=path,UParams=Uparams)
u2n_streamlines=unfold2nativeStreamlines(utracking,coords)
streamline.save_vtk_streamlines(ntracking.streamlines,
                                path+"native_streamlines.vtk")
streamline.save_vtk_streamlines(utracking.streamlines,
                                path + "Unfolded/unfold_streamlines.vtk")
streamline.save_vtk_streamlines(u2n_streamlines,
                    path + "from_unfold_streamlines.vtk")


def plot_streamlines(streamlines):
    if has_fury:
        # Prepare the display objects.
        color = colormap.line_colors(streamlines)
Example #4
0
    def track(self, ang_thr=None, default_sphere=default_sphere):
        default_sphere = default_sphere.subdivide()
        default_sphere = default_sphere.subdivide()
        default_sphere = default_sphere.subdivide()
        default_sphere.vertices = np.append(default_sphere.vertices,
                                            [[1, 0, 0]])
        default_sphere.vertices = np.append(default_sphere.vertices,
                                            [[-1, 0, 0]])
        default_sphere.vertices = np.append(default_sphere.vertices,
                                            [[0, 1, 0]])
        default_sphere.vertices = np.append(default_sphere.vertices,
                                            [[0, -1, 0]])
        default_sphere.vertices = default_sphere.vertices.reshape([-1, 3])

        # this needs to be moved into tracking class (in unfoldTracking)
        def loc_track(path,
                      default_sphere,
                      coords=None,
                      npath=None,
                      UParams=None,
                      ang_thr=None):
            data, affine = load_nifti(path + 'data.nii.gz')
            data[np.isnan(data) == 1] = 0
            mask, affine = load_nifti(path + 'nodif_brain_mask.nii.gz')
            mask[np.isnan(mask) == 1] = 0
            mask[:, :, 1:] = 0
            stopper = copy.deepcopy(mask)
            #stopper[:, :, :] = 1
            gtab = gradient_table(path + 'bvals', path + 'bvecs')

            csa_model = CsaOdfModel(gtab, smooth=1, sh_order=12)
            peaks = peaks_from_model(csa_model,
                                     data,
                                     default_sphere,
                                     relative_peak_threshold=0.99,
                                     min_separation_angle=25,
                                     mask=mask)
            if ang_thr is not None:
                peaks.ang_thr = ang_thr
            if os.path.exists(path + 'grad_dev.nii.gz'):
                gd, affine_g = load_nifti(path + 'grad_dev.nii.gz')
                nmask, naffine = load_nifti(npath + 'nodif_brain_mask.nii.gz')
                nmask[np.isnan(nmask) == 1] = 0
                nmask[:, :, 1:] = 0
                seedss = copy.deepcopy(nmask)
                seedss = utils.seeds_from_mask(seedss, naffine, [2, 2, 2])
                useed = []
                UParams = coords.Uparams
                for seed in seedss:
                    us = coords.rFUa_xyz(seed[0], seed[1], seed[2])
                    vs = coords.rFVa_xyz(seed[0], seed[1], seed[2])
                    ws = coords.rFWa_xyz(seed[0], seed[1], seed[2])
                    condition = us >= UParams.min_a and us <= UParams.max_a and vs >= UParams.min_b and vs <= UParams.max_b \
                                and ws >= UParams.min_c and ws <= UParams.max_c
                    if condition == True:
                        useed.append([float(us), float(vs), float(ws)])
                seeds = np.asarray(useed)

            else:
                gd = None
                seedss = copy.deepcopy(mask)
                seeds = utils.seeds_from_mask(seedss, affine, [2, 2, 2])

            stopping_criterion = BinaryStoppingCriterion(stopper)
            tracked = tracking(peaks,
                               stopping_criterion,
                               seeds,
                               affine,
                               graddev=gd,
                               sphere=default_sphere)
            tracked.localTracking()
            return tracked

        # this needs to be moved to unfoldStreamlines (in unfoldTracking)
        def unfold2nativeStreamlines(tracking, coords):
            points, X = getPointsData(coords.X_uvwa_nii)
            points, Y = getPointsData(coords.Y_uvwa_nii)
            points, Z = getPointsData(coords.Z_uvwa_nii)
            allLines = tracking.streamlines.get_data()
            x = coords.rFX_uvwa(allLines[:, 0], allLines[:, 1], allLines[:, 2])
            y = coords.rFY_uvwa(allLines[:, 0], allLines[:, 1], allLines[:, 2])
            z = coords.rFZ_uvwa(allLines[:, 0], allLines[:, 1], allLines[:, 2])
            allLines = np.asarray([x, y, z]).T
            pointsPerLine = tracking.NpointsPerLine
            streamlines = []
            first = 0
            for i in range(0, len(pointsPerLine) - 1):
                templine = []
                points = allLines[first:first + pointsPerLine[i]]
                for p in range(0, pointsPerLine[i]):
                    if (np.isnan(np.sum(points[p])) == 0):
                        templine.append(points[p])
                if (len(templine) >
                        1):  # and len(templine) == pointsPerLine[i]):
                    streamlines.append(templine)
                first = first + pointsPerLine[i]
            return streamlines

            # path="/home/uzair/PycharmProjects/Unfolding/data/diffusionSimulations_nonConformal_scale/"

        ntracking = loc_track(self.npath, default_sphere, ang_thr=ang_thr)
        coords = coordinates.coordinates(self.npath, '')
        utracking = loc_track(self.upath,
                              default_sphere,
                              coords=coords,
                              npath=self.npath,
                              UParams=self.Uparams,
                              ang_thr=ang_thr)
        u2n_streamlines = unfold2nativeStreamlines(utracking, coords)
        streamline.save_vtk_streamlines(ntracking.streamlines,
                                        self.npath + "native_streamlines.vtk")
        streamline.save_vtk_streamlines(utracking.streamlines,
                                        self.upath + "unfold_streamlines.vtk")
        streamline.save_vtk_streamlines(
            u2n_streamlines, self.npath + "from_unfold_streamlines.vtk")
Example #5
0
def animate():
    global y
    global m
    global d
    global run
    plt.pause(0.01)
    print('Current Date:', m, '/', d, '/', y)
    xcoords, ycoords, zcoords = coordinates(y, m, d)
    sc._offsets3d = (xcoords, ycoords, zcoords)
    if m == 1:
        if d == 31:
            m = 2
            d = 1
        else:
            d += 1
    elif m == 2:
        if d == 28:
            m = 3
            d = 1
        else:
            d += 1
    elif m == 3:
        if d == 31:
            m = 4
            d = 1
        else:
            d += 1
    elif m == 4:
        if d == 30:
            m = 5
            d = 1
        else:
            d += 1
    elif m == 5:
        if d == 31:
            m = 6
            d = 1
        else:
            d += 1
    elif m == 6:
        if d == 30:
            m = 7
            d = 1
        else:
            d += 1
    elif m == 7:
        if d == 31:
            m = 8
            d = 1
        else:
            d += 1
    elif m == 8:
        if d == 31:
            m = 9
            d = 1
        else:
            d += 1
    elif m == 9:
        if d == 30:
            m = 10
            d = 1
        else:
            d += 1
    elif m == 10:
        if d == 31:
            m = 11
            d = 1
        else:
            d += 1
    elif m == 11:
        if d == 30:
            m = 12
            d = 1
        else:
            d += 1
    elif m == 12:
        if d == 31:
            m = 1
            d = 1
            y += 1
        else:
            d += 1

    return d, m, y
    t2 = time()

    # Set parameters for super pixel kernel
    spxl_out = np.zeros((1920 / 32) * (1080 / 30), dtype=int)
    spxl_out_gpu = gpuarray.to_gpu(spxl_out)
    
    # Run super pixel kernel
    
    ################################
    # CHOOSE A KERNEL TO RUN BELOW #
    ################################
    # run_super_pixel(denoised_gpu, spxl_out_gpu, block=(32, 30, 1), grid=(1920 / 32, 1080 / 30))
    run_super_pixel_r(denoised_gpu, spxl_out_gpu, block=(32, 1, 1), grid=(1920 / 32, 1080 / 30))

    t3 = time()
    result = spxl_out_gpu.get()
    output = coordinates(result)
    
    time_array.append(t3 - t0)
    time_array_rga.append(t1 - t0)
    time_array_min.append(t2 - t1)
    time_array_sup.append(t3 - t2)

    # Save image
    draw_and_save(output, image_number)

print "Per frame processing time: ", np.mean(time_array)
print "Per frame rga time: ", np.mean(time_array_rga)
print "Per frame min_filt time: ", np.mean(time_array_min)
print "Per frame superpixel time: ", np.mean(time_array_sup)
Example #7
0
 def f (group):  
     codigo = group.codigo
     lat, lng = coordinates(codigo)
     (group['latitude'],group['longitude']) = lat,lng   
     return group       
Example #8
0
 def __init__(self, width=1, height=1, var=1, rel_density = 0):
     self.loc = coordinates()                # center of city
     self.loc.gen_city_loc(width, height)    # center of city
     self.var = var                          # variance of population distribution
     self.rel_density = rel_density          # relative density, should be a % of the total population
Example #9
0
 def __init__(self, sysTime):
     self.astro = coordinates(sysTime)
Example #10
0
 def loadCoordinates(self, path=None, prefix=None):
     self.coords = coordinates.coordinates(path, prefix)
    # Save output from RGA
    # misc.imsave("cs205_images/mu_stack/mu_{}.jpeg".format(image_number), mu)
    # misc.imsave("cs205_images/sig2_stack/sig2_{}.jpeg".format(image_number), sig2)
    # misc.imsave("cs205_images/cont_output/cont_{}.jpeg".format(image_number), OUT)

    # Apply 3x3 minimum filter
    filt_out = min_filter(OUT, iterations=1)
    t2 = time()

    # Save output from 3x3 minimum filter
    # misc.imsave("cs205_images/filtered_output/filt_{}.jpeg".format(image_number), filt_out)

    # Aggregate into superpixels and flag anomalous behavior
    superpixel_output = super_pixel(filt_out, 12.5 * 700, r0, r1)
    t3 = time()
    output = coordinates(superpixel_output)

    # Track how much time each module took.
    time_array.append(t3 - t0)
    time_array_rga.append(t1 - t0)
    time_array_min.append(t2 - t1)
    time_array_sup.append(t3 - t2)

    #############################
    # OVERLAY ANOMALOUS REGIONS #
    #############################

    im = Image.open(home + '/../thouis/miscreants/{}.png'.format(image_number))
    draw = ImageDraw.Draw(im)
    numAnom = len(output)
    
Example #12
0
                messageSize, messageType, messageTime, destRightAscension, destDeclination = struct.unpack(
                    "<hhqIi", data)
                logging.info("Received Message Size: %d", messageSize)
                logging.info("Received Message Type: %d", messageType)
                logging.info("Received Message Time: %d", messageTime)
                logging.info("Destination Right Ascension: %d",
                             destRightAscension)
                logging.info("Destination Declination: %d", destDeclination)

                sense = SenseHat()
                [yaw, roll, pitch] = sense.get_orientation_degrees().values()
                logging.info("pitch: %s", pitch)
                logging.debug("roll: %s", roll)
                logging.info("yaw: %s", yaw)

                coords = coordinates(datetime.utcnow())
                [Ra, Dec] = coords.getRaDec(yaw, pitch)
                logging.info(
                    "Right Ascension. Degrees: %s. Radians: %s. Hours: %s",
                    Ra.d, Ra.r, Ra.h)
                logging.info(
                    "Declination. Degrees: %s. Radians: %s. Hours: %s", Dec.d,
                    Dec.r, Dec.h)

                [RaInt, DecInt] = angleToStellarium(Ra, Dec)
                #"<hhqIi"
                sendbackdata = struct.pack("3iIii", 24, 0, time.time(), RaInt,
                                           DecInt, 0)
                for x in range(10):
                    connection.send(sendbackdata)
Example #13
0
    furniture17 = [
        "carpet17", "dinner_table17", "first_chair17", "second_chair17",
        "third_chair17", "fourth_chair17", "gimble17", "painting1_17",
        "painting2_17", "frame1_17", "frame2_17", "painting3_17", "frame3_17",
        "book1_17", "cover1_17", "candle1_17", "candle2_17", "Walls17"
    ]
    cursor = database.cursor()

    # if the database is empty, create five tables for each object
    cursor.execute(
        "SELECT COUNT(DISTINCT `table_name`) FROM `information_schema`.`columns` WHERE `table_schema` = "
        "'blender'")
    data = cursor.fetchone()

    if data[0] == 0:
        for obj in bpy.data.collections['Furniture13'].objects:
            material.material(obj, database, True)
        for obj in bpy.data.collections['Furniture17'].objects:
            material.material(obj, database, True)
        for obj in bpy.data.collections['Furniture13'].objects:
            edges_vertices_faces.edges_vertices_faces(obj, database, True)
        for obj in bpy.data.collections['Furniture17'].objects:
            edges_vertices_faces.edges_vertices_faces(obj, database, True)
        for obj in bpy.data.collections['Furniture13'].objects:
            coordinates.coordinates(obj, database, True)
        for obj in bpy.data.collections['Furniture17'].objects:
            coordinates.coordinates(obj, database, True)
    print("All tables inserted")
    register()
    database.close()