From 782b9169779ef23a2c9854f4f735ec10dc442db1 Mon Sep 17 00:00:00 2001 From: Tim-Oliver Husser Date: Sat, 11 Nov 2023 16:53:01 +0100 Subject: [PATCH] refactored a little bit --- .../processors/astrometry/_dotnet_request.py | 2 +- .../astrometry/_dotnet_request_builder.py | 27 +++++++++---------- pyobs/images/processors/astrometry/dotnet.py | 5 ++-- 3 files changed, 15 insertions(+), 19 deletions(-) diff --git a/pyobs/images/processors/astrometry/_dotnet_request.py b/pyobs/images/processors/astrometry/_dotnet_request.py index b1ccdbd6..783baafc 100644 --- a/pyobs/images/processors/astrometry/_dotnet_request.py +++ b/pyobs/images/processors/astrometry/_dotnet_request.py @@ -31,7 +31,7 @@ def _handle_request_error(self): error_msg = self._generate_request_error_msg() raise exc.ImageError(error_msg) - def _is_request_successful(self): + def _is_request_successful(self) -> bool: return self._status_code != 200 or "error" in self._response_data async def send(self, url: str, timeout: int): diff --git a/pyobs/images/processors/astrometry/_dotnet_request_builder.py b/pyobs/images/processors/astrometry/_dotnet_request_builder.py index a36c8321..2b1c1c9f 100644 --- a/pyobs/images/processors/astrometry/_dotnet_request_builder.py +++ b/pyobs/images/processors/astrometry/_dotnet_request_builder.py @@ -1,4 +1,4 @@ -from typing import Dict, Any +from typing import Optional import pandas as pd from astropy.io.fits import Header @@ -14,17 +14,8 @@ def __init__(self, source_count: int, radius: float): self._radius = radius self._request_data = {} - self._catalog: pd.DataFrame = None - self._header: Header = None - - def add_catalog_from_image(self, image: Image): - if image.catalog is None: - raise exc.ImageError("No catalog found in image.") - - self._catalog = image.catalog[["x", "y", "flux", "peak"]].to_pandas() - - def add_header_from_image(self, image: Image): - self._header = image.header + self._catalog = pd.DataFrame() + self._header: Optional[Header] = None def _filter_catalog(self): self._catalog = self._catalog.dropna(how="any") @@ -57,13 +48,19 @@ def _build_request_data(self): "flux": self._catalog["flux"].tolist(), } - def __call__(self) -> _DotNetRequest: + def __call__(self, image: Image) -> _DotNetRequest: + # set catalog and header + if image.catalog is None: + raise exc.ImageError("No catalog found in image.") + self._catalog = image.catalog[["x", "y", "flux", "peak"]].to_pandas() + self._header = image.header + + # select stars self._filter_catalog() self._validate_catalog() self._select_brightest_stars() + # validate header and build request self._validate_header() - self._build_request_data() - return _DotNetRequest(self._request_data) diff --git a/pyobs/images/processors/astrometry/dotnet.py b/pyobs/images/processors/astrometry/dotnet.py index 0d7df503..76c4d31c 100644 --- a/pyobs/images/processors/astrometry/dotnet.py +++ b/pyobs/images/processors/astrometry/dotnet.py @@ -44,9 +44,8 @@ def __init__( self._request_builder = _DotNetRequestBuilder(source_count, radius) async def _process(self, image: Image) -> Image: - self._request_builder.add_catalog_from_image(image) - self._request_builder.add_header_from_image(image) - request = self._request_builder() + # build the request + request = self._request_builder(image) logger = _RequestLogger(log, image, request.request_data) logger.log_request_data()