def main(): piccoloLogging() log.info('waiting for reboot button') button = gpiozero.Button(REBOOT_BUTTON_PIN) button.when_held = action while True: time.sleep(0.1)
def main(): parser = argparse.ArgumentParser() parser.add_argument('picco', metavar='PICCO', nargs='+', help='input piccolo json files') parser.add_argument( '-c', '--calibration-files', default=[], nargs='*', help= 'radiometric calibration files, you can use this option multiple time and/or use wildcards' ) parser.add_argument('-p', '--prefix', default='.', help='the name of the output directory') parser.add_argument('--include-saturated', action='store_true', default=False, help='include saturated spectra') parser.add_argument( '--use-original-wavelength-coefficients', action='store_true', default=False, help= 'use original wavelength coefficients insteat of piccolo coefficients') parser.add_argument('-d', '--debug', action='store_true', default=False, help='enable debug') args = parser.parse_args() # start logging piccoloLogging(debug=args.debug) use_piccolo_coeff = not args.use_original_wavelength_coefficients out = Path(args.prefix) if not out.exists(): parser.error(f'output directory {out} does not exist') if not out.is_dir(): parser.error(f'output directory {out} is not a directory') infiles = args.picco infiles.sort() data = read_picco(infiles, calibration=args.calibration_files, piccolo=use_piccolo_coeff, include_saturated=args.include_saturated) for s in data.keys(): for c in data[s].keys(): outname = out.joinpath('%s_%s.nc' % (s, c)) data[s][c].data.to_netcdf(outname, engine='netcdf4')
def main(): parser = piccolo.PiccoloArgumentParser() parser.addRunOptions() parser.addIntegrationTimeOptions() parser.addSchedulerOptions() args = parser.parse_args() piccoloLogging(debug=args.debug) if args.start: start = datetime.datetime.combine( datetime.datetime.now(), datetime.datetime.strptime(args.start, "%H:%M").time()) start = start.replace(tzinfo=tzlocal()) start = str(start) else: start = None if args.stop: stop = datetime.datetime.combine( datetime.datetime.now(), datetime.datetime.strptime(args.stop, "%H:%M").time()) stop = stop.replace(tzinfo=tzlocal()) stop = str(stop) else: stop = None pclient = piccolo.PiccoloSystem(args.piccolo_url) loop = asyncio.get_event_loop() if args.list_spectrometers: loop.run_until_complete(pclient.spec.pprint()) else: times = {} for d in ['upwelling', 'downwelling', 'minimal', 'maximal']: times[d] = getattr(args, d) loop.run_until_complete(setIntegrationTimes(pclient, times)) loop.run_until_complete( pclient.control.record_sequence(args.run, nsequence=args.number_sequences, auto=args.auto, delay=args.delay, at_time=start, interval=args.interval, end_time=stop)) pclient.shutdown()
def main(): parser = argparse.ArgumentParser() parser.add_argument('input', metavar='INPUT', help='name of the input directory') parser.add_argument('output', metavar='OUTPUT', help='name of the output directory') parser.add_argument('-d', '--debug', action='store_true', default=False, help='enable debug') args = parser.parse_args() # start logging piccoloLogging(debug=args.debug) log = logging.getLogger("piccolo.discard_saturated") inpath = Path(args.input) outpath = Path(args.output) if not outpath.exists(): os.mkdir(outpath) for f in inpath.rglob('*.pico'): log.debug('reading file %s' % f) try: spectra = PiccoloSpectraList(data=open(f, 'r').read()) except: log.error('cannot read file %s' % f) continue if spectra.isSaturated: prefix = 'saturated' else: prefix = 'not-saturated' o = outpath.joinpath(prefix, f.relative_to(inpath)) if not o.parent.exists(): os.makedirs(o.parent) shutil.copy2(f, o)
def main(): parser = piccolo.PiccoloArgumentParser() parser.addIntegrationTimeOptions() args = parser.parse_args() piccoloLogging(debug=args.debug) pclient = piccolo.PiccoloSystem(args.piccolo_url) loop = asyncio.get_event_loop() if args.list_spectrometers: loop.run_until_complete(pclient.spec.pprint()) else: times = {} for d in ['upwelling', 'downwelling', 'minimal', 'maximal']: times[d] = getattr(args, d) loop.run_until_complete(setIntegrationTimes(pclient, times)) pclient.shutdown()
def main(): parser = piccolo.PiccoloArgumentParser() parser.add_argument('-s', '--simulate-trigger', action='store_true', default=False, help='trigger every 1 second, useful for debugging') parser.addRunOptions() args = parser.parse_args() piccoloLogging(debug=args.debug) if trigger.value: # If the trigger signal is high initially this probably # indicates an electronics problem. Check the connections and the LED log.error( """Cannot start Piccolo Client because the Pixhawk trigger signal is active (high). Check that the trigger signal from the Pixhawk is connected and that it is low. The Pixhawk trigger LED should be off.""") log.info('waiting to reset trigger') while trigger.value: pass log.debug('Finished setting up port ') pclient = piccolo.PiccoloSystem(args.piccolo_url) def stop_piccolo(signum, frame): pclient.shutdown() sys.exit(1) for s in [signal.SIGINT, signal.SIGTERM]: signal.signal(s, stop_piccolo) loop = asyncio.get_event_loop() if args.list_spectrometers: loop.run_until_complete(pclient.spec.pprint()) else: loop.run_until_complete( trigger_loop(pclient, args.run, args.number_sequences, args.auto, args.delay, args.simulate_trigger)) pclient.shutdown()
def main(): serverCfg = piccolo.PiccoloServerConfig() # start logging handler = piccoloLogging(logfile=serverCfg.cfg['logging']['logfile'], debug=serverCfg.cfg['logging']['debug']) log = logging.getLogger("piccolo.server") if serverCfg.cfg['daemon']['daemon']: import daemon try: import lockfile except ImportError: print( "The 'lockfile' Python module is required to run Piccolo Server. Ensure that version 0.12 or later of lockfile is installed." ) sys.exit(1) try: from lockfile.pidlockfile import PIDLockFile except ImportError: print( "An outdated version of the 'lockfile' Python module is installed. Piccolo Server requires at least version 0.12 or later of lockfile." ) sys.exit(1) from lockfile import AlreadyLocked, NotLocked # create a pid file and tidy up if required pidfile = PIDLockFile(serverCfg.cfg['daemon']['pid_file'], timeout=-1) try: pidfile.acquire() except AlreadyLocked: try: os.kill(pidfile.read_pid(), 0) print('Process already running!') exit(1) except OSError: #No process with locked PID print('PID file exists but process is dead') pidfile.break_lock() try: pidfile.release() except NotLocked: pass pstd = open(serverCfg.cfg['daemon']['logfile'], 'w') with daemon.DaemonContext(pidfile=pidfile, files_preserve=[handler.stream], stderr=pstd): # start piccolo piccolo_server(serverCfg) else: # start piccolo piccolo_server(serverCfg)
raise Warning('piccolo system is not busy') self._tQ.sync_q.put('abort') @piccoloGET def pause(self): """pause current batch""" if not self._busy.locked(): raise Warning('piccolo system is not busy') self._tQ.sync_q.put('pause') @piccoloGET def get_current_sequence(self): """return current squence number""" return self._current_sequence @piccoloGET def status(self): if self._busy.locked(): return self._status else: return 'idle' @piccoloChanged def callback_status(self, cb): self._statusChanged = cb if __name__ == '__main__': from piccolo3.common import piccoloLogging piccoloLogging(debug=True)
pclient.spec[s].get_max_time()) # get the channels print('channels', pclient.spec[s].channels) # get the current time for c in pclient.spec[s].channels: print(c, await pclient.spec[s].get_current_time(c)) # set the current times for c in pclient.spec[s].channels: await pclient.spec[s].set_current_time(c, 200) # record some data await pclient.control.record_sequence(RUN, nsequence=NSEQ, auto=AUTO, delay=DELAY, at_time=START, interval=INTERVAL, end_time=END) if __name__ == '__main__': from piccolo3.common import piccoloLogging piccoloLogging() # start event loop and run piccolo program until complete loop = asyncio.get_event_loop() loop.set_debug(enabled=True) loop.run_until_complete(main())
def main(): parser = argparse.ArgumentParser() parser.add_argument('picco', metavar='PICCO', nargs='+', help='input piccolo json files') parser.add_argument('-d', '--debug', action='store_true', default=False, help='enable debug') args = parser.parse_args() # start logging piccoloLogging(debug=args.debug) log = logging.getLogger("piccolo.display") if len(args.picco) > 1: data = {} for f in args.picco: log.debug('reading file %s' % f) spectra = PiccoloSpectraList(data=open(f, 'r').read()) for s in spectra: normalised_dark = s.dark_pixels / s['IntegrationTime'] if s['SerialNumber'] not in data: data[s['SerialNumber']] = {'mean': [], 'std': []} data[s['SerialNumber']]['mean'].append( numpy.mean(normalised_dark)) data[s['SerialNumber']]['std'].append( numpy.std(normalised_dark)) for s in data: x = numpy.arange(len(data[s]['mean'])) pyplot.errorbar(x, data[s]['mean'], yerr=data[s]['std'], fmt='o', label=s) else: spectra = PiccoloSpectraList(data=open(args.picco[0], 'r').read()) for s in spectra: normalised_dark = s.dark_pixels / s['IntegrationTime'] p = pyplot.plot(normalised_dark, 'o', label='{} {}'.format(s['SerialNumber'], s['Direction'])) pyplot.axhline(normalised_dark.mean(), color=p[0].get_color()) pyplot.legend(bbox_to_anchor=(0., 1.02, 1., .102), loc='lower left', ncol=2, mode="expand", borderaxespad=0.) pyplot.show()
def main(): parser = argparse.ArgumentParser() parser.add_argument('picco', metavar='PICCO', nargs='+', help='input piccolo json files') parser.add_argument('-d', '--debug', action='store_true', default=False, help='enable debug') parser.add_argument('--direction', action='append', help='select directions to plot') parser.add_argument('--dark', action='store_true', default=False, help='show dark spectra') parser.add_argument( '--use-original-wavelength-coefficients', action='store_true', default=False, help= 'use original wavelength coefficients insteat of piccolo coefficients') args = parser.parse_args() # start logging piccoloLogging(debug=args.debug) log = logging.getLogger("piccolo.display") use_piccolo_coeff = not args.use_original_wavelength_coefficients if args.direction is None: directions = ['upwelling', 'downwelling'] else: directions = args.direction if args.dark: spectrum = 'Dark' else: spectrum = 'Light' axes = {} fig, a = pyplot.subplots(1, len(directions), sharex=True, sharey=True) if len(directions) == 1: a = [a] for i in range(len(directions)): a[i].set_title(directions[i]) a[i].set_xlabel('wavelength') if i == 0: a[i].set_ylabel('intensity') else: a[i].get_yaxis().set_visible(False) axes[directions[i]] = a[i] colours = ['red', 'green', 'blue', 'orange', 'pink'] instruments = {} for f in args.picco: log.info('reading file %s' % f) spectra = PiccoloSpectraList(data=open(f, 'r').read()) if not spectra.haveSpectrum(spectrum): log.warning('{} spectrum not available in file {}'.format( spectrum, f)) continue for d in directions: for s in spectra.getSpectra(d, spectrum): if s['SerialNumber'] not in instruments: c = colours[len(instruments)] instruments[s['SerialNumber']] = (c, s['SaturationLevel']) w, p = s.getData(piccolo=use_piccolo_coeff) if (s.isSaturated): style = '--' else: style = '-' axes[d].plot(w, p, ls=style, color=instruments[s['SerialNumber']][0]) handles = [] labels = [] haveLabels = False for d in directions: for s in instruments: h = axes[d].axhline(instruments[s][1], color=instruments[s][0]) if not haveLabels: handles.append(h) labels.append(s) haveLabels = True fig.legend(handles=handles, loc="lower center", labels=labels, ncol=len(instruments)) pyplot.subplots_adjust(bottom=0.18) pyplot.show()