Skip to content

Commit 98e3bf4

Browse files
authored
feat: exception context
feat: exception context
2 parents ba64070 + b3a9721 commit 98e3bf4

File tree

7 files changed

+33
-10
lines changed

7 files changed

+33
-10
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
</p>
2424
</p>
2525

26-
*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.
26+
*prose* is a Python package to build modular image processing pipelines for Astronomy.
2727

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

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ sd_hide_title: true
1111

1212
+++
1313

14-
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.
14+
A Python package to build modular image processing pipelines for Astronomy.
1515

1616
```{admonition} Where to start?
1717
:class: tip

docs/md/debug.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
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).
44

5-
## 1. Find from which block the error come from
5+
## 1. Find from which block the error comes from
66

7-
The error might be on the [Sequence](prose.Sequence) `_run` function, but scrolling up will reveal in which block the error actually occurs.
7+
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)!
88

99
## 2. Show the last image
1010

@@ -41,4 +41,4 @@ for block in sequence.blocks:
4141

4242
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
4343

44-
And if you have any question, just [open a github issue](https://github.com/lgrcia/prose/issues/new/choose)!
44+
And if you have any question, just [open a Github issue](https://github.com/lgrcia/prose/issues/new/choose)!

prose/blocks/geometry.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,14 @@ class ComputeTransformTwirl(Block):
165165
Parameters
166166
----------
167167
ref : Image
168-
image containing detected sources
168+
Image containing detected sources
169169
n : int, optional
170-
number of stars to consider to compute transformation, by default 10
170+
Number of stars to consider to compute transformation, by default 10
171+
172+
Raises
173+
------
174+
SingularMatrix
175+
Transformation matrix could not be computed. Check the sources in both the reference and input image.
171176
"""
172177

173178
def __init__(self, reference_image: Image, n=10, rtol=0.02, **kwargs):

prose/core/block.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
from prose.console_utils import warning
66
from prose.core.image import Buffer, Image
77

8+
import contextlib
9+
10+
11+
@contextlib.contextmanager
12+
def _exception_context(msg):
13+
try:
14+
yield
15+
except Exception as ex:
16+
if ex.args:
17+
msg = f"[{msg}] {ex.args[0]}"
18+
else:
19+
str(msg)
20+
ex.args = (msg,) + ex.args[1:]
21+
raise
22+
823

924
class Block(object):
1025
"""Single unit of processing acting on the :py:class:`~prose.Image` object
@@ -71,8 +86,9 @@ def _run(self, buffer):
7186
image = buffer
7287
else:
7388
raise ValueError("block must be run on a Buffer or an Image")
74-
self._check_require(image)
75-
self.run(image)
89+
with _exception_context(self.__class__.__name__):
90+
self._check_require(image)
91+
self.run(image)
7692
self.processing_time += time() - t0
7793
self.runs += 1
7894

prose/fluxes.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,8 @@ def mask(self, array):
496496
_new.errors = self.errors[..., array]
497497
if self.time is not None:
498498
_new.time = self.time[array]
499+
if self.apertures is not None:
500+
_new.apertures = self.apertures[array, ...]
499501

500502
return _new
501503

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "prose"
3-
version = "3.2.6"
3+
version = "3.2.7"
44
description = "Modular image processing pipelines for Astronomy"
55
authors = ["Lionel Garcia"]
66
license = "MIT"

0 commit comments

Comments
 (0)