Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue 1.0 process #121

Merged
merged 36 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
6580edd
remove process_list and check_iterable
juliotux Sep 23, 2023
ed8408b
py_utils: finish removing check_iterable
juliotux Sep 23, 2023
01c82b3
astrometry: added test for framedata solving
juliotux Sep 23, 2023
0c4382c
astrometry: re-enable test for solve xy
juliotux Sep 23, 2023
7b262d4
detection: deprecate sepfind
juliotux Sep 23, 2023
6fec887
background: more tests
juliotux Sep 24, 2023
f08f6fd
background: more documentation
juliotux Sep 24, 2023
b72189e
aperture: allow only 2d arrays
juliotux Sep 24, 2023
0a19a76
aperture: more tests
juliotux Sep 24, 2023
3e15858
test_aperture: fixed pep8
juliotux Sep 24, 2023
87a5f2c
testing: finished path tests
juliotux Sep 24, 2023
68892f8
filecollection: more tests
juliotux Sep 24, 2023
7fdd779
drop reproject.py
juliotux Sep 24, 2023
0f5054b
physical: tests for derivative functions
juliotux Sep 24, 2023
7828449
qfloat: implemented copysign
juliotux Sep 24, 2023
2055acb
aperture: more tests for recenter methods
juliotux Sep 24, 2023
ffedb25
aperture: improve tests
juliotux Sep 24, 2023
cfcb2e2
aperture: increase tests coverage
juliotux Sep 24, 2023
55ecc54
detection: added test for convolution
juliotux Sep 24, 2023
7205d8d
qfloat: more deriv tests
juliotux Sep 24, 2023
4ed7ecf
image.processing: added dark tests
juliotux Sep 24, 2023
5dc0662
image.processing: increased coverage
juliotux Sep 24, 2023
bf94d14
bump python dev to 3.12
juliotux Sep 24, 2023
6455e60
try fix ci tests
juliotux Sep 24, 2023
28fb33d
aperture: remove unused imports
juliotux Sep 24, 2023
d306c43
move setup.cfg to pyproject.toml
juliotux Sep 24, 2023
27ed40a
test_aperture: fix photutils deprecation
juliotux Sep 24, 2023
e794572
aperture: re-added missing import
juliotux Sep 24, 2023
22f96a9
vizier: avoid warnings of unclosed files
juliotux Sep 24, 2023
d52c1f6
fixed some warnings
juliotux Sep 24, 2023
edc176f
tox: fix config file path for coverage
juliotux Sep 24, 2023
907215b
ci: fix coverage test
juliotux Sep 24, 2023
527e562
unblock devdeps CI
juliotux Sep 24, 2023
2121c0b
astrometry: only create new cfg file when needed
juliotux Sep 27, 2023
0f8e49b
fixed pep8 typos
juliotux Sep 27, 2023
9f15707
skip_astrometry to tests that need it
juliotux Sep 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions .github/workflows/unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
fail-fast: false
matrix:
include:
- name: Python 3.11 with devdeps and online catalogs
python: '3.11'
toxenv: py311-test-devdeps-online
- name: Python 3.12 with devdeps and online catalogs
python: '3.12-dev'
toxenv: py312-test-devdeps-online

