Skip to content
camera.py 13 KiB
Newer Older
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'''REST API for Camera related operations'''

from flask import request
Davide Ricci's avatar
Davide Ricci committed
from config import constants
Davide Ricci's avatar
Davide Ricci committed
from .baseresource import ResourceDev
from .sequencer_instance import seq
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/frame/binning")
Davide Ricci's avatar
Davide Ricci committed
class FrameBinning(ResourceDev):
    """Binning of the camera."""

Davide Ricci's avatar
Davide Ricci committed
    # def get(self):
    #     """Retrieve the binning of the camera."""
    #     res = {
    #         "response": self.dev.binning,
    #         "error": self.dev.error,
    #         "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
    #     }
    #     return res

    def put(self):
        """Set a new binning for the camera."""
        binning = request.json
        self.dev.binning = binning
            "response": self.dev.binning,
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/cooler")
Davide Ricci's avatar
Davide Ricci committed
class Cooler(ResourceDev):
    """Manage the CCD cooler status"""

    def get(self):
        """Check wether the CCD cooler is on or off."""
        res = {
            "raw": self.dev.cooler,
            "response": constants.on_off[self.dev.cooler],
            "error": self.dev.error,
            "timestamp": self.timestamp,
        }
        return res

    def put(self):
        """Set on or off the CCD cooler."""
        state = request.json
        self.dev.cooler = state
            "response": self.dev.cooler,
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
# # @api.route("/cooler/fan")
# class CoolerFan(ResourceDev):
#     """Info on the cooler power % of stress"""
Davide Ricci's avatar
Davide Ricci committed
#     def get(self):
#         """Retrieve the CCD cooler power percentage."""
#         res = {
#             "response": self.dev.fan,
#             "error": self.dev.error,
#            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
#         }
#         return res
Davide Ricci's avatar
Davide Ricci committed

Davide Ricci's avatar
Davide Ricci committed
# # @api.route("/cooler/temperature")
# class CoolerTemperature(ResourceDev):
#     """Info on the cooler temperature"""
Davide Ricci's avatar
Davide Ricci committed
#     def get(self):
#         """Retrieve the CCD cooler temperature."""
#         res = {
#             "response": self.dev.temperature,
#             "error": self.dev.error,
#             "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
#         }
#         return res
# @api.route("/cooler/temperature/setpoint")
Davide Ricci's avatar
Davide Ricci committed
class CoolerTemperatureSetpoint(ResourceDev):
    """Manage the CCD temperature"""

