def dlg_button_szr_packer(butt_szr, parent): butt_szr.wxClass.__init__(butt_szr, parent, *butt_szr._args) cb = butt_szr.callback if cb: child_sizer = butt_szr.GetChildren()[0].GetSizer() buttons = [c.GetWindow() for c in child_sizer.GetChildren() if c.IsWindow()] for event in butt_szr.events: for butt in buttons: event(butt, cb)
def run(self, path): if not self.validate(path): return False print "--analysis[%i]: working on '%s' " % (os.getpid(), self.path) # loop through events eventcounter = 1 for pfile, xfile in zip( glob.glob(os.path.join(self.path, "particle_file*")), glob.glob(os.path.join(self.path, "DAT*.long"))): if eventcounter % 100 == 0: print "--analysis[%i]: at event %i" % (os.getpid(), eventcounter) pass # create event ev = event() ev.particles_from_file(pfile) ev.xmax_from_file(xfile) # analyse event for analysis in self.analysis: analysis.analyse(ev) pass if eventcounter >= self.options.nevents: break del ev eventcounter += 1 pass print "--analysis[%i]: analysed %i events" % (os.getpid(), eventcounter) self.finalize() return True
def addevent(self,anevent): """ add event - anevent is talkweb.ui.xevent or talkweb.ui.event """ evt = type(anevent) if evt is type(event()): #if type(self.events) is not list: #self.events = [] self.events.append(anevent) elif evt is type(xevent()): self.events = anevent self.events.setcell(self)
def clone(self): """ do not use """ ##@rewrite dirty - we need satype abstract clone not everybody do this ... copyofevents=None evt = type(self.events) if evt is type(event()): copyofevents=[] for anevent in self.events: copyofevents.append(anevent.clone()) elif evt is type(xevent()): copyofevents=self.events.clone() return cell(self.data,self.datatype,self.css,copyofevents,self.id)
def plot0(evline): global savedir # --------------------------------------------------------------------------- # ------------------------------------------------- Grab and Check Event Data # --------------------------------------------------------------------------- # Based on the event record, create an event object. Make sure it's ok. probe, date, time = evline.split() ev = event(probe=probe, date=date, time=time, mins=60) if not ev.isok(): print 'SKIPPING ' + ev.name + ' DUE TO BAD DATA. ' return False # --------------------------------------------------------------------------- # -------------------------------------------------------- Set Up Plot Window # --------------------------------------------------------------------------- PW = plotWindow(nrows=3, ncols=-2) title = ev.label() rowlabels = ( notex('Poloidal'), notex('Toroidal'), notex('Parallel') ) PW.setParams(title=title, rowlabels=rowlabels) # --------------------------------------------------------------------------- # ------------------------------------------------- Add Waveforms and Spectra # --------------------------------------------------------------------------- # Index the poloidal, toroidal, and field-aligned modes. modes = ('p', 't', 'z') # Plot waveforms. PW.setParams( **ev.coords('t', 'b') ) [ PW[i].setLine(ev.get('B' + m), 'r') for i, m in enumerate(modes) ] [ PW[i].setLine(ev.get('E' + m), 'b') for i, m in enumerate(modes) ] # --------------------------------------------------------------------------- # ----------------------------------------------------------- Create the Plot # --------------------------------------------------------------------------- if '-i' not in argv: print 'Plotting ' + ev.name return PW.render() else: if not os.path.exists(savedir): os.mkdir(savedir) return not PW.render(savedir + ev.name + '.png')
def __init__( self , inputFile = "internalChargeInjection_00A.txt" , fiber_ = 4): self.data = [] self.eventList = [] self.fiber = fiber_ keep = False dataFile = open("internalChargeInjection_00A.txt") for line in dataFile : if line[0:-1] == "" and keep : keep = False self.eventList.append( event( self.data ) ) self.data = [] if keep : self.data.append( line[8:19] ) if line.find("Reading Fiber:"+str(self.fiber) ) != -1 : keep = True
def prepare_pulling_out(self, curr_vehicle): # if self.curr >= 9773. and curr_vehicle.stop == 2: # import pdb; pdb.set_trace() stop = curr_vehicle.stop assert self.inservice[curr_vehicle.stop_idx - 1] == curr_vehicle if curr_vehicle.status < 4: first_attempt = True else: first_attempt = False if self.first_service is None: self.first_service = self.curr first_attempt = False if curr_vehicle.idx == VEHICLE_IDX: delay_reason = None delay_status = None delay_speed = None delayed, req_time, prev, delay_reason, delay_status, delay_speed = self.check_lane_zero_short(curr_vehicle, first_attempt, delay_reason, delay_status, delay_speed) else: delayed, req_time, prev = self.check_lane_zero_short(curr_vehicle, first_attempt) if delayed: if not req_time > self.curr: import pdb; pdb.set_trace() curr_vehicle.status = 4 curr_vehicle.end_time = req_time self.add_event( event( curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) return if curr_vehicle.status == 4 and self.eventheap != []: broken = False heap_len = len(self.eventheap) event_holder = [] while self.eventheap != []: next_event = heappop(self.eventheap) heappush(event_holder, next_event) if next_event.time > self.curr + 1e-05: break if next_event.typ == 'prepare_pulling_out' and curr_vehicle.stop_idx < next_event.vehicle.stop_idx: if next_event.time <= self.curr: import pdb; pdb.set_trace() curr_vehicle.end_time = next_event.time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) broken = True break elif spmatch and next_event.typ == 'enter_system' and stop <= g_out + 1: assert self.waiting != [] if not free_curb: next_spot = - min(self.waiting) else: next_spot = min(self.waiting) if idx2spot(next_spot) >= curr_vehicle.stop - 1: if (self.inservice[next_spot - 1] is not None) and (self.inservice[next_spot - 1].pout_start > self.curr - 1e-03) and (self.inservice[next_spot - 1].pout_start != self.inservice[next_spot - 1].serv_end): import pdb; pdb.set_trace() curr_vehicle.end_time = next_event.time + 1e-9 self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) broken = True break for event_visited in event_holder: self.add_event( event_visited ) if broken: assert heap_len + 1 == len(self.eventheap) return assert heap_len == len(self.eventheap) if spmatch and self.eventheap != []: broken = False heap_len = len(self.eventheap) event_holder = [] first_service = self.first_service if self.first_service is None: first_service = self.curr while self.eventheap != []: next_event = heappop(self.eventheap) heappush(event_holder, next_event) if curr_vehicle.status == 3 and next_event.time > self.curr + meanDRIV - (self.curr - first_service) % meanDRIV - 0.9 * SMALL_INTERVAL: break if curr_vehicle.status > 3 and next_event.time > self.curr + meanDRIV - SMALL_INTERVAL: break if next_event.typ == 'prepare_pulling_out' and next_event.vehicle.stop == stop + 1 and next_event.vehicle.status == 3 and (not self.check_lane_zero_short(next_event.vehicle, True, curr_time = next_event.time)[0]): if curr_vehicle.status == 3: curr_vehicle.status == 3.5 curr_vehicle.end_time = next_event.time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) broken = True break for event_visited in event_holder: self.add_event( event_visited ) if broken: assert heap_len + 1 == len(self.eventheap) return assert heap_len == len(self.eventheap) # this is an optional check and only applies to double-sided design if spmatch and side == 'double' and self.eventheap != []: broken = False heap_len = len(self.eventheap) event_holder = [] first_service = self.first_service if self.first_service is None: first_service = self.curr while self.eventheap != []: next_event = heappop(self.eventheap) heappush(event_holder, next_event) if curr_vehicle.status == 3 and next_event.time > self.curr + meanDRIV - (self.curr - first_service) % meanDRIV - 0.9 * SMALL_INTERVAL: break if curr_vehicle.status > 3 and next_event.time > self.curr + meanDRIV - SMALL_INTERVAL: break if curr_vehicle.stop == next_event.vehicle.stop and curr_vehicle.stop_idx < next_event.vehicle.stop_idx: assert curr_vehicle.stop_idx + 1 == next_event.vehicle.stop_idx if curr_vehicle.status == 3 and next_event.typ == 'prepare_pulling_out': curr_vehicle.status = 4 curr_vehicle.end_time = self.curr + meanDRIV - (self.curr - first_service) % meanDRIV self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) broken = True break if curr_vehicle.status == 4 and (next_event.typ == 'prepare_pulling_out' and (next_event.vehicle.status == 3 or 0 <= next_event.time - self.curr < 100 * SMALL_INTERVAL)): curr_vehicle.end_time = self.curr + meanDRIV self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) broken = True break # if curr_vehicle.status == 4 and next_event.typ == 'start_service' and 0 <= next_event.time - self.curr < 100 * SMALL_INTERVAL: # curr_vehicle.end_time = next_event.time + 1e-9 # self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) # broken = True # break # if control == 'full' and curr_vehicle.stop_idx == 2 and next_event.typ == 'enter_system' and self.waiting != [] and (- min(self.waiting)) == 1: # curr_vehicle.end_time = next_event.time + 1e-9 # self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out') ) # broken = True # break for event_visited in event_holder: self.add_event( event_visited ) if broken: assert heap_len + 1 == len(self.eventheap) return assert heap_len == len(self.eventheap) if spmatch and first_attempt: est_pout_start = curr_vehicle.serv_end elif spmatch and ( (self.curr - self.first_service) % meanDRIV > 1e-03 and meanDRIV - (self.curr - self.first_service) % meanDRIV > 1e-03): # if self.inservice[stop] is not None and self.inservice[stop].status == 4: # import pdb; pdb.set_trace() est_pout_start = self.curr - (self.curr - self.first_service) % meanDRIV else: est_pout_start = self.curr # Now, the current vehicle is ready to start the exit maneuver curr_vehicle.status = 4 curr_vehicle.prev = prev if prev != None: curr_vehicle.nex = prev.nex try: prev.nex.prev = curr_vehicle except: pass prev.nex = curr_vehicle elif self.head != None: self.head.prev = curr_vehicle curr_vehicle.nex = self.head self.head = curr_vehicle else: self.head = curr_vehicle if spmatch and first_attempt and meanDRIV - (curr_vehicle.serv_end - self.first_service) % meanDRIV > SMALL_INTERVAL: assert simType == 'cav' assert curr_vehicle.status == 4 curr_vehicle.status = 5 curr_vehicle.curr_loc = curr_vehicle.stop * LOT_LENGTH curr_vehicle.dest_to_stop = self.n + CAR_LENGTH curr_vehicle.pout_start = curr_vehicle.serv_end curr_vehicle.pout_time = self.timePOUT.next() - (curr_vehicle.serv_end - self.first_service) % meanDRIV curr_vehicle.pout_end = curr_vehicle.pout_time + curr_vehicle.pout_start curr_vehicle.prod_time += curr_vehicle.pout_time curr_vehicle.update_traj() elif spmatch and est_pout_start != self.curr: assert simType == 'cav' assert curr_vehicle.status == 4 curr_vehicle.status = 5 curr_vehicle.curr_loc = curr_vehicle.stop * LOT_LENGTH curr_vehicle.dest_to_stop = self.n + CAR_LENGTH curr_vehicle.pout_start = est_pout_start curr_vehicle.pout_time = self.timePOUT.next() curr_vehicle.pout_end = curr_vehicle.pout_time + curr_vehicle.pout_start curr_vehicle.prod_time += curr_vehicle.pout_time curr_vehicle.update_traj() else: curr_vehicle.start_out() assert curr_vehicle.pout_end > self.curr self.add_event( event( curr_vehicle.pout_end, curr_vehicle, 'finish_pulling_out') ) # and we update the trajectories of all upcoming vehicles if curr_vehicle.nex is not None: car = curr_vehicle.nex if car.after_plin: if not (prev is not None and prev.status == 2): import pdb; pdb.set_trace() car.after_plin = False while car != None: car.update_loc() car.update_traj() car = car.nex # lastly we schedule the replacement vehicles new_vehicle = vehicle(self) if spmatch: assert simType == 'cav' enter_time = self.curr + meanDRIV if self.curr == curr_vehicle.serv_end or (first_attempt and meanDRIV - (curr_vehicle.serv_end - self.first_service) % meanDRIV > SMALL_INTERVAL): enter_time = curr_vehicle.serv_end + meanDRIV - (curr_vehicle.serv_end - self.first_service) % meanDRIV if control == 'full': if spot2blk(stop) <= m_out: enter_time += meanDRIV * (m_out + 1 - spot2blk(stop)) enter_time = self.check_enter_zero_short(enter_time, curr_vehicle.stop) self.add_event( event(enter_time - 100 * SMALL_INTERVAL, curr_vehicle, 'add_stop_idx') ) self.add_event( event(enter_time, new_vehicle, 'enter_system') ) else: self.add_event( event( self.curr, new_vehicle, 'enter_system') ) if not free_curb: heappush( self.waiting, (- curr_vehicle.stop_idx) ) else: heappush( self.waiting, curr_vehicle.stop_idx ) return
def prepare_pulling_out(self, curr_vehicle): stop = curr_vehicle.stop assert self.inservice[curr_vehicle.stop_idx - 1] == curr_vehicle if curr_vehicle.status == 3: curr_vehicle.status = 4 first_attempt = True else: first_attempt = False assert curr_vehicle.status == 4 if self.first_service is None: self.first_service = self.curr first_attempt = False if curr_vehicle.idx == VEHICLE_IDX: delay_reason = None delay_status = None delay_speed = None req_time = self.curr # Firstly, check if any vehicles in the neighborhood have started their exit maneuvers # or have not finished their enter maneuvers for k in in_range(curr_vehicle.stop_idx, self.N): if (self.inservice[k - 1] is not None) and (self.inservice[k - 1].status == 2): # if curr_vehicle.idx == VEHICLE_IDX and self.inservice[k - 1].plin_end - min(meanDRIV, max(0, self.inservice[k - 1].plin_time - .5)) > req_time: # delay_reason = 1 # delay_status = 2 # req_time = max( req_time, self.inservice[k - 1].plin_end - min(meanDRIV, max(0, self.inservice[k - 1].plin_time - .5)) ) if curr_vehicle.idx == VEHICLE_IDX and self.inservice[ k - 1].plin_end > req_time: delay_reason = 1 delay_status = 2 req_time = max(req_time, self.inservice[k - 1].plin_end) for k in out_range(curr_vehicle.stop_idx, self.N): if (self.inservice[k - 1] is not None) and (self.inservice[k - 1].status == 5): if curr_vehicle.idx == VEHICLE_IDX and self.inservice[ k - 1].pout_end > req_time: delay_reason = 1 delay_status = 5 req_time = max(req_time, self.inservice[k - 1].pout_end) if req_time > self.curr: curr_vehicle.end_time = req_time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out')) if curr_vehicle.idx == VEHICLE_IDX: self.debug_times.append( tuple((delay_reason, delay_status, req_time))) assert delay_reason != 5 return # Lastly, check if any vehicles are traveling on the through lane, # s.t. the exit maneuver of the current vehicle will be blocked or block the movements of the existing vehicles assert req_time == self.curr if curr_vehicle.idx == VEHICLE_IDX: delayed, req_time, prev, delay_reason, delay_status, delay_speed = self.check_lane_short( curr_vehicle, first_attempt, delay_reason, delay_status, delay_speed) else: delayed, req_time, prev = self.check_lane_short( curr_vehicle, first_attempt) if delayed: if not req_time > self.curr: import pdb pdb.set_trace() curr_vehicle.end_time = req_time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out')) if curr_vehicle.idx == VEHICLE_IDX: self.debug_times.append( tuple((delay_reason, delay_status, req_time))) if delay_reason == 5: assert delay_speed is not None self.debug_speed.append(delay_speed) return # Now, the current vehicle is ready to start the exit maneuver curr_vehicle.prev = prev if prev != None: curr_vehicle.nex = prev.nex try: prev.nex.prev = curr_vehicle except: pass prev.nex = curr_vehicle elif self.head != None: self.head.prev = curr_vehicle curr_vehicle.nex = self.head self.head = curr_vehicle else: self.head = curr_vehicle curr_vehicle.start_out() if spmatch and first_attempt and meanDRIV - ( self.curr - self.first_service) % meanDRIV > SMALL_INTERVAL: assert simType == 'cav' assert curr_vehicle.pout_time == meanPOUT curr_vehicle.pout_time -= (self.curr - self.first_service) % meanDRIV curr_vehicle.pout_end = curr_vehicle.pout_time + curr_vehicle.pout_start curr_vehicle.prod_time -= (self.curr - self.first_service) % meanDRIV curr_vehicle.update_traj() assert curr_vehicle.pout_end > self.curr self.add_event( event(curr_vehicle.pout_end, curr_vehicle, 'finish_pulling_out')) # and we update the trajectories of all upcoming vehicles car = curr_vehicle.nex while car != None: car.update_loc() car.update_traj() car = car.nex # lastly we schedule the replacement vehicles new_vehicle = vehicle(self) if spmatch: if first_attempt and meanDRIV - (self.curr - self.first_service ) % meanDRIV > SMALL_INTERVAL: assert simType == 'cav' self.add_event( event( self.curr + meanDRIV - (self.curr - self.first_service) % meanDRIV, new_vehicle, 'enter_system')) else: self.add_event( event(self.curr + meanDRIV, new_vehicle, 'enter_system')) else: self.add_event(event(self.curr, new_vehicle, 'enter_system')) heappush(self.waiting, (-curr_vehicle.stop_idx)) return
def start_pulling_in(self, curr_vehicle): curr_vehicle.update_loc() if np.abs(curr_vehicle.curr_loc - curr_vehicle.dest_to_stop) > 1e-5: if curr_vehicle.end_time <= self.curr + SMALL_INTERVAL: import pdb pdb.set_trace() self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_pulling_in')) return curr_vehicle.curr_loc = curr_vehicle.dest_to_stop delayed = False req_time = self.curr ################################################# 0-degree Short Specific ################################################# # if the vehicle has arrived at the desired destination while its enter maneuver blocked by vehicles on the through lane # i.e. 1) if its immediate proceeding vehicle is having an exit maneuver at the spot in front # if (curr_vehicle.prev is not None) and (curr_vehicle.prev.stop == curr_vehicle.stop + 1) and (curr_vehicle.prev.status == 5): # assert curr_vehicle.prev.pout_end > self.curr # delayed = True # req_time = max( req_time, curr_vehicle.prev.pout_end ) # or 2) if the immediate proceeding vehicle is stopped, or having an enter maneuver into the spot in front. # if (curr_vehicle.prev is not None) and (curr_vehicle.status not in [2, 5]) and (curr_vehicle.prev.curr_loc <= curr_vehicle.dest_to_stop + 1.5 * CAR_LENGTH): # cp = curr_vehicle.prev.traj.head # if cp.data.t > self.curr: # if cp.data.t <= self.curr + 2 * SMALL_INTERVAL: # delayed = True # req_time = max( req_time, cp.data.t ) # else: # import pdb; pdb.set_trace() # else: # while (cp.nex is not None) and (cp.nex.data.t <= self.curr): # cp = cp.nex # assert cp is not None # if (cp.data.v == 0.0): # assert cp.nex.data.t > self.curr # delayed = True # req_time = max( req_time, cp.nex.data.t ) # else: # assert curr_vehicle.prev.status != 2 ########################################################################################################################### if delayed: assert req_time > self.curr curr_vehicle.traj = DLinkedList() curr_vehicle.traj.addEnd( changePoint(curr_vehicle.dest_to_stop, self.curr, 0.0)) curr_vehicle.traj.addEnd( changePoint(curr_vehicle.dest_to_stop, req_time, 'D')) curr_vehicle.end_time = req_time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_pulling_in')) car = curr_vehicle.nex while car is not None: car.update_loc() car.update_traj() car = car.nex return assert self.inservice[curr_vehicle.stop_idx - 1] is None self.inservice[curr_vehicle.stop_idx - 1] = curr_vehicle curr_vehicle.start_in() car = curr_vehicle.nex while car != None: car.update_loc() car.update_traj() car = car.nex assert curr_vehicle.end_time is not None self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_service')) return
def where(): # What range of lshell values do we want to look at? lmin, lmax = 5.6, 6.5 # Pick a random date and probe. We don't benefit from looping over them all, # since they are not randomly distributed in time. date = choice( ulist( line.split()[1] for line in read('events.txt') ) ) probe = choice( ('a', 'b') ) # Grab the data. If the lshell values are bad, reroll. ev = event(probe=probe, date=date) if not np.all( np.isfinite(ev.lshell) ): print probe, date, ' X' return where() # The orbit is about nine hours. If we pick the largest value between 09:00 # and 15:00, that should be near apogee for an orbit that does not cross # midnight in either direction. ibuff = int(ev.t.size*9./24) iapo = ibuff + np.argmax( ev.lshell[ibuff:-ibuff] ) # Find the minimum in the 9 hours before the perigee. iper0 = np.argmin( ev.lshell[iapo - ibuff:iapo] ) + (iapo - ibuff) iper1 = np.argmin( ev.lshell[iapo:iapo + ibuff] ) + iapo # Get the actual apogee. iapo = np.argmax( ev.lshell[iper0:iper1] ) + iper0 # What fraction of this orbit is spent between lmin and lmax? Assume time # steps of uniform size. ttotal = ev.t[iper1] - ev.t[iper0] inrange = ( ev.lshell > lmin )*( ev.lshell < lmax ) pinrange = np.sum( inrange[iper0:iper1] )*1./(iper1 - iper0) tinrange = ttotal*pinrange # Just use Matplotlib for now. We can clean it up later if necessary. ''' PW = plotWindow() PW.setLine(ev.t, ev.lshell, 'k') [ PW.setLine( np.ones(ev.t.shape)*lval, 'r:' ) for lval in (lmin, lmax) ] PW.render() ''' # Plot the probe's path. plt.plot(ev.t, ev.lshell, 'k') # Indicate prime lshell values for seeing giant pulsations. plt.plot(ev.t, np.ones(ev.t.shape)*lmin, 'r:') plt.plot(ev.t, np.ones(ev.t.shape)*lmax, 'r:') # Indicate the orbit we're tallying. plt.plot(np.ones(100)*ev.t[iper0], np.linspace(0, 7, 100), 'g:') plt.plot(np.ones(100)*ev.t[iper1], np.linspace(0, 7, 100), 'g:') # Give numbers for the orbit duration and how long is spent in Pg range. plt.gca().text(s=timestr(tinrange)[1][:5] + ' (' + format(100*pinrange, '.0f') + '%)' + ' with ' + str(lmin) + ' < L < ' + str(lmax) , x=ev.t[iapo], y=0.5*(lmin + lmax), horizontalalignment='center') plt.gca().text(s=timestr( ev.t[iper1] - ev.t[iper0] )[1][:5] + ' Orbit Time', x=0.5*( ev.t[iper0] + ev.t[iper1] ), y=1, horizontalalignment='center') # Clean up the plot a little bit. plt.gca().set_xlim( [0, 86400] ) plt.gca().set_ylim( [0, 7] ) return plt.show()
def prepare_pulling_out(self, curr_vehicle): stop = curr_vehicle.stop assert self.inservice[curr_vehicle.stop_idx - 1] == curr_vehicle if curr_vehicle.status < 4: first_attempt = True else: first_attempt = False if self.first_service is None: self.first_service = self.curr first_attempt = False if curr_vehicle.idx == VEHICLE_IDX: delay_reason = None delay_status = None delay_speed = None delayed, req_time, prev, delay_reason, delay_status, delay_speed = self.check_lane_zero_short( curr_vehicle, first_attempt, delay_reason, delay_status, delay_speed) else: delayed, req_time, prev = self.check_lane_zero_short( curr_vehicle, first_attempt) if delayed: if not req_time > self.curr: import pdb pdb.set_trace() curr_vehicle.status = 4 curr_vehicle.end_time = req_time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out')) return if curr_vehicle.status == 4 and self.eventheap != []: broken = False heap_len = len(self.eventheap) event_holder = [] while self.eventheap != []: next_event = heappop(self.eventheap) heappush(event_holder, next_event) if next_event.time > self.curr + 1e-05: break if next_event.typ == 'prepare_pulling_out' and curr_vehicle.stop_idx < next_event.vehicle.stop_idx: if next_event.time <= self.curr: import pdb pdb.set_trace() curr_vehicle.end_time = next_event.time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'prepare_pulling_out')) broken = True break for event_visited in event_holder: self.add_event(event_visited) if broken: assert heap_len + 1 == len(self.eventheap) return assert heap_len == len(self.eventheap) # Now, the current vehicle is ready to start the exit maneuver est_pout_start = self.curr curr_vehicle.status = 4 curr_vehicle.prev = prev if prev != None: curr_vehicle.nex = prev.nex try: prev.nex.prev = curr_vehicle except: pass prev.nex = curr_vehicle elif self.head != None: self.head.prev = curr_vehicle curr_vehicle.nex = self.head self.head = curr_vehicle else: self.head = curr_vehicle curr_vehicle.start_out() assert curr_vehicle.pout_end > self.curr self.add_event( event(curr_vehicle.pout_end, curr_vehicle, 'finish_pulling_out')) # and we update the trajectories of all upcoming vehicles if curr_vehicle.nex is not None: car = curr_vehicle.nex if car.after_plin: if not (prev is not None and prev.status == 2): import pdb pdb.set_trace() car.after_plin = False while car != None: car.update_loc() car.update_traj() car = car.nex # lastly we schedule the replacement vehicles new_vehicle = vehicle(self) self.add_event(event(self.curr, new_vehicle, 'enter_system')) if not free_curb: heappush(self.waiting, (-curr_vehicle.stop_idx)) else: heappush(self.waiting, curr_vehicle.stop_idx) return
def plot1(evline): global savedir # # Force it to use a nice event. # evline = 'a\t2014-05-02\t10:10:00' # --------------------------------------------------------------------------- # ------------------------------------------------- Grab and Check Event Data # --------------------------------------------------------------------------- # Based on the event record, create an event object. Make sure it's ok. probe, date, time = evline.split() ev = event(probe=probe, date=date, time=time) if not ev.isok(): print 'SKIPPING ' + ev.name + ' DUE TO BAD DATA. ' return False # --------------------------------------------------------------------------- # -------------------------------------------------------- Set Up Plot Window # --------------------------------------------------------------------------- # Create a plot window to look at both probes at the same time -- both the # waveforms and the spectra. PW = plotWindow(nrows=3, ncols=2) # Set the title and labels. title = notex( 'RBSP-' + probe.upper() + ' on ' + date + ' from ' + notex( timestr(ev.t0)[1][:5] ) + ' to ' + notex( timestr(ev.t1)[1][:5] ) ) rowlabels = ( notex('Poloidal'), notex('Toroidal'), notex('Parallel') ) collabels = ( notex('B (Red) ; E (Blue)'), notex('Coh. (Black) ; CSD (Green) ; Par. (Violet)') ) PW.setParams(title=title, collabels=collabels, rowlabels=rowlabels) # --------------------------------------------------------------------------- # ------------------------------------------------- Add Waveforms and Spectra # --------------------------------------------------------------------------- # Index the poloidal, toroidal, and field-aligned modes. modes = ('p', 't', 'z') # Plot waveforms. PW[:, 0].setParams( **ev.coords('t', 'b', cramped=True) ) [ PW[i, 0].setLine(ev.get('B' + m), 'r') for i, m in enumerate(modes) ] [ PW[i, 0].setLine(ev.get('E' + m), 'b') for i, m in enumerate(modes) ] # Plot coherence. PW[:, 1].setParams( **ev.coords('f', 'c', cramped=True) ) [ PW[i, 1].setLine( ev.csd(m), 'g' ) for i, m in enumerate(modes) ] [ PW[i, 1].setLine( ev.coh(m), 'k' ) for i, m in enumerate(modes) ] [ PW[i, 1].setLine( 0.1 + 0.8*ev.isodd(m), 'm' ) for i, m in enumerate(modes) ] # --------------------------------------------------------------------------- # -------------------------------------------------------------- Screen Event # --------------------------------------------------------------------------- # Let's keep track of all the strong waves we find. waves = [] # Only look at the poloidal mode. Ignore any components of the spectra that # are not coherent or not spectrally dense. for m in modes[:1]: mname = {'p':'Poloidal', 't':'Toroidal', 'z':'Parallel'}[m] # Find any harmonics worth talking about. # harm = ev.harm(m)*ev.iscoh(m)*ev.iscsd(m)*ev.ispc4()*ev.has('Ey') harm = ev.harm(m)*ev.iscoh(m)*ev.ispc4()*ev.has('Bx')*ev.has('Ey') for i in np.nonzero(harm==1)[0]: # for i in np.nonzero(harm)[0]: waves.append( {'strength':ev.coh(m)[i]*ev.csd(m)[i], 'frequency':ev.frq()[i], 'harmonic': harm[i], 'lag':ev.lag(m)[i], 'mode':mname, 'mlt':ev.avg('mlt'), 'lpp':ev.lpp, 'va':ev.va(m)[i], 'mlat':ev.avg('mlat'), 'lshell':ev.avg('lshell'), 'compression':ev.comp()[i] } ) if len(waves) == 0: print 'SKIPPING ' + ev.name + ' DUE TO NO SUITABLE MODES. ' # return False # print 'CSD magnitudes: ' # for c in ev.csd('p'): # print '\t', c # print 'FFT frequencies... note that there are twice as many compared to the CSD' # for x in ev.fft('Ep'): # print '\t', np.abs(x) print 'root unnormalized autospectral densities. ' print 'freq\tBx ASD\tBx FFT\tEy ASD\tEy FFT' for i in range(10): print format(ev.frq()[i], '5.1f') + '\t' + format(np.sqrt( ev.asd('Bx') )[i], '5.1f') + '\t' + format(np.abs( ev.fft('Bx') )[i], '5.1f') + '\t' + format(np.sqrt( ev.asd('Ey') )[i], '5.1f') + '\t' + format(np.abs( ev.fft('Ey') )[i], '5.1f') print 'max poloidal E, B' print '\t', np.max( ev.get('Ep') ), np.max( ev.get('Bp') ) sidelabels = [] for w in waves: sidelabels.append( format(w['frequency'], '.0f') + notex('mHz') + ' \\qquad ' + format(w['lag'], '+.0f') + '^\\circ' + ' \\qquad ' + ' | \\widetilde{B_z} / \\widetilde{B_x} | \\! = \\! ' + format(100*w['compression'], '.0f') + '\\% \\qquad ' + ' | \\widetilde{E_y} / \\widetilde{B_x} | \\! = \\! ' + format(1e3*w['va'], '.0f') + notex('km/s') ) PW.setParams( sidelabel=' $\n$ '.join( [ ev.label() ] + sidelabels) ) # --------------------------------------------------------------------------- # ----------------------------------------------------------- Create the Plot # --------------------------------------------------------------------------- if '-i' not in argv: print 'Plotting ' + ev.name return PW.render() else: if not os.path.exists(savedir): os.mkdir(savedir) return not PW.render(savedir + ev.name + '.png')
def plot2(evline): global savedir # # Force it to use a nice event. # evline = 'b\t2012-10-23\t19:40:00' # --------------------------------------------------------------------------- # ------------------------------------------------- Grab and Check Event Data # --------------------------------------------------------------------------- # Based on the event record, create a pair of event objects. probe, date, time = evline.split() ev = { 'a':event(probe='a', date=date, time=time), 'b':event(probe='b', date=date, time=time) } # If the events have flawed data, start over. if not ev['a'].isok() or not ev['b'].isok(): print 'SKIPPING ' + ev[probe].name + ' DUE TO BAD DATA. ' return False # --------------------------------------------------------------------------- # -------------------------------------------------------- Set Up Plot Window # --------------------------------------------------------------------------- # Create a plot window to look at both probes at the same time -- both the # waveforms and the spectra. PW = plotWindow(nrows=4, ncols=3) # Set the title and labels. Label the rows with probe position data. title = notex(probe.upper() + ' ' + date + ' ' + time) collabels = ( notex('Poloidal'), notex('Toroidal'), notex('Parallel') ) rowlabels = ( ev['a'].lab(), ev['b'].lab(), ev['a'].lab(), ev['b'].lab() ) PW.setParams(title=title, collabels=collabels, rowlabels=rowlabels) # --------------------------------------------------------------------------- # ----------------------------------------- Add Waveforms and Spectra to Plot # --------------------------------------------------------------------------- # Index all probe/mode combinations. pm = [ (p, m) for p in ('a', 'b') for m in ('p', 't', 'z') ] # For each probe and mode, compute coherence and (complex phase) lag. frq = [ ev[p].coh(m)[0] for p, m in pm ] coh = [ ev[p].coh(m)[1] for p, m in pm ] lag = [ ev[p].lag(m)[1] for p, m in pm ] # Iterate over the probe/mode combinations. for i, (p, m) in enumerate(pm): # Plot the fields. PW[i/3, i%3].setParams( **ev[p].coords('t', 'b', cramped=True) ) PW[i/3, i%3].setLine(ev[p].get('E' + m), 'b') PW[i/3, i%3].setLine(ev[p].get('B' + m), 'r') # Plot the spectra. Scale to the unit interval. PW[i/3 + 2, i%3].setParams( **ev[p].coords('f', 'c', cramped=True) ) PW[i/3 + 2, i%3].setLine( frq[i], coh[i], 'k') # PW[i/3 + 2, i%3].setLine( frq[i], lag[i]/360 + 0.5, 'g') # # Summarize the spectra. # fr, ph, pc = ev[p].fpp(m) # PW[i/3, i%3].setParams(text=fr + ' \\qquad ' + ph) # --------------------------------------------------------------------------- # -------------------------------------- Look for Fundamental Mode Pc4 Events # --------------------------------------------------------------------------- fundlabels = [] for i, f in enumerate( frq[0] ): # Fundamental FLRs should be around 10mHz. if not 6 < f < 20: continue # Find places where the coherence is significantly above average. iscoherent = np.array( [ c[i] > np.mean(c) + 2*np.std(c) for c in coh ] ) # In fundamental modes, mlat and phase lag have opposite signs. mlatsign = np.array( [ np.sign( ev[p].avg('mlat') ) for p, m in pm ] ) lagsign = np.array( [ np.sign( l[i] ) for l in lag ] ) # Skip anything within one degree of the magnetic equator. isoffeq = np.array( [ np.abs( ev[p].avg('mlat') ) > 1 for p, m in pm ] ) # Find the frequency/mode combinations -- if any -- which are coherent and # fundamental. iscoherentfund = (mlatsign!=lagsign)*iscoherent*isoffeq # # Only keep events which trigger in the poloidal mode. # if not any( iscoherentfund[::3] ): # continue # Can we find any simultaneous observations by both probes? if not any( iscoherentfund[:3] ) or not any( iscoherentfund[3:] ): continue # Note the nontrivial fundamental modes, if any. for x in np.nonzero(iscoherentfund)[0]: modenames = {'p':'Poloidal', 't':'Toroidal', 'z':'Parallel'} fundlabels.append( pm[x][0].upper() + ' ' + format(f, '.0f') + 'mHz ' + modenames[ pm[x][1] ] ) # If no fundamental modes were found, bail. if not fundlabels: print 'SKIPPING ' + ev[probe].name + ' DUE TO NO SUITABLE MODES. ' return False # Otherwise, note the events on the plot. PW.setParams( sidelabel=' $\n$ '.join( notex(x) for x in fundlabels ) ) # --------------------------------------------------------------------------- # ----------------------------------------------------------- Create the Plot # --------------------------------------------------------------------------- if '-i' not in argv: print 'Plotting ' + ev[probe].name return PW.render() else: if not os.path.exists(savedir): os.mkdir(savedir) return not PW.render(savedir + ev[probe].name + '.png')
def plotloc(): # # Debug: force it to regenerate the list each time. # if os.path.exists('locations.txt'): # os.remove('locations.txt') # --------------------------------------------------------------------------- # ------------------------------------------------------ List Event Locations # --------------------------------------------------------------------------- if not os.path.exists('locations.txt'): # Flip through each event in the listing. for evline in np.random.permutation( read('events.txt') ): # Create an event object. Make sure it's usable. probe, date, time = evline.split() ev = event(probe=probe, date=date, time=time) if not ev.isok(): print 'SKIPPING ' + ev.name + ' DUE TO BAD DATA. ' continue # Find the strong Pc4 poloidal waves in this event. waves = [] for m in ('p', 't', 'z')[:1]: mname = {'p':'Poloidal', 't':'Toroidal', 'z':'Parallel'}[m] # Find any harmonics worth talking about. harm = ev.harm(m)*ev.iscoh(m)*ev.iscsd(m)*ev.ispc4() for i in np.nonzero(harm)[0]: waves.append( {'strength':ev.coh(m)[i]*ev.csd(m)[i], 'frequency':ev.frq()[i], 'harmonic': harm[i], 'mode':mname, 'mlt':ev.avg('mlt'), 'lpp':lpp(evline), 'mlat':ev.avg('mlat'), 'lshell':ev.avg('lshell') } ) # If no modes were found, bail. if len(waves) == 0: print 'SKIPPING ' + ev.name + ' DUE TO NO SUITABLE MODES. ' continue # If there are multiple strong modes, keep only the strongest. It's # possible, in principle, to have a strong even harmonic and a strong odd # harmonic superimposed... but it's unlikely. if len(waves) > 1: maxstrength = max( w['strength'] for w in waves ) maxwave = [ w for w in waves if w['strength'] == maxstrength ][0] else: maxwave = waves[0] # Save the mode, its location, and the location of the plasmapause. append(format(maxwave['harmonic'], '.0f') + '\t' + format(maxwave['lshell'], '.1f') + '\t' + format(maxwave['mlt'], '.1f') + '\t' + format(maxwave['mlat'], '.1f') + '\t' + format(maxwave['lpp'], '.1f') + '\t' + format(maxwave['frequency'], '.0f'), 'locations.txt') print 'Saving ' + ev.name # --------------------------------------------------------------------------- # ------------------------------------------------------ Load Event Locations # --------------------------------------------------------------------------- locs = read('locations.txt') locarr = np.array( [ [ float(x) for x in l.split('\t') ] for l in locs ] ) # Split each row into its own 1D array. harm = locarr[:, 0] lshell = locarr[:, 1] mlt = locarr[:, 2] mlat = locarr[:, 3] lpp = locarr[:, 4] freq = locarr[:, 5] # --------------------------------------------------------------------------- # -------------------------------------------------- Plot Event Location Data # --------------------------------------------------------------------------- # Indicate which places are odd or even harmonics. isodd = harm%2 == 1 iseven = harm == 2 # Split between large and small plasmasphere. lppavg = np.mean(lpp) isbigpp = lpp > lppavg issmallpp = lpp < lppavg # Sanity check... scatter plot of frequency against lshell. plt.scatter(lshell, freq) # Round lshell to the nearest half integer. lround = 0.5*np.round(2*lshell) lbins = sorted( set(lround) ) bigf, smallf = [], [] # Let's also plot the average at each lshell. for l in lbins: # Find the events that are at this lshell. ishere = lround == l indbig = np.nonzero(isbigpp*ishere*isodd)[0] if indbig.size>0: bigf.append( np.mean( freq[indbig] ) ) else: bigf.append(None) indsmall = np.nonzero(issmallpp*ishere*isodd)[0] if indsmall.size>0: smallf.append( np.mean( freq[indsmall] ) ) else: smallf.append(None) plt.plot(lbins, bigf, 'r') plt.plot(lbins, smallf, 'b') plt.show() return
def start_pulling_in(self, curr_vehicle): # if self.curr >= 36600. and curr_vehicle.stop == 2: # import pdb; pdb.set_trace() curr_vehicle.update_loc() if np.abs( curr_vehicle.curr_loc - curr_vehicle.dest_to_stop ) > 1e-5: if curr_vehicle.end_time <= self.curr + SMALL_INTERVAL: import pdb; pdb.set_trace() self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) return if self.eventheap != []: heap_len = len(self.eventheap) event_holder = [] next_event = heappop(self.eventheap) while self.eventheap != [] and next_event.time - self.curr < 100 * SMALL_INTERVAL: assert next_event.time >= self.curr if next_event.typ == 'start_pulling_in' and next_event.vehicle.stop > curr_vehicle.stop: assert next_event.time + 1e-10 > self.curr curr_vehicle.end_time = next_event.time + 1e-10 curr_vehicle.traj = DLinkedList() curr_vehicle.traj.addEnd( changePoint(curr_vehicle.dest_to_stop, self.curr, 0.0) ) curr_vehicle.traj.addEnd( changePoint(curr_vehicle.dest_to_stop, curr_vehicle.end_time, 'D') ) for event_visited in event_holder: self.add_event( event_visited ) self.add_event( next_event ) assert heap_len == len(self.eventheap) self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) car = curr_vehicle.nex while car is not None: car.update_loc() car.update_traj() car = car.nex return heappush(event_holder, next_event) next_event = heappop(self.eventheap) for event_visited in event_holder: self.add_event( event_visited ) self.add_event( next_event ) assert heap_len == len(self.eventheap) curr_vehicle.curr_loc = curr_vehicle.dest_to_stop delayed = False req_time = self.curr ################################################# 0-degree Short Specific ################################################# # if the vehicle has arrived at the desired destination while its enter maneuver blocked by vehicles on the through lane # i.e. 1) if its immediate proceeding vehicle is having an exit maneuver at the spot in front if (curr_vehicle.prev is not None) and (curr_vehicle.prev.status == 5): assert (curr_vehicle.prev.stop >= curr_vehicle.stop + 1) if curr_vehicle.prev.stop == curr_vehicle.stop + 1: assert curr_vehicle.prev.pout_end > self.curr delayed = True req_time = max( req_time, curr_vehicle.prev.pout_end ) # or 2) if its immediate proceeding vehicle is having an enter maneuver into the spot in front elif (curr_vehicle.prev is not None) and (curr_vehicle.prev.status in [1, 2]) and curr_vehicle.prev.stop == curr_vehicle.stop + 1: if curr_vehicle.prev.status == 2: assert curr_vehicle.prev.plin_end > self.curr delayed = True req_time = max( req_time, curr_vehicle.prev.plin_end ) else: assert curr_vehicle.prev.status == 1 assert curr_vehicle.prev.end_time >= self.curr delayed = True req_time = max( req_time, curr_vehicle.prev.end_time ) # or 3) if the immediate proceeding vehicle is stopped. elif (curr_vehicle.prev is not None) and (curr_vehicle.prev.curr_loc <= curr_vehicle.dest_to_stop + 1.5 * CAR_LENGTH): assert curr_vehicle.status in [1, 6] cp = curr_vehicle.prev.traj.head if cp.data.t > self.curr: if cp.data.t <= self.curr + 2 * SMALL_INTERVAL: delayed = True req_time = max( req_time, cp.data.t ) else: import pdb; pdb.set_trace() else: while (cp.nex is not None) and (cp.nex.data.t <= self.curr): cp = cp.nex if cp.nex is not None and cp.nex.data.t <= self.curr + SMALL_INTERVAL: cp = cp.nex assert cp is not None if (cp.data.v == 0.0): assert cp.nex.data.t > self.curr delayed = True req_time = max( req_time, cp.nex.data.t ) ########################################################################################################################### if delayed: assert req_time > self.curr curr_vehicle.traj = DLinkedList() curr_vehicle.traj.addEnd( changePoint(curr_vehicle.dest_to_stop, self.curr, 0.0) ) curr_vehicle.traj.addEnd( changePoint(curr_vehicle.dest_to_stop, req_time, 'D') ) curr_vehicle.end_time = req_time self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) car = curr_vehicle.nex while car is not None: car.update_loc() car.update_traj() car = car.nex return assert self.inservice[curr_vehicle.stop_idx - 1] is None self.inservice[curr_vehicle.stop_idx - 1] = curr_vehicle curr_vehicle.start_in() car = curr_vehicle.nex while car != None: car.update_loc() car.update_traj() car = car.nex assert curr_vehicle.end_time is not None self.add_event( event(curr_vehicle.end_time, curr_vehicle, 'start_service') ) return
def enter_system(self, curr_vehicle, debug_idx = None): assert curr_vehicle.status == 0 if self.entry_blocked == self.curr: self.add_event( event( self.entry_cleared, curr_vehicle, 'enter_system' ) ) return if spmatch: assert simType == 'cav' if side == 'single' and self.inservice[0] is not None and self.inservice[0].plin_end is not None and self.inservice[0].plin_end + meanDRIV > self.curr + SMALL_INTERVAL: self.entry_blocked = self.curr self.entry_cleared = self.inservice[0].plin_end + meanDRIV self.add_event( event( self.entry_cleared, curr_vehicle, 'enter_system') ) return if side == 'double' and self.inservice[0] is not None and self.inservice[0].plin_end is not None and self.inservice[0].plin_end + meanDRIV > self.curr + SMALL_INTERVAL: self.entry_blocked = self.curr self.entry_cleared = self.inservice[0].plin_end + meanDRIV self.add_event( event( self.entry_cleared, curr_vehicle, 'enter_system') ) return if side == 'double' and self.inservice[1] is not None and self.inservice[1].plin_end is not None and self.inservice[1].plin_end + meanDRIV > self.curr + SMALL_INTERVAL: self.entry_blocked = self.curr self.entry_cleared = self.inservice[1].plin_end + meanDRIV self.add_event( event( self.entry_cleared, curr_vehicle, 'enter_system') ) return if self.head == None: self.inCount += 1 self.head = curr_vehicle heapify(self.waiting) if not free_curb: curr_vehicle.assign_spot( -heappop(self.waiting) ) else: curr_vehicle.assign_spot( heappop(self.waiting) ) curr_vehicle.curr_loc = CAR_LENGTH assert curr_vehicle.dest_to_stop >= curr_vehicle.curr_loc curr_vehicle.update_traj() assert curr_vehicle.end_time != None and curr_vehicle.end_time >= self.curr self.add_event( event( curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) return # if there is no vehicle on the driving lane # the replacement vehicle is assigned to the spot with the largest index if self.head == None: assert not spmatch self.inCount += 1 self.head = curr_vehicle heapify(self.waiting) if not free_curb: curr_vehicle.assign_spot( -heappop(self.waiting) ) else: curr_vehicle.assign_spot( heappop(self.waiting) ) curr_vehicle.update_traj() assert curr_vehicle.end_time != None and curr_vehicle.end_time >= self.curr self.add_event( event( curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) return # if there are vehicles on the driving lane, find the last one req_time = self.curr car = self.head while car.nex is not None: car = car.nex car.update_loc() # if the last one is within CAR_LENGTH (i.e. first lane block occupied) # the replacement vehicle cannot enter under either access control if car.curr_loc <= CAR_LENGTH + SMALL_INTERVAL: car_time = car.calc_time(CAR_LENGTH + SMALL_INTERVAL) if car_time == self.curr: cp = car.traj.head assert cp.data.t <= self.curr while cp.nex is not None and cp.nex.data.t <= self.curr: cp = cp.nex if cp.nex is None: import pdb; pdb.set_trace() else: assert cp.nex.data.t > self.curr if cp.data.v > 0.0: pass else: import pdb; pdb.set_trace() else: assert car_time > self.curr req_time = max( req_time, car_time ) if spmatch and req_time <= self.curr: if car.curr_loc < 2 * CAR_LENGTH - SMALL_INTERVAL: if car.status not in [1, 6]: print ('!!!!!!!!!!!!!!!!') import pdb; pdb.set_trace() assert car.dest_to_stop >= 2 * CAR_LENGTH car_time = car.calc_time(2 * CAR_LENGTH) req_time = max( req_time, car_time ) if req_time > self.curr: self.entry_blocked = self.curr self.entry_cleared = req_time self.add_event( event( self.entry_cleared, curr_vehicle, 'enter_system') ) return if debug_idx is not None and curr_vehicle.idx == debug_idx: import pdb; pdb.set_trace() if control == 'partial': self.inCount += 1 curr_vehicle.prev = car car.nex = curr_vehicle heapify(self.waiting) if not free_curb: curr_vehicle.assign_spot( -heappop(self.waiting) ) else: curr_vehicle.assign_spot( heappop(self.waiting) ) if spmatch: assert simType == 'cav' assert curr_vehicle.prev.curr_loc >= 2 * CAR_LENGTH - SMALL_INTERVAL curr_vehicle.curr_loc = LOT_LENGTH assert curr_vehicle.dest_to_stop >= curr_vehicle.curr_loc curr_vehicle.update_traj() assert curr_vehicle.end_time != None and curr_vehicle.end_time >= self.curr self.add_event( event( curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) return assert control == 'full' assert curr_vehicle.curr_loc == 0.0 if spmatch: curr_vehicle.curr_loc = CAR_LENGTH # car is the last vehicle on the driving lane # and also the prev for the replacement vehicle if the latter can enter j_new = [] last = car # if self.curr >= 32810.: # import pdb; pdb.set_trace() # j_new will include the spots that the replacement vehicle can head to # without being blocked or delayed by the last vehicle on the lane in expectation for j in sorted(self.waiting, reverse = True): j = - j assert j > 0 if side == 'double': J = idx2spot(j) else: assert side == 'single' J = j if (J < car.stop - 1) or (car.status == 6): j_new.append(j) elif car.status == 2: # K_in with K = car.j and J = idx2spot(j) assert car.stop_idx != j assert car.plin_start <= self.curr assert car.stop >= 2 assert (car.stop - 1) * LOT_LENGTH >= curr_vehicle.curr_loc if ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV >= max(0.0, meanPLIN - (self.curr - car.plin_start)): j_new.append(j) elif car.status == 5: # K_out with K = car.j and J = idx2spot(j) assert car.pout_start <= self.curr <= car.pout_end assert (car.stop - 1) * LOT_LENGTH >= curr_vehicle.curr_loc if spmatch and ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV >= car.pout_end - self.curr - 7e-06: j_new.append(j) elif spmatch and ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV >= car.pout_end - self.curr - 200 * SMALL_INTERVAL: import pdb; pdb.set_trace() j_new.append(j) elif (not spmatch) and ( (car.stop - 1) * LOT_LENGTH / rateDRIV >= max(0.0, meanPOUT - (self.curr - car.pout_start) - 7e-06) ): j_new.append(j) else: assert car.status == 1 # I_in with K = car.j and J = idx2spot(j) assert car.stop_idx != j assert car.stop >= 2 if not car.curr_loc >= LOT_LENGTH + curr_vehicle.curr_loc - SMALL_INTERVAL: import pdb; pdb.set_trace() if (car.curr_loc - LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV >= meanPLIN: j_new.append(j) if j_new != []: assert j_new[-1] == max(j_new) car_time = 0.0 else: j = - sorted(self.waiting, reverse = True)[0] if side == 'double': assert (idx2spot(j) >= car.stop - 1) else: assert side == 'single' assert (j >= car.stop - 1) if car.status == 2: assert car.stop_idx != j assert car.plin_start <= self.curr assert ( ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV < meanPLIN - (self.curr - car.plin_start) ) car_time = meanPLIN - (self.curr - car.plin_start) - ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV elif car.status == 5: assert car.pout_start <= self.curr <= car.pout_end if spmatch: assert ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV < car.pout_end - self.curr car_time = car.pout_end - self.curr - ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV else: assert (car.stop - 1) * LOT_LENGTH / rateDRIV < meanPOUT - (self.curr - car.pout_start) car_time = meanPOUT - (self.curr - car.pout_start) - (car.stop - 1) * LOT_LENGTH / rateDRIV else: assert car.status == 1 assert car.stop_idx != j assert (car.curr_loc - LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV < meanPLIN car_time = meanPLIN - (car.curr_loc - LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV while (j_new != []) and (car.prev is not None): car = car.prev car.update_loc() for idx in range(len(j_new)): j = j_new[idx] if side == 'double': J = idx2spot(j) else: assert side == 'single' J = j if (J < car.stop - 1) or (car.status == 6): pass elif car.status == 2: # K_in with K = car.j and J = idx2spot(j) assert car.stop_idx != j assert car.plin_start <= self.curr assert (car.stop - 1) * LOT_LENGTH >= curr_vehicle.curr_loc if ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV < max(0.0, meanPLIN - (self.curr - car.plin_start)): j_new = j_new[:idx] if idx == 0: car_time = max(car_time, meanPLIN - (self.curr - car.plin_start) - ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV) break elif car.status == 5: # K_out with K = car.j and J = idx2spot(j) assert car.pout_start <= self.curr <= car.pout_end assert (car.stop - 1) * LOT_LENGTH >= curr_vehicle.curr_loc if spmatch: if ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV < car.pout_end - self.curr - 3e-06: if ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV > car.pout_end - self.curr - 100 * SMALL_INTERVAL: import pdb; pdb.set_trace() else: j_new = j_new[:idx] if idx == 0: car_time = max(car_time, car.pout_end - self.curr - ((car.stop - 1) * LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV) break else: if ((car.stop - 1) * LOT_LENGTH / rateDRIV < max(0.0, meanPOUT - (self.curr - car.pout_start) - 3e-06)): j_new = j_new[:idx] if idx == 0: car_time = max(car_time, meanPOUT - (self.curr - car.pout_start) - (car.stop - 1) * LOT_LENGTH / rateDRIV) break else: assert car.status == 1 # I_in with K = car.j and J = idx2spot(j) assert car.stop_idx != j assert car.curr_loc >= LOT_LENGTH + curr_vehicle.curr_loc if (car.curr_loc - LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV < meanPLIN: j_new = j_new[:idx] if (idx == 0): car_time = max(car_time, meanPLIN - (car.curr_loc - LOT_LENGTH - curr_vehicle.curr_loc) / rateDRIV) break if j_new == []: car_time = self.curr + car_time if car_time == self.curr: car_time += SMALL_INTERVAL if car_time <= self.curr: import pdb; pdb.set_trace() curr_vehicle.curr_loc = 0.0 self.add_event( event( car_time, curr_vehicle, 'enter_system') ) return # car.prev is None # i.e. there is at least one spot where a replacement vehicle can head to # without being blocked or delayed by any vehicle already on the lane # if there are multiple, choose the largest self.inCount += 1 assert j_new[-1] == max(j_new) assert j_new[0] == min(j_new) if not free_curb: curr_vehicle.assign_spot( j_new[-1] ) assert (- j_new[-1]) in self.waiting self.waiting.remove( - j_new[-1] ) else: curr_vehicle.assign_spot( j_new[0] ) assert j_new[0] in self.waiting self.waiting.remove( j_new[0] ) curr_vehicle.prev = last last.nex = curr_vehicle if spmatch: assert simType == 'cav' assert curr_vehicle.prev.curr_loc >= 2 * CAR_LENGTH - SMALL_INTERVAL curr_vehicle.curr_loc = CAR_LENGTH assert curr_vehicle.dest_to_stop >= curr_vehicle.curr_loc curr_vehicle.update_traj() assert curr_vehicle.end_time != None and curr_vehicle.end_time >= self.curr self.add_event( event( curr_vehicle.end_time, curr_vehicle, 'start_pulling_in') ) return
def decodeSingularEvent(ev): ou = event() ou.meta = ev.meta for x in ev.data: ou.data[x] = decodeList(ev.data[x]) return ou #ou is an event
SEED_PLIN[N - 1], SEED_DRIV[N - 1]) elif angle == 0 and mode == 'singlelane': # test = SingleLaneSystem(N, SEED_SERV[N-1], SEED_DRIV[N-1]) test = SingleLaneSystem(N) elif angle == 90: test = system90(N, SEED_SERV[N - 1], SEED_POUT[N - 1], SEED_PLIN[N - 1], SEED_DRIV[N - 1]) else: print('Configuration not specified!') import pdb pdb.set_trace() if mode == 'singlelane': test.inCount += 1 car = SLvehicle(test, getin=True, stop_idx=test.N) test.add_event(event(car.serv_time, car, 'prepare_pulling_out')) for j in range(test.N - 1, 0, -1): test.inCount += 1 car.nex = SLvehicle(test, getin=True, stop_idx=j, prev=car) car = car.nex test.add_event(event(car.serv_time, car, 'prepare_pulling_out')) else: for j in range(1, test.N + 1): test.inCount += 1 car = vehicle(test, getin=True, stop_idx=j) test.inservice[j - 1] = car test.add_event(event(car.serv_time, car, 'prepare_pulling_out')) # test.add_event( event(WARMUP_UNIT, None, 'start_counting') ) count = []
def makeEventListFromFile(file): #initalisation des constantes TDM_ID = 0b1110 Hit_Amplitude_Id = 0b0011 Hit_Time_Id = 0b0010 Gtrig_Header_Id = 0b0001 Gtrig_trailer_1_Id = 0b0100 Gtrig_trailer_2_Id = 0b0101 Special_Word_id = 0b1111 #variable pin_complete_slots = [] treatingEvent = [] nEvent=0 #retour nbLigne=0 listEvent=[] #lecture with open(file, "r+b") as file: line = file.read(4) nbLigne=nbLigne+1 rightLine = getRightLine(line) Word_Id = rightLine[0:4] while line != b'': if int(Word_Id, 2) == TDM_ID and int(rightLine[4:6], 2) == 0: # si nous somme dans au début d'un slot (0 ou 2) slot = int(rightLine[6:11], 2) # on définit notre numero de slot 1 ou 2 et on lit la ligne suivante # Si le slot actuel n'est pas dans la liste de slots deja traiter alors on l'ajoute, # Si on l'a dejà traité alors on a nouvel évenement: liste de slots traiter à vide et on ajoute ce slot là if slot not in pin_complete_slots: pin_complete_slots.append(slot) else: pin_complete_slots = [] pin_complete_slots.append(slot) line = file.read(4) nbLigne=nbLigne+1 if line != b'': Word_Id = getRightLine(line)[0:4] while int(Word_Id, 2) != TDM_ID and line != b'': if int(Word_Id, 2) == Special_Word_id and int(rightLine[11], 2) == 0 and int(rightLine[12:32], 2) == 3: print("Gtrig + Spill Reset for slot {}".format(slot)) nmo = 1 else: #A ce moment, on est soit dans un évenement, soit en début d'évenement soit à la fin # Pour rappel: # un évenemetn est de la forme: # GTRIGHeader # + # GTRIGheader2 -> GTRIGtrailer2 if ( Word_Id == Gtrig_Header_Id): # if new Event nEvent=nEvent+1 eventID=int(line[5:length(line)],2) #toVerify currentEvent= event() treatingEvent.append(currentEvent) elif (Word_Id == Gtrig_trailer_1_Id): ## Chercher l'évenemnt associer IDCurrentEvent=int(line[5:length(line)],2)-268435456 ## #to verify the bits taken and the substraction for k in treatingEvent: #Recherche de l'évenement associer if (k.getID == IDCurrentEvent): k.changeTrailer1=True if (k.getTrailer1 and k.getTrailer2): if (sum(k.getPixels) != 0): #Si c'est un vrai évenement on le considère listEvent.append(k) treatingEvent.remove(k) # on a finit de traiter cet évenement break; elif (Word_Id == Gtrig_trailer_2_Id): ##Chercher l'évènme associer, vérifier si c'est la fin de l'évenement IDCurrentEvent=int(line[12:length(line)],2)-536870912 #to verify the bits taken and the substraction for k in treatingEvent: if (k.getID == IDCurrentEvent): k.changeTrailer2=True if (k.getTrailer1 and k.getTrailer2): if (sum(k.getPixels) != 0): #Si c'est un vrai évenement on le considère listEvent.append(k) treatingEvent.remove(k) #On a finit de traiter cet évenemnt break; line = file.read(4) nbLigne=nbLigne+1 print(nbLigne)