- name: Python 3.8 with old deps (online)
python: '3.8'
Expand Down Expand Up @@ -58,13 +58,10 @@ jobs:
with:
python-version: ${{ matrix.python }}
cache: pip
cache-dependency-path: '**/setup.cfg'
cache-dependency-path: '**/pyproject.toml'
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install tox
- name: Print Python, pip, setuptools, and tox versions
run: |
python -m pip install --upgrade --quiet pip setuptools tox
python -c "import sys; print(f'Python {sys.version}')"
python -c "import pip; print(f'pip {pip.__version__}')"
python -c "import setuptools; print(f'setuptools {setuptools.__version__}')"
Expand All @@ -78,7 +75,7 @@ jobs:
path: .tox
# setup.cfg and pyproject.toml have versioning info that would
# impact the tox environment.
key: ${{ github.ref }}-${{ matrix.toxenv }}-tox-${{ hashFiles('setup.cfg') }}
key: ${{ github.ref }}-${{ matrix.toxenv }}-tox-${{ hashFiles('pyproject.toml') }}
- name: Cache astropy cache
uses: actions/cache@v3
with:
Expand Down Expand Up @@ -106,13 +103,13 @@ jobs:
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-${{ runner.arch }}-conda-${{ hashFiles('pyproject.toml', 'setup.cfg') }}
${{ runner.os }}-${{ runner.arch }}-conda-${{ hashFiles('pyproject.toml') }}
- name: Cache env
uses: actions/cache@v3
with:
path: ${{ env.CONDA }}/envs
key:
${{ github.ref }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.get-date.outputs.today }}-conda-envs-${{ hashFiles('pyproject.toml', 'setup.cfg') }}
${{ github.ref }}-${{ runner.os }}-${{ runner.arch }}-${{ steps.get-date.outputs.today }}-conda-envs-${{ hashFiles('pyproject.toml') }}
- uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
Expand Down Expand Up @@ -148,7 +145,7 @@ jobs:
- name: Run Pytest and generate coverage
shell: bash -l {0}
run: |
pytest --pyargs ./tests ./docs --remote-data --cov astropop --cov-config=./setup.cfg
pytest --pyargs ./tests ./docs --remote-data --cov astropop --cov-config=./pyproject.toml
coverage xml -o ./coverage.xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
6 changes: 3 additions & 3 deletions astropop/_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from astropy.table import Table

from .logger import logger
from .py_utils import check_iterable, broadcast
from .py_utils import broadcast


__all__ = ['SQLDatabase', 'SQLTable', 'SQLRow', 'SQLColumn', 'SQLColumnMap']
Expand Down Expand Up @@ -75,7 +75,7 @@ def add_column(self, name):

def get_column_name(self, item, add_columns=False):
"""Get the column name for a given keyword."""
if check_iterable(item):
if not np.isscalar(item):
return [self.get_column_name(i) for i in item]

item = item.lower()
Expand All @@ -88,7 +88,7 @@ def get_column_name(self, item, add_columns=False):

def get_keyword(self, item):
"""Get the keyword for a given column."""
if check_iterable(item):
if not np.isscalar(item):
return [self.get_keyword(i) for i in item]

item = item.lower()
Expand Down
41 changes: 26 additions & 15 deletions astropop/astrometry/astrometrynet.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
improvements.
"""


import os
import shutil
from subprocess import CalledProcessError
Expand Down Expand Up @@ -249,6 +248,9 @@
'To astrometry.cfg file. If no depths are given, use these.'
)
}
# These are the parameters that can be set in the astrometry.cfg file
_conf_file = ['inparallel', 'minwidth', 'maxwidth', 'depths',
'add_path', 'autoindex', 'index']


def get_options_help():
Expand Down Expand Up @@ -621,6 +623,7 @@ def _updated_config(self, config=None):

def _write_config(self, fname, config=None):
"""Create the astrometry.cfg file for the run."""
# write the new cfg
f = open(fname, 'w')
config = config or self.config
for k, v in config.items():
Expand All @@ -643,12 +646,27 @@ def _pop_config(self, options):
"""Pop the config from options."""
options = options.copy()
cfg = {}
for i in ['minwidth', 'maxwidth', 'inparallel', 'autoindex', 'index',
'add_path', 'depths']:
for i in _conf_file:
if i in options:
cfg[i] = options.pop(i)
return options, cfg

def _get_args(self, root, fname, options, output_dir,
correspond):
args = [self._command, fname, '--dir', output_dir]
# if any of the options is from config file, rewrite it.
if any([i in _conf_file for i in options.keys()]):
# pop some options and put them in config
options, cfg = self._pop_config(options)
cfg = self._updated_config(cfg)
config_file = os.path.join(output_dir, root + '.cfg')
self._write_config(config_file, cfg)
args += ['--config', config_file]

args += self._parse_options(options)
args += ['--corr', correspond]
return args

def _run_solver(self, filename, options, output_dir=None, **kwargs):
"""Run the astrometry.net localy using the given params.

