def print_algorithms(self): algorithms = Config().get('algorithms.single') + Config().get( 'algorithms.double') Calibration().load() device_classes = Nvidia().get_nvidia_device_classes() for device_class in device_classes: data = {} for algorithm in algorithms: data[algorithm] = {} for miner_name in Config().get('miners'): miner = eval('%s()' % (miner_name.title())) if algorithm in miner.supported_algorithms(): data[algorithm][miner_name] = Calibration( ).get_miner_hashrate_for_algorithm_on_device( miner_name, algorithm, device_class) else: data[algorithm][miner_name] = "-" self.display_device_algorithm_table(device_class, data) print "\nnote: - means not supported\n"
def calibrate(alpha, flags, nooutliers=False): ll.info(__name__) images = glob.glob( f'/Users/torres/OneDrive/UNB/2020-08 Visão Computacional/' f'Trabalho 1/Calibration{res.cam}/*.jpg') images = sorted(images) calib = Calibration(delay=10, sample_size=10, cbcols=8, cbrows=6, alpha=alpha, nooutliers=nooutliers) ll.info('Made calib object') ll.debug(f'Reading {len(images)} images…') for filename in images: img = cv2.imread(filename, cv2.IMREAD_UNCHANGED) calib.add_sample(img, filename) params = calib.calculate_camera_params(flags=flags) if not params: ll.error('Erro ao calibrar.') ll.info(f'Writing camera params to file {res.file}') filenames = '\n'.join(images) comment = (f"With files:\n{filenames}\n" f'Camera: {res.cam}') params.write_to_file(res.file, comment) return params
def visualization(labels, pointcloud, img, test, calib_info, rotation=None): img_shape = [1242, 375] mesh = o3d.geometry.TriangleMesh.create_coordinate_frame(size=10) calib = Calibration(calib_info) pts_rect = calib.lidar_to_rect(pointcloud[:, 0:3]) fov_flag = get_fov_flag(pts_rect, img_shape, calib) points, _ = calib.lidar_to_img(pointcloud[fov_flag][:, :3]) # print(points.shape) pcd = get_pcd(pointcloud[fov_flag][:, :3]) bboxes, meshes = get_bboxes(labels, calib, rotation) # o3d.visualization.draw_geometries(bboxes+pcd+[]+[],width=960,height=640,point_show_normal=False) vis = o3d.visualization.Visualizer() vis.create_window(width=1023, height=1023, left=5, top=5) vis.get_render_option().background_color = np.array([0., 0., 0.]) vis.get_render_option().show_coordinate_frame = False vis.get_render_option().point_size = 2 from testo3d import get_strong bboxes = get_strong(bboxes) ctr = vis.get_view_control() param = o3d.io.read_pinhole_camera_parameters('1130.json') ctr.convert_from_pinhole_camera_parameters(param) # ctr.set_zoom(0.8) for t in bboxes + pcd: vis.add_geometry(t) vis.run() param = vis.get_view_control().convert_to_pinhole_camera_parameters() o3d.io.write_pinhole_camera_parameters('1130.json', param) vis.capture_screen_image('/home/zzj/Desktop/test.png', True) bboxes = get_2Dlabels(labels) draw_2Dlabels(bboxes, img, points) exit()
def start_calibration(self): if self._calibrating or self._tracking: return None if self._tracker is not None: calib = Calibration(self._q) calib.run(self._tracker, self._on_calib_done) self._calibrating = True return calib
def __init__(self): super().__init__() self.calibration = Calibration() self.eye_tracker = EyeTracker() self.vector = None self.left_eye = None self.right_eye = None
def work(self, input_items, output_items): inp = input_items[0] for i in range(len(inp)): data = [] for x in inp[i]: data.append(x & 0xFF) data.append(x >> 8) frame = Frame(data, self.frame_prev) if not frame: print "no frame" + str(frame) continue if not frame.is_broken(): self.frame_prev = frame self.conf = frame.get(SF_TYPE_CONFIG) if self.conf is not None: frame_num = self.conf.frame_num node_id = self.conf.id calibration_num = self.conf.calibration_num de = DataEvent( [EVENT_CONFIG, frame_num, node_id, calibration_num]) wx.PostEvent(self.panel, de) del de else: frame_num = 'N/A' self.meas = frame.get(SF_TYPE_MEASUREMENTS) if self.meas is not None and self.conf is not None: temp = self.meas.temp hum = self.meas.hum_down pres = self.meas.pressure de = DataEvent( [EVENT_MEASSURE, self.conf.frame_num, temp, hum, pres]) wx.PostEvent(self.panel, de) del de #self._dump_frame(frame, frame_num) #self._dump_eval(frame) if not self.calibrated and self.conf is not None: self.calibrated = self.calib.addFragment( self.conf.calibration_num, self.conf.calibration_data) if self.calibrated: print("calibration complete at frame %s" % frame_num) calib_data = self.calib.data() self.calib = Calibration(calib_data) de = DataEvent([EVENT_CALIBRATED]) wx.PostEvent(self.panel, de) del de print("frame: %s %s" % ( frame_num, not frame.is_broken(), )) return len(inp)
def __init__(self, label): QtCore.QObject.__init__(self) self.label = ord(label.upper()) - 64 self.controller = Leap.Controller() self.calibration = Calibration(self.controller) self.status = None self.status_bar = None self.status_mutex = False self.stop_thread_flag = False self.stop_thread_mutex = False
def calibrate(): images = glob.glob( f'/Users/torres/OneDrive/UNB/2020-08 Visão Computacional/' f'Trabalho 1/Calibration{cam}/*.jpg') calib = Calibration(delay=10, sample_size=10, cbcols=8, cbrows=6, alpha=1) for filename in images: img = cv2.imread(filename, cv2.IMREAD_UNCHANGED) calib.add_sample(img) return calib
def work(self, input_items, output_items): inp = input_items[0] for i in range(len(inp)): data = [] for x in inp[i]: data.append(x&0xFF) data.append(x>>8) frame = Frame(data, self.frame_prev) if not frame: print "no frame" + str(frame) continue if not frame.is_broken(): self.frame_prev = frame self.conf = frame.get(SF_TYPE_CONFIG) if self.conf is not None: frame_num = self.conf.frame_num node_id = self.conf.id calibration_num = self.conf.calibration_num self.node_id.setText(str(node_id)) self.frame_num.setText(str(frame_num)) else: frame_num = 0 self.meas = frame.get(SF_TYPE_MEASUREMENTS) if self.meas is not None and self.conf is not None: temp = self.meas.temp hum = self.meas.hum_down pres = self.meas.pressure self.plot.update_figure(frame_num, temp, hum, pres) if not self.calibrated and self.conf is not None: self.calibrated = self.calib.addFragment(self.conf.calibration_num, self.conf.calibration_data) if self.calibrated: print("calibration complete at frame %s" % frame_num) calib_data = self.calib.data() self.calib = Calibration(calib_data) self.calibrated_label.setText("calibrated") self.calibrated_label.setStyleSheet("color: green") print("frame: %s %s" % (frame_num, not frame.is_broken(), )) return len(inp)
def __init__(self, con, loop=None): """:param web.rest.base.Connection con: the base http connection""" self.conn = con conf = Config() self.ws = None self.cal = Calibration() self.url = conf.get_rest_base() + "/warning" self.ws_url = conf.get_ws_base() + "/warn" self.configs = [] if loop is not None: self.loop = loop else: self.loop = asyncio.new_event_loop() self.__current = {}
def dot_product_calibration_set(ideals, measured, *args, **kwargs): ''' This function is used for calculating calibration uncertainty due to un-biased, non-systematic errors. It creates an ensemble of calibration instances. the set of measurement lists used in the ensemble is the python 'zip' of measured and ideal lists. it is equivalent to making a calibration for each connection instance of a measurement. This requires the same number of repeat elements for takes: ideals: list of ideal Networks measured: list of measured Networks *args,**kwargs: passed to Calibration initializer returns: cal_ensemble: a list of Calibration instances. ''' # this is a way to sort the measured list by alphabetically ordering # of the Network element names measured_range = range(len(measured)) name_list = [k.name for k in measured] sorted_index = sorted(measured_range, key=lambda k: name_list[k]) measured = [measured[k] for k in sorted_index] measured_iterable = \ [[ measure for measure in measured \ if ideal.name in measure.name] for ideal in ideals] m_array = array(measured_iterable) return [Calibration(ideals = ideals, measured = list(m_array[:,k]),\ *args, **kwargs)\ for k in range(m_array.shape[1])]
def get_current_payrate(self): hashrates = Calibration().get_hashrates(self) return Pools().get_payrate(self, hashrates, self.algos[0]['pool'], self.algos[0]['miner'], self.algos[0]['algo'], self.algos[0]['region'])
def sighup_handler(self, x, y): Log().add('info', 'SIGHUP caught, reloading config and benchmark data') Config().reload() Calibration().load() Miners().reload_config() for device in Nvidia().get_nvidia_devices(): if not self.device_in_list(device): device.update() if device.state == 'active': device.log( 'info', 'currently running algorithm %s with %s [profile=%s] [region=%s]' % (device.algos[0]['algo'], device.algos[0]['miner'], device.profile, device.algos[0]['region'])) elif device.state == 'calibrating': device.log( 'info', 'calibration in progress with algorithm %s using %s [region=%s]' % (device.algos[0]['algo'], device.algos[0]['miner'], device.algos[0]['region'])) self.devices.append(device) for device in self.devices: if device.state == 'active': device.apply_profile() Log().add('info', 'reload complete')
def binomial_coefficient_calibration_set(ideals, measured, n, *args, **kwargs): ''' Produces a ensemble of calibration instances based on choosing sub-sets of the ideal/measurement lists from an overdetermined calibration. This concept is described in 'De-embeding and Un-terminating' by Penfield and Baurer. so, if the calibration ideals and measured lists have length 'm' then the resultant ensemble of calibrations is 'm choose n' long. takes: ideals: list of ideal Networks measured: list of measured Networks n: length of ideal/measured lists to pass to calibrations (must be < len(ideals) ) *args,**kwargs: passed to Calibration initializer returns: cal_ensemble: a list of Calibration instances. ''' if n >= len(ideals): raise ValueError('n must be larger than # of standards') ideal_subsets = \ [ ideal_subset for ideal_subset in combinations(ideals,n)] measured_subsets = \ [ measured_subset for measured_subset in combinations(measured,n)] return [Calibration(ideals = list(k[0]), measured=list(k[1]),\ *args, **kwargs) for k in zip(ideal_subsets, measured_subsets)]
def main(): debug_mode = rospy.get_param(NODE_NAME + "/debug", DEFAULT_DEBUG_MODE) if debug_mode: log_level = rospy.DEBUG rospy.loginfo( "[{0}] Launching calibration node in debug mode".format(NODE_NAME)) else: log_level = rospy.INFO rospy.init_node(NODE_NAME, anonymous=True, log_level=log_level) update_rate = rospy.get_param('~update_rate', DEFAULT_UPDATE_RATE) playback = rospy.get_param('/' + 'px150' + '/' + 'playback', DEFAULT_PLAYBACK) # state_machine_input = StateMachineInput(NODE_NAME) calibration = Calibration(NODE_NAME, playback=playback) calibration_state_machine = CalibrationStateMachine( calibration, update_rate, NODE_NAME) rospy.loginfo( '[{0}] Calibration state machine successfully generated'.format( NODE_NAME)) rospy.core.add_preshutdown_hook( lambda reason: calibration_state_machine.request_shutdown()) calibration_state_machine.run()
def load(self, hdf5_file): """Load the data from the given hdf5 file and the sqlite3 database.""" # Load the calibration object associated with this data. self.calib = Calibration(self.detector, _date_from_shot(self.shot)) # Load the raw data. data_name = 'data_{0}'.format(self.detector.sn) self.y = hdf5_file.get(data_name).value # Read data from the database. query = 'SELECT shot, aperture, filter, port, dt, t0, timestamp ' query += 'FROM xRayData WHERE shot=? AND detector=?' row = dbutil.fetchall(const.DB_XRAY_PATH, query, (self.shot, int(self.detector.sn)))[0] self.shot = row[0] self.aperture = row[1] self.filter = row[2] self.port = row[3] self.dt = row[4] self.t0 = row[5] self.timestamp = row[6] if self.aperture is not None: self.aperture = mp.XRayAperture.get(self.aperture) if self.filter is not None: self.filter = mp.XRayFilter.get(self.filter) if self.port is not None: self.port = mp.Port.get(self.port)
def newMux(self, mux): channel = 1 # Variable to control de number of channels # Initialize mux dictionary with basic informations muxDictionary = { "Id": mux[0], "Datetime": mux[1], "Volt": mux[2], "Temperature": mux[3] } # Scroll the channels and set the info into the dictionary for i in range(4, len(mux)): if str(mux[i]) != "nan": if i % 2 == 0: option = "Ch%d%s" % (channel, "A") try: muxDictionary[option] = cal.convertChannelA( mux[0], channel, mux[i]) except: muxDictionary[option] = float("nan") # Update the respective pv pvName = pvp.pvName(int(mux[0]), int(channel), "A") if pvName != "Dis.": if str(muxDictionary[option]) not in ["Dis.", "error"]: EpicsServer.driver.write( pvName, float(muxDictionary[option])) else: EpicsServer.driver.write(pvName, 0) else: # Add to dictionary with convertion to Celsius degrees try: muxDictionary["Ch%d%s" % (channel, "B")] = cal.convertChannelB( mux[i]) except: muxDictionary["Ch%d%s" % (channel, "B")] = str( mux[i]) + " (error)" # Update the respective pv pvName = pvp.pvName(mux[0], channel, "B") if pvName != "Dis.": if str(muxDictionary[option]) not in ["Dis.", "error"]: EpicsServer.driver.write( pvName, float(muxDictionary[option])) else: EpicsServer.driver.write(pvName, 0) channel += 1 muxDictionary["Number of channels"] = channel - 1 return muxDictionary
def get_power_limit_for_algorithm(self, miner_name, algorithm): calibrated = Calibration().get('%s.%s.%s' % (self.dclass, miner_name, algorithm)) if calibrated: return calibrated['power_limit'] return None
def calibrate(self, the_number): is_equal = the_number == self.comparator if is_equal: message = self.equal_message.format(the_number) elif the_number > self.comparator: message = self.high_message.format(the_number) else: message = self.low_message.format(the_number) return Calibration(is_equal, message)
def work(self, input_items, output_items): inp = input_items[0] for i in range(len(inp)): data = [] for x in inp[i]: data.append(x&0xFF) data.append(x>>8) frame = Frame(data, self.frame_prev) if not frame: print "no frame" + str(frame) continue if not frame.is_broken(): self.frame_prev = frame self.conf = frame.get(SF_TYPE_CONFIG) if self.conf is not None: frame_num = self.conf.frame_num node_id = self.conf.id calibration_num = self.conf.calibration_num de = DataEvent([EVENT_CONFIG, frame_num, node_id, calibration_num]) wx.PostEvent(self.panel, de) del de else: frame_num = 'N/A' self.meas = frame.get(SF_TYPE_MEASUREMENTS) if self.meas is not None and self.conf is not None: temp = self.meas.temp hum = self.meas.hum_down pres = self.meas.pressure de = DataEvent([EVENT_MEASSURE, self.conf.frame_num, temp, hum, pres]) wx.PostEvent(self.panel, de) del de #self._dump_frame(frame, frame_num) #self._dump_eval(frame) if not self.calibrated and self.conf is not None: self.calibrated = self.calib.addFragment(self.conf.calibration_num, self.conf.calibration_data) if self.calibrated: print("calibration complete at frame %s" % frame_num) calib_data = self.calib.data() self.calib = Calibration(calib_data) de = DataEvent([EVENT_CALIBRATED]) wx.PostEvent(self.panel, de) del de print("frame: %s %s" % (frame_num, not frame.is_broken(), )) return len(inp)
def update_camera_matrix(params: CameraParams) -> CameraParams: """"Treat the source as already undistorted. Thus, the new camera matrix becomes the matrix and the distortion coefficients are zeroed.""" if params.newcameramtx is None: params.newcameramtx, _ = Calibration.get_optimal_camera_matrix(params) params.camera_matrix = params.newcameramtx params.newcameramtx = None params.distortion_coefficients = None return params
def init_simul(filename, test_num, cbr_num=50, div_step=1): data = read_data_skeleton(filename) # test_num, data = interval_compasation(data, test_num, div_step) test_num = min(test_num, len(data)) skeletons = [] for i in range(test_num): skeletons.append(Skeleton(data[i])) cbr_num = min(test_num, cbr_num) cal_skeletons = [] for i in range(cbr_num): cal_skeletons.append(skeletons[i * div_step]) calibration = Calibration(cal_skeletons) lower_init_mean, upper_init_mean = calibration.get_init_mean(0, filename) return skeletons, lower_init_mean, upper_init_mean, test_num
def mbtc_per_day(self): if self.state in ['active', 'calibrating']: hashrates = Calibration().get_hashrates(self) return Pools().get_payrate(self, hashrates, self.algos[0]['pool'], self.algos[0]['miner'], self.algos[0]['algo'], self.algos[0]['region']) return 0
def get_best_miner_for_algorithm(self, algorithm, supported_miners=[]): calibration_data = Calibration().get_hashrates(self) best_hashrate = 0 best_miner = None if calibration_data: for miner_name in calibration_data.keys(): if algorithm in calibration_data[miner_name].keys( ) and calibration_data[miner_name][algorithm][ "hashrate"] > best_hashrate: if Miners().enabled(miner_name) and Miners().is_up( miner_name): if supported_miners == [] or miner_name in supported_miners: best_hashrate = calibration_data[miner_name][ algorithm]["hashrate"] best_miner = miner_name return best_miner
class GazeTracker(): def __init__(self): super().__init__() self.calibration = Calibration() self.eye_tracker = EyeTracker() self.vector = None self.left_eye = None self.right_eye = None def update(self, frame): self.eye_tracker.update(frame) self.left_eye = self.eye_tracker.left_eye() self.right_eye = self.eye_tracker.right_eye() self._calculate_vector() def _calculate_vector(self): vector = None vector_left = None vector_right = None # print(self.left_eye) # print(self.right_eye) if self.left_eye and self.left_eye.purkinje and self.left_eye.pupil_center: vector_left = (self.left_eye.purkinje[0] - self.left_eye.pupil_center[0], self.left_eye.purkinje[1] - self.left_eye.pupil_center[1]) if self.right_eye and self.right_eye.purkinje and self.right_eye.pupil_center: vector_right = (self.right_eye.purkinje[0] - self.right_eye.pupil_center[0], self.right_eye.purkinje[1] - self.right_eye.pupil_center[1]) if vector_left: vector = vector_left elif vector_right: vector = vector_right elif vector_left and vector_right: vector = ((vector_left[0] + vector_right[0]) // 2, (vector_left[1] + vector_right[1]) // 2) self.vector = vector def get_vector(self): return self.vector def get_gaze(self): gaze = None if self.vector: # try: gaze = self.calibration.compute(self.vector) # except sklearn.exceptions.NotFittedError: # except: # print("CALIBRATION REQUIRED!") return gaze
def __init__(self): self.frame = None self.eye_left = None self.eye_right = None self.calibration = Calibration() self._face_detector = dlib.get_frontal_face_detector() cwd = os.path.abspath(os.path.dirname(__file__)) model_path = os.path.abspath(os.path.join(cwd, "prathikeyedata.dat")) self._predictor = dlib.shape_predictor(model_path)
def __init__(self): self.frame = None self.eye_left = None self.eye_right = None self.calibration = Calibration() # _face_detector is used to detect faces self._face_detector = dlib.get_frontal_face_detector() # _predictor is used to get facial landmarks of a given face model_path = "shape_predictor_68_face_landmarks.dat" self._predictor = dlib.shape_predictor(model_path)
def convertValues(muxData): muxId = muxData[0] dataToConvert = muxData[4:] for i in range(len(dataToConvert)): sensor = cal.muxHeader["mux%d" % muxId][i//2] if "Dis" not in dataToConvert[i]: # Convertion to subchannel A if i % 2 == 0: if sensor == "PT100": dataToConvert[i] = cal.convertPT100(dataToConvert[i]) elif sensor == "VWS2100": dataToConvert[i] = cal.convertVWS2100((i//2) + 1, dataToConvert[i]) else: dataToConvert[i] = cal.convertVWTS6000(muxId, (i//2) + 1, dataToConvert[i]) updateEpicsPV(muxId, (i//2) + 1, "A", dataToConvert[i]) # Convertion to subchannel B else: dataToConvert[i] = cal.convertChannelB(dataToConvert[i]) updateEpicsPV(muxId, (i//2) + 1, "B", dataToConvert[i]) return muxData[:4] + dataToConvert
def __init__(self): self.frame = None self.eye_left = None self.eye_right = None self.calibration = Calibration() # _face_detector is used to detect faces self._face_detector = dlib.get_frontal_face_detector() # _predictor is used to get facial landmarks of a given face cwd = os.path.abspath(os.path.dirname(__file__)) model_path = os.path.abspath(os.path.join(cwd, "trained_models/shape_predictor_68_face_landmarks.dat")) self._predictor = dlib.shape_predictor(model_path)
def __init__(self, *args, **kwds): gr.sync_block.__init__( self, name="rstt_panel", in_sig=[(np.int16, 240)], out_sig=None, ) self.panel = rsttWxPanel(*args, **kwds) self.calib = CalibrationCollector() self.frame_prev = None self.calibrated = False self.conf = None
def __init__(self, *args, **kwds): gr.sync_block.__init__( self, name = "rstt_panel", in_sig = [(np.int16, 240)], out_sig = None, ) self.panel = rsttWxPanel(*args, **kwds); self.calib = CalibrationCollector() self.frame_prev = None self.calibrated = False self.conf = None
def check_hashrate(self): hashrates = Calibration().get_hashrates(self) if len(self.algos) == 0: return miner = self.algos[0]['miner'] algo = self.algos[0]['algo'] if not miner in hashrates.keys() or not algo in hashrates[miner].keys( ): self.log( 'warning', 'running uncalibrated algorithm %s with miner %s' % (algo, miner)) return if self.algos[0]['algo'] in Config().get('algorithms.single'): baseline = float(hashrates[miner][algo]['hashrate']) else: baseline = float(hashrates[miner][algo]['hashrate'][0]) threshold_pc_value = ( baseline / 100) * Config().get('hashrate_alert_threshold_percent') hr_s = Units().hashrate_str(self.algos[0]['hashrate'][0]) bl_s = Units().hashrate_str(baseline) if self.algos[0]['hashrate'][0] < baseline and ( baseline - self.algos[0]['hashrate'][0]) >= threshold_pc_value: self.log( 'warning', 'hashrate %d%% below calibrated rate [%s < %s]' % (Config().get('hashrate_alert_threshold_percent'), hr_s, bl_s)) if self.algos[0]['hashrate'][0] > baseline and ( self.algos[0]['hashrate'][0] - baseline) >= threshold_pc_value: self.log( 'warning', 'hashrate %d%% above calibrated rate [%s > %s]' % (Config().get('hashrate_alert_threshold_percent'), hr_s, bl_s))
def __init__(self,con,loop=None): ''':param web.rest.base.Connection con: the base http connection ''' self.conn = con conf = Config() self.ws = None self.cal = Calibration() self.url = conf.get_rest_base()+ "/warning" self.ws_url = conf.get_ws_base()+ "/warn" self.configs = [] if loop is not None: self.loop = loop else: self.loop = asyncio.new_event_loop() self.__current = {}
def __init__(self): path = 'frames/' day_images = SkyCameraFile.glob(path) day_images.sort() times = np.array([SkyCameraFile.parseTime(x).datetime for x in day_images]) self.day_images = day_images self.times = times self.calibration = Calibration(catalog=SkyCatalog(True)) self.calibration.load() self.helper = CloudDetectionHelper() try: with open('cd_sst.cache', 'rb') as f: self.cache = pickle.load(f) except: self.cache = pd.DataFrame(index=pd.Index([], dtype=np.datetime64), columns=['pos_x', 'pos_y', 'radius', 'stripe_min', 'stripe_max'])
def __init__(self, *args, **kwds): gr.sync_block.__init__( self, name = "rstt_panel", in_sig = [(np.int16, 240)], out_sig = None, ) QtWidgets.QWidget.__init__(self) vlayout = Qt.QVBoxLayout() layout = Qt.QHBoxLayout() label_nr = Qt.QLabel("Frame Nr") self.frame_num = Qt.QLabel("xxx") self.frame_num.setStyleSheet("font-weight: bold") label_node = Qt.QLabel("Node ID") self.node_id = Qt.QLabel("xxxxxxxx") self.node_id.setStyleSheet("font-weight: bold") self.calibrated_label = Qt.QLabel("not calibrated") self.calibrated_label.setStyleSheet("font-weight:bold; color: red") plotWidget = QtWidgets.QWidget(self) self.plot = RsttCanvas(plotWidget, width=5, height=4, dpi=100) layout.addWidget(label_nr) layout.addWidget(self.frame_num) layout.addWidget(label_node) layout.addWidget(self.node_id) layout.addWidget(self.calibrated_label) vlayout.addWidget(self.plot) vlayout.addLayout(layout) self.setLayout(vlayout) self.calib = CalibrationCollector() self.frame_prev = None self.calibrated = False self.conf = None
RFduinoConn = BleConn(inputArgs.sourceMac, inputArgs.MAC, inputArgs.interface) def getValue(): if inputArgs.uuid: return RFduinoConn.readValueFromUUID(inputArgs.uuid) else: return RFduinoConn.readValueFromHandle(inputArgs.handle) def unpackFloat(hex): return struct.unpack("f", binascii.unhexlify(hex))[0] def unpackInt(hex): return struct.unpack("h", binascii.unhexlify(hex))[0] c = Calibration() dsp = DSP(9) value = getValue() if inputArgs.debug: print value while inputArgs.continuous: value = getValue() hexStr = "".join(value.split(" ")) gx = unpackInt(hexStr[:4]) gy = unpackInt(hexStr[4:8]) gz = unpackInt(hexStr[8:12]) ax = unpackInt(hexStr[12:16]) ay = unpackInt(hexStr[16:20])
class WsWarning(object): def __init__(self,con,loop=None): ''':param web.rest.base.Connection con: the base http connection ''' self.conn = con conf = Config() self.ws = None self.cal = Calibration() self.url = conf.get_rest_base()+ "/warning" self.ws_url = conf.get_ws_base()+ "/warn" self.configs = [] if loop is not None: self.loop = loop else: self.loop = asyncio.new_event_loop() self.__current = {} def get_configs(self): if len(self.configs) == 0: try: pkt = self.conn.get(self.url) if pkt['status'] == 'OK': for c in pkt['configs']: u = self.url + "/"+ str(c['id']) pkt_c = self.conn.get(u) if pkt_c['status'] == 'OK': c = {'id':c['id'],'name':pkt_c['name'],'config':[]} for w in pkt_c['data']: pol = w['pol'] hk = w['warn'] c['config'].append({ 'pol' : pol, 'hk' : hk, 'min_a' : self.cal.calibrate(pol,hk,w['min_a']), 'min_w' : self.cal.calibrate(pol,hk,w['min_w']), 'max_w' : self.cal.calibrate(pol,hk,w['max_w']), 'max_a' : self.cal.calibrate(pol,hk,w['max_a']) }) self.configs.append(c) else: warnings.warn('error while loading configuration',RuntimeWarning) else: warnings.warn('error while loading configurations',RuntimeWarning) except Exception as e: warnings.warn(str(e),RuntimeWarning) return self.configs def set_config(self,conf): if type(conf) == int: #load conf from id self.get_configs() for i in self.configs: if conf == i['id']: self.__set_config(i) break else: raise RuntimeError('config not found') elif type(conf) == str: self.get_configs() for i in self.configs: if conf == i['name']: self.__set_config(i) break else: raise RuntimeError('config not found') elif type(conf) == dict: #set new config self.__set_config(conf) else: raise RuntimeError('Bad Configuration') def add_warning(self,pol,hk,min_a,min_w,max_w,max_a): warn = { 'pol' : pol, 'warn' : hk, 'min_a' : self.cal.reverse(pol,hk,min_a), 'min_w' : self.cal.reverse(pol,hk,min_w), 'max_w' : self.cal.reverse(pol,hk,max_w), 'max_a' : self.cal.reverse(pol,hk,max_a) } if self.__current.get('config') is None: self.__current['config'] = [] self.__current['config'].append(warn) if self.ws is not None: self.__add_warning(warn) async def connect(self): if self.ws is None: self.ws = WsBase(self.conn) await self.ws.connect(self.ws_url) def clear_config(self): if self.ws is not None and self.__current.get('config') is not None: for c in self.__current['config']: pkt = {'pol':c['pol'],'remove':c['warn']} self.loop.call_soon_threadsafe(asyncio.async,self.ws.send(pkt)) self.__current = {} def save_config(self,name=None,force_new=False): if force_new and self.__current.get('id') is not None: del self.__current['id'] if name is not None: self.__current['name'] = name pkt = {'save':self.__current.get('name','unnamed_config'), 'config' : self.__current.get('config',[]) } res = {'status':'ERROR'} if self.__current.get('id') is None: #save new config res = self.conn.post(self.url,message) else: #update existing conf url = self.url + "/" + str(self.__current['id']) res = self.conn.put(self.url,pkt) if res['status'] == 'OK': self.__current['id'] = res['id'] async def recv(self): ''' waits for warning packet and decodes it from json string :return: dictionary of the decoded json. ''' pkt = await self.ws.recv() return pkt def __set_config(self,conf): self.clear_config() self.__current = {'config':[]} self.__current['id'] = conf.get('id') self.__current['name'] = conf.get('name') for c in conf['config']: pol = c['pol'] hk = c['hk'] warn = { 'pol' : pol, 'warn' : hk, 'min_a' : self.cal.reverse(pol,hk,c['min_a']), 'min_w' : self.cal.reverse(pol,hk,c['min_w']), 'max_w' : self.cal.reverse(pol,hk,c['max_w']), 'max_a' : self.cal.reverse(pol,hk,c['max_a']) } self.__current['config'].append(warn) if self.ws is not None: self.__add_warning(warn) def __add_warning(self,warn): self.loop.call_soon_threadsafe(asyncio.async,self.ws.send(warn))
class CDSST: def __init__(self): path = 'frames/' day_images = SkyCameraFile.glob(path) day_images.sort() times = np.array([SkyCameraFile.parseTime(x).datetime for x in day_images]) self.day_images = day_images self.times = times self.calibration = Calibration(catalog=SkyCatalog(True)) self.calibration.load() self.helper = CloudDetectionHelper() try: with open('cd_sst.cache', 'rb') as f: self.cache = pickle.load(f) except: self.cache = pd.DataFrame(index=pd.Index([], dtype=np.datetime64), columns=['pos_x', 'pos_y', 'radius', 'stripe_min', 'stripe_max']) def save_cache(self): with open('cd_sst.cache', 'wb') as f: pickle.dump(self.cache, f) def detect(self, filename): image = cv2.imread(filename) time = SkyCameraFile.parseTime(filename).datetime mask = np.uint8(self.helper.get_mask(image).copy()) self.calibration.selectImage(filename) pos = self.calibration.project() pos = (pos[0], pos[1]) if time in self.cache.index: sun_x, sun_y, radius, min_x, max_x = self.cache.loc[time] sun = None sun_pos = None if not np.isnan(sun_x): sun_pos = (sun_x, sun_y) sun = CDSunRemoval.circle_mask(sun_pos, radius, mask.shape) sun_line = None if not np.isnan(min_x): sun_line = np.zeros(mask.shape, np.uint8) sun_line[:, min_x:max_x + 1] = True else: sun_line, min_x, max_x = CDSunRemoval.find_sun_line(image, pos) sun, sun_pos, radius = CDSunRemoval.find_sun(pos, mask) sun_x = sun_y = None if sun_pos is not None: sun_x = sun_pos[0] sun_y = sun_pos[1] self.cache.loc[time] = [sun_x, sun_y, radius, min_x, max_x] if sun_pos is None: sun_pos = pos mask = self.helper.fullmask.copy() mask[self.helper.mask == 0] = 0 mask = cv2.morphologyEx(mask, cv2.MORPH_CLOSE, np.ones((11, 11), np.uint8)) _, contours, _ = cv2.findContours(mask, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) cloudiness = np.ones(mask.shape, np.float32) * .5 did_sun = False for contour in contours: area = cv2.contourArea(contour) is_sun = False if area > 100: # TODO: try different numbers single_contour = np.zeros(mask.shape, np.uint8) cv2.drawContours(single_contour, [contour], 0, 1, cv2.FILLED) if sun is not None and not did_sun: sun_area = np.sum(sun[self.helper.mask == 1]) if area > 0.9 * sun_area: joint_area = np.sum(np.logical_and(single_contour, sun)) if sun_area / joint_area > 0.9: is_sun = True if is_sun: if sun_area * 1.2 < area: difference = np.uint8(np.logical_and(np.logical_not(sun), single_contour)) _, contours2, _ = cv2.findContours(difference, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE) # filter smaller ones here! currently done with the if at the beginning contours += contours2 did_sun = True if not is_sun: cloudiness[single_contour > 0] = 1.0 b, g, r = cv2.split(np.int32(image)) mask = self.helper.mask rmb = r - b rmb[mask == 0] = 0 cloudiness[rmb < -10] = 0 cloudiness[rmb > 50] = 1 delta = np.timedelta64(39, 's') delta2 = np.timedelta64(0, 's') time_diff = time - self.times before = np.logical_and(time_diff > delta2, time_diff < delta) if np.sum(before) == 0: raise ValueError('No previous image found.') current_index = np.where(before)[0][0] prev_img = cv2.imread(self.day_images[current_index]) gray_prev = cv2.cvtColor(prev_img, cv2.COLOR_BGR2GRAY) gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) flow = cv2.calcOpticalFlowFarneback(gray_prev, gray_image, None, 0.5, 3, 15, 3, 5, 1.2, 0) flow2 = -cv2.calcOpticalFlowFarneback(gray_image, gray_prev, None, 0.5, 3, 15, 3, 5, 1.2, 0) mag1, _ = cv2.cartToPolar(flow[...,0], flow[...,1]) mag2, _ = cv2.cartToPolar(flow2[...,0], flow2[...,1]) movement = np.logical_and(mag1 > 1, mag2 > 1) no_movement = np.logical_not(movement) brightness = np.mean(image, 2) cloudiness[np.logical_and(movement == 1, cloudiness != 0)] = 1 cloudiness[self.helper.mask == 0] = 1 if sun is not None: cloudiness[sun == 1] = 1 if sun_line is not None: sun_line_dilated = cv2.morphologyEx(sun_line, cv2.MORPH_DILATE, np.ones((1, 3))) cloudiness[sun_line_dilated == 1] = 1 y, x = np.mgrid[0:brightness.shape[0], 0:brightness.shape[1]] x1 = [] y1 = [] out = [] for i in range(brightness.shape[0]): for j in range(brightness.shape[1]): if cloudiness[i, j] != 1: x1.append(x[i, j]) y1.append(y[i, j]) out.append(brightness[i, j]) x = np.array(x1) - sun_pos[0] y = np.array(y1) - sun_pos[1] out = np.array(out) dist = np.sqrt(x * x + y * y) A = np.array([dist, np.ones(x.shape), x, y]).transpose() A_inv = np.linalg.pinv(A) param = np.dot(A_inv, out) y, x = np.mgrid[0:brightness.shape[0], 0:brightness.shape[1]] x = x - pos[0] y = y - pos[1] dist = np.sqrt(x * x + y * y) A = np.array([dist, np.ones(x.shape), x, y]).transpose() gradient = np.dot(A, param).transpose() rect_size = 15 rect_border = (rect_size - 1) // 2 brightness_norm = brightness - gradient stddev = np.zeros(brightness.shape) for y in range(image.shape[0]): for x in range(image.shape[1]): if cloudiness[y, x] == 1: continue lx = x - rect_border rx = x + rect_border + 1 uy = y - rect_border dy = y + rect_border + 1 if lx < 0: lx = 0 if uy < 0: uy = 0 if rx > image.shape[1]: rx = image.shape[1] if dy > image.shape[0]: dy = image.shape[0] mask_part = cloudiness[uy:dy, lx:rx] stddev[y, x] = np.std(brightness_norm[uy:dy, lx:rx][mask_part != 1]) def_clear = np.sum(cloudiness == 0) cloudiness[cloudiness == 0.5] = (stddev > 3)[cloudiness == 0.5] if sun is None or (sun_line is None and radius < 100): if def_clear < 0.1 * np.sum(self.helper.mask == 1): cloudiness[np.logical_and(cloudiness == 0, rmb > -8)] = 1 cloudiness = self.helper.close_result(cloudiness) cloudiness[self.helper.mask == 0] = 0.5 if sun is not None: cloudiness[sun == 1] = 0.5 if sun_line is not None: cloudiness[sun_line_dilated == 1] = 0.5 return cloudiness def get_cloud_cover(self, cloudiness): return np.sum(cloudiness == 1) / np.sum(cloudiness != 0.5)
def loadData(self, shotNum, skipAPD = 1): """Load all the data for the given shot. Parameters: shotNum -- The shot number to load. skipAPD -- Set to 1 to skip the first APD (because of saturation). """ from numpy import arange self.shotNum = shotNum self.data = {} # Clear old data. self.filename = util.getDataFilePath(shotNum) nc = pycdf.CDF(self.filename) #print "Loading Raw Data\n" str_rawData = nc.var('str_rawdata').get() str_voltsPerBit = nc.var('str_voltsperbit').get() str_deltat = nc.var('str_deltat').get() str_zeroBit = nc.var('str_offset').get() acq_rawData = nc.var('rawdata').get() acq_voltsPerBit = nc.var('voltsperbit').get() acq_deltat = nc.var('deltat').get() acq_offset = nc.var('offset').get() roa = nc.var('roa').get() # take the poly list from the netCDF file (one entry for each channel) and unique-ify it # to have only one entry per poly plist_long = nc.var('poly').get() seen = {} for item in plist_long: seen[item] = 1 plist_short = seen.keys() plist_short.sort() # probably unnecessary, but just in case self.polyList = plist_short # load the calibration data after the file data, so that the poly list can be loaded for this shot self.calib = Calibration() self.calib.loadCalibration(shotNum, plist_short, skipAPD) # The number of data segments is one less than the total number of # segments. The last segment in the data file is used for calculating # the amplifier offsets. self.segments = arange(str_rawData.shape[1] - 1) apdIndex = 0 for poly in self.polyList: self.data[poly] = {} calib = self.calib.getPolyCalibration(poly) for segment in self.segments: numAPD = calib.numAPD ps = PolySegData() ps.calib = calib ps.poly = poly ps.segment = segment ps.shotNum=self.shotNum # If calib.skipAPD is 1, then we don't load the data for the # first APD. start = apdIndex + calib.skipAPD end = apdIndex + numAPD ps.str_voltsPerBit = str_voltsPerBit[start:end] ps.str_deltat = str_deltat[start:end] ps.str_zeroBit = str_zeroBit[start:end] ps.acq_voltsPerBit = acq_voltsPerBit[start:end] ps.acq_deltat = acq_deltat[start:end] ps.acq_offset = acq_offset[start:end] ps.roa = roa[start] # correction because p20 and p21 were flipped in the calib file # for Fall 2012 only, radial calib redone in December #if poly == 20: # ps.roa = 0.6030 #elif poly == 21: # ps.roa = 0.5181 ps.str_rawData = str_rawData[start:end, segment] ps.acq_rawData = acq_rawData[start:end, segment] # It's a bit inefficient to store the offset data with each # PolySegData object, but it is simple. ps.str_offsetRaw = str_rawData[start:end, len(self.segments)] ps.acq_offsetRaw = acq_rawData[start:end, len(self.segments)] # Set the usability flags for the DC and AC channels # The AC channels are set to be unused until AC calib is figured out ps.chanFlagDC = ones(numAPD - calib.skipAPD) #ps.chanFlagAC = ones(numAPD - calib.skipAPD) ps.chanFlagAC = zeros(numAPD - calib.skipAPD) self.data[poly][segment] = ps apdIndex += numAPD
class Data: """Class providing an interface to the raw data NetCDF files.""" def __init__(self): """Constructor.""" self.filename = None # The filename the data was loaded from. # Laser fire times come from the laser diode data in mdsplus. self.laserFireTimes = None self.shotNum = None self.data = {} self.polyList = None self.segments = None self.prelasing = None def loadData(self, shotNum, skipAPD = 1): """Load all the data for the given shot. Parameters: shotNum -- The shot number to load. skipAPD -- Set to 1 to skip the first APD (because of saturation). """ from numpy import arange self.shotNum = shotNum self.data = {} # Clear old data. self.filename = util.getDataFilePath(shotNum) nc = pycdf.CDF(self.filename) #print "Loading Raw Data\n" str_rawData = nc.var('str_rawdata').get() str_voltsPerBit = nc.var('str_voltsperbit').get() str_deltat = nc.var('str_deltat').get() str_zeroBit = nc.var('str_offset').get() acq_rawData = nc.var('rawdata').get() acq_voltsPerBit = nc.var('voltsperbit').get() acq_deltat = nc.var('deltat').get() acq_offset = nc.var('offset').get() roa = nc.var('roa').get() # take the poly list from the netCDF file (one entry for each channel) and unique-ify it # to have only one entry per poly plist_long = nc.var('poly').get() seen = {} for item in plist_long: seen[item] = 1 plist_short = seen.keys() plist_short.sort() # probably unnecessary, but just in case self.polyList = plist_short # load the calibration data after the file data, so that the poly list can be loaded for this shot self.calib = Calibration() self.calib.loadCalibration(shotNum, plist_short, skipAPD) # The number of data segments is one less than the total number of # segments. The last segment in the data file is used for calculating # the amplifier offsets. self.segments = arange(str_rawData.shape[1] - 1) apdIndex = 0 for poly in self.polyList: self.data[poly] = {} calib = self.calib.getPolyCalibration(poly) for segment in self.segments: numAPD = calib.numAPD ps = PolySegData() ps.calib = calib ps.poly = poly ps.segment = segment ps.shotNum=self.shotNum # If calib.skipAPD is 1, then we don't load the data for the # first APD. start = apdIndex + calib.skipAPD end = apdIndex + numAPD ps.str_voltsPerBit = str_voltsPerBit[start:end] ps.str_deltat = str_deltat[start:end] ps.str_zeroBit = str_zeroBit[start:end] ps.acq_voltsPerBit = acq_voltsPerBit[start:end] ps.acq_deltat = acq_deltat[start:end] ps.acq_offset = acq_offset[start:end] ps.roa = roa[start] # correction because p20 and p21 were flipped in the calib file # for Fall 2012 only, radial calib redone in December #if poly == 20: # ps.roa = 0.6030 #elif poly == 21: # ps.roa = 0.5181 ps.str_rawData = str_rawData[start:end, segment] ps.acq_rawData = acq_rawData[start:end, segment] # It's a bit inefficient to store the offset data with each # PolySegData object, but it is simple. ps.str_offsetRaw = str_rawData[start:end, len(self.segments)] ps.acq_offsetRaw = acq_rawData[start:end, len(self.segments)] # Set the usability flags for the DC and AC channels # The AC channels are set to be unused until AC calib is figured out ps.chanFlagDC = ones(numAPD - calib.skipAPD) #ps.chanFlagAC = ones(numAPD - calib.skipAPD) ps.chanFlagAC = zeros(numAPD - calib.skipAPD) self.data[poly][segment] = ps apdIndex += numAPD def getSegments(self): """Return a list of available segment numbers.""" return self.segments def getPolyList(self): """Return the list of polys to fit.""" return self.polyList def getPolyListSortedROA(self): """Return the list of polys in order of increasing ROA.""" def sortFn(p1, p2): ps1 = self.getPolySegData(p1, 0) ps2 = self.getPolySegData(p2, 0) if ps1.roa == ps2.roa: return 0 elif ps1.roa > ps2.roa: return 1 else: return -1 tmpList = list(self.getPolyList()) tmpList.sort(sortFn) return tmpList def getPolySegData(self, poly, segment): """Get the data for a given poly and segment combination. Parameters: poly -- The poly number. segment -- The segment number. Returns: The data for the given poly and segment in the form of a PolySegData object. """ return self.data[poly][segment] def setPolySegData(self, poly, segment, ps): """Set the data for a given poly and segment to the given PolySegData object. Parameters: poly -- The poly number. segment -- The segment number. ps -- The PolySegData object. Returns: Nothing. """ self.data[poly][segment] = ps def getReadme(self, bCompact=True): """Return a string to save to the readme variable in mdsplus.""" ret = '' for segment in self.getSegments(): for poly in self.getPolyList(): ps = self.getPolySegData(poly, segment) st = None if bCompact: st = ps.getCompactErrWarnStr() else: st = ps.getErrWarnStr() if st != None: ret += '%s\n' % st return ret
def __init__(self, calibration_file): self.calibration = Calibration() self.calibration.load(calibration_file)
class StarCheckerHelper: def __init__(self, calibration_file): self.calibration = Calibration() self.calibration.load(calibration_file) def prepare(self, path, star_finder): with warnings.catch_warnings(): warnings.simplefilter('ignore', AstropyWarning) self.calibration.selectImage(path) self.names, self.vmag, alt, az = self.calibration.catalog.filter(Configuration.min_alt * u.deg, Configuration.max_mag) altaz = np.array([alt.radian, az.radian]).transpose() self.pos = np.column_stack(self.calibration.project(altaz)) self.finder = star_finder self.image = cv2.imread(path) self.finder.setImage(self.image) self.altaz = np.array([alt.degree, az.degree]).transpose() def count_stars(self): min_az = 0 max_az = 360 min_alt = Configuration.min_alt max_alt = 90 alt_step = Configuration.alt_step az_step = Configuration.az_step alt_bins = int((max_alt - min_alt) / alt_step) az_bins = int((max_az - min_az) / az_step) counts = np.zeros([alt_bins, az_bins, 4]) for alt_bin in range(alt_bins): alt = min_alt + alt_step * alt_bin for az_bin in range(az_bins): az = min_az + az_step * az_bin counts[alt_bin, az_bin, 2] = alt counts[alt_bin, az_bin, 3] = az for i in range(self.pos.shape[0]): aa = self.altaz[i] if aa[0] > alt and aa[0] <= alt + alt_step and aa[1] > az and aa[1] <= az + az_step: counts[alt_bin, az_bin, 0] += 1 if self.finder.isStar(self.pos[i][0], self.pos[i][1]): counts[alt_bin, az_bin, 1] += 1 return counts def get_image(self): result = self.image.copy() good_color = (0, 255, 0) bad_color = (0, 0, 255) for i in range(self.pos.shape[0]): if self.finder.isStar(self.pos[i][0], self.pos[i][1]): color = good_color else: color = bad_color cv2.circle(result, (int(self.pos[i][0]), int(self.pos[i][1])), 3, color) return result
def get_sigma_tau_w(w_arr, tau, r, m, sV0, E_f): T = 2. * tau / r # scale parameter with respect to a reference volume s = ((T * (m + 1) * sV0 ** m) / (2. * E_f * pi * r ** 2)) ** (1. / (m + 1)) ef0 = np.sqrt(w_arr * T / E_f) Gxi = 1 - np.exp(-(ef0 / s) ** (m + 1)) mu_int = ef0 * (1 - Gxi) sigma = mu_int *E_f return sigma cali = Calibration(experi_data=exp_data, w_arr=w_arr, tau_arr=tau_arr, m = 5., sV0=0.0085, alpha = 0., shape = 0.176, loc = 0.0057, scale = 0.76, bc=5, sig_mu=3.4) damage = cali.get_damage_portion(cali.sV0, 8.5e-2) print((np.sum(2*cali.tau_arr/cali.r*cali.tau_weights))) # # # print cali.sig_mu*(1-cali.V_f)/(cali.bc*cali.V_f) # print np.sum(cali.tau_weights*cali.matrix_stress(9.5, 4.4e-2))
class rsttPanel(gr.sync_block, QtWidgets.QWidget): def __init__(self, *args, **kwds): gr.sync_block.__init__( self, name = "rstt_panel", in_sig = [(np.int16, 240)], out_sig = None, ) QtWidgets.QWidget.__init__(self) vlayout = Qt.QVBoxLayout() layout = Qt.QHBoxLayout() label_nr = Qt.QLabel("Frame Nr") self.frame_num = Qt.QLabel("xxx") self.frame_num.setStyleSheet("font-weight: bold") label_node = Qt.QLabel("Node ID") self.node_id = Qt.QLabel("xxxxxxxx") self.node_id.setStyleSheet("font-weight: bold") self.calibrated_label = Qt.QLabel("not calibrated") self.calibrated_label.setStyleSheet("font-weight:bold; color: red") plotWidget = QtWidgets.QWidget(self) self.plot = RsttCanvas(plotWidget, width=5, height=4, dpi=100) layout.addWidget(label_nr) layout.addWidget(self.frame_num) layout.addWidget(label_node) layout.addWidget(self.node_id) layout.addWidget(self.calibrated_label) vlayout.addWidget(self.plot) vlayout.addLayout(layout) self.setLayout(vlayout) self.calib = CalibrationCollector() self.frame_prev = None self.calibrated = False self.conf = None def work(self, input_items, output_items): inp = input_items[0] for i in range(len(inp)): data = [] for x in inp[i]: data.append(x&0xFF) data.append(x>>8) frame = Frame(data, self.frame_prev) if not frame: print "no frame" + str(frame) continue if not frame.is_broken(): self.frame_prev = frame self.conf = frame.get(SF_TYPE_CONFIG) if self.conf is not None: frame_num = self.conf.frame_num node_id = self.conf.id calibration_num = self.conf.calibration_num self.node_id.setText(str(node_id)) self.frame_num.setText(str(frame_num)) else: frame_num = 0 self.meas = frame.get(SF_TYPE_MEASUREMENTS) if self.meas is not None and self.conf is not None: temp = self.meas.temp hum = self.meas.hum_down pres = self.meas.pressure self.plot.update_figure(frame_num, temp, hum, pres) if not self.calibrated and self.conf is not None: self.calibrated = self.calib.addFragment(self.conf.calibration_num, self.conf.calibration_data) if self.calibrated: print("calibration complete at frame %s" % frame_num) calib_data = self.calib.data() self.calib = Calibration(calib_data) self.calibrated_label.setText("calibrated") self.calibrated_label.setStyleSheet("color: green") print("frame: %s %s" % (frame_num, not frame.is_broken(), )) return len(inp)