def do_static_tf(disco: Disco_Driver,progress_func, s_tf_output_dir,s_tf_amplitude=.5,s_tf_steps=100, **kwargs): mkdir(s_tf_output_dir) tf_vin = [] tf_vout = [] v_min = 2.5-s_tf_amplitude v_max = 2.5+s_tf_amplitude progress_func("Static TF",0., "", 0.) input_range = np.arange(v_min, v_max, (v_max-v_min)/s_tf_steps) i = 0. for step in input_range: progress_func("Static TF", 0., f"Current voltage = {step:.3f}V", i/len(input_range)) i+=1. disco.analog_out_gen(shape='DC', channel=0,offset=step) time.sleep(.3) res = disco.analog_in_read(ch1=True, ch2=True, frequency=disco.max_sampling_buffer*4, samplesCount=disco.max_sampling_buffer, ch1range=10.) real_fs = res[1] data = pds.DataFrame(data={"input": res[0][0], "output": res[0][1]}, index=np.arange(0., disco.max_sampling_buffer / real_fs, 1. / real_fs)) data.to_csv(s_tf_output_dir + f"/static_tf_snapshot_{step}V.csv.gz") tf_vin.append(np.mean(res[0][0])) tf_vout.append(np.mean(res[0][1])) progress_func("Static TF done!", 0., "",1.) tf = pds.DataFrame(data={"Vout": tf_vout}, index=tf_vin) tf.to_csv(s_tf_output_dir + f"/static_tf.csv.gz") disco.analog_out_disable(channel=0)
def main(): mkdir(cfg.log_dir()) log.basicConfig( filename=f'{cfg.log_dir()}/disco-server-{datetime.datetime.now()}.log', format='%(asctime)s - %(message)s', level=log.INFO) log.getLogger().addHandler(log.StreamHandler(sys.stdout)) discos = { "CHX": Disco_Driver(cfg.asic_chx_disco.get()), "CHY": Disco_Driver(cfg.asic_chy_disco.get()), "CHZ": Disco_Driver(cfg.asic_chz_disco.get()) } turn_all_off(discos) atexit.register(functools.partial(turn_all_off, discos=discos)) for sig in (signal.SIGABRT, signal.SIGILL, signal.SIGINT, signal.SIGSEGV, signal.SIGTERM): signal.signal(sig, functools.partial(turn_all_off, discos=discos)) try: cmd_thread = Thread(target=cmd_loop, args=(discos, )) cmd_thread.start() while True: time.sleep(.1) except Exception as e: turn_all_off(discos) log.error(str(e))
def __init__(self, parent=None): super(ApplicationWindow, self).__init__(parent) self.settings_ui = SettingsPannel() self.progress_pannel = ProgressPannel() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.actionSettings.triggered.connect(self.settings_ui.show) self.asicsList = [] self.acknowledgedAsicID = False self.asicPowered = False self.asicFileName = "" self.path = cfg.global_workdir.get() + "/ASICs" mkdir(self.path) # create a "monitor" file in the working directory self.measuementRequested = False #self.showMaximized() #self.showFullScreen() # self.ui.power_button.clicked.connect(self.turn_on) # self.is_on = False # self.tempWorker = TemperaturesWorker() # self.tempWorker.updateTemperatures.connect(self.updateTemperatures) # self.tempWorker.start() # self.tempWorker.moveToThread(self.tempWorker) self.ui.pathWorkDir.setText(cfg.global_workdir.get()) self.arduinoStatusWorker = ArduinoStatusWorker() self.arduinoStatusWorker.updateStatus.connect( self.ui.statusbar.showMessage) self.arduinoStatusWorker.start() self.arduinoStatusWorker.moveToThread(self.arduinoStatusWorker) self.voltagesWorker = VoltagesWorker() self.voltagesWorker.updateVoltages.connect(self.updateVoltages) self.voltagesWorker.updateVoltages.connect(self.asicRecording) self.voltagesWorker.start() self.voltagesWorker.moveToThread(self.voltagesWorker) self.ui.power_button.clicked.connect(self.voltagesWorker.startAlims, Qt.QueuedConnection) self.voltagesWorker.signalUpdatePower.connect(self.updatePowerButton) self.ui.asicSN.setValidator(QRegExpValidator("[0-9]{3}")) #3 Chifre self.ui.asicSN.returnPressed.connect(lambda: print("Declenché")) #test self.ui.asicSN.returnPressed.connect( lambda: self.asicManagement(self.ui.asicSN.text())) self.ui.asicSN.textChanged.connect(lambda: self.asicManagement(False)) self.ui.Launch_Measurements.clicked.connect(self.requestMeasurement) self.ui.asicsListe.currentIndexChanged.connect( lambda: self.ui.asicSN.setText(self.ui.asicsListe.currentText())) self.ui.asicsListe.currentIndexChanged.connect( lambda: self.asicManagement(False)) self.ui.ButtonBurninStepPre.clicked.connect( lambda: self.burninStepRecorder("PreBurnIn")) self.ui.ButtonBurninStepPost.clicked.connect( lambda: self.burninStepRecorder("PostBurnIn"))
def main(args=sys.argv): lib_dir = os.path.dirname(os.path.realpath(__file__)) bin_dir = lib_dir + "/../../../../bin" desktop_entry_path = os.path.expanduser( "~") + '/.local/share/applications/Juice-scm-egse.desktop' if not os.path.exists(desktop_entry_path): with open(desktop_entry_path, 'w') as d: d.write( desktop_entry.format(exec=bin_dir + "/Juice_SCM_GSE", icon="juice-scm-egse.svg", path=bin_dir)) mkdir(config.log_dir()) log.basicConfig(filename=f'{config.log_dir()}/gui-{datetime.now()}.log', format='%(asctime)s - %(message)s', level=log.INFO) log.getLogger().addHandler(log.StreamHandler(sys.stdout)) app = QApplication(args) application = ApplicationWindow() application.show() sys.exit(app.exec_())
def start_measurement(self): now = str(datetime.now()) work_dir = f'/{config.global_workdir.get()}/run-{now}/' self.Launch_Measurements.emit(work_dir) mkdir(work_dir) manifest = { section_name: { name: (value if 'pass' not in name else '******') for name, value in section_values.items() } for section_name, section_values in config._config.items() } manifest["result_dir"] = work_dir manifest["notes"] = self.ui.notes.toPlainText() manifest["start_time"] = now with open(f'{work_dir}/config.json', 'w') as out: out.write(json.dumps(manifest)) manifest_html = json.dumps(manifest, indent=4).replace(' ', ' ').replace( ',\n', ',<br>').replace('\n', '<br>') html = f''' <!DOCTYPE html> <html> <body> <h1>Measurement started at {now}</h1> <p> {manifest_html} </p> </body> </html> ''' send_mail(server=config.mail_server.get(), sender="*****@*****.**", recipients=config.mail_recipients.get(), subject="Starting measurement", html_body=html, username=config.mail_login.get(), password=config.mail_password.get(), port=465, use_tls=True)
def do_psd(disco: Disco_Driver,progress_func, psd_output_dir, psd_snapshots_count=10, psd_sampling_freq=[100000], **kwargs): mkdir(psd_output_dir) snapshot_asic_out = [] sampling_freq_chx = int() remove_offset(disco) progress_func("psd",0.,"", 0.) for f in psd_sampling_freq: for step in range(psd_snapshots_count): progress_func("psd",0.,f"Current snapshot {step}/{psd_snapshots_count}",float(step)/float(psd_snapshots_count)) res = disco.analog_in_read(ch1=False, ch2=True, frequency=f, samplesCount=disco.max_sampling_buffer) sampling_freq_chx = res[1] snapshot_asic_out.append(res[0][0]) progress_func("psd analysis", 0.,"", 0.) for i in range(len(snapshot_asic_out)): progress_func("psd analysis", 0., f"Saving snapshot {i}/{len(snapshot_asic_out)}", float(i)/float(len(snapshot_asic_out))) np.savetxt(psd_output_dir + f"/snapshot_psd_{f}Hz_{i}_asic_out.csv.gz", snapshot_asic_out[i]) freq_ch1, psd = noise.psd(snapshot_asic_out, sampling_freq_chx, window=True, removeMean=True) progress_func("psd analysis", 0.,"", 1.) df = pds.DataFrame(data={"PSD_ASIC_OUTPUT": psd}, index=freq_ch1) df.to_csv(psd_output_dir + f"/psd_{f}Hz.csv.gz")
def do_dynamic_tf(disco: Disco_Driver,progress_func, d_tf_output_dir, d_tf_frequencies=np.logspace(0,6,num=200), **kwargs): mkdir(d_tf_output_dir) tf_g = [] tf_phi = [] tf_f = [] progress_func("TF",0.,"", 0.) i = 0. dc = remove_offset(disco) for f in d_tf_frequencies: progress_func("TF", 0., f"Current frequency {f:.1f}Hz", i/len(d_tf_frequencies)) i+=1. disco.analog_out_gen(frequency=f, shape='Sine', channel=0, amplitude=.2,offset=dc) time.sleep(.3) res = disco.analog_in_read(ch1=True, ch2=True, frequency=min(f*disco.max_sampling_buffer/10.,disco.max_sampling_freq), samplesCount=disco.max_sampling_buffer, ch1range=10.) real_fs = res[1] data = pds.DataFrame(data={"input": res[0][0], "output": res[0][1]}, index=np.arange(0., disco.max_sampling_buffer/real_fs, 1. / real_fs)) data.to_csv(d_tf_output_dir + f"/dynamic_tf_snapshot_{f}Hz.csv.gz") window = np.hanning(len(res[0][0])) in_spect = fft.fft(waveform=res[0][0], sampling_frequency=real_fs, window=window, remove_mean=True) out_spect = fft.fft(waveform=res[0][1], sampling_frequency=real_fs, window=window, remove_mean=True) freq = in_spect["f"] peaks = peakutils.indexes(in_spect["mod"], min_dist=2) for peak in peaks: f = in_spect["f"][peak] g = 20. * np.log10(out_spect["mod"][peak] / in_spect["mod"][peak]) tf_phi.append(out_spect["phi"][peak] - in_spect["phi"][peak]) tf_g.append(g) tf_f.append(f) progress_func("TF done!", 0., "", 1.) tf = pds.DataFrame(data={"G(dB)":tf_g,"Phi(rad)":tf_phi},index=tf_f) tf.to_csv(d_tf_output_dir + f"/dynamic_tf.csv.gz") disco.analog_out_disable(channel=0)
def main(): socket = setup_ipc() ser = setup_serial(socket) if ser.is_open: path = cfg.global_workdir.get() + "/monitor" mkdir(path) fname = f"{path}/all-{str(datetime.datetime.now())}.txt" with open(fname, 'w') as out: reset_and_flush(ser) out.write(ser.readline().decode()) # comment line out.write(ser.readline().decode()) # header columns names last_publish = time.time() while True: try: line = ser.readline().decode() out.write(str(datetime.datetime.now()) + '\t' + line) now = time.time() if (now - last_publish) >= 1.: last_publish = now values = line.split('\t') tempA, tempB, tempC = float(values[-4]), float( values[-3]), float(values[-2]) socket.send( f"Temperatures {now},{tempA},{tempB},{tempC}". encode()) message = f"Voltages {now}" for v in values[:-4]: message += f",{float(v)}" socket.send(message.encode()) except serial.serialutil.SerialException: for _ in [None, None]: ser.close() ser = setup_serial(socket) reset_and_flush(ser) ser.readline(), ser.readline()
def main(): socket, sockPair = setup_ipc() ser = setup_serial(socket) nbrIteration = 0 #atexit.register(exit_handler) if ser.is_open: path = cfg.global_workdir.get() + "/monitor" mkdir(path) #create a "monitor" file in the working directory fname = f"{path}/all-{str(datetime.datetime.now())}.txt" #create a file with the current date to dump the data print(fname) with open(fname, 'w') as out: reset_and_flush(ser) out.write(ser.readline().decode()) # comment line out.write(ser.readline().decode()) # header columns names last_publish = time.time() while True: try: msg = sockPair.recv(flags=zmq.NOBLOCK) msg = msg.decode("utf-8") if "alim" in msg: ser.write(f"{msg}".encode()) if "ASIC_JUICEMagic3" in msg: out.write(msg + '\n') except zmq.ZMQError: pass try: line = ser.readline().decode( ) #get and decode the data on the serial communication out.write(str(datetime.datetime.now()) + '\t' + line) now = time.time() values = line.split('\t') for val in values: if "_CH" in val: nbrIteration = 0 if nbrIteration == 0: #la premiere iteration n'a que les entête pass elif nbrIteration == 1: valuesVoltage = values[:-1] else: valuesVoltage = [ float(vOld) + float(vNew) for vOld, vNew in zip(valuesVoltage, values[:-1]) ] nbrIteration += 1 if ( now - last_publish ) >= 0.33: #Wait 0.3 second just because (old:temp measurments are slow) last_publish = now #values = line.split('\t') #tempA, tempB, tempC = float(values[-4]), float(values[-3]), float(values[-2]) #tempA, tempB, tempC = float(10), float(11), float(12) #socket.send(f"Temperatures {now},{tempA},{tempB},{tempC}".encode()) message = f"Voltages {now}" for v in valuesVoltage: #values[:-1] exept the last one v = float(v) if nbrIteration > 1: v = v / (nbrIteration - 1) message += f",{v}" nbrIteration = 0 socket.send(message.encode()) out.flush() except serial.serialutil.SerialException: for _ in [None, None]: ser.close() ser = setup_serial(socket) reset_and_flush(ser) ser.readline(), ser.readline()
import configparser, os from appdirs import user_config_dir, user_data_dir from juice_scm_gse.utils import mkdir _CONFIG_FNAME = str(user_config_dir(appname="Juice_SCM_EGSE", appauthor="LPP")) + "/config.ini" mkdir(os.path.dirname(_CONFIG_FNAME)) _config = configparser.ConfigParser() _config.read(_CONFIG_FNAME) class ConfigEntry: def __init__(self, key1, key2, default=""): self.key1 = key1 self.key2 = key2 self.default = default def get(self): if self.key1 in _config and self.key2 in _config[self.key1]: return _config[self.key1][self.key2] else: return self.default def set(self, value): if self.key1 not in _config: _config.add_section(self.key1) _config[self.key1][self.key2] = value with open(_CONFIG_FNAME, 'w') as f: _config.write(f)