Expand All @@ -658,19 +676,12 @@ def _run_solver(self, filename, options, output_dir=None, **kwargs):
basename = os.path.basename(filename)
root, _ = os.path.splitext(basename)
output_dir, tmp_dir = self._get_output_dir(root, output_dir)
solved_file = os.path.join(output_dir, root + '.solved')
# Ensure the output directory exist
os.makedirs(output_dir, exist_ok=True)
correspond = os.path.join(output_dir, root + '.corr')

# pop some options and put them in config
options, cfg = self._pop_config(options)
cfg = self._updated_config(cfg)
config_file = os.path.join(output_dir, root + '.cfg')
self._write_config(config_file, cfg)

args = [self._command, filename, '--dir', output_dir]
args += ['--config', config_file]
args += self._parse_options(options)
args += ['--corr', correspond]
solved_file = os.path.join(output_dir, root + '.solved')
args = self._get_args(root, filename, options, output_dir=output_dir,
correspond=correspond)

try:
process, _, _ = run_command(args, **kwargs)
Expand Down
5 changes: 2 additions & 3 deletions astropop/astrometry/coords_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
import numpy as np
from astropy.coordinates import SkyCoord
from astropy import units
from ..py_utils import check_iterable

__all__ = ['guess_coordinates']


def guess_coordinates(ra, dec, skycoord=True):
"""Try to guess the format or ra and dec passed."""
# TODO: this needs a refactor!

Check notice on line 13 in astropop/astrometry/coords_utils.py

View check run for this annotation

codefactor.io / CodeFactor

astropop/astrometry/coords_utils.py#L13

unresolved comment '# TODO: this needs a refactor!' (C100)
# process as lists of coordinates
if check_iterable(ra) and check_iterable(dec):
if not np.isscalar(ra) and not np.isscalar(dec):
if len(ra) != len(dec):
raise ValueError('RA and Dec do not match in dimensions.')
try:
Expand All @@ -22,7 +21,7 @@
s = None
except ValueError:
s = SkyCoord(ra, dec, unit=(units.hourangle, units.deg))
elif check_iterable(ra) or check_iterable(dec):
elif not np.isscalar(ra) or not np.isscalar(dec):
raise ValueError('RA and Dec do not match in dimensions.')

# process as single coordinates
Expand Down
4 changes: 2 additions & 2 deletions astropop/catalogs/_online_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from astropy.coordinates import SkyCoord, Angle
from astropy.units import UnitTypeError
from ..astrometry.coords_utils import guess_coordinates
from ..py_utils import string_fix, process_list
from ..py_utils import string_fix


MAX_PARALLEL_QUERY = 30
Expand All @@ -32,7 +32,7 @@ def _fix_query_table(table):
for i in table.columns:
tdtype = table[i].dtype.char
if tdtype in ('b', 'B', 'S', 'a', 'O'):
row = process_list(string_fix, table[i])
row = [string_fix(r) for r in table[i]]
table[i] = np.array(row, dtype=str)
return table

Expand Down
3 changes: 2 additions & 1 deletion astropop/catalogs/vizier.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,8 @@ class NewViz(VizierSourcesCatalog):
def __init__(self, *args, **kwargs):
super(NewViz, self).__init__(filename, *args, **kwargs)

conf = yaml.safe_load(open(filename, 'r'))
with open(filename, 'r') as f:
conf = yaml.safe_load(f)
available_filters = conf.get('available_filters', None)
if available_filters:
available_filters = list(available_filters.keys())
Expand Down
7 changes: 3 additions & 4 deletions astropop/file_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from .fits_utils import _fits_extensions, \
_fits_extensions_with_compress
from .framedata import check_framedata
from .py_utils import check_iterable
from .logger import logger

__all__ = ['FitsFileGroup']
Expand All @@ -25,23 +24,23 @@ def list_fits_files(location, fits_extensions=None,
if fits_extensions is None:
fits_extensions = _fits_extensions

if not check_iterable(fits_extensions):
if np.isscalar(fits_extensions):
fits_extensions = [fits_extensions]

f = []
for i in fits_extensions:
files = glob.glob(os.path.join(location, '**/*'+i), recursive=True)
# filter only glob include
if glob_include is not None:
if not check_iterable(glob_include):
if np.isscalar(glob_include):
glob_include = [glob_include]
for inc in glob_include:
files = [i for i in files if fnmatch.fnmatch(i, inc)]
f.extend(files)

# Filter excluded files
if glob_exclude is not None:
if not check_iterable(glob_exclude):
if np.isscalar(glob_exclude):
glob_exclude = [glob_exclude]
for exc in glob_exclude:
f = [i for i in f if not fnmatch.fnmatch(i, exc)]
Expand Down
6 changes: 3 additions & 3 deletions astropop/image/imcombine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from astropy.stats import mad_std

from ..framedata import FrameData, check_framedata
from ..py_utils import check_iterable, check_number
from ..py_utils import check_number
from ..logger import logger
from ._tools import merge_header

Expand Down Expand Up @@ -71,7 +71,7 @@ def _sigma_clip(data, threshold=3, cen_func='median', dev_func='mad_std',
if check_number(threshold):
slow = threshold
shigh = threshold
elif check_iterable(threshold):
elif not np.isscalar(threshold):
slow, shigh = threshold
else:
raise TypeError(f'Sigma clipping threshold {threshold} not'
Expand Down Expand Up @@ -250,7 +250,7 @@ def set_sigma_clip(self, sigma_limits=None,
self._sigma_dev_func = None
return

if check_iterable(sigma_limits):
if not np.isscalar(sigma_limits):
if len(sigma_limits) not in (1, 2):
raise ValueError('Invalid sigma clipping thresholds'
r' {sigma_limits}')
Expand Down
19 changes: 5 additions & 14 deletions astropop/math/_deriv.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ def _deriv_mod_1(x, y):
return numerical_derivative(np.mod, 1)(x, y)


@np.vectorize
def _deriv_fabs(x):
if x >= 0:
return 1
return -1


@np.vectorize
def _deriv_copysign(x, y):
if x >= 0:
Expand Down Expand Up @@ -81,14 +74,12 @@ def _deriv_copysign(x, y):
'arctan2': (lambda y, x: x/(x**2+y**2), # Correct for x == 0
lambda y, x: -y/(x**2+y**2)), # Correct for x == 0
'arctanh': (lambda x: 1/(1-x**2)),
'copysign': (_deriv_copysign,
lambda x, y: 0),
'cos': (lambda x: -np.sin(x)),
'cosh': (np.sinh),
'copysign': (_deriv_copysign, lambda x, y: 0),
'exp': (np.exp),
'expm1': (np.exp),
'exp2': (lambda x: np.exp2(x)*np.log(2)),
'fabs': (_deriv_fabs),
'hypot': [lambda x, y: x/np.hypot(x, y),
lambda x, y: y/np.hypot(x, y)],
'log': (lambda x: 1/x), # for np, log=ln
Expand Down Expand Up @@ -125,7 +116,7 @@ def propagate_1(func, fx, x, sx):
if func not in derivatives.keys():
raise ValueError(f'func {func} not in derivatives.')

if hasattr(derivatives[func], '__len__'):
if np.size(derivatives[func]) != 1:
raise ValueError(f'func {func} is not a 1 variable function.')

try:
Expand All @@ -137,7 +128,7 @@ def propagate_1(func, fx, x, sx):
if len(shape) == 0:
return np.nan
else:
return np.empty(shape).fill(np.nan)
return np.full(shape, fill_value=np.nan)


def propagate_2(func, fxy, x, y, sx, sy):
Expand All @@ -163,7 +154,7 @@ def propagate_2(func, fxy, x, y, sx, sy):
if func not in derivatives.keys():
raise ValueError(f'func {func} not in derivatives.')

if len(derivatives[func]) != 2:
if np.size(derivatives[func]) != 2:
raise ValueError(f'func {func} is not a 2 variable function.')

deriv_x, deriv_y = derivatives[func]
Expand Down Expand Up @@ -206,7 +197,7 @@ def numerical_derivative(func, arg_ref, step=STEP_SIZE):
- Implementation based on `uncertainties` package.
"""
if not callable(func):
raise ValueError(f'function {func} not callable.')
raise TypeError(f'function {func} not callable.')

# If reference variable is in kwargs (str) instead of args (int).
change_kwargs = isinstance(arg_ref, str)
Expand Down
Loading
Loading