-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skycoord Guiding Statistics
- Loading branch information
Showing
12 changed files
with
343 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from copy import copy | ||
from typing import Any, Union, Dict | ||
|
||
from astropy.coordinates import SkyCoord | ||
|
||
from pyobs.images import Image | ||
from pyobs.images.meta import SkyOffsets | ||
from pyobs.images.processors.offsets import Offsets | ||
from pyobs.object import get_object | ||
|
||
|
||
class DummySkyOffsets(Offsets): | ||
def __init__(self, coord0: Union[SkyCoord, Dict[str, Any]], coord1: Union[SkyCoord, Dict[str, Any]], **kwargs: Any) -> None: | ||
super().__init__(**kwargs) | ||
sky_coord0 = get_object(coord0, SkyCoord) | ||
sky_coord1 = get_object(coord1, SkyCoord) | ||
self._offset = SkyOffsets(sky_coord0, sky_coord1) | ||
|
||
async def __call__(self, image: Image) -> Image: | ||
image.set_meta(copy(self._offset)) | ||
return image | ||
|
||
|
||
__all__ = ["DummySkyOffsets"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .uptime import GuidingStatisticsUptime | ||
from .pixeloffset import GuidingStatisticsPixelOffset | ||
from .skyoffsets import GuidingStatisticsSkyOffset |
61 changes: 61 additions & 0 deletions
61
pyobs/modules/pointing/guidingstatistics/guidingstatistics.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
from abc import abstractmethod, ABCMeta | ||
from collections import defaultdict | ||
from typing import List, Dict, Tuple, Any | ||
|
||
from pyobs.images import Image | ||
|
||
|
||
class GuidingStatistics(object, metaclass=ABCMeta): | ||
"""Calculates statistics for guiding.""" | ||
|
||
def __init__(self) -> None: | ||
self._sessions: Dict[str, List[Any]] = defaultdict(list) | ||
|
||
def init_stats(self, client: str, default: Any = None) -> None: | ||
""" | ||
Inits a stat measurement session for a client. | ||
Args: | ||
client: name/id of the client | ||
default: first entry in session | ||
""" | ||
|
||
self._sessions[client] = [] | ||
|
||
if default is not None: | ||
self._sessions[client].append(self._get_session_data(default)) | ||
|
||
@abstractmethod | ||
def _build_header(self, data: Any) -> Dict[str, Tuple[Any, str]]: | ||
raise NotImplementedError | ||
|
||
def add_to_header(self, client: str, header: Dict[str, Tuple[Any, str]]) -> Dict[str, Tuple[Any, str]]: | ||
""" | ||
Add statistics to given header. | ||
Args: | ||
client: id/name of the client | ||
header: Header dict to add statistics to. | ||
""" | ||
|
||
data = self._sessions.pop(client) | ||
session_header = self._build_header(data) | ||
|
||
return header | session_header | ||
|
||
@abstractmethod | ||
def _get_session_data(self, input_data: Image) -> Any: | ||
raise NotImplementedError | ||
|
||
def add_data(self, input_data: Image) -> None: | ||
""" | ||
Adds data to all client measurement sessions. | ||
Args: | ||
input_data: Image witch metadata | ||
""" | ||
|
||
data = self._get_session_data(input_data) | ||
|
||
for k in self._sessions.keys(): | ||
self._sessions[k].append(data) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import logging | ||
from typing import List, Dict, Tuple, Any, Optional | ||
|
||
import numpy as np | ||
|
||
from pyobs.images import Image | ||
from .guidingstatistics import GuidingStatistics | ||
from pyobs.images.meta import PixelOffsets | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class GuidingStatisticsPixelOffset(GuidingStatistics): | ||
@staticmethod | ||
def _calc_rms(data: List[Tuple[float, float]]) -> Optional[Tuple[float, float]]: | ||
""" | ||
Calculates RMS of data. | ||
Args: | ||
data: Data to calculate RMS for. | ||
Returns: | ||
Tuple of RMS. | ||
""" | ||
if len(data) < 3: | ||
return None | ||
|
||
flattened_data = np.array(list(map(list, zip(*data)))) | ||
data_len = len(flattened_data[0]) | ||
rms = np.sqrt(np.sum(np.power(flattened_data, 2), axis=1) / data_len) | ||
return tuple(rms) | ||
|
||
def _build_header(self, data: List[Tuple[float, float]]) -> Dict[str, Tuple[Any, str]]: | ||
header = {} | ||
rms = self._calc_rms(data) | ||
|
||
if rms is not None: | ||
header["GUIDING RMS1"] = (float(rms[0]), "RMS for guiding on axis 1") | ||
header["GUIDING RMS2"] = (float(rms[1]), "RMS for guiding on axis 2") | ||
|
||
return header | ||
|
||
def _get_session_data(self, data: Image) -> Tuple[float, float]: | ||
if data.has_meta(PixelOffsets): | ||
meta = data.get_meta(PixelOffsets) | ||
primitive = tuple(meta.__dict__.values()) | ||
return primitive | ||
else: | ||
log.warning("Image is missing the necessary meta information!") | ||
raise KeyError("Unknown meta.") | ||
|
||
|
||
|
Oops, something went wrong.