def __init__(self, telescope: Union[str, ITelescope], camera: Union[str, ICamera], filters: Union[str, IFilters], flat_fielder: Union[dict, FlatFielder], log_file: str = None, *args, **kwargs): """Initialize a new flat fielder. Args: telescope: Name of ITelescope. camera: Name of ICamera. filters: Name of IFilters, if any. pointing: Pointing to use. log_file: Name of file to store flat field log in. """ Module.__init__(self, *args, **kwargs) # store telescope, camera, and filters self._telescope = telescope self._camera = camera self._filters = filters self._abort = threading.Event() # flat fielder self._flat_fielder = get_object(flat_fielder, FlatFielder, vfs=self.vfs, observer=self.observer, callback=self.callback) # init log file self._publisher = None if log_file is None else CsvPublisher(log_file)
def open(self): """Open module.""" Module.open(self) # open mixins WeatherAwareMixin.open(self) MotionStatusMixin.open(self)
def __init__(self, *args, **kwargs): """Initialize a new base roof.""" Module.__init__(self, *args, **kwargs) # init mixins WeatherAwareMixin.__init__(self, *args, **kwargs) MotionStatusMixin.__init__(self, *args, **kwargs)
def __init__(self, telescope: Union[str, ITelescope], camera: Union[str, ICamera], target_pixel: Tuple = None, attempts: int = 5, tolerance: float = 1, max_offset: float = 120, log_file: str = None, *args, **kwargs): """Create a new base acquisition. Args: telescope: Name of ITelescope. camera: Name of ICamera. target_pixel: (x, y) tuple of pixel that the star should be positioned on. If None, center of image is used. attempts: Number of attempts before giving up. tolerance: Tolerance in position to reach in arcsec. max_offset: Maximum offset to move in arcsec. log_file: Name of file to write log to. """ Module.__init__(self, *args, **kwargs) # store telescope and camera self._telescope = telescope self._camera = camera # store self._target_pixel = target_pixel self._attempts = attempts self._tolerance = tolerance self._max_offset = max_offset # init log file self._publisher = CsvPublisher(log_file) # init camera settings mixin CameraSettingsMixin.__init__(self, *args, **kwargs)
def __init__(self, focuser: Union[str, IFocuser], camera: Union[str, ICamera], filters: Union[str, IFilters] = None, offset: bool = False, *args, **kwargs): """Initialize a new auto focus system. Args: focuser: Name of IFocuser. camera: Name of ICamera. filters: Name of IFilters, if any. offset: If True, offsets are used instead of absolute focus values. """ Module.__init__(self, *args, **kwargs) # test import import lmfit # store focuser and camera self._focuser = focuser self._camera = camera self._filters = filters self._offset = offset self._abort = threading.Event() # storage for data self._data_lock = threading.RLock() self._data: List[Dict[str, float]] = []
def open(self): """Open module.""" Module.open(self) import pyinotify class EventHandler(pyinotify.ProcessEvent): """Event handler for file watcher.""" def __init__(self, main, *args, **kwargs): """Create event handler.""" pyinotify.ProcessEvent.__init__(self, *args, **kwargs) self.main = main def process_IN_CLOSE_WRITE(self, event): """React to IN_CLOSE_WRITE events.""" self.main.add_image(event.pathname) # start watching directory if self._watchpath: log.info('Start watching directory %s for changes...', self._watchpath) wm = pyinotify.WatchManager() wm.add_watch(self._watchpath, pyinotify.IN_CLOSE_WRITE) self._notifier = pyinotify.ThreadedNotifier( wm, default_proc_fun=EventHandler(self)) #, name='observer') self._notifier.start()
def __init__(self, warn_sound: str, warn_interval: float = 1, start_sound: str = None, started_sound: str = None, stop_sound: str = None, stopped_sound: str = None, player: str = 'mpg123', trigger_file: str = None, *args, **kwargs): """Initialize a new warning. Args: warn_sound: Name of file to play. warn_interval: Interval in seconds between sounds. start_sound: Sound to play when starting systems. started_sound: Sound to play when systems started. stop_sound: Sound to play when stopping systems. stopped_sound: Sound to play when systems stopped. trigger_file: File, which triggers to switch on-off and vice versa, when created. Will be deleted afterwards. """ Module.__init__(self, *args, **kwargs) # store self._warn_sound = warn_sound self._warn_interval = warn_interval self._start_sound = start_sound self._started_sound = started_sound self._stop_sound = stop_sound self._stopped_sound = stopped_sound self._trigger_file = trigger_file self._player = player self._autonomous = False # threads self._add_thread_func(self._heartbeat) self._add_thread_func(self._check_autonomous) self._add_thread_func(self._check_trigger)
def open(self): """Open image writer.""" Module.open(self) # subscribe to channel with new images log.info('Subscribing to new image events...') self.comm.register_event(NewImageEvent, self.process_new_image_event)
def __init__(self, watchpath: str = None, destinations: list = None, *args, **kwargs): """Create a new image watcher. Args: watchpath: Path to watch. destinations: Filename patterns for destinations. """ Module.__init__(self, *args, **kwargs) # test import import pyinotify # add thread func self._add_thread_func(self._worker, True) # variables self._watchpath = watchpath self._notifier = None self._queue = Queue() # filename patterns if not destinations: raise ValueError( 'No filename patterns given for the destinations.') self._destinations = destinations
def __init__(self, url: str = None, system_init_time: int = 300, *args, **kwargs): """Initialize a new pyobs-weather connector. Args: url: URL to weather station system_init_time: Time in seconds the full system needs to initialize """ Module.__init__(self, *args, **kwargs) # store and create session self._system_init_time = system_init_time self._url = url self._session = requests.session() # current status self._is_good = None # whole status self._status: Dict[str, Any] = {} self._status_lock = threading.RLock() # add thread func self._add_thread_func(self._update, True)
def __init__(self, pipeline: Union[dict, Pipeline], archive: Union[dict, Archive], sources: Union[str, List[str]] = None, cache_size: int = 20, *args, **kwargs): """Creates a new image writer. Args: pipeline: Pipeline to use for reduction. archive: Used for retrieving calibration files. If None, no calibration is done. sources: List of sources (e.g. cameras) to process images from or None for all. cache_size: Size of cache for calibration files. """ Module.__init__(self, *args, **kwargs) # stuff self._sources = [sources] if isinstance(sources, str) else sources self._queue = Queue() self._archive = None if archive is None else get_object( archive, Archive) self._pipeline = get_object(pipeline, Pipeline) self._cache = DataCache(size=cache_size) # add thread func self._add_thread_func(self._worker, True)
def __init__(self, min_alt: int = 30, max_alt: int = 85, num_alt: int = 8, num_az: int = 24, finish: int = 90, exp_time: float = 1., acquisition: str = 'acquisition', *args, **kwargs): """Initialize a new auto focus system. Args: min_alt: Mininum altitude to use. max_alt: Maximum altidude to use. num_alt: Number of altitude points to create on grid. num_az: Number of azimuth points to create on grid. finish: When this number in percent of points have been finished, terminate mastermind. exp_time: Exposure time in secs. acquisition: IAcquisition unit to use. """ Module.__init__(self, *args, **kwargs) # store self._min_alt = min_alt self._max_alt = max_alt self._num_alt = num_alt self._num_az = num_az self._finish = 1. - finish / 100. self._exp_time = exp_time self._acquisition = acquisition # add thread func self._add_thread_func(self._run_thread, False)
def __init__(self, port: int = 37075, cache_size: int = 25, *args, **kwargs): """Initializes file cache. Args: port: Port for HTTP server. cache_size: Size of file cache, i.e. number of files to cache. """ Module.__init__(self, *args, **kwargs) # add thread func self._add_thread_func(self._http, False) # init tornado web server tornado.web.Application.__init__(self, [ (r"/(.*)", MainHandler), ]) # store stuff self._io_loop = None self._cache = DataCache(cache_size) self._lock = threading.RLock() self._is_listening = False self._port = port self._cache_size = cache_size
def close(self): """Close image watcher.""" Module.close(self) # stop watching if self._notifier: log.info('Stop watching directory...') self._notifier.stop()
def open(self): """Open module.""" Module.open(self) # subscribe to events if self.comm: self.comm.register_event(BadWeatherEvent) self.comm.register_event(GoodWeatherEvent)
def open(self): """Open module.""" Module.open(self) # subscribe to events if self.comm: self.comm.register_event(NewImageEvent) self.comm.register_event(ExposureStatusChangedEvent)
def open(self): """Open module.""" Module.open(self) # subscribe to events self.comm.register_event(FocusFoundEvent, self._on_focus_found) if self._filter_offsets is not None and self._filter_wheel is not None: self.comm.register_event(FilterChangedEvent, self._on_filter_changed)
def open(self): """Open module.""" Module.open(self) # subscribe to events if self.comm: self.comm.register_event(TaskStartedEvent, self._on_task_started) self.comm.register_event(TaskFinishedEvent, self._on_task_finished) self.comm.register_event(GoodWeatherEvent, self._on_good_weather)
def open(self): """Open module""" Module.open(self) # check telescope and camera try: self.proxy(self._telescope, ITelescope) self.proxy(self._camera, ICamera) except ValueError: log.warning('Either camera or telescope do not exist or are not of correct type at the moment.')
def open(self): """Open module""" Module.open(self) # check flat field try: self.proxy(self._flatfield, IFlatField) except ValueError: log.warning( 'Flatfield module does not exist or is not of correct type at the moment.' )
def open(self): """Open module""" Module.open(self) # register event self.comm.register_event(FocusFoundEvent) # check focuser and camera try: self.proxy(self._focuser, IFocuser) self.proxy(self._camera, ICamera) except ValueError: log.warning('Either camera or focuser do not exist or are not of correct type at the moment.')
def open(self): """Open module.""" Module.open(self) # get a list of all events events = list(set([t['event'] for t in self._triggers])) # start self._running = True # register them for event in events: self.comm.register_event(event, self._handle_event)
def open(self): """Open module.""" Module.open(self) # subscribe to events if self.comm: self.comm.register_event(TaskStartedEvent) self.comm.register_event(TaskFinishedEvent) # start self._running = True # open scheduler self._task_archive.open()
def __init__(self, telescope: typing.Union[str, ITelescope], pointing: typing.Union[dict, SkyFlatsBasePointing], *args, **kwargs): """Initialize a new flat field pointing. Args: telescope: Telescope to point pointing: Pointing for calculating coordinates. """ Module.__init__(self, *args, **kwargs) # store telescope and pointing self._telescope = telescope self._pointing = pointing
def __init__(self, camera: Union[str, ICamera], telescope: Union[str, ITelescope], offsets: Union[dict, BaseGuidingOffset], max_offset: float = 30, max_exposure_time: float = None, min_interval: float = 0, max_interval: float = 600, separation_reset: float = None, pid: bool = False, log_file: str = None, *args, **kwargs): """Initializes a new science frame auto guiding system. Args: telescope: Telescope to use. offsets: Auto-guider to use max_offset: Max offset in arcsec to move. max_exposure_time: Maximum exposure time in sec for images to analyse. min_interval: Minimum interval in sec between two images. max_interval: Maximum interval in sec between to consecutive images to guide. separation_reset: Min separation in arcsec between two consecutive images that triggers a reset. pid: Whether to use a PID for guiding. log_file: Name of file to write log to. """ Module.__init__(self, *args, **kwargs) # store self._camera = camera self._telescope = telescope self._enabled = False self._max_offset = max_offset self._max_exposure_time = max_exposure_time self._min_interval = min_interval self._max_interval = max_interval self._separation_reset = separation_reset self._pid = pid self._loop_closed = False # headers of last and of reference image self._last_header = None self._ref_header = None # create auto-guiding system self._guiding_offset = get_object(offsets, BaseGuidingOffset) # init log file self._publisher = None if log_file is None else CsvPublisher(log_file)
def __init__(self, message: str = 'Hello world', interval: int = 10, *args, **kwargs): """Creates a new StandAlone object. Args: message: Message to log in the given interval. interval: Interval between messages. """ Module.__init__(self, *args, **kwargs) # add thread func self._add_thread_func(self._message_func, True) # store self._message = message self._interval = interval
def open(self): """Open module""" Module.open(self) # check telescope, camera, and filters try: self.proxy(self._telescope, ITelescope) self.proxy(self._camera, ICamera) self.proxy(self._filters, IFilters) except ValueError: log.warning('Either telescope, camera or filters do not exist or are not of correct type at the moment.') # subscribe to events if self.comm: self.comm.register_event(BadWeatherEvent, self._abort_weather) self.comm.register_event(RoofClosingEvent, self._abort_weather)
def __init__(self, flatfield: typing.Union[str, IFlatField], functions: typing.Dict[str, str], priorities: typing.Union[dict, SkyflatPriorities], min_exptime: float = 0.5, max_exptime: float = 5, timespan: float = 7200, filter_change: float = 30, count: int = 20, *args, **kwargs): """Initialize a new flat field scheduler. Args: flatfield: Flat field module to use functions: Dict with flat functions priorities: Class handling priorities min_exptime: Minimum exposure time [s] max_exptime: Maximum exposure time [s] timespan: Time to scheduler after start [s] filter_change: Time required for filter change [s] count: Number of flats to take per filter/binning """ Module.__init__(self, *args, **kwargs) # store self._flatfield = flatfield self._count = count # abort self._abort = threading.Event() # priorities prio = get_object(priorities, SkyflatPriorities) # create scheduler self._scheduler = Scheduler(functions, prio, self.observer, min_exptime=min_exptime, max_exptime=max_exptime, timespan=timespan, filter_change=filter_change, count=count)
def __init__(self, triggers: list, *args, **kwargs): """Initialize a new trigger module. Args: triggers: List of dictionaries defining the trigger. Must contain fields for event, module and method, may contain a sender. """ Module.__init__(self, *args, **kwargs) # store self._running = False # store triggers and convert event strings to actual classes self._triggers = triggers for trigger in self._triggers: # get class and store it kls = get_class_from_string(trigger['event']) trigger['event'] = kls
def open(self): """Open module.""" Module.open(self) # check telescope try: self.proxy(self._telescope, ITelescope) except ValueError: log.warning( 'Given telescope does not exist or is not of correct type at the moment.' ) # check camera try: self.proxy(self._camera, ICamera) except ValueError: log.warning( 'Given camera does not exist or is not of correct type at the moment.' )