def on_pulse(self, p): if p.direction in self.inp: out_pulses = [] for o in self.outp: np = pulse.Pulse(p.pos, o) np.move() out_pulses.append(np) return out_pulses
def testFramesToGray(self): """ This function assures that variances() returns a one dimensional matrix. """ testing_uid = "1kzd0DmeunLGEeB0nWLFFaIfuFZn" pulse = p.Pulse() pulse.pulsebox_to_frames(testing_uid) gray = pulse.frames_to_gray() self.assertEqual(len(gray), 300)
def test_signal_diff(self): """ This function test to assure that signal_diff() returns a size of 200. """ testing_uid = "1kzd0DmeunLGEeB0nWLFFaIfuFZn" pulse = p.Pulse() pulse.pulsebox_to_frames(testing_uid) red = pulse.signal_diff() self.assertEqual(len(red), 200)
def test_range_of_bpm(self): """ This function assures that variances() returns a one dimensional matrix. """ testing_uid = "1kzd0DmeunLGEeB0nWLFFaIfuFZn" pulse = p.Pulse() pulse.pulsebox_to_frames(testing_uid) hr = pulse.bpm() self.assertTrue(int(hr) > 0 and int(hr) <= 220)
def test_get_peaks(self): """ This function assures that get_peaks() returns a one dimentional matrix. """ testing_uid = "1kzd0DmeunLGEeB0nWLFFaIfuFZn" pulse = p.Pulse() pulse.pulsebox_to_frames(testing_uid) peaks = pulse.get_peaks() peaks_dim = peaks.shape[1] self.assertEqual(peaks_dim, 1)
def test_variances(self): """ This function assures that variances() returns a one dimensional matrix. """ testing_uid = "1kzd0DmeunLGEeB0nWLFFaIfuFZn" pulse = p.Pulse() pulse.pulsebox_to_frames(testing_uid) v = pulse.variances() v_dim = v.shape[1] self.assertEqual(v_dim, 1)
def __main__(): if len(sys.argv) != 6: print "python start.py <c_key> <c_secret> <a_token> <a_token_s> <geotags>" sys.exit(-1) c_key = sys.argv[1] c_secret = sys.argv[2] a_token = sys.argv[3] a_token_s = sys.argv[4] geotags = sys.argv[5] p = pulse.Pulse(c_key, c_secret, a_token, a_token_s, eval(geotags)) p.start()
def pulses(self, period_at_mjd, time_to_skip=0.0): """Generator method to generate/iterate over pulse profiles from datfile. 'period_at_mjd' is a function that, given a mjd, will return the spin period at that mjd. Skip 'time_to_skip' seconds at the start of the observation. (First pulse period after skip is still called pulse #1) """ if not hasattr(self.infdata, 'epoch'): raise NotImplementedError( "Cannot use 'pulses(...)' if there is no MJD in inf file") # Initialize self.rewind() if time_to_skip > 0.0: print "Burning %f s at start of obs." % time_to_skip self.read_Tseconds(time_to_skip) pulse_number = 1 # Copy current mjd and time since reading data # will modify the object attributes current_time = self.currtime_actual current_mjd = self.currmjd_actual # # NOTE: Using currmjd_actual, is this correct? # Should we be using currmjd_desired instead? # current_period = period_at_mjd(current_mjd) current_pulse = self.read_Tseconds(current_period) while current_pulse is not None: # yield (return) current pulse (and other information) yield pulse.Pulse(number=pulse_number, mjd=current_mjd, \ time=current_time, duration=current_period, \ profile=current_pulse, origfn=self.datfn, \ dt=self.infdata.dt, dm=self.infdata.DM, \ telescope=self.infdata.telescope, \ lofreq=self.infdata.lofreq, \ chan_width=self.infdata.chan_width, \ bw = self.infdata.BW) # Update pulse number, mjd, period and pulse pulse_number += 1 current_time = self.currtime_actual current_mjd = self.currmjd_actual current_period = period_at_mjd(current_mjd) current_pulse = self.read_Tseconds(current_period)
def packetHandler(self, hdr, data): # Use the ImpactDecoder to turn the rawpacket into a hierarchy # of ImpactPacket instances, then send it to the Visualiser # which drives the Holiday lights. try: p = self.decoder.decode(data) except (Exception, KeyboardInterrupt) as e: print e return try: protocol = p.child().__class__.__name__ size = p.get_size() src = False if protocol == 'IP' or protocol == 'UDP': src = p.child().get_ip_src() dest = p.child().get_ip_dst() elif protocol == 'IP6': src = p.child().get_source_address() dest = p.child().get_destination_address() print "IP6", src, dest src = False if src: l = size_to_length(size) if src[0:2] == '10': col = local_ip_to_rgb(src) #col = ip_to_rgb(dest) v = SPEED / l i = 0 else: if RETURN_SAME: col = local_ip_to_rgb(src) else: col = ip_to_rgb(src) v = -SPEED / l i = -52 gradient = make_pulse(col, l) #print gradient self.queue.put(pulse.Pulse(i, v, gradient)) #print protocol, src, " -> ", dest, "Size ", size except Exception as e: print "Decoding failed" print e return
def __init__(self, app_name, app_nick, proxy_name, proxy, proxy_ip, proxy_port): super(ProxyItem, self).__init__() self.app_name = app_name self.app_nick = app_nick self.proxy = proxy self.proxy_name = proxy_name self.proxy_nick = "" self.proxy_ip = proxy_ip self.proxy_port = proxy_port self.sort_key = proxy_name self.send_stat_delay_timer = 0 self.receive_stat_delay_timer = 0 self.dropping = False self.sort_order = 0 # Don't allow the local user to drop more files if we're already waiting on a previous request self.blocking_new_sends = False self.active_receive_request = None self.builder = Gtk.Builder.new_from_file( os.path.join(config.pkgdatadir, "warp-window.ui")) self.widget = self.builder.get_object("proxy_widget") self.page_stack = self.builder.get_object("page_stack") self.status_page = self.builder.get_object("status_page") self.nick_label = self.builder.get_object("nick_label") self.progress_box = self.builder.get_object("progress_box") self.send_progress_bar = self.builder.get_object("send_progress_bar") self.receive_progress_bar = self.builder.get_object( "receive_progress_bar") self.sender_awaiting_approval_label = self.builder.get_object( "sender_awaiting_approval_label") self.sender_awaiting_approval_cancel_button = self.builder.get_object( "sender_awaiting_approval_cancel_button") self.send_file_menu_button = self.builder.get_object( "send_file_menu_button") self.req_transfer_label = self.builder.get_object("req_transfer_label") self.problem_info_label = self.builder.get_object("problem_info_label") self.problem_more_info_label = self.builder.get_object( "problem_more_info_label") self.connecting_label = self.builder.get_object("connecting_label") self.sender_awaiting_approval_cancel_button.connect( "clicked", self.cancel_send_request) self.recent_menu = Gtk.RecentChooserMenu( show_tips=True, sort_type=Gtk.RecentSortType.MRU, show_not_found=False) self.recent_menu.connect("item-activated", self.recent_item_selected) self.send_file_menu_button.set_popup(self.recent_menu) self.recent_menu.add(Gtk.SeparatorMenuItem(visible=True)) picker = Gtk.MenuItem(label=_("Browse..."), visible=True) picker.connect("activate", self.open_file_picker) self.recent_menu.add(picker) self.proxy.lock = threading.Lock() self.file_sender = transfers.FileSender(self.app_name, self.proxy_name, self.proxy_nick, self.proxy, self.send_progress_callback) entry = Gtk.TargetEntry.new("text/uri-list", 0, 0) self.status_page.drag_dest_set(Gtk.DestDefaults.ALL, (entry, ), Gdk.DragAction.COPY) self.status_page.connect("drag-drop", self.on_drag_drop) self.status_page.connect("drag-data-received", self.on_drag_data_received) self.status_page.connect("drag-motion", self.on_drag_motion) self.show_connecting() self.pulse = pulse.Pulse(self.proxy, self.proxy_ip, self.proxy_port) self.pulse.connect("state-changed", self.pulse_state_changed) self.pulse.start() self.hide_receive_stats() self.hide_send_stats() self.widget.show_all()
def on_beat(self, beats) -> Sequence[pulse.Pulse]: if beats % self.interval - self.offset == 0: return [pulse.Pulse(self.pos, o) for o in self.outp] return []
def view_heartrate(uid): pulse = p.Pulse() pulse.pulsebox_to_frames(uid) hr = pulse.bpm() os.system('rm -rf images') return jsonify({'pulse': hr})
def testSystemSpeed(self): """This function runs the entire heart rate system.""" testing_video = "https://firebasestorage.googleapis.com/v0/b/pulse-box.appspot.com/o/data%2F1kzd0DmeunLGEeB0nWLFFaIfuFZn%2Fhr_test.MOV?alt=media&token=221ee115-5fb1-4c38-8264-5b1f8a859fda" pulse = p.Pulse() pulse.video_to_frames(testing_video) pulse.bpm()
import pulse as p import matplotlib.pyplot as plt pulse = p.Pulse() testing_uid = "1kzd0DmeunLGEeB0nWLFFaIfuFZn" pulse.pulsebox_to_frames(testing_uid) peaks = pulse.get_peaks() reds = pulse.signal_diff() plt.figure(figsize=(15,5)) plt.title("Signal Differentiation") plt.ylabel("average red constant value") plt.xlabel("frame number") plt.plot(reds) plt.plot(peaks[:200], reds[peaks[:200]], 'x') plt.show()