Skip to content

Commit

Permalink
Merge pull request #162 from neutrinoceros/require_astropy_5
Browse files Browse the repository at this point in the history
BLD: require astropy>=5.0, drop dependency on packaging
  • Loading branch information
DrSoulain authored Feb 15, 2023
2 parents ff81ac4 + d21b4a3 commit 9a881d3
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 54 deletions.
1 change: 0 additions & 1 deletion amical/get_infos_obs.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

from amical.tools import mas2rad


if sys.version_info >= (3, 9):
import importlib.resources as importlib_resources
else:
Expand Down
38 changes: 0 additions & 38 deletions amical/mf_pipeline/bispect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import os
import sys
import time
import warnings
from pathlib import Path

import numpy as np
Expand All @@ -36,14 +35,6 @@
from .idl_function import dblarr, dist, regress_noc


def _ASTROPY_VERSION():
from importlib.metadata import version

from packaging.version import Version

return Version(version("astropy"))


def _compute_complex_bs(
ft_arr,
index_mask,
Expand Down Expand Up @@ -1004,40 +995,11 @@ def _compute_phs_error(complex_bs, fitmat, index_mask, npix, imsize=3):

def _add_infos_header(infos, hdr, mf, pa, filename, maskname, npix):
"""Save important informations and some parts of the original header."""
from astropy.io import fits
from packaging.version import Version

infos["pixscale"] = mf.pixelSize
infos["pa"] = pa
infos["filename"] = filename
infos["maskname"] = maskname
infos["isz"] = npix

# Raise a warning that old astropy version drop commentary cards, but only if
# there are any in the original header
hdr_commentary_keys = fits.Card._commentary_keywords
if any(hck in hdr for hck in hdr_commentary_keys) and (
_ASTROPY_VERSION() < Version("5.0rc")
):
warnings.warn(
"Commentary cards are removed from the header with astropy"
f" version < 5.0. Your astropy version is"
f" {_ASTROPY_VERSION()}",
RuntimeWarning,
)
# HACK: astropy _HeaderCommentaryCards are registered as mappings,
# so munch tries to access their keys, leading to attribute error
# to prevent this, we remove commentary cards as a temporary fix.
# (As of September 2 2021, with astropy version 4.3.1)
# See:
# https://github.com/SydneyAstrophotonicInstrumentationLab/AMICAL/issues/31
# https://github.com/astropy/astropy/issues/11866
# Resolved upstream with
# https://github.com/astropy/astropy/pull/11923
hdr = hdr.copy()
for key in hdr_commentary_keys:
hdr.remove(key, ignore_missing=True, remove_all=True)

infos["hdr"] = hdr

# Save keys of the original header (as needed):
Expand Down
13 changes: 0 additions & 13 deletions amical/tests/test_extraction.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
import astropy
import munch
import pytest
from astropy.io import fits
from packaging.version import Version

from amical.mf_pipeline.bispect import _add_infos_header

# Astropy versions for
ASTROPY_VERSION = Version(astropy.__version__)


@pytest.fixture()
def commentary_infos():
Expand Down Expand Up @@ -57,18 +52,10 @@ def test_add_infos_header_commentary(commentary_infos):
munch.munchify(commentary_infos)


@pytest.mark.xfail(
ASTROPY_VERSION < Version("5.0rc"),
reason="Munch cannot handle commentary cards for Astropy < 5.0",
)
def test_commentary_infos_keep(commentary_infos):
assert "HISTORY" in commentary_infos.hdr


@pytest.mark.skipif(
ASTROPY_VERSION < Version("5.0"),
reason="Astropy < 5.0 raised a warning for commentary cards",
)
def test_no_commentary_warning_astropy_version():
# Add hdr to infos placeholders for everything but hdr
mf = munch.Munch(pixelSize=1.0)
Expand Down
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,14 @@ classifiers = [
]
requires-python = ">=3.8"
dependencies = [
"astropy",
"astropy>=5.0",
"astroquery",
"corner",
"emcee",
"h5py",
"matplotlib",
"munch",
"numpy",
"packaging>=21.0",
"pypdf>=3.2.0",
"scipy",
"tabulate",
Expand Down

0 comments on commit 9a881d3

Please sign in to comment.