Skip to content

Commit

Permalink
refactored a little bit
Browse files Browse the repository at this point in the history
  • Loading branch information
thusser committed Nov 11, 2023
1 parent 8436b61 commit 782b916
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
2 changes: 1 addition & 1 deletion pyobs/images/processors/astrometry/_dotnet_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
27 changes: 12 additions & 15 deletions pyobs/images/processors/astrometry/_dotnet_request_builder.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Dict, Any
from typing import Optional

import pandas as pd
from astropy.io.fits import Header
Expand All @@ -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")
Expand Down Expand Up @@ -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)
5 changes: 2 additions & 3 deletions pyobs/images/processors/astrometry/dotnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 782b916

Please sign in to comment.