def calculate_msd(): parameterFile = "parameters.json" parser = argparse.ArgumentParser() parser.add_argument("-d", "--directory", type=str, default="./", help="input directory") #parser.add_argument("-o", "--output", type=str, help="output directory") #parser.add_argument("-p", "--prefix", type=str, default="cornea",help="prefix for output file") parser.add_argument("-s", "--skip", type=int, default=1100, help="skip this many samples") parser.add_argument("-m", "--howmany", type=int, default=30, help="read this many samples") parser.add_argument("-t", "--step", type=int, default=4, help="step snapshots with this spacing in flow field") parser.add_argument("-a", "--average", type=int, default=5, help="average over these many samples in flow field") args = parser.parse_args() param = read_param_CAPMD.Param( p.paramsFromFile(capmd.Parameters(), parameterFile)) sheet = Dynamics(initype="fromCSV", param=param, datapath='output/', multiopt="many") skip = 0 step = 1 howmany = 500 sheet.readDataMany("CAPMD", skip, step, howmany, False, readtypes=[1]) sheet.validate_initialise() sheet.getMSD(False) plt.show() return 0
parser.add_argument("-c", "--conffile", type=str, default="plane_periodic.conf", help="configuration file") parser.add_argument("-d", "--directory", type=str, default="/home/sh18581/Documents/Dome/samos_check/periodic_test/data_phi_1/data_v0_0.01/data_nu_0.01/",help="input directory") parser.add_argument("-s", "--skip", type=int, default=300, help="skip this many samples") parser.add_argument("-m", "--howmany", type=int, default=500, help="read this many samples") parser.add_argument("-t", "--step", type=int, default=20, help="step snapshots with this spacing") parser.add_argument("-o", "--outfile", type=str, default="correlations.p", help="pickle file name") args = parser.parse_args() # Choose to show as plots as well: plotall = True # Use the Configuration constructor in its readCSV format to generate the topology # fromCSV(kwargs["parampath"],kwargs["datapath"],kwargs["multiopt"]) parampath0 = args.directory + args.conffile param = Param(parampath0) Cells = Dynamics(initype="fromCSV",param=param,datapath=args.directory,multiopt="many") # Now read in as desired # def readDataMany(self,skip=0,step=1,howmany='all',Nvariable=False,readtypes = 'all'): Cells.readDataMany("SAMoS",args.skip,1,args.howmany,False,readtypes = 'all') Cells.validate_initialise() # Start collecting all of this in data dictionary data={'configuration':args.directory,'skip':args.skip,'howmany':args.howmany,'step':args.step} # 1st basic set of analyses # Will save as pickle file regardless # A - Velocity distributions and mean velocity # vav, vdist,vdist2 = getVelDist(self,bins,bins2,usetype='all',verbose=True): # Bins are in normalised units (by mean velocity)
def main(): ctrl = Controller() dyn = Dynamics()
class VideoStreamHandler(socketserver.StreamRequestHandler): command = Dynamics() identify_features = features() print("Video Server Active") def handle(self): global command global distance global previous_distance stream_bytes = b'' AEB = 0 try: while True: stream_bytes += self.rfile.read(1024) first = stream_bytes.find(b'\xff\xd8') last = stream_bytes.find(b'\xff\xd9') if first != -1 and last != -1: jpg = stream_bytes[first:last + 2] stream_bytes = stream_bytes[last + 2:] #read images in stream img = cv2.imdecode(np.frombuffer(jpg, dtype=np.uint8), cv2.IMREAD_COLOR) #Perspective Transform src = np.float32([[00, 100], [320, 100], [-10, 150], [330, 150]]) dst = np.float32([[0, 0], [320, 0], [0, 240], [320, 240]]) M = cv2.getPerspectiveTransform(src, dst) image = cv2.warpPerspective(img, M, (320, 240)) #Image Processing -Identify Features img, image, stop, average_heading, sigFlag, carFlag = self.identify_features.haar( img, image) #Display Processed Images and views cv2.imshow('Feild Of View', img) cv2.imshow('Birds Eye', image) #img #HC-SR04 distance data a = (previous_distance + distance) / 2 b = previous_distance - distance if distance < 25: #Object under threshold distance AEB = 1 #Emergency Brakes Flag else: AEB = 0 if cv2.waitKey(3) & 0xFF == ord('q'): break if sigFlag == 0: # Signal is Green #Set Lane Departure limits if ((average_heading < 150) and (stop == 0)) and AEB == 0: print("Turn left") self.command.fleft() elif ((average_heading > 170) and (stop == 0)) and AEB == 0: print("Turn right") self.command.fright() elif ((170 >= average_heading >= 150) and (stop == 0)) and AEB == 0: print("In lane") self.command.forward() elif stop == 1: print("BRAKES ACTIVE due to Stop sign") self.command.brake() elif AEB == 1: self.command.brake() if carFlag == 1: #If car spotted print("Car Ahead at " + str(distance) + " cm") else: print( "Obstacle Ahead!, Emergency Brakes Active") else: pass elif sigFlag == 1: # Signal is Red pass print("Signal Red, waiting to turn Green...") self.command.brake() finally: cv2.destroyAllWindows() self.command.halt() self.command.closeconn() sys.exit()