Skip to content

Commit

Permalink
feat: exception context
Browse files Browse the repository at this point in the history
feat: exception context
  • Loading branch information
lgrcia authored Oct 4, 2023
2 parents ba64070 + b3a9721 commit 98e3bf4
Show file tree
Hide file tree
Showing 7 changed files with 33 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
</p>
</p>

*prose* is a Python package to build image processing pipelines for Astronomy. Beyond featuring the blocks to build pipelines from scratch, it provides pre-implemented ones to perform common tasks such as automated calibration, reduction and photometry.
*prose* is a Python package to build modular image processing pipelines for Astronomy.

*powered by [astropy](https://www.astropy.org/) and [photutils](https://photutils.readthedocs.io)*!

Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sd_hide_title: true

+++

A Python package to build image processing pipelines for Astronomy. Beyond featuring the blocks to build pipelines from scratch, it provides pre-implemented ones to perform common tasks such as automated calibration, reduction and photometry.
A Python package to build modular image processing pipelines for Astronomy.

```{admonition} Where to start?
:class: tip
Expand Down
6 changes: 3 additions & 3 deletions docs/md/debug.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Finding why a specific error is thrown when running a [Sequence](prose.Sequence) can be challenging. Here are a few steps to debug a [Sequence](prose.Sequence).

## 1. Find from which block the error come from
## 1. Find from which block the error comes from

The error might be on the [Sequence](prose.Sequence) `_run` function, but scrolling up will reveal in which block the error actually occurs.
The error might be on the [Sequence](prose.Sequence) `_run` function, but scrolling up will reveal in which block the error actually occurs (if not specified). For each block, the documentation (should) contain explanation for each possible exceptions being raised. If not, [open a Github issue](https://github.com/lgrcia/prose/issues/new/choose)!

## 2. Show the last image

Expand Down Expand Up @@ -41,4 +41,4 @@ for block in sequence.blocks:

This way, the error will be thrown on a specific block, and you can track the changes of each of them on your test image

And if you have any question, just [open a github issue](https://github.com/lgrcia/prose/issues/new/choose)!
And if you have any question, just [open a Github issue](https://github.com/lgrcia/prose/issues/new/choose)!
9 changes: 7 additions & 2 deletions prose/blocks/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,14 @@ class ComputeTransformTwirl(Block):
Parameters
----------
ref : Image
image containing detected sources
Image containing detected sources
n : int, optional
number of stars to consider to compute transformation, by default 10
Number of stars to consider to compute transformation, by default 10
Raises
------
SingularMatrix
Transformation matrix could not be computed. Check the sources in both the reference and input image.
"""

def __init__(self, reference_image: Image, n=10, rtol=0.02, **kwargs):
Expand Down
20 changes: 18 additions & 2 deletions prose/core/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@
from prose.console_utils import warning
from prose.core.image import Buffer, Image

import contextlib


@contextlib.contextmanager
def _exception_context(msg):
try:
yield
except Exception as ex:
if ex.args:
msg = f"[{msg}] {ex.args[0]}"
else:
str(msg)
ex.args = (msg,) + ex.args[1:]
raise


class Block(object):
"""Single unit of processing acting on the :py:class:`~prose.Image` object
Expand Down Expand Up @@ -71,8 +86,9 @@ def _run(self, buffer):
image = buffer
else:
raise ValueError("block must be run on a Buffer or an Image")
self._check_require(image)
self.run(image)
with _exception_context(self.__class__.__name__):
self._check_require(image)
self.run(image)
self.processing_time += time() - t0
self.runs += 1

Expand Down
2 changes: 2 additions & 0 deletions prose/fluxes.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,8 @@ def mask(self, array):
_new.errors = self.errors[..., array]
if self.time is not None:
_new.time = self.time[array]
if self.apertures is not None:
_new.apertures = self.apertures[array, ...]

return _new

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "prose"
version = "3.2.6"
version = "3.2.7"
description = "Modular image processing pipelines for Astronomy"
authors = ["Lionel Garcia"]
license = "MIT"
Expand Down

0 comments on commit 98e3bf4

Please sign in to comment.