Skip to content

Commit

Permalink
tests are passing again
Browse files Browse the repository at this point in the history
  • Loading branch information
thusser committed Dec 21, 2023
1 parent a0c853a commit 5d6c395
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 38 deletions.
2 changes: 1 addition & 1 deletion pyobs/images/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ def to_bytes(self) -> bytes:

def write_catalog(self, f: Any, *args: Any, **kwargs: Any) -> None:
"""Write catalog to file object."""
if self.catalog is None:
if self._catalog is None:
return

hdu = table_to_hdu(self._catalog)
Expand Down
2 changes: 1 addition & 1 deletion pyobs/images/processors/_daobackgroundremover.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _estimate_background(self, image: Image) -> npt.NDArray[float]:
filter_size=self._filter_size,
sigma_clip=self._sigma_clip,
bkg_estimator=self._bkg_estimator,
mask=image.mask,
mask=image.safe_mask,
)

return bkg.background
Expand Down
2 changes: 1 addition & 1 deletion pyobs/images/processors/detection/daophot.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ async def __call__(self, image: Image) -> Image:
Image with attached catalog.
"""

if image.data is None:
if image.safe_data is None:
log.warning("No data found in image.")
return image

Expand Down
18 changes: 12 additions & 6 deletions pyobs/images/processors/detection/pysep.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,22 @@ class SepSourceDetection(SourceDetection):
__module__ = "pyobs.images.processors.detection"

_CATALOG_KEYS = [
"x", "y",
"x",
"y",
"peak",
"flux",
"fwhm",
"a", "b", "theta",
"a",
"b",
"theta",
"ellipticity",
"tnpix",
"kronrad",
"fluxrad25", "fluxrad50", "fluxrad75",
"xwin", "ywin",
"fluxrad25",
"fluxrad50",
"fluxrad75",
"xwin",
"ywin",
]

def __init__(
Expand Down Expand Up @@ -77,7 +83,7 @@ async def __call__(self, image: Image) -> Image:
Image with attached catalog.
"""

if image.data is None:
if image.safe_data is None:
log.warning("No data found in image.")
return image

Expand All @@ -104,7 +110,7 @@ async def __call__(self, image: Image) -> Image:

@staticmethod
def _get_mask_or_default(image: Image) -> np.ndarray:
if image.mask is not None:
if image.safe_mask is not None:
return image.mask

return np.zeros(image.data.shape, dtype=bool)
Expand Down
2 changes: 1 addition & 1 deletion pyobs/images/processors/misc/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async def __call__(self, image: Image) -> Image:
"""

output_image = image.copy()
if output_image.data is None:
if output_image.safe_data is None:
log.warning("No data found in image.")
return image

Expand Down
4 changes: 2 additions & 2 deletions pyobs/images/processors/misc/softbin.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ async def __call__(self, image: Image) -> Image:
"""

output_image = image.copy()
if output_image.data is None:
if output_image.safe_data is None:
log.warning("No data found in image.")
return image

output_image.data = self._reshape_image(output_image.data)
if output_image.data is None:
if output_image.safe_data is None:
log.warning("No data found in image after reshaping.")
return image

Expand Down
8 changes: 1 addition & 7 deletions pyobs/images/processors/offsets/nstar.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,12 +128,6 @@ async def _boxes_from_ref(self, image: Image, star_box_size: int) -> List:
# run pipeline on 1st image
img = await self.run_pipeline(image)

# check data and catalog
if img.data is None:
raise ValueError("No data found in image.")
if img.catalog is None:
raise ValueError("No catalog found in image.")

# do photometry and get catalog
sources = self._fits2numpy(img.catalog)

Expand Down Expand Up @@ -273,7 +267,7 @@ def _calculate_offsets(self, image: Image) -> Tuple[Optional[float], Optional[fl
"""

# data?
if image.data is None:
if image.safe_data is None:
return None, None

# calculate offset for each star
Expand Down
4 changes: 0 additions & 4 deletions pyobs/images/processors/offsets/projected.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@ def _process(self, image: Image) -> Tuple[npt.NDArray[float], npt.NDArray[float]
# get image data and header
data, hdr = image.data, image.header

# no data?
if data is None:
raise ValueError("Image contains no data.")

# trimsec
if "TRIMSEC" in hdr:
m = re.match(r"\[([0-9]+):([0-9]+),([0-9]+):([0-9]+)\]", hdr["TRIMSEC"])
Expand Down
9 changes: 3 additions & 6 deletions pyobs/images/processors/photometry/pysep.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,15 @@ def _photometry(image: Image) -> Image:
from pyobs.images.processors.detection import SepSourceDetection

# check data
if image.data is None:
if image.safe_data is None:
log.warning("No data found in image.")
return image
if image.catalog is None:
if image.safe_catalog is None:
log.warning("No catalog found in image.")
return image

# no mask?
mask = image.mask if image.mask is not None else np.ones(image.data.shape, dtype=bool)

# remove background
data, bkg = SepSourceDetection.remove_background(image.data, mask)
data, bkg = SepSourceDetection.remove_background(image.data, image.safe_mask)

# fetch catalog
sources = image.catalog.copy()
Expand Down
2 changes: 1 addition & 1 deletion pyobs/modules/camera/basecamera.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ async def __expose(self, exposure_time: float, image_type: ImageType, broadcast:
self._exposure = ExposureInfo(start=datetime.datetime.utcnow(), exposure_time=exposure_time)
try:
image = await self._expose(exposure_time, open_shutter, abort_event=self.expose_abort)
if image is None or image.data is None:
if image is None or image.safe_data is None:
raise exc.GrabImageError("Could not take image.")

except exc.PyObsError:
Expand Down
2 changes: 1 addition & 1 deletion pyobs/utils/focusseries/projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def analyse_image(self, image: Image, focus_value: float) -> None:
"""

# clean data
if image.data is None:
if image.safe_data is None:
return
data = self._clean(image.data)

Expand Down
2 changes: 1 addition & 1 deletion tests/images/processors/test_removebackground.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ def test_call_const_background(mocker):
image = Image(data=np.ones((20, 20)))
output_image = remover(image)

np.testing.assert_array_equal(output_image.data, np.zeros((20, 20)))
np.testing.assert_array_equal(output_image.data, np.zeros((20, 20)))
20 changes: 14 additions & 6 deletions tests/images/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,28 @@ def assert_array_equal_or_none(check_value, value):


def assert_equal_image_params(image, data=None, mask=None, uncertainty=None, catalog=None, raw=None, meta={}):
assert_array_equal_or_none(data, image.data)
assert_array_equal_or_none(mask, image.mask)
assert_array_equal_or_none(uncertainty, image.uncertainty)
assert_array_equal_or_none(data, image.safe_data)
assert_array_equal_or_none(mask, image.safe_mask)
assert_array_equal_or_none(uncertainty, image.safe_uncertainty)

if catalog is None:
assert image.catalog is None
assert image.safe_catalog is None
else:
assert_array_equal_or_none(catalog.as_array(), image.catalog.as_array())
assert_array_equal_or_none(raw, image.raw)
assert_array_equal_or_none(raw, image.safe_raw)
assert image.meta == meta


def assert_equal_image(image, other):
assert_equal_image_params(image, other.data, other.mask, other.uncertainty, other.catalog, other.raw, other.meta)
assert_equal_image_params(
image,
other.safe_data,
other.safe_mask,
other.safe_uncertainty,
other.safe_catalog,
other.safe_raw,
other.safe_meta,
)


@pytest.fixture()
Expand Down

0 comments on commit 5d6c395

Please sign in to comment.