Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
 def __init__(self, archive: typing.Union[dict, Archive], site: str,
              instrument: str, filter_names: list, binnings: list, *args,
              **kwargs):
     SkyflatPriorities.__init__(self)
     self._archive = get_object(archive, Archive)
     self._filter_names = filter_names
     self._binnings = binnings
     self._site = site
     self._instrument = instrument
Exemplo n.º 4
0
    def __init__(self,
                 roof: typing.Union[str, IRoof],
                 telescope: typing.Union[str, ITelescope],
                 flatfield: typing.Union[str, IFlatField],
                 functions: dict,
                 priorities: typing.Union[dict, SkyflatPriorities],
                 min_exptime: float = 0.5,
                 max_exptime: float = 5,
                 timespan: float = 7200,
                 filter_change: float = 30,
                 count: int = 20,
                 combine_binnings: bool = True,
                 readout: dict = None,
                 *args,
                 **kwargs):
        """Init a new SkyFlats script.

        Args:
            roof: Roof to use
            telescope: Telescope to use
            flatfield: FlatFielder to use
            functions: Dict with solalt-exptime functions for all filters/binning
            priorities: SkyflatPriorities object that returns priorities
            min_exptime: Minimum exposure time for flats
            max_exptime: Maximum exposure time for flats
            timespan: Timespan from now that should be scheduled [s]
            filter_change: Time required for filter change [s]
            count: Number of flats to schedule
            combine_binnings: Whether different binnings use the same functions.
            readout: Dictionary with readout times (in sec) per binning (as BxB).
        """
        Script.__init__(self, *args, **kwargs)

        # store modules
        self._roof = roof
        self._telescope = telescope
        self._flatfield = flatfield

        # stuff
        self._count = count

        # get archive and priorities
        priorities = get_object(priorities, SkyflatPriorities)

        # create scheduler
        self._scheduler = Scheduler(functions,
                                    priorities,
                                    self.observer,
                                    min_exptime=min_exptime,
                                    max_exptime=max_exptime,
                                    timespan=timespan,
                                    filter_change=filter_change,
                                    count=count,
                                    combine_binnings=combine_binnings,
                                    readout=readout)
Exemplo n.º 5
0
    def __init__(self, photometry: Photometry, radius_column: str = 'radius', *args, **kwargs):
        """Initialize a new projection focus series.

        Args:
            photometry: Photometry to use for estimating PSF sizes
        """

        # stuff
        self._photometry: Photometry = get_object(photometry, Photometry)
        self._radius_col = radius_column
        self._data: List[Dict[str, float]] = []
Exemplo n.º 6
0
    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)
Exemplo n.º 7
0
    def _get_target_radec(self, img: Image, ra: float,
                          dec: float) -> Tuple[float, float]:
        """Returns RA/Dec coordinates of pixel that needs to be centered.

        Params:
            img: Image to analyze.
            ra: Requested RA.
            dec: Requested Declination.

        Returns:
            (ra, dec) of pixel that needs to be moved to the centre of the image.

        Raises:
            ValueError if target coordinates could not be determined.
        """

        # get objects
        photometry = get_object(self._photometry, Photometry)
        astrometry = get_object(self._astrometry, Astrometry)

        # copy image
        image = img.copy()

        # find stars
        log.info('Searching for stars...')
        if len(photometry.find_stars(image)) == 0:
            raise ValueError('Could not find any stars in image.')

        # do astrometry
        log.info('Calculating astrometric solution...')
        if not astrometry.find_solution(image):
            raise ValueError('Could not find astrometric solution.')

        # get WCS on new image return x/y coordinates of requested RA/Dec
        wcs = WCS(image.header)
        return wcs.all_world2pix(ra, dec, 0)
Exemplo n.º 8
0
    def run(self, *args, **kwargs):
        """Move telescope to pointing."""

        # get telescope
        log.info('Getting proxy for telescope...')
        telescope: ITelescope = self.proxy(self._telescope, ITelescope)

        # pointing
        pointing = get_object(self._pointing,
                              SkyFlatsBasePointing,
                              observer=self.observer)

        # point
        pointing(telescope).wait()
        log.info('Finished pointing telescope.')
Exemplo n.º 9
0
    def __init__(self,
                 tasks: Union[dict, TaskArchive],
                 schedule_range: int = 24,
                 safety_time: int = 60,
                 twilight: str = 'astronomical',
                 *args,
                 **kwargs):
        """Initialize a new scheduler.

        Args:
            scheduler: Scheduler to use
            schedule_range: Number of hours to schedule into the future
            safety_time: If no ETA for next task to start exists (from current task, weather became good, etc), use
                         this time in seconds to make sure that we don't schedule for a time when the scheduler is
                         still running
            twilight: astronomical or nautical
        """
        Module.__init__(self, *args, **kwargs)

        # get scheduler
        self._task_archive = get_object(tasks, TaskArchive)

        # store
        self._schedule_range = schedule_range
        self._safety_time = safety_time
        self._twilight = twilight
        self._running = True
        self._need_update = False

        # time to start next schedule from
        self._schedule_start = None

        # ID of currently running task
        self._current_task_id = None

        # blocks
        self._blocks: List[ObservingBlock] = []
        self._scheduled_blocks: List[ObservingBlock] = []

        # update thread
        self._add_thread_func(self._schedule_thread, True)
        self._add_thread_func(self._update_thread, True)
Exemplo n.º 10
0
    def _get_config_script(self, config: dict) -> Script:
        """Get config script for given configuration.

        Args:
            config: Config to create runner for.

        Returns:
            Script for running config

        Raises:
            ValueError: If could not create runner.
        """

        # what do we run?
        config_type = config['type']
        if config_type not in self.scripts:
            raise ValueError('No script found for configuration type "%s".' % config_type)

        # create script handler
        return get_object(self.scripts[config_type],
                          configuration=config, task_archive=self.task_archive, comm=self.comm, observer=self.observer)
Exemplo n.º 11
0
    def __init__(self, tasks: Union[TaskArchive, dict], allowed_overrun: int = 300, *args, **kwargs):
        """Initialize a new auto focus system.

        Args:
            tasks: Task archive to use
            allowed_overrun: Allowed time for a task to exceed it's window in seconds
        """
        Module.__init__(self, *args, **kwargs)

        # store
        self._allowed_overrun = allowed_overrun
        self._running = False

        # add thread func
        self._add_thread_func(self._run_thread, True)

        # get task archive
        self._task_archive: TaskArchive = get_object(tasks, object_class=TaskArchive,
                                                     comm=self.comm, vfs=self.vfs, observer=self.observer)

        # observation name and exposure number
        self._task = None
        self._obs = None
        self._exp = None
Exemplo n.º 12
0
    def __init__(self, focuser: Union[str, IFocuser], camera: Union[str, ICamera], filters: Union[str, IFilters],
                 series: FocusSeries, 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)

        # store focuser and camera
        self._focuser = focuser
        self._camera = camera
        self._filters = filters
        self._offset = offset
        self._abort = threading.Event()

        # create focus series
        self._series: FocusSeries = get_object(series, FocusSeries)

        # init camera settings mixin
        CameraSettingsMixin.__init__(self, *args, filters=filters, **kwargs)