Davide Ricci's avatar
Davide Ricci committed
    # def get(self):
    #     """Retrieve the temperature of the CCD."""
    #     res = {
    #         "response": self.dev.setpoint,
    #         "error": self.dev.error,
    #         "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
    #     }
    #     return res

    def put(self):
        """Set a new temperature of the CCD."""
        state = request.json
        self.dev.temperature = state
            "response": self.dev.temperature,
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/filters")
Davide Ricci's avatar
Davide Ricci committed
class Filters(ResourceDev):
    """Camera filters names."""

    def get(self):
        """Retrieve the filter names."""
        res = {
            "response": constants.filter_number,
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/filter")
Davide Ricci's avatar
Davide Ricci committed
class Filter(ResourceDev):
    """Camera filter information."""

    def get(self):
        """Retrieve the current filter."""
            "raw": self.dev.filter,
            "response": constants.filter_name[self.dev.filter],
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/filter/movement")
Davide Ricci's avatar
Davide Ricci committed
class FilterMovement(ResourceDev):
    """Manage the camera filter wheel."""

    def get(self):
        """Check if the filter wheel is moving."""
            "raw": self.dev.is_moving,
            "response": constants.filter_state[self.dev.is_moving],
            "error": self.dev.error,
            "timestamp": self.timestamp,

    def post(self):
        """Set a new filter."""
        target = request.json
        self.dev.filter = target
            "response": self.dev.filter,
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
# # @api.route("/frame")
# class Frame(ResourceDev):
#     """Camera frame information."""
Davide Ricci's avatar
Davide Ricci committed
#     def get(self):
#         """Retrieve the current frame."""
#         frame = {
#             "xrange": self.dev.xrange,
#             "yrange": self.dev.yrange,
#             "binning": self.dev.binning,
#             "maxrange": self.dev.max_range,
#         }
#         res = {
#             "response": frame,
#             "error": self.dev.error,
#             "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
#         }
#         return res
# @api.route("/frame/custom")
Davide Ricci's avatar
Davide Ricci committed
class FrameCustom(ResourceDev):
    """Camera custom frame."""

    def put(self):
        """Set a custom windowing."""
        new_frame = request.json
        self.dev.binning = new_frame["binning"]
        frame = {
            "xrange": new_frame["xrange"],
            "yrange": new_frame["yrange"],
            "binning": new_frame["binning"]
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/frame/full")
Davide Ricci's avatar
Davide Ricci committed
class FrameFull(ResourceDev):
    """Camera full frame."""

    def put(self):
        """Set the ccd to full frame in current binning."""
            "response": self.dev.full_frame(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/frame/half")
Davide Ricci's avatar
Davide Ricci committed
class FrameHalf(ResourceDev):
    """Camera frame of half size the full frame."""

    def put(self):
        """Set a center ccd window spanning half the
        size of the full frame in the current binning."""
            "response": self.dev.half_frame(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/frame/small")
Davide Ricci's avatar
Davide Ricci committed
class FrameSmall(ResourceDev):
    """Camera frame of 2 arcmin."""
        """Set a center ccd window spanning 2 arcminutes
        on the sky."""
            "response": self.dev.small_frame(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
# # @api.route("/frame/temperature")
# class FrameTemperature(ResourceDev):
#     """Ambient temperature."""
Davide Ricci's avatar
Davide Ricci committed
#     def get(self):
#         """Retrieve the ambient temperature"""
#         res = {
#             "response": self.dev.ambient,
#             "error": self.dev.error,
#             "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
#         }
#         return res
# @api.route("/snapshot/")
Davide Ricci's avatar
Davide Ricci committed
class Snapshot(ResourceDev):
    """The acquired image."""

Davide Ricci's avatar
Davide Ricci committed
    # def get(self):
    #     """Get the acquired image."""
    #     res = {
    #         "response": self.dev.download(),
    #         "error": self.dev.error,
    #         "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
    #     }
    #     return res
Davide Ricci's avatar
Davide Ricci committed
        """Start a simple acquisition."""
        new = request.json  # exptime, type
            "response": self.dev.start(new["exptime"],
                                          self.timestamp),
            "error": self.dev.error,
            "timestamp": self.timestamp,
        }
        return res

    def delete(self):
        """Stop the acquisition process."""
        res = {
            "response": self.dev.abort(),
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/snapshot/state")
Davide Ricci's avatar
Davide Ricci committed
class SnapshotState(ResourceDev):
    """Manage the acquisition of an image."""

    def get(self):
        """Retrieve the status of the acquisition process."""
        res = {            
            "raw": self.dev.state,
            "response": constants.camera_state[self.dev.state],
            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/snapshot/acquisition")
Davide Ricci's avatar
Davide Ricci committed
class SnapshotAcquisition(ResourceDev):
Davide Ricci's avatar
Davide Ricci committed
    """Manage the acquisition of an image using th sequencer."""
        """Retrieve the status of the acquisition process."""
Davide Ricci's avatar
Davide Ricci committed

                "paused": seq.tpl.paused if seq.tpl else None,
                "quitting": seq.tpl.aborted if seq.tpl else None,
            "error": "ciccio",
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed

        """Start a new acquisition."""
        data = request.json  # exptime, type, repeat, recenter
Davide Ricci's avatar
Davide Ricci committed

        # Run the template given its parameters in the json.
Davide Ricci's avatar
Davide Ricci committed

            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed

            "error": self.dev.error,
            "timestamp": self.timestamp,
# @api.route("/snapshot/recenter")
Davide Ricci's avatar
Davide Ricci committed
class SnapshotRecenter(ResourceDev):
    """Manage the recentering via the the apply_offset function"""
Davide Ricci's avatar
Davide Ricci committed

        """Retrieve the recenter status and parameters of the box."""

        res = {
            "response": {
                "recenter": getattr(seq.tpl, 'recenter', None),
                "box": getattr(seq.tpl, 'box', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
        """Set a given box to the recentering function"""
        data = request.json  # exptime, type, repeat, recenter
            "response": getattr(seq.tpl, 'box', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
        return res

        """Enable the recentering function."""

            "response": getattr(seq.tpl, 'recenter', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
        """Disable the recentering function."""

            "response": getattr(seq.tpl, 'recenter', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed

# @api.route("/snapshot/domeslewing")
Davide Ricci's avatar
Davide Ricci committed
class SnapshotDomeslewing(ResourceDev):
    """Get dome slewing status"""
        """Retrieve the domeslewing status"""

        res = {
            "response": {
                "domeslewing": getattr(seq.tpl, 'domeslewing', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
            "response":  getattr(seq.tpl, 'domeslewing', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
            "response":  getattr(seq.tpl, 'domeslewing', None),
            "error": "ciccio",
            "timestamp": self.timestamp,
# @api.route("/cooler/warmup")
Davide Ricci's avatar
Davide Ricci committed
class CoolerWarmup(ResourceDev):
    """Manage the warmup of the CCD."""

    def post(self):
        """Start the warm up the CCD."""

    def delete(self):
        """Stop the warm up of the CCD."""

Davide Ricci's avatar
Davide Ricci committed
# @api.route("/connection")
Davide Ricci's avatar
Davide Ricci committed
class Connection(ResourceDev):
Davide Ricci's avatar
Davide Ricci committed
    '''Manage the connection to ASCOM.'''

    def get(self):
        '''Check if the telescope is connected to ASCOM.'''

        res = {
            "response": self.dev.connection,
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
        }
        return res

# @api.route("/settings")
Davide Ricci's avatar
Davide Ricci committed
class Settings(ResourceDev):
Davide Ricci's avatar
Davide Ricci committed
    '''General telescope settings.'''

    def get(self):
        '''Retrieve all-in-one the settings of the camera.'''

        res = {
            "response": self.dev.all,
            "error": self.dev.error,
            "timestamp": self.timestamp,
Davide Ricci's avatar
Davide Ricci committed
        }
        return res

Davide Ricci's avatar
Davide Ricci committed
# # @api.route("/status")
# class Status(ResourceDev):
#     '''General camera status.'''
Davide Ricci's avatar
Davide Ricci committed
#     def get(self):
#         '''Retrieve the status of each compoent.'''

#         connection = Connection(dev=self.dev).get()
#         if connection["response"]:

#             settings = Settings(dev=self.dev).get() etc
Davide Ricci's avatar
Davide Ricci committed

Davide Ricci's avatar
Davide Ricci committed
#         else:
#             res = {
#                 "connection": connection,
#             }
Davide Ricci's avatar
Davide Ricci committed

Davide Ricci's avatar
Davide Ricci committed
#         return res