def getMeasurement(self):

        newMeasurement = Measurement()
        newMeasurement.timeStamp = time.time()
        newMeasurement.value = 1
        newMeasurement.units = self.sensorUnits
        return newMeasurement
    def __init__(self):
        self.tracker = TrackerManager()
        self.measurement = Measurement()

        self.headmovement_trigger_counter = 0
        self.headmovement_ref_position = [0, 0, 1]
        self.auto_trigger_by_headmovement = False

        self._timer = QtCore.QTimer()
        self._timer.timeout.connect(self.callback_thread)
        self.timer_interval_ms = 20
        self._timer.start(20)

        self.measurement_running_flag = False
        self.measurement_position = []
        self.measurement_valid = False
        self.measurement_history = np.array([])
        self.measurement_trigger = False
        self.reference_measurement_trigger = False

        self.measurement_done_lock = threading.Lock()

        self.gui_handle = []

        self.measurements = np.array([])
        self.raw_signals = np.array([])
        self.raw_feedbackloop = np.array([])

        self.measurements_reference = np.array([])
        self.raw_signals_reference = np.array([])
        self.raw_feedbackloop_reference = np.array([])

        self.positions = np.array([])
        self.positions_list = MeasurementListModel()

        self.hp_irs = np.array([])
        self.raw_signals_hp = np.array([])
        self.raw_feedbackloop_hp = np.array([])
        self.numHPMeasurements = 0

        self.numMeasurements = 0

        self.guidance_running = False
        self.recommended_points = {}
        self.point_recommender = pointrecommender.PointRecommender(
            self.tracker)
        #self.point_recommender.get_head_rotation_to_point(260, 40)

        today = date.today()
        self.current_date = today.strftime("%d_%m_%Y")

        self.reproduction_mode = False
        self.reproduction_running = False
        self.reproduction_player = None

        self.send_osc_data = False
        self.osc_send_ip = '127.0.0.1'
        self.osc_send_port = 1337
        self.osc_send_address = '/guided_hrtfs/angle'
        self.osc_send_client = None
Exemplo n.º 3
0
 def __init__(self, gui):
     self.debug = True
     Measurement.__init__(self, gui)
     self.hardware = self.gui.hardware_components['em_hardware']
     self.hardware.connect()
     self._id = pythoncom.CoMarshalInterThreadInterfaceInStream(
         pythoncom.IID_IDispatch, self.hardware.Scope)
     em_gui.__init__(self, gui)
    def __init__(self, name):
        Measurement.__init__(self, name, mclass="Pulse_Cal")
        ###########################################################
        ##
        ##  hardcoded in ADwin program (adjust there if necessary!)
        ##

        self.max_SP_bins = 500
        self.max_RO_dim = 1000000
 def __init__(self,name):
     Measurement.__init__(self,name,mclass='ADwin_SSRO')
     
         ########################################################### 
 ##
 ##  hardcoded in ADwin program (adjust there if necessary!)
 ##
     self.max_repetitions = 20000
     self.max_SP_bins = 500
     self.max_SSRO_dim = 1000000
Exemplo n.º 6
0
    async def _on_telemetry(self, sid, data):
        # Visualize data received data
        print('Telemetry received: ', data)

        # Communication
        return_msg = dict()
        if data is not None:

            meas_list = str.split(data['sensor_measurement'])

            # Parse data accordingly to sensor type
            if meas_list[0] == "L":
                measurement = Measurement(
                    sensor=Sensor.LIDAR,
                    data=np.array([float(x) for x in meas_list[1:3]]),
                    ts_us=int(meas_list[3]))
                groundtruth = [float(x) for x in meas_list[4:8]]

            elif meas_list[0] == "R":

                measurement = Measurement(
                    sensor=Sensor.RADAR,
                    data=np.array([float(x) for x in meas_list[1:4]]),
                    ts_us=int(meas_list[4]))
                groundtruth = [float(x) for x in meas_list[5:9]]

            else:
                raise ValueError('Not correct sensor type')

            self.ekf.process_measurement(measurement)
            estimation = self.ekf.get_estimation()

            # Stack history of estimation vs groundtruth
            self.estimations_history.append(estimation)
            self.groundtruth_history.append(groundtruth)

            # Calculate RMSE
            estimation_rmse = rmse(self.estimations_history,
                                   self.groundtruth_history)

            # Create message
            return_msg['estimate_x'] = float(estimation[0])
            return_msg['estimate_y'] = float(estimation[1])
            return_msg['rmse_x'] = estimation_rmse[0]
            return_msg['rmse_y'] = estimation_rmse[1]
            return_msg['rmse_vx'] = estimation_rmse[2]
            return_msg['rmse_vy'] = estimation_rmse[3]

            # Message sending
            print("Sending data: ", return_msg)
            await self._sio.emit('estimate_marker', return_msg)

        else:
            # If data is not valid, send dummy response
            await self._sio.emit('manual', {})
    def __init__(self, name):
        Measurement.__init__(self, name, mclass="ADwin_SSRO")

        ###########################################################
        ##
        ##  hardcoded in ADwin program (adjust there if necessary!)
        ##
        self.max_repetitions = 20000
        self.max_SP_bins = 500
        self.max_SSRO_dim = 3500000
        self.d = expdict.ssroprotocol
Exemplo n.º 8
0
    def __init__(self,name):
        Measurement.__init__(self,name,mclass='Pulse_Cal')
    ###########################################################
##
##  hardcoded in ADwin program (adjust there if necessary!)
##

        self.max_SP_bins = 500
        self.max_RO_dim = 1000000

##
###########################################################


        self.set_phase_locking_on = 0
        self.set_gate_good_phase = -1

        self.f_drive            =                   2.828e9

        self.par = {}
        
        self.par['AWG_start_DO_channel'] =         1
        self.par['AWG_done_DI_channel'] =          8
        self.par['send_AWG_start'] =               1
        self.par['wait_for_AWG_done'] =            0
        self.par['green_repump_duration'] =        10
        self.par['CR_duration'] =                  60
        self.par['SP_duration'] =                  50
        self.par['SP_filter_duration'] =           0
        self.par['sequence_wait_time'] =           int(np.ceil(1e-3)+2)
        self.par['wait_after_pulse_duration'] =    1
        self.par['CR_preselect'] =                 1000

        self.par['reps_per_datapoint'] =           1000
        self.par['sweep_length'] =                 int(21)
        self.par['RO_repetitions'] =               int(21*1000)
        self.par['RO_duration'] =                  22

        self.par['cycle_duration'] =               300
        self.par['CR_probe'] =                     100

        self.par['green_repump_amplitude'] =       200e-6
        self.par['green_off_amplitude'] =          0e-6
        self.par['Ex_CR_amplitude'] =              20e-9 #OK
        self.par['A_CR_amplitude'] =               15e-9 #OK
        self.par['Ex_SP_amplitude'] =              0 
        self.par['A_SP_amplitude'] =               15e-9 #OK: PREPARE IN MS = 0
        self.par['Ex_RO_amplitude'] =              8e-9 #OK: READOUT MS = 0
        self.par['A_RO_amplitude'] =               0e-9

        self.par['min_sweep_par'] =                  0
        self.par['max_sweep_par'] =                  1
        self.par['sweep_par_name'] =                 ''
        self.par['sweep_par']   =                  np.linspace(1,21,21)
Exemplo n.º 9
0
    def getAccMeasurement(self):
        address = self.address_book['ACC_ADDRESS']
        raw_data = self.readBlock(address, 'OUT_X_L_A')
        time_meas = time.time()
        acc_LSB = 0.732 * 1e-3  # g/LSB  TODO: make this dependent on the initialisation command
        factor_ms2_per_gn = 9.80665  # From http://www.bipm.org/utils/common/pdf/si_brochure_8_en.pdf#page=51
        acc = [row * acc_LSB * factor_ms2_per_gn for row in raw_data]

        # Create new measurement object
        newMeasurement = Measurement()
        newMeasurement.timeStamp = time_meas
        newMeasurement.value = acc
        newMeasurement.units = 'm/s^2'
        return newMeasurement
Exemplo n.º 10
0
    def getMagMeasurement(self):
        address = self.address_book['MAG_ADDRESS']
        raw_data = self.readBlock(address, 'OUT_X_L_M')
        time_meas = time.time()
        mag_LSB = 0.48 * 1e-3  # G/LSB  TODO: make this dependent on the initialisation command
        factor_tesla_per_gauss = 1e-4  # http://en.wikipedia.org/wiki/Gauss_%28unit%29
        mag_flux_density = [row * mag_LSB * factor_tesla_per_gauss for row in raw_data]

        # Create new measurement object
        newMeasurement = Measurement()
        newMeasurement.timeStamp = time_meas
        newMeasurement.value = mag_flux_density
        newMeasurement.units = 'T'
        return newMeasurement
Exemplo n.º 11
0
    def _perform_measurements(self):
        """TODO: Docstring for _perform_measurements.
        :returns: TODO

        """
        shutil.rmtree(config.DEFAULT_LOG_FILE_DIR, ignore_errors=True)
        makedirs(config.DEFAULT_LOG_FILE_DIR)
        with open(self.metafile_path, 'w') as mf:
            meta_writer = csv.writer(mf)
            meta_writer.writerow(['filename', 'taskname', 'alg'] +
                                 self._metafile_header_params())
            for alg_executable in config.ALGORITHMS:
                for point in Collector.parameter_space():
                    measurement = Measurement(alg_executable)
                    measurement.run(self.text_files_dir, self.regex_files_dir,
                                    point, meta_writer, self.task)
Exemplo n.º 12
0
    def runner__get_new_state_of_world(self, identifier):
        #
        # VARIABLES
        #
        from environment import Environment
        from measurement import Measurement
        from runner import Runner

        #
        # CODE
        #

        # we need the environment
        environment_directory = 'environments/'
        environment = Environment(identifier)
        environment.read_environment_file("./" + environment_directory +
                                          identifier + ".xml")
        environment.initialize()

        # and we need to create an exogenous network
        environment.network.create_exogenous_network(
            environment.parameter.network_density)
        # and also a measurement
        measurement = Measurement()

        runner = Runner(identifier, environment, measurement)
        print runner
        print
        runner.get_new_state_of_world(1)
        print runner
        runner.get_new_state_of_world(0)
        print runner
        runner.get_new_state_of_world(-1)
        print runner
  def test_get_url_response_time_almostok(self, mock_requests):
    # Mock correct response
    classinst = Measurement("http://example.com", 5)
    mock_requests.return_value.status_code = 503
    mock_requests.return_value.headers = {'Date': 'Wed, 31 Mar 2021 08:47:43 GMT'}
    mock_requests.return_value.text = "Mocked request response gateway timeout"
    
    ret = classinst.get_url_response_time()

    metricsDict = dict()
    metricsDict['url']          = "http://example.com"
    metricsDict['status_code']  = 503
    metricsDict['receivedtext'] = "Mocked request response gateway timeout"

    # do not use assertDictContainsSubset, deprecated
    self.assertEqual(dict(ret, **metricsDict), ret, "Wrong return from mock")
    self.assertIn("resptimems", ret, "No response time measurement in return from function when return code != 200")
Exemplo n.º 14
0
def main():
    test_file_path = os.path.join(TEST_DIR, TEST_FILENAME)
    packets = read_exchange_data(test_file_path)
    packet_exchanges = get_exchange_times(packets)
    measurement = Measurement(packet_exchanges, TEST_FILENAME)
    #measurement.filter_unreceived()
    measurement.show_send_periods()
    measurement.show_success_chance()
    measurement.show_anomalies_in_tx()
    return
Exemplo n.º 15
0
def tune_with_TPE(dp, xgb_model, opt):
    """
	Hyperparameter tuning using TPE:
	https://github.com/hyperopt/hyperopt/wiki/FMin

	for XGBOOST params doc see:
	https://github.com/dmlc/xgboost/blob/master/doc/parameter.md
	"""
    # add xgb_model,measurer
    X_train, X_test, y_train, y_test = get_data(dp)
    xgb_model.set_data((X_train, X_test, y_train, y_test))
    n2p_ratio = len(y_train[y_train == 0]) / len(y_train[y_train == 1])

    # set optimizer parameters
    opt.set_max_eval(2)

    # # add params to handle cv task
    # skf = StratifiedKFold(n_splits=3,shuffle=True,random_state=100)
    # X = np.concatenate([X_train,X_test])
    # y = np.concatenate([y_train,y_test])
    # xgb_model.set_data(xgb.DMatrix(X,label=y))

    # define search space
    search_space = {"n_estimators": hp.quniform("n_estimators",100,1500,50),
    "eta": hp.quniform("eta",0.025,0.1,0.025),
    "max_depth": hp.choice("max_depth",[3,4]),
    "min_child_weight": hp.quniform('min_child_weight',1,4,1),
    "subsample": hp.quniform("subsample",0.9,1.0,0.1),
    "colsample_bytree": hp.quniform("colsample_bytree",0.8,1.0,0.1),
    "gamma": hp.quniform("gamma",0,0.2,0.05),
    "scale_pos_weight": hp.quniform("scale_pos_weight",\
     n2p_ratio/10,n2p_ratio,n2p_ratio/10),
    # "alpha": hp.choice("alpha",[1e-5,1e-2,1,10]),
    "nthread":8,
    "silent":1,
    "seed":100,
    "measurer": Measurement(),
    "xgb_model": xgb_model,
    # "folds":list(skf.split(X,y)),
    # "tree_method":"auto",
    # "predictor":"cpu_predictor"
    }

    opt.set_search_space(search_space)
    opt.set_objective(objective)
    # start optimization
    best = opt.optimize()
    opt.save_trials(CURRENT_DIR)

    # retrain and save best model
    train_dmat, _ = xgb_model.get_train_test_Dmat()
    best_model = xgb.train(best,
                           train_dmat,
                           num_boost_round=int(best["n_estimators"]))
    xgb_model.set_model(best_model)
    xgb_model.save_model(save_path=MODEL_DIR,
                         model_name=str(best),
                         prefix="TPE_200_BestModel")
Exemplo n.º 16
0
    def __init__(self,name):
        Measurement.__init__(self,name,mclass='MBI')


###########################################################
##
##  hardcoded in ADwin program (adjust there if necessary!)
##

        self.max_SP_bins = 500
        self.max_RO_dim = 1000000

##
###########################################################
        
# load dictionary of sil
        self.sildic = exp.current_sample
        self.ssrodic = exp.ssroprotocol
        self.MBIdic = exp.MBIprotocol
        self.hardwaredic = exp.hardware
        self.pulsedic = exp.pulses

        self.MW_freq = self.sildic['MW_source_freq']
        self.MW_power = self.sildic['MW_source_power']
        self.set_phase_locking_on=0
        self.set_gate_good_phase=-1
       
        self.nr_of_datapoints= 21
        self.repetitions_per_datapoint = 500
        self.nr_of_RO_steps =    1
        self.do_shelv_pulse = False
        self.do_incr_RO_steps = exp.MBIprotocol['do_incr_RO_steps']
        self.incr_RO_steps = exp.MBIprotocol['incr_RO_steps']
        self.Ex_RO_amplitude = self.ssrodic['Ex_RO_amplitude']
        self.A_RO_amplitude = self.ssrodic['A_RO_amplitude']
        self.Ex_final_RO_amplitude = self.ssrodic['Ex_RO_amplitude']
        self.A_final_RO_amplitude = self.ssrodic['A_RO_amplitude']
        self.final_RO_duration= self.ssrodic['RO_duration']
        self.RO_duration= self.ssrodic['RO_duration']
        self.wait_after_RO = self.ssrodic['wait_after_pulse_duration']
        self.wait_for_AWG_done = 1.
        self.par = {}
        
        self.par['MBI_threshold']    =              1 # pass if counts > (MBI_threshold-1)
        self.par['RO_repetitions']  =               100
Exemplo n.º 17
0
    def getMeasurement(self):

        # Read raw data
        rawData = self.__readSensor()

        newMeasurement = Measurement()

        if rawData[0].strip()[-3:] == 'YES':
            time_meas = time.time()
            time.sleep(0.2)
            # Extract temperature from raw data
            self.temperature = self.__formatSensorData(rawData[1])

            newMeasurement.timeStamp = time_meas
            newMeasurement.value = self.temperature
            newMeasurement.units = self.sensorUnits

        return newMeasurement
Exemplo n.º 18
0
 def addMeasurement(self, name, lumi, lumiErr):
     #verify that this name is not already used
     for meas in self.measurements:
         if meas.name == name:
             raise RuntimeError("Measurement %s already exists in TopLevelXML %s. Please use a different name." % (name, self.name))
         pass
     #add measurement to the list
     self.measurements.append(Measurement(name, lumi, lumiErr))
     return self.measurements[len(self.measurements) - 1]
Exemplo n.º 19
0
def test_readcsv():
    mock_data1_file = os.path.join(dir_path, '../data/mock_data1/tagdata.csv')
    measurements = Measurement.readcsv(mock_data1_file)
    # based on manual inspection
    assert(measurements[-1].tagId == "1")
    assert(measurements[-1].anchorId == "4")
    assert(measurements[-1].rssi == "-90.375")
    assert(measurements[-1].timestamp == "60")
    assert(len(measurements) == 240)
Exemplo n.º 20
0
    def getGyrMeasurement(self):
        address = self.address_book['GYR_ADDRESS']
        time_before = time.time()
        raw_data = self.readBlock(address, 'OUT_X_L_G')
        time_meas = time.time()
        deltaT = time_meas-time_before
        #  print "max measurement delay [s]: " + str(deltaT)

        gyr_LSB = 0.07  # deg/s/LSB TODO: make this dependent on the initialisation command
        factor_rad_per_deg = 180 / np.pi
        rate = [row * gyr_LSB * factor_rad_per_deg for row in raw_data]

        # Create new measurement object
        newMeasurement = Measurement()
        newMeasurement.timeStamp = time_meas
        newMeasurement.value = rate
        newMeasurement.units = 'rad/s'
        return newMeasurement
Exemplo n.º 21
0
    def __init__(self, name):
        Measurement.__init__(self, name, mclass='MBI')

        ###########################################################
        ##
        ##  hardcoded in ADwin program (adjust there if necessary!)
        ##

        self.max_SP_bins = 500
        self.max_RO_dim = 1000000

        ##
        ###########################################################

        # load dictionary of sil
        self.sildic = exp.current_sample
        self.ssrodic = exp.ssroprotocol
        self.MBIdic = exp.MBIprotocol
        self.hardwaredic = exp.hardware
        self.pulsedic = exp.pulses

        self.MW_freq = self.sildic['MW_source_freq']
        self.MW_power = self.sildic['MW_source_power']
        self.set_phase_locking_on = 0
        self.set_gate_good_phase = -1

        self.nr_of_datapoints = 21
        self.repetitions_per_datapoint = 500
        self.nr_of_RO_steps = 1
        self.do_shelv_pulse = False
        self.do_incr_RO_steps = exp.MBIprotocol['do_incr_RO_steps']
        self.incr_RO_steps = exp.MBIprotocol['incr_RO_steps']
        self.Ex_RO_amplitude = self.ssrodic['Ex_RO_amplitude']
        self.A_RO_amplitude = self.ssrodic['A_RO_amplitude']
        self.Ex_final_RO_amplitude = self.ssrodic['Ex_RO_amplitude']
        self.A_final_RO_amplitude = self.ssrodic['A_RO_amplitude']
        self.final_RO_duration = self.ssrodic['RO_duration']
        self.RO_duration = self.ssrodic['RO_duration']
        self.wait_after_RO = self.ssrodic['wait_after_pulse_duration']
        self.wait_for_AWG_done = 1.
        self.par = {}

        self.par['MBI_threshold'] = 1  # pass if counts > (MBI_threshold-1)
        self.par['RO_repetitions'] = 100
Exemplo n.º 22
0
def get_shopping_list(menu):
    ingredients = dict()
    for meal in menu:

        try:
            meal_ingredients = recipes[meal]
        except KeyError:
            continue  # TODO deal with lack of recipe in recipe book

        for meal_ingredient, amount in meal_ingredients:
            if meal_ingredient in ingredients:
                ingredients[meal_ingredient] += Measurement(amount)
            else:
                ingredients[meal_ingredient] = Measurement(amount)

    ingredient_list = list()
    for ingredient, amount in ingredients:
        ingredient_list.append([ingredient, f'{amount.value} {amount.unit}'])
    return ingredient_list
Exemplo n.º 23
0
    def measurement__write_measurement(self, identifier):
        #
        # VARIABLES
        #
        from environment import Environment
        from measurement import Measurement
        from runner import Runner

        #
        # CODE
        #

        # we need the environment
        environment_directory = 'environments/'
        measurement_directory = 'measurements/'
        environment = Environment(identifier)
        environment.read_environment_file("./" + environment_directory +
                                          identifier + ".xml")
        environment.initialize()

        # and we need to create an exogenous network
        environment.network.create_exogenous_network(
            environment.parameter.network_density)
        # and also a measurement
        measurement = Measurement()
        for agent in environment.network.network.nodes():
            F0s = 1.0
            F1s = 1.0

            # we need the previous decisions of neighbors
            neighbors_previous_decision = []
            for neighbor in environment.network.network.neighbors(agent):
                neighbors_previous_decision.append(neighbor.previous_x)
            agent.compute_decision(neighbors_previous_decision,
                                   environment.parameter.num_agents, F0s, F1s)

        runner = Runner(identifier, environment, measurement)
        print runner

        runner.do_run()
        print runner

        measurement.write_measurement(measurement_directory + identifier)
Exemplo n.º 24
0
    def __init__(self, name):
        Measurement.__init__(self, name, mclass='Seg_RO')

        ###########################################################
        ##
        ##  hardcoded in ADwin program (adjust there if necessary!)
        ##
        self.sildic = expdict.current_sample
        self.ssrodic = expdict.ssroprotocol
        self.MBIdic = expdict.MBIprotocol
        self.hardwaredic = expdict.hardware
        self.pulsedic = expdict.pulses

        self.MW_freq = self.sildic['MW_source_freq']
        self.MW_power = self.sildic['MW_source_power']

        self.max_repetitions = 1000000
        self.max_SP_bins = 500
        self.max_SSRO_dim = 3500000
        self.d = expdict.ssroprotocol
Exemplo n.º 25
0
    def write_measurement_to_database(self, measurement, table_name):
        # This function writes to the db
        # TODO: check if the table exists before trying to insert data into it
        meas = Measurement.convert_to_dict(measurement)

        list_of_keys = meas.keys()
        list_of_values = [meas[key] for key in list_of_keys]

        sql_str = 'INSERT INTO  ' + table_name + ' ' + _assemble_insert_args(meas)

        self.modify_db(sql_str, list_of_values)
Exemplo n.º 26
0
    def test_fire_sales(self,
                        args):  # TODO not consistent with other test names
        import logging
        import networkx as nx

        from environment import Environment
        from runner import Runner
        from measurement import Measurement

        #
        # INITIALIZATION
        #
        environment_directory = str(args[1])
        identifier = str(args[2])
        log_directory = str(args[3])
        measurement_directory = str(args[4])

        # Configure logging parameters so we get output while the program runs
        logging.basicConfig(format='%(asctime)s %(message)s',
                            datefmt='%m/%d/%Y %H:%M:%S',
                            filename=log_directory + identifier + ".log",
                            level=logging.INFO)
        logging.info('START logging for run: %s',
                     environment_directory + identifier + ".xml")

        environment = Environment()
        environment.initialize(environment_directory, identifier)
        runner = Runner()
        measurement = Measurement()

        #
        # UPDATE STEP
        #
        for i in range(environment.parameters.numSimulations):
            environment.initialize(environment_directory, identifier)
            runner.initialize(environment)
            measurement.initialize()  # clear the previous measurement

            # do the run
            runner.do_run(measurement, "info")

            # do the histograms, i.e. add the current measurement to the histogram
            measurement.do_histograms()
            logging.info('')

        #
        # MEASUREMENT AND LOGGING
        #
        measurement.write_histograms(measurement_directory, environment)
        logging.info('FINISHED logging for run: %s \n',
                     environment_directory + identifier + ".xml")
Exemplo n.º 27
0
    def __init__(self,name):
        Measurement.__init__(self,name,mclass='Seg_RO')
        
            ########################################################### 
    ##
    ##  hardcoded in ADwin program (adjust there if necessary!)
    ##
        self.sildic = expdict.current_sample
        self.ssrodic = expdict.ssroprotocol
        self.MBIdic = expdict.MBIprotocol
        self.hardwaredic = expdict.hardware
        self.pulsedic = expdict.pulses

        self.MW_freq = self.sildic['MW_source_freq']
        self.MW_power = self.sildic['MW_source_power']
        
        
        self.max_repetitions = 1000000
        self.max_SP_bins = 500
        self.max_SSRO_dim = 3500000
        self.d = expdict.ssroprotocol
Exemplo n.º 28
0
def load_measurements(src_path, dest_list, predicate = lambda m: True):
    print("Loading from", src_path)
    with open(src_path) as dat:
        for ln in dat:
            if Measurement.CSV_HEADER in ln: continue
            try:
                m = Measurement(ln[:-1])
                if predicate and predicate(m):
                    dest_list.append(m)
            except Exception as e:
                print(e)
    print(src_path, "loaded successfully")
Exemplo n.º 29
0
    def tune_hyperparams_scikit(self, model, X_train, y_train):
        """
		Tuning parameters of model using scikit learn GridSearch
		"""
        print("Started CV task at " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

        # create gini scorer
        measurer = Measurement()
        gini_score = measurer.get_gini_scorer()

        params = [{
            "learning_rate": [0.01],
            "n_estimators": [100, 200],
            "seed": [100],
            "max_depth": [2],
            "min_child_weight": [1, 5],
            "subsample": [1]
        }]

        print("Running GridSearch")
        gscv = GridSearchCV(model,
                            params,
                            cv=2,
                            n_jobs=-1,
                            scoring=gini_score,
                            verbose=3,
                            error_score=0)
        gscv.fit(X_train, y_train)
        best_model = gscv.best_estimator_
        # save best model
        save_model(best_model, MODEL_DIR, prefix="CV5-bestModel-")
        # save CV results
        gscv_resutls = pd.DataFrame(gscv.cv_results_)
        gscv_resutls.to_csv("GridSearchRestest.csv", index=False)

        print("Finished CV task at " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Exemplo n.º 30
0
def visualize():
    test_file_path = os.path.join(TEST_DIR, TEST_FILENAME)
    exchange_data = read_exchange_data(test_file_path)
    packet_exchanges = Exchange.list_to_exchange(exchange_data)
    measurement = Measurement(exchanges=packet_exchanges,
                              test_name=TEST_FILENAME)
    measurement.filter_unreceived()
    measurement.filter_by_range(low=FILTER_MIN, high=FILTER_MAX)
    measurement.plot()

    results = count_results(packet_exchanges)
    print_sorted(results)

    print("Filtered:")
    results = filter_results_by_frequency(results)
    print_sorted(results)
Exemplo n.º 31
0
    def opds_entry(self):
        """Create an OPDS entry using only resources directly
        associated with this Identifier.
        This makes it possible to create an OPDS entry even when there
        is no Edition.
        Currently the only things in this OPDS entry will be description,
        cover image, and popularity.
        NOTE: The timestamp doesn't take into consideration when the
        description was added. Rather than fixing this it's probably
        better to get rid of this hack and create real Works where we
        would be using this method.
        """
        id = self.urn
        cover_image = None
        description = None
        most_recent_update = None
        timestamps = []
        for link in self.links:
            resource = link.resource
            if link.rel == LinkRelations.IMAGE:
                if not cover_image or (
                        not cover_image.representation.thumbnails
                        and resource.representation.thumbnails):
                    cover_image = resource
                    if cover_image.representation:
                        # This is technically redundant because
                        # minimal_opds_entry will redo this work,
                        # but just to be safe.
                        mirrored_at = cover_image.representation.mirrored_at
                        if mirrored_at:
                            timestamps.append(mirrored_at)
            elif link.rel == LinkRelations.DESCRIPTION:
                if not description or resource.quality > description.quality:
                    description = resource

        if self.coverage_records:
            timestamps.extend(
                [c.timestamp for c in self.coverage_records if c.timestamp])
        if timestamps:
            most_recent_update = max(timestamps)

        quality = Measurement.overall_quality(self.measurements)
        from ..opds import AcquisitionFeed
        return AcquisitionFeed.minimal_opds_entry(
            identifier=self,
            cover=cover_image,
            description=description,
            quality=quality,
            most_recent_update=most_recent_update)
Exemplo n.º 32
0
    def opds_entry(self):
        """Create an OPDS entry using only resources directly
        associated with this Identifier.
        This makes it possible to create an OPDS entry even when there
        is no Edition.
        Currently the only things in this OPDS entry will be description,
        cover image, and popularity.
        NOTE: The timestamp doesn't take into consideration when the
        description was added. Rather than fixing this it's probably
        better to get rid of this hack and create real Works where we
        would be using this method.
        """
        id = self.urn
        cover_image = None
        description = None
        most_recent_update = None
        timestamps = []
        for link in self.links:
            resource = link.resource
            if link.rel == LinkRelations.IMAGE:
                if not cover_image or (
                        not cover_image.representation.thumbnails and
                        resource.representation.thumbnails):
                    cover_image = resource
                    if cover_image.representation:
                        # This is technically redundant because
                        # minimal_opds_entry will redo this work,
                        # but just to be safe.
                        mirrored_at = cover_image.representation.mirrored_at
                        if mirrored_at:
                            timestamps.append(mirrored_at)
            elif link.rel == LinkRelations.DESCRIPTION:
                if not description or resource.quality > description.quality:
                    description = resource

        if self.coverage_records:
            timestamps.extend([
                c.timestamp for c in self.coverage_records if c.timestamp
            ])
        if timestamps:
            most_recent_update = max(timestamps)

        quality = Measurement.overall_quality(self.measurements)
        from ..opds import AcquisitionFeed
        return AcquisitionFeed.minimal_opds_entry(
            identifier=self, cover=cover_image, description=description,
            quality=quality, most_recent_update=most_recent_update
        )
Exemplo n.º 33
0
    def test_fire_sales(self, args):
        import logging
        import networkx as nx

        from environment import Environment
        from runner import Runner
        from measurement import Measurement

        #
        # INITIALIZATION
        #
        environment_directory = str(args[1])
        identifier = str(args[2])
        log_directory = str(args[3])
        measurement_directory = str(args[4])

        # Configure logging parameters so we get output while the program runs
        logging.basicConfig(
            format="%(asctime)s %(message)s",
            datefmt="%m/%d/%Y %H:%M:%S",
            filename=log_directory + identifier + ".log",
            level=logging.INFO,
        )
        logging.info("START logging for run: %s", environment_directory + identifier + ".xml")

        environment = Environment()
        environment.initialize(environment_directory, identifier)
        runner = Runner()
        measurement = Measurement()

        #
        # UPDATE STEP
        #
        for i in range(environment.parameters.numSimulations):
            environment.initialize(environment_directory, identifier)
            runner.initialize(environment)
            measurement.initialize()  # clear the previous measurement

            # do the run
            runner.do_run(measurement, "info")

            # do the histograms, i.e. add the current measurement to the histogram
            measurement.do_histograms()
            logging.info("")

            #
            # MEASUREMENT AND LOGGING
            #
        measurement.write_histograms(measurement_directory, environment)
        logging.info("FINISHED logging for run: %s \n", environment_directory + identifier + ".xml")
    def run(self, *args, initial_port=None, baud=None, dry=None):
        port = self.get_port(initial_port)
        ser = Serial(port, baud)

        measurement = Measurement()

        while 1:
            try:
                while not ser.is_open:
                    port = self.get_port(initial_port)
                    print('.', end='', flush=True)
                    if port:
                        ser.setPort(port)
                        try:
                            ser.open()
                            print('Serial connected', port, baud)
                            break
                        except SerialException as e:
                            print('\n', e)
                    time.sleep(5)
                serial_line = ser.readline().decode("utf-8")
                measurement.parse_line(serial_line)
                if measurement.completed:
                    if measurement.is_complete():
                        if dry:
                            print(measurement.as_dict())
                        else:
                            ok = send_measurement(measurement)
                            print('measurement send,', ok)
                    measurement = Measurement()

            except KeyboardInterrupt:
                print('Serial reader closed, keyboard interrupt')
                ser.close()
                break

            except SerialException as e:
                print('Serial exception', e)
                ser.close()

            except Exception:
                # Something went very wrong ?? Very dirty fix for now
                update_script = '/home/pi/update.sh'
                if os.path.isfile(update_script):
                    subprocess.call(update_script)
Exemplo n.º 35
0
def setup_2obs2parts_sameparams():
    out = {}
    params = {'beta1': 1, 'beta2': 1, 'z': 1, 'var': 1/(2*np.pi)}
    meas_data = pd.DataFrame(
                                     {
                                        'control': [1, 2],
                                        'control_2': [1, 1],
                                        'meas1': [-1, 5],
                                        'meas2': [0, 5],
                                        'meas3': [-1, 6]
                                     },
                                     index = [[1, 2], [1, 1]]
                             )
    out['meas_obj'] = Measurement([params, params, params], meas_data)
    out['facs_data'] = np.array([[-3, -2], [2, 3]])
    return out
Exemplo n.º 36
0
def test_zrangebyscore():
    fakeAnchorId = "fakeAnchorId"
    fakeTagId = "fakeTagId"
    fakeRssi = "0"
    fakeTimestamp = 0
    Measurement.zremrangebyrank(r, fakeTagId, 0, -1)
    fake_measurement = Measurement(fakeAnchorId, fakeTagId, fakeRssi, fakeTimestamp)
    fake_measurement.save(r)
    measurements = Measurement.zrangebyscore(r, fakeTagId, fakeTimestamp, fakeTimestamp)
    assert(len(measurements) == 1)
    assert(measurements[0].rssi == fakeRssi)
    assert(measurements[0].tagId == fakeTagId)
    assert(measurements[0].timestamp == fakeTimestamp)
    assert(measurements[0].anchorId == fakeAnchorId)
Exemplo n.º 37
0
def prepare_sampling(file):
    # INPUT: list of tuples
    print('prepare sampling')
    unsampledMeasures = list()
    print('sampling file: {}'.format(file))
    with open(file, 'r') as f:
        for row in f.readlines():
            # 2017-01-03T10:04:45
            liste = row.split(',')
            datetime_object = datetime.datetime.strptime(
                liste[0], '%Y-%m-%dT%H:%M:%S')
            unsampledMeasures.append(
                Measurement(datetime_object, liste[1],
                            liste[2].replace('\n', '')))
    print('Starting Sampling!')
    startSampling(unsampledMeasures)
Exemplo n.º 38
0
 def run(self):
     logging.info("Start "+self.version)
     #
     # Collect measurements
     #
     self.measurement=Measurement(None,self.ini)
     #
     #
     if self.want_collect_measurements:
         self.measurement.collect_new()
     #
     # Collect raw_reports
     #
     #
     self.report=Report(None, self.ini)
     if self.want_collect_reports:
         self.report.collect_new()
     #
     # Dispatch raw_reports
     #
     if self.want_dispatch_reports:
         self.report.dispatch_new()
     #
     # Dispatch measurements
     #
     if self.want_dispatch_measurements:
         self.measurement.dispatch_new()
     #
     # Load mappings (how to transfer the values found in measurements in the reports)
     #
     self.mapping=Mapping(None, self.ini)
     self.mapping.load()
     #
     # Complete reports
     #
     if self.want_run_merge:
         self.complete_report()
     # 
     # send files from outbox and erase them one by one
     #
     if self.want_send_ftp:
         sender=Ftp_sender(None,self.ini)
         sender.send_all()
     #
     logging.info("Stop")
Exemplo n.º 39
0
    def addMeasurement(self, name, lumi, lumiErr):
        """
        Add measurement to this configuration

        @param name Name of measurement
        @param lumi Luminosity to use
        @param lumiErr Error on the luminosity to use
        """

        #verify that this name is not already used
        for meas in self.measurements:
            if meas.name == name:
                raise RuntimeError("Measurement %s already exists in fitConfig %s. Please use a different name." % (name, self.name))
            pass
        
        #add measurement to the list
        self.measurements.append(Measurement(name, lumi, lumiErr))
        return self.measurements[len(self.measurements) - 1]
Exemplo n.º 40
0
 def make_predictions(self, trained_model, data):
     X_train, X_test, y_train, y_test = data
     #get predictions
     print(type(trained_model))
     print("Making predictions!")
     train_pred = trained_model.predict(X_train)
     train_pred_prob = trained_model.predict_proba(X_train)
     test_pred = trained_model.predict(X_test)
     test_pred_prob = trained_model.predict_proba(X_test)
     print(test_pred_prob)
     # print metrics
     measurer = Measurement()
     print("Train resutls:")
     measurer.print_measurements(y_train, train_pred, train_pred_prob[:, 1])
     print("Test resutls:")
     measurer.print_measurements(y_test, test_pred, test_pred_prob[:, 1])
Exemplo n.º 41
0
    def cal_dut(self):
        self.dutMenu.setDisabled(True)
        self.fileMenu.setDisabled(True)

        self.meas = Measurement(self.dut, parent=self)

        # Signals
        self.meas.clear_test_results.connect(self.clear_test_result)
        self.meas.add_test_result.connect(self.add_test_result)
        self.meas.change_last_test_result.connect(self.change_last_test_result)

        if self.meas.init_instruments():                # Hardware init
            self.meas.resp_dlg = self.responseDialog
            self.meas.sens_dlg = self.sensDialog
            self.responseDialog.show()

            if self.dut['Group'] == 'amp':              # Charge amp
                rslt = self.meas.measure_charge_amp()
            else:                                       # Opnemer
                # Ref meting
                rslt = self.meas.measure_ref()
                # DUT meting
                if rslt:
                    rslt = self.meas.measure_dut()
            if rslt:
                self.meas.calc_full_response()
                self.meas.calc_pass_fail()
                resultDialog = resultdialog.ResultDialog(self.dut, self)
                resultDialog.exec_()
                # TEDS
                if self.dut['TEDS']:
                    self.show_teds_dialog()

                if self.dut['Group'] == 'amp':
                    QMessageBox.warning(self, 'Let op', 'Vergeet niet de bekabeling van het trilstation te herstellen!')

        self.dutMenu.setDisabled(False)
        self.fileMenu.setDisabled(False)
Exemplo n.º 42
0
    def xgbcv(self, X, y, params=None):
        """
		Tuning parameters of model using XGBoost CVs
		"""
        print("Started CV task at " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))

        # create gini scorer
        measurer = Measurement()
        gini_score = measurer.xgb_gini_scorer
        # create StratifiedKFold object
        skf = StratifiedKFold(n_splits=3, shuffle=True, random_state=100)
        # dmat
        dtrain = xgb.DMatrix(X, label=y)
        if not params:
            params = {
                "learning_rate": 0.1,
                "n_estimators": 20,
                "seed": 100,
                "max_depth": 3,
                "min_child_weight": 1,
                "subsample": 1,
                "tree_method": "gpu_hist",
                "predictor": "cpu_predictor",
                "objective": 'binary:logistic'
            }

        cv_results = xgb.cv(params,
                            dtrain,
                            num_boost_round=int(params["n_estimators"]),
                            feval=gini_score,
                            folds=list(skf.split(X, y)),
                            verbose_eval=5)
        cv_results.to_csv("cv_resutls.csv", index=False)

        print("Finished CV task at " +
              datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
Exemplo n.º 43
0
    measurement_directory = str(args[4])

    # Configure logging parameters so we get output while the program runs
    logging.basicConfig(format='%(asctime)s %(message)s',
                        datefmt='%m/%d/%Y %H:%M:%S',
                        filename=log_directory + identifier + ".log",
                        level=logging.INFO)
    logging.info('START logging for run: %s',
                 environment_directory + identifier + ".xml")

    environment = Environment(identifier)
    environment.read_environment_file("./" + environment_directory +
                                      identifier + ".xml")
    environment.initialize()

    measurement = Measurement()

    #
    # UPDATE STEP
    #
    runner = Runner(identifier, environment, measurement)
    if environment.parameter.compute_goodness == "True":  # compute_goodness = False if we have a normal run
        #print "NOW RUNNING: " + environment.identifier
        #start_time = datetime.now()
        #print "START: " + str(start_time)

        runner.compute_goodness()

        #end_time = datetime.now()
        #print "END: " + str(end_time)
        #print "TIME: " + str(end_time - start_time) + "\n"
Exemplo n.º 44
0
def startMeasurement(filepath, file_type, covalent_radii_cut_off, c, n1, n2,
                     calculate):
    if n1 > n2:
        print("Final m cannot be smaller than initial m")
        return

    print("Starting script...")

    slab = read(filepath)

    total_particles = len(slab)

    print("Slab %s read with success. Total particles %d" %
          (filepath, total_particles))

    print("Creating graph...")

    if file_type == 'V':
        G = generateGraphFromSlabVinkFile(slab, covalent_radii_cut_off)
    else:
        G = generateGraphFromSlab(slab, covalent_radii_cut_off)

    total_nodes = G.get_total_nodes()
    if total_nodes == 0 or G.get_total_edges() == 0:
        print("No edges found in graph. Check covalent_radii_cut_off")
        return

    print("Graph created with success. Nodes found: %d" % total_nodes)

    cell = slab.get_cell()

    # somente para celulas ortogonais
    if not is_orthorhombic(cell):
        print("Unit cell is not orthorhombic")
        return

    measurement = Measurement()
    measurement.fromFile(filepath, covalent_radii_cut_off, c, n1, n2)
    measurement.createFile()

    (pbcX, pbcY, pbcZ) = slab.get_pbc()
    (dmin, dmax) = getMaxMinSlabArray(slab)
    maxM = getNumberRandomPositions(n2 - 1, total_particles)

    configurationalEntropy = bg.ConfigurationalEntropy(G, 3, len(slab), pbcX,
                                                       pbcY, pbcZ, maxM)
    configurationalEntropy.add_positions(slab.get_positions(wrap=True))

    print("Generating random positions...")

    configurationalEntropy.init_search(0, cell[0][0], 0, cell[1][1], 0,
                                       cell[2][2], n2 - 1, maxM, dmin, dmax)

    print("Random positions generated.")

    H_n_values = []
    for n in range(n1, n2):
        measurement.start()

        m = getNumberRandomPositions(n, total_particles)
        H_n, H1n = run(configurationalEntropy, m, n, c)

        measurement.writeResult(n, m, H_n, H1n)
        measurement.end()

        H_n_values.append((n, H_n, H1n, "Y"))

    calculateConfigurationalEntropy(n1, n2, H_n_values, c, calculate)

    print("Program ended correctly")
Exemplo n.º 45
0
class Ridirect(object):
    
        
    def __init__(self, gui,ini):
        self.version="V1.12"
        self.gui=gui
        if not self.gui is None:
            pass #just in case where, one day, we have a TKinter GUI
        #
        # recall parms in .ini
        #
        self.ini=ini
        self.debug= self.ini.get('mode','debug')=="yes"
        self.want_collect_measurements= self.ini.get('mode','collect_measurements')=="yes"
        self.want_collect_reports= self.ini.get('mode','collect_reports')=="yes"
        self.want_dispatch_measurements= self.ini.get('mode','dispatch_measurements')=="yes"
        self.want_dispatch_reports= self.ini.get('mode','dispatch_reports')=="yes"
        self.want_run_merge= self.ini.get('mode','run_merge')=="yes"
        self.want_send_ftp= self.ini.get('mode','send_ftp')=="yes"
        #
        #
        self.report=None
        self.measurement=None
        self.mapping=None
        #
        self.outbox=self.ini.get('files', 'outbox_path')
        #
        #
        #
        # set-up log file
        #
        log_path=self.ini.get('files','log_path').strip()
        log_file="ridirect.log"
        if log_path<>"." and log_path<>"":
            log_file=os.path.join(log_path, log_file)   
        #
        logger=logging.getLogger()
        logger.setLevel(logging.INFO)
        formatter=logging.Formatter('%(asctime)s :: %(levelname)s :: %(message)s')
        file_handler = RotatingFileHandler(log_file, 'a', 1000000, 1)

        file_handler.setLevel(logging.DEBUG)
        file_handler.setFormatter(formatter)
        logger.addHandler(file_handler)

        stream_handler = logging.StreamHandler()
        stream_handler.setLevel(logging.DEBUG)
        formatter=logging.Formatter('%(asctime)s \t %(filename)s \t %(levelname)s \t %(message)s', "%H:%M:%S")
        stream_handler.setFormatter(formatter)
        logger.addHandler(stream_handler)

        

    def complete_report(self):
        op_path=self.ini.get('files','operations_path')
        #
        # for each site
        #
        for site in os.listdir(op_path):
            #
            # for each techno -2G or 3G-
            #
            site_path=os.path.join(op_path,site)
            for techno in os.listdir(site_path):
                tech_path=os.path.join(site_path,techno)
                #
                # Check content
                #
                complete_report_present=False
                measurement_present=False
                for f in os.listdir(tech_path):
                    if f.startswith('Complete'):
                        complete_report_present=True;
                    if f=="measurement":
                        measurement_present=True
                #
                # if "Complete_" report is lacking and measurements are present
                #
                if not complete_report_present and measurement_present:
                    #
                    # proceed with merge
                    #
                    logging.info("Merging "+tech_path)
                    try:
                        self.merge(tech_path)
                    except Exception as e:
                        logging.error(e)
                        logging.error("Cannot restore formulas for "+tech_path)


                        
    def merge(self, folder):
        #
        # get techno from folder path, not from filename because it may be dualtech
        #
        ignore_head, techno=os.path.split(folder)
        subfolder ="report"
        #
        # find and analyze the report first
        #
        rf=None
        sector_list=None
        path=os.path.join(folder,subfolder)
        for f in os.listdir(path):
            #
            # loop is needed because filename is unknown.
            # Only one file is present in principle.
            #
            if self.report.parse_filename(f):
                #
                # open report
                #
                rf=Report_file(folder,f,techno)
                rf.open_in()
                #
                # version number for the report template  (to guide mapping)
                # ex V1.3c
                #
                version=rf.get_version()
                #
                # get list of sectors from report
                #
                # dict 2G900, 2G1800, 3G 900, 3G 1800 where dict[3G 1800]=(12, 234, 33)
                #
                sector_list=rf.get_sectors()
                break
        #
        # report not properly analysed,
        # discontinue - complete file will not be created
        #
        if rf is None:
            return
        if sector_list is None:
            return
        if len(sector_list)==0:
            return
        #
        # then, first loop on measurements to
        # to take an inventory and
        # check that they match the sectors
        # if not an error is logged
        #
        measured_sector_list=[]
        for f in os.listdir(os.path.join(folder, "measurement")): #todo check naming
            m=self.measurement.parse_filename(f)
            if m:
                if m.sector in sector_list[(m.techno,m.band)]:
                    if m.sector not in measured_sector_list:
                        measured_sector_list.append(m.sector)
                else:
                    logging.error("Foreign "+techno+" sector "+m.sector+" for "+rf.filename)
        #
        # count total number of sectors found in the report
        # compare it with the number of sectors mentionned in measurements
        #
        unique_sector_list=[]
        for tec, ban in sector_list:
            for sector in sector_list[(tec,ban)]:
                if sector not in unique_sector_list:
                    unique_sector_list.append(sector)
        if len(measured_sector_list)<>len(unique_sector_list):
            logging.error("Measurements do not match "+m.techno+" sectors for "+rf.filename)
        #
        # create the write-enabled copy of the report, so that we are ready to insert
        #
        rf.open_out()
        #
        # second loop on measurements to collect the mesures with the filenames sorted
        # in ascending order
        # only the matching sectors are processed
        #
        modified=False
        subfolder="measurement"
        for f in sorted(os.listdir(os.path.join(folder, subfolder))): #todo check naming
            m=self.measurement.parse_filename(f)
            if m:
                if m.sector in sector_list[(m.techno, m.band)]:
                    #
                    #
                    #
                    mf=Measurement_file(os.path.join(folder, subfolder, f), m.techno, m.sector)
                    mf.open()
                    #
                    # collect the measurements
                    # we need to pass the mapping limited to the version of the report, the techno and the band
                    #
                    measurements=mf.get_measurements(self.mapping.get_subset(m.techno, m.band, version))
                    #
                    # stuff the measurements in the report
                    #
                    for measure in measurements.keys():
                        if m.techno=="3G" and m.band=="2100":
                            step=4
                        else:
                            step=1
                        if not modified:
                            rf.restore_formulas()
                        rf.insert(sector_list[(m.techno,m.band)].index(m.sector), measure,measurements[measure],step,m.band)
                        modified=True
        #
        # save the report with a new name starting with Complete_ and copy it to
        # outbox for future sending
        #
        if modified:
            rf.close(self.outbox)

        

    def run(self):
        logging.info("Start "+self.version)
        #
        # Collect measurements
        #
        self.measurement=Measurement(None,self.ini)
        #
        #
        if self.want_collect_measurements:
            self.measurement.collect_new()
        #
        # Collect raw_reports
        #
        #
        self.report=Report(None, self.ini)
        if self.want_collect_reports:
            self.report.collect_new()
        #
        # Dispatch raw_reports
        #
        if self.want_dispatch_reports:
            self.report.dispatch_new()
        #
        # Dispatch measurements
        #
        if self.want_dispatch_measurements:
            self.measurement.dispatch_new()
        #
        # Load mappings (how to transfer the values found in measurements in the reports)
        #
        self.mapping=Mapping(None, self.ini)
        self.mapping.load()
        #
        # Complete reports
        #
        if self.want_run_merge:
            self.complete_report()
        # 
        # send files from outbox and erase them one by one
        #
        if self.want_send_ftp:
            sender=Ftp_sender(None,self.ini)
            sender.send_all()
        #
        logging.info("Stop")
Exemplo n.º 46
0
 def __init__(self,name):
     Measurement.__init__(self,name,mclass='ESR')
Exemplo n.º 47
0
 def distance(self, old_pat, new_pat, order):
     old_gaps = self.convert_pattern_to_gaps(old_pat)
     new_gaps = self.convert_pattern_to_gaps(new_pat)
     m = Measurement()
     return m.compute_diff(old_gaps, new_gaps, order)
Exemplo n.º 48
0
#
# INITIALIZATION
#
	environment_directory = str(args[1])
	identifier = str(args[2])
	log_directory = str(args[3])
	measurement_directory = str(args[4])

	# Configure logging parameters so we get output while the program runs
	logging.basicConfig(format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %H:%M:%S',  filename = log_directory + identifier + ".log", level=logging.INFO)
	logging.info('START logging for run: %s',  environment_directory + identifier + ".xml")

	environment = Environment()
	environment.initialize(environment_directory,  identifier)
	runner = Runner()
	measurement = Measurement()


#
# UPDATE STEP
#
	for i in range(environment.parameters.numSimulations):
		logging.info('  STARTED with run %s',  str(i))
		environment.initialize(environment_directory,  identifier)
		runner.initialize(environment)
		measurement.initialize() # clear the previous measurement
		
		# do the run
		runner.do_run(measurement,  "info")
		# do the histograms, i.e. add the current measurement to the histogram
		measurement.do_histograms()
Exemplo n.º 49
0
	def bRun_exec(self, bRun, cbAlgorithm):
		activeAlgorithm = cbAlgorithm.get_active_id()

		if activeAlgorithm == "1":
			wAlgorithm = Superposition_1()
		elif activeAlgorithm == "2":
			wAlgorithm = Superposition_2()
		elif activeAlgorithm == "11":
			wAlgorithm = Measurement()
		else:
			wAlgorithm = Gtk.Window()
			wAlgorithm.set_title("Algorithm")

			wAlgorithm.add( Gtk.Label("this is a dummy window") )
	
		wAlgorithm.set_transient_for(self)
		#wAlgorithm.set_type_hint(Gtk.gdk.WINDOW_TYPE_HINT_DIALOG)

		wAlgorithm.connect("destroy", lambda *w: Gtk.main_quit() )

		wAlgorithm.show_all()
 def test_convert_to_dict(self):
     m = Measurement(timeStamp=1, value=2, units='degC')
     outputs = m.convert_to_dict()
     self.assertDictEqual(outputs, {'timeStamp': 1, 'value': 2, 'units': 'degC'})
Exemplo n.º 51
0
class MainWindow(QMainWindow):

    def __init__(self, parent=None):
        super().__init__(parent)

        # DUT data
        self.dut = {'Type': None}

        # Meting
        self.meas = None

        # Settings
        self.settings = QSettings(config.SETTINGS_FILE, QSettings.IniFormat)

        # Logging
        logging.basicConfig(filename='tril.log', level=logging.DEBUG,
                            format='%(levelname)s: %(asctime)s %(message)s',
                            datefmt='%d-%m-%Y %H:%M:%S',
                            filemode='w')
        logger = logging.getLogger('tril')
        logger.info('Programma gestart')

        # Mainwindow settings
        self.setWindowTitle('Shake It!')
        self.restoreGeometry(self.settings.value('MainGeometry'))

        # File menu
        self.fileMenu = self.menuBar().addMenu('&Bestand')
        eraseRefSpecAction = self.fileMenu.addAction('Wis Ref Spectra', self.del_ref_trace)
        # eraseRefSpecAction.setShortcut('Ctrl+W')
        self.fileMenu.addSeparator()
        self.fileMenu.addAction('Standaarden', self.show_standards_dialog)
        self.fileMenu.addSeparator()
        self.tedsMenuAction = self.fileMenu.addAction('TEDS', self.show_teds_dialog)
        self.fileMenu.addSeparator()
        stopAction = self.fileMenu.addAction('Stop', self.close)
        stopAction.setShortcut('Ctrl+Q')

        # DUT menu
        self.dutMenu = self.menuBar().addMenu('&Kalibreren')
        selectDutAction = self.dutMenu.addAction('Selecteer &DUT', self.select_dut)
        selectDutAction.setShortcut('Ctrl+D')

        # Help menu
        self.helpMenu = self.menuBar().addMenu('&Help')
        self.helpMenu.addAction('Over', self.about_box)

        # Statusbar
        statusbar = self.statusBar()
        self.status = QLabel('Klaar...')
        statusbar.addPermanentWidget(self.status, 1)

        # ResultTable
        self.resultTable = QTableWidget()
        self.resultTable.setColumnCount(3)
        self.resultTable.verticalHeader().hide()
        self.resultTable.horizontalHeader().setStretchLastSection(True)
        # self.resultTable.horizontalHeader().setResizeMode(QHeaderView.Stretch)
        self.resultTable.setShowGrid(0)
        self.resultTable.setHorizontalHeaderLabels(['Stap', 'Resultaat', ''])
        self.resultTable.horizontalHeader().setDefaultAlignment(Qt.AlignLeft)
        self.resultTable.horizontalHeader().setClickable(0)
        self.resultTable.verticalHeader().setDefaultSectionSize(20)
        self.resultTable.setFocusPolicy(Qt.NoFocus)
        self.resultTable.setColumnWidth(0, 200)
        self.resultTable.setColumnWidth(1, 75)
        self.resultTable.setColumnWidth(2, 200)

        # Central Widget
        layout = QHBoxLayout()
        layout.addWidget(self.resultTable)
        layout.setContentsMargins(10, 10, 10, 10)
        mainWidget = QWidget()
        mainWidget.setLayout(layout)
        self.setCentralWidget(mainWidget)

        self.busy_timer = None

        # Response Window
        self.responseDialog = response.ResponseDlg(self, Qt.WindowTitleHint)
        self.responseDialog.setWindowTitle("Frequency Response")
        self.responseDialog.restoreGeometry(self.settings.value('RespGeometry'))

        # Sensitivity Window
        self.sensDialog = response.ResponseDlg(self, Qt.WindowTitleHint)
        self.sensDialog.setWindowTitle("Reference Sensitivity")
        self.sensDialog.restoreGeometry(self.settings.value('SensGeometry'))

    def show_standards_dialog(self):
        inp, rslt = QInputDialog.getText(self, "Wachtwoord", "Geef wachtwoord:", mode=QLineEdit.Password, flags=Qt.WindowTitleHint)
        if inp == config.WACHTWOORD and rslt is True:
            dlg = standards.StandardsDialog(self, Qt.WindowTitleHint)
            dlg.exec_()

    def show_teds_dialog(self):
        rslt = QMessageBox.information(self, 'TEDS', 'Verbind de opnemer met de TEDS aansluiting.', QMessageBox.Ok|QMessageBox.Cancel)
        if rslt == QMessageBox.Ok:
            sens = self.dut.get('refsens', 1.)
            tedsDialog = teds.TEDSDialog(self, Qt.WindowTitleHint, refsens=sens, parent=self)
            tedsDialog.exec_()

    def change_last_test_result(self, result):
        if result[:5] != 'Bezig':
            self.progress.setVisible(False)
            self.resultTable.removeCellWidget(self.resultTable.rowCount()-1, 2)
            if self.busy_timer:
                self.killTimer(self.busy_timer)
                self.busy_timer = None

        resultItem = QTableWidgetItem(result)
        if result == 'Pass': color = QColor(Qt.darkGreen)
        elif result == 'Fail': color = QColor(Qt.darkRed)
        else: color = QColor(Qt.darkBlue)
        resultItem.setTextColor(color)
        resultItem.setFlags(Qt.ItemIsEnabled)
        self.resultTable.setItem(self.resultTable.rowCount()-1, 1, resultItem)

    def add_test_result(self, test, result, duration=0):
        testItem = QTableWidgetItem(test)
        resultItem = QTableWidgetItem(result)
        progressItem = QTableWidgetItem('')
        if result == 'Pass': color = QColor(Qt.darkGreen)
        elif result == 'Fail': color = QColor(Qt.darkRed)
        else: color = QColor(Qt.darkBlue)
        resultItem.setTextColor(color)
        if len(result) == 0:
            testItem.setTextColor(QColor(Qt.darkBlue))
            font = QFont()
            font.setBold(True)
            testItem.setFont(font)
        testItem.setFlags(Qt.ItemIsEnabled)
        resultItem.setFlags(Qt.ItemIsEnabled)
        progressItem.setFlags(Qt.ItemIsEnabled)
        self.resultTable.insertRow(self.resultTable.rowCount())
        self.resultTable.setItem(self.resultTable.rowCount()-1, 0, testItem)
        self.resultTable.setItem(self.resultTable.rowCount()-1, 1, resultItem)
        self.resultTable.setItem(self.resultTable.rowCount()-1, 2, progressItem)

        # Toon progress bar
        if result[:5] == 'Bezig':
            self.progress = QProgressBar()
            self.progress.setTextVisible(False)
            self.progress.setMaximum(duration)
            self.progress.setStyleSheet('margin: 5px;')
            self.progress_value = 0
            self.resultTable.setCellWidget(self.resultTable.rowCount()-1, 2, self.progress)
            self.busy_timer = self.startTimer(1000)

        QApplication.processEvents()

    def timerEvent(self, event):
        self.progress_value += 1
        self.progress.setValue(self.progress_value)

    def del_ref_trace(self):
        rslt = QMessageBox.warning(self, 'Wis Ref Spectra', 'Weet u zeker dat u de Ref Spectra wilt wissen?', QMessageBox.Ok|QMessageBox.Cancel)
        if rslt == QMessageBox.Ok:
            ref_files_4808 = ['.\\Ref\\LF_4808_ref_spectrum.npz', '.\\Ref\\HF_4808_ref_spectrum.npz']
            for ref_file in ref_files_4808:
                if os.path.exists(ref_file):
                    os.remove(ref_file)

            ref_files_4809 = ['.\\Ref\\LF_4809_ref_spectrum.npz', '.\\Ref\\HF_4809_ref_spectrum.npz']
            for ref_file in ref_files_4809:
                if os.path.exists(ref_file):
                    os.remove(ref_file)

    def select_dut(self):
        dutDialog = dutdialog.DutDialog(self, Qt.WindowTitleHint, default=self.dut['Type'])
        if dutDialog.exec_() and dutDialog.dut_db:
            self.dut = dutDialog.dut_db
            self.status.setText('DUT: %s' % self.dut['Type'])
            logging.info('DUT %s geselecteerd.' % self.dut['Type'])
            self.cal_dut()

    def cal_dut(self):
        self.dutMenu.setDisabled(True)
        self.fileMenu.setDisabled(True)

        self.meas = Measurement(self.dut, parent=self)

        # Signals
        self.meas.clear_test_results.connect(self.clear_test_result)
        self.meas.add_test_result.connect(self.add_test_result)
        self.meas.change_last_test_result.connect(self.change_last_test_result)

        if self.meas.init_instruments():                # Hardware init
            self.meas.resp_dlg = self.responseDialog
            self.meas.sens_dlg = self.sensDialog
            self.responseDialog.show()

            if self.dut['Group'] == 'amp':              # Charge amp
                rslt = self.meas.measure_charge_amp()
            else:                                       # Opnemer
                # Ref meting
                rslt = self.meas.measure_ref()
                # DUT meting
                if rslt:
                    rslt = self.meas.measure_dut()
            if rslt:
                self.meas.calc_full_response()
                self.meas.calc_pass_fail()
                resultDialog = resultdialog.ResultDialog(self.dut, self)
                resultDialog.exec_()
                # TEDS
                if self.dut['TEDS']:
                    self.show_teds_dialog()

                if self.dut['Group'] == 'amp':
                    QMessageBox.warning(self, 'Let op', 'Vergeet niet de bekabeling van het trilstation te herstellen!')

        self.dutMenu.setDisabled(False)
        self.fileMenu.setDisabled(False)

    def clear_test_result(self):
        self.resultTable.setRowCount(0)

    def about_box(self):
        QMessageBox.about(self, 'Over Shake It!',
                          '''
                          <b>Shake It!</b> v %s
                          <p>Copyright &copy; 2016 Albert & Jan Willem
                          <p>Python %s - PyQt %s - Qt %s
                          ''' % (config.VERSION, platform.python_version(), PYQT_VERSION_STR, QT_VERSION_STR))

    def closeEvent(self, event):
        # Save settings
        self.settings.setValue("MainGeometry", self.saveGeometry())
        self.settings.setValue("RespGeometry", self.responseDialog.saveGeometry())
        self.settings.setValue("SensGeometry", self.sensDialog.saveGeometry())
        logging.info('Programma afgesloten')

    def keyPressEvent(self, e):
        if e.key() == Qt.Key_Escape:
            if self.meas:
                self.meas.stop()