-
-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1704 from larrybradley/repr
Add __repr__ and __str__ strings for several classes
- Loading branch information
Showing
13 changed files
with
153 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
""" | ||
Tests for the interpolators module. | ||
""" | ||
|
||
import numpy as np | ||
import pytest | ||
|
||
from photutils.background.background_2d import Background2D | ||
from photutils.background.interpolators import (BkgIDWInterpolator, | ||
BkgZoomInterpolator) | ||
from photutils.utils._optional_deps import HAS_SCIPY | ||
|
||
|
||
@pytest.mark.skipif(not HAS_SCIPY, reason='scipy is required') | ||
def test_zoom_interp(): | ||
bkg = Background2D(np.ones((300, 300)), 100) | ||
mesh = np.array([[0.01, 0.01, 0.02], | ||
[0.01, 0.02, 0.03], | ||
[0.03, 0.03, 12.9]]) | ||
|
||
interp = BkgZoomInterpolator(clip=False) | ||
zoom = interp(mesh, bkg) | ||
assert zoom.shape == (300, 300) | ||
|
||
cls_repr = repr(interp) | ||
assert cls_repr.startswith(f'{interp.__class__.__name__}') | ||
|
||
|
||
@pytest.mark.skipif(not HAS_SCIPY, reason='scipy is required') | ||
def test_idw_interp(): | ||
bkg = Background2D(np.ones((300, 300)), 100) | ||
mesh = np.array([[0.01, 0.01, 0.02], | ||
[0.01, 0.02, 0.03], | ||
[0.03, 0.03, 12.9]]) | ||
|
||
interp = BkgIDWInterpolator() | ||
zoom = interp(mesh, bkg) | ||
assert zoom.shape == (300, 300) | ||
|
||
cls_repr = repr(interp) | ||
assert cls_repr.startswith(f'{interp.__class__.__name__}') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Licensed under a 3-clause BSD style license - see LICENSE.rst | ||
""" | ||
This module provides tools for class __repr__ and __str__ strings. | ||
""" | ||
|
||
|
||
def make_repr(self, params, ellipsis=(), long=False): | ||
cls_name = f'{self.__class__.__name__}' | ||
if long: | ||
cls_name = f'{self.__class__.__module__}.{cls_name}' | ||
|
||
cls_info = [] | ||
for param in params: | ||
if param in ellipsis: | ||
value = '...' | ||
else: | ||
value = getattr(self, param) | ||
cls_info.append((param, value)) | ||
|
||
if long: | ||
delim = ': ' | ||
join_str = '\n' | ||
else: | ||
delim = '=' | ||
join_str = ', ' | ||
|
||
fmt = [f'{key}{delim}{val!r}' for key, val in cls_info] | ||
fmt = f'{join_str}'.join(fmt) | ||
|
||
if long: | ||
return f'<{cls_name}>\n{fmt}' | ||
else: | ||
return f'{cls_name}({fmt})' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters