diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6f1cc34f..40c46a51 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -73,37 +73,26 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, macos-latest, macos-12] + os: [ubuntu-latest, macos-latest, macos-13] python-version: [3.9] - + include: + - environment: ci/environment.yml + - environment: ci/environment_noxspec.yml + os: macos-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - # - name: Set up Python - # uses: actions/setup-python@v5 - # with: - # python-version: ${{ matrix.python-version }} - # - name: Cache conda - # uses: actions/cache@v4 - # env: - # # Increase this value to reset cache if etc/example-environment.yml has not changed - # CACHE_NUMBER: 0 - # with: - # path: ~/conda_pkgs_dir - # key: conda-${{ matrix.os }}-python-${{ matrix.python-version }}-${{ hashFiles('ci/environment.yml') }} - name: Add conda ${{ matrix.python-version }} to system path uses: conda-incubator/setup-miniconda@v3 with: activate-environment: "test_env" auto-activate-base: false - architecture: "x64" - miniforge-variant: Mambaforge - #miniforge-version: latest + miniforge-variant: Miniforge3 python-version: ${{ matrix.python-version }} auto-update-conda: true - environment-file: ci/environment.yml + environment-file: ${{ matrix.environment }} use-only-tar-bz2: true channel-priority: true channels: conda-forge, xspecmodels, threeml @@ -118,7 +107,7 @@ jobs: miniconda_os=Linux compilers="gcc_linux-64 gxx_linux-64 gfortran_linux-64" - else # osx + else miniconda_os=MacOSX compilers="clang_osx-64 clangxx_osx-64 gfortran_osx-64" @@ -155,13 +144,15 @@ jobs: #conda install --use-local astromodels conda install -c ${CONDA}/envs/test_env/conda-bld/ astromodels - - name: Test conda build + - name: Test import xspec + if: matrix.os != 'macos-latest' shell: bash -l {0} run: | cd astromodels/tests - echo "======> importing XSPEC..." python -c "import astromodels.xspec" - python -m pytest -vv --cov=astromodels --cov-report=xml + - name: Test astromodels + shell: bash -l {0} + run: python -m pytest -vv --cov=astromodels --cov-report=xml env: OMP_NUM_THREADS: 1 MKL_NUM_THREADS: 1 @@ -174,33 +165,28 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [ubuntu-latest, macos-latest, macos-13] python-version: [3.9] - + include: + - environment: ci/environment.yml + - environment: ci/environment_noxspec.yml + os: macos-latest steps: - name: Checkout uses: actions/checkout@v4 with: fetch-depth: 0 - - name: Cache conda - uses: actions/cache@v4 - env: - # Increase this value to reset cache if etc/example-environment.yml has not changed - CACHE_NUMBER: 0 - with: - path: ~/conda_pkgs_dir - key: conda-${{ matrix.os }}-python-${{ matrix.python-version }}-${{ hashFiles('ci/environment.yml') }} - name: Add conda ${{ matrix.python-version }} to system path uses: conda-incubator/setup-miniconda@v3 with: activate-environment: "test_env" auto-activate-base: false - architecture: "x64" - miniforge-variant: Mambaforge + #architecture: "x64" + miniforge-variant: Miniforge3 #miniforge-version: latest python-version: ${{ matrix.python-version }} auto-update-conda: true - environment-file: ci/environment.yml + environment-file: ${{ matrix.environment }} use-only-tar-bz2: true channel-priority: true channels: conda-forge, xspecmodels, threeml @@ -254,12 +240,16 @@ jobs: LABEL="--label dev" fi - if [[ ${{matrix.os}} == ubuntu-latest ]]; then anaconda -v --show-traceback -t $UPLOAD_TOKEN upload -u threeml ${CONDA}/envs/test_env/conda-bld/linux-64/*.tar.bz2 --force $LABEL + elif [[ ${{matrix.os}} == macos-latest ]]; + then + + anaconda -v --show-traceback -t $UPLOAD_TOKEN upload -u threeml ${CONDA}/envs/test_env/conda-bld/osx-arm64/*.tar.bz2 --force $LABEL + else anaconda -v --show-traceback -t $UPLOAD_TOKEN upload -u threeml ${CONDA}/envs/test_env/conda-bld/osx-64/*.tar.bz2 --force $LABEL diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bb8a6de3..d393e33d 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -48,7 +48,8 @@ jobs: - name: Execute the notebooks #shell: bash -l {0} run: | - + # Make sure we fail in case of error + set -e # Download an example file wget https://www.astropy.org/astropy-data/photometry/spitzer_example_image.fits diff --git a/.github/workflows/test_and_build.yml b/.github/workflows/test_and_build.yml index 0e17e96c..a32a82b3 100644 --- a/.github/workflows/test_and_build.yml +++ b/.github/workflows/test_and_build.yml @@ -37,7 +37,7 @@ jobs: fail-fast: false matrix: python-version: ["3.9", "3.10", "3.11"] - os: ["ubuntu-latest", "macos-latest", "macos-12"] + os: ["ubuntu-latest", "macos-latest", "macos-13"] runs-on: ${{ matrix.os }} steps: - name: Checkout @@ -100,36 +100,28 @@ jobs: strategy: fail-fast: false matrix: - os: ["ubuntu-latest", "macos-latest", "macos-12"] + os: ["ubuntu-latest", "macos-latest", "macos-13"] python-version: [3.9] + include: + - environment: ci/environment.yml + - environment: ci/environment_noxspec.yml + os: macos-latest runs-on: ${{ matrix.os }} steps: - name: Checkout uses: actions/checkout@v4 - # - name: Cache conda - # uses: actions/cache@v4 - # env: - # # Increase this value to reset cache if etc/example-environment.yml has not changed - # CACHE_NUMBER: 0 - # with: - # path: ~/conda_pkgs_dir - # key: conda-${{ matrix.os }}-python-${{ matrix.python-version }}-${{ hashFiles('ci/environment.yml') }} - name: Add conda ${{ matrix.python-version }} to system path uses: conda-incubator/setup-miniconda@v3 with: activate-environment: "test_env" auto-activate-base: false - architecture: "x64" - #mamba-version: "*" miniforge-version: latest python-version: ${{ matrix.python-version }} auto-update-conda: true - environment-file: ci/environment.yml + environment-file: ${{ matrix.environment }} use-only-tar-bz2: true channel-priority: strict channels: conda-forge, xspecmodels - - - name: Init Env shell: bash -l {0} run: | @@ -166,14 +158,13 @@ jobs: # stop the build if there are Python syntax errors or undefined names flake8 - - name: Test conda install + - name: Test import xspec + if: matrix.os != 'macos-latest' shell: bash -l {0} - run: | - - echo "======> importing XSPEC..." - python -c "import astromodels.xspec" - python -m pytest -vv --cov=astromodels --cov-report=xml - + run: python -c "import astromodels.xspec" + - name: Test astromodels + shell: bash -l {0} + run: python -m pytest -vv --cov=astromodels --cov-report=xml env: OMP_NUM_THREADS: 1 MKL_NUM_THREADS: 1 diff --git a/astromodels/functions/function.py b/astromodels/functions/function.py index d58757a1..d9b4b6f4 100644 --- a/astromodels/functions/function.py +++ b/astromodels/functions/function.py @@ -24,6 +24,7 @@ from astromodels.utils.logging import setup_logger from astromodels.utils.pretty_list import dict_to_list from astromodels.utils.table import dict_to_table +from astromodels.utils.file_utils import copy_if_needed from yaml.reader import ReaderError log = setup_logger(__name__) @@ -1479,7 +1480,7 @@ def __call__(self, x): # Transform the input to an array of floats. If x is a single number, this will be an array of size 1 - new_input = np.array(x, dtype=float, ndmin=1, copy=False) + new_input = np.array(x, dtype=float, ndmin=1, copy=copy_if_needed) # Compute the function @@ -1705,8 +1706,8 @@ def __call__(self, x, y, *args, **kwargs): # Transform the input to an array of floats - new_x = np.array(x, dtype=float, ndmin=1, copy=False) - new_y = np.array(y, dtype=float, ndmin=1, copy=False) + new_x = np.array(x, dtype=float, ndmin=1, copy=copy_if_needed) + new_y = np.array(y, dtype=float, ndmin=1, copy=copy_if_needed) # Compute the function @@ -1876,9 +1877,9 @@ def __call__(self, x, y, z): # This is either a single number or a list # Transform the input to an array of floats - new_x = np.array(x, dtype=float, ndmin=1, copy=False) - new_y = np.array(y, dtype=float, ndmin=1, copy=False) - new_z = np.array(z, dtype=float, ndmin=1, copy=False) + new_x = np.array(x, dtype=float, ndmin=1, copy=copy_if_needed) + new_y = np.array(y, dtype=float, ndmin=1, copy=copy_if_needed) + new_z = np.array(z, dtype=float, ndmin=1, copy=copy_if_needed) # Compute the function diff --git a/astromodels/functions/functions_1D/extinction.py b/astromodels/functions/functions_1D/extinction.py index 3c55d5c6..c5fac1d4 100644 --- a/astromodels/functions/functions_1D/extinction.py +++ b/astromodels/functions/functions_1D/extinction.py @@ -9,6 +9,7 @@ from astromodels.functions.function import Function1D, FunctionMeta from astromodels.utils.logging import setup_logger +from astromodels.utils.file_utils import copy_if_needed log = setup_logger(__name__) @@ -89,7 +90,7 @@ def evaluate(self, x, e_bmv, rv, redshift): if isinstance(x, astropy_units.Quantity): - _x = np.array(x.to("keV").value, ndmin=1, copy=False, dtype=float) + _x = np.array(x.to("keV").value, ndmin=1, copy=copy_if_needed, dtype=float) _unit = astropy_units.cm**2 _y_unit = astropy_units.dimensionless_unscaled diff --git a/astromodels/functions/template_model.py b/astromodels/functions/template_model.py index 677cc9da..dda4d3fb 100644 --- a/astromodels/functions/template_model.py +++ b/astromodels/functions/template_model.py @@ -20,6 +20,7 @@ from astromodels.functions.function import Function1D, FunctionMeta from astromodels.utils import get_user_data_path from astromodels.utils.logging import setup_logger +from astromodels.utils.file_utils import copy_if_needed log = setup_logger(__name__) @@ -760,7 +761,7 @@ def _interpolate(self, energies, scale, parameters_values): # the logarithm below will fail. energies = np.array( - energies.to("keV").value, ndmin=1, copy=False, dtype=float + energies.to("keV").value, ndmin=1, copy=copy_if_needed, dtype=float ) # Same for the scale diff --git a/astromodels/utils/file_utils.py b/astromodels/utils/file_utils.py index 5c16a394..f4dfda58 100644 --- a/astromodels/utils/file_utils.py +++ b/astromodels/utils/file_utils.py @@ -3,11 +3,19 @@ import os from pathlib import Path - +from typing import Optional +import numpy as np import pkg_resources _custom_config_path = os.environ.get("ASTROMODELS_CONFIG") +copy_if_needed: Optional[bool] + +if np.lib.NumpyVersion(np.__version__) >= "2.0.0": + copy_if_needed = None +else: + copy_if_needed = False + def _get_data_file_path(data_file: str) -> Path: """ diff --git a/astromodels/xspec/factory.py b/astromodels/xspec/factory.py index edef7d3e..0adddfb1 100644 --- a/astromodels/xspec/factory.py +++ b/astromodels/xspec/factory.py @@ -431,6 +431,7 @@ def get_models(model_dat_path): from astromodels.functions.function import FunctionMeta, Function1D import numpy as np import astropy.units as u +from astromodels.utils.file_utils import copy_if_needed from astromodels.xspec import _xspec import six @@ -486,7 +487,7 @@ def evaluate(self, x, $PARAMETERS_NAMES$): if isinstance(x, u.Quantity): - x = np.array(x.to('keV').value, ndmin=1, copy=False, dtype=float) + x = np.array(x.to('keV').value, ndmin=1, copy=copy_if_needed, dtype=float) quantity = True diff --git a/ci/environment_noxspec.yml b/ci/environment_noxspec.yml new file mode 100644 index 00000000..16b332f5 --- /dev/null +++ b/ci/environment_noxspec.yml @@ -0,0 +1,27 @@ +name: test_env + +channels: + - conda-forge + - defaults + +dependencies: + - python + - numpy + - pyyaml>=5.1 + - astropy + - scipy + - numdifftools + - hdf5 + - pytables + - pandas>=0.23 + - dill + - wcslib + - future + - numba + - h5py + - interpolation>=2.2.3 + - libgfortran + - omegaconf + - colorama + - rich + - joblib diff --git a/conda-dist/recipe/meta.yaml b/conda-dist/recipe/meta.yaml index bf055a51..9e072ca5 100644 --- a/conda-dist/recipe/meta.yaml +++ b/conda-dist/recipe/meta.yaml @@ -13,10 +13,10 @@ requirements: - {{ compiler('c') }} # [linux] - {{ compiler('cxx') }} # [linux] - {{ compiler('fortran') }} # [linux] - - xspec-modelsonly - - cfitsio - - ccfits - - wcslib + - xspec-modelsonly #[not arm64] + - cfitsio # [not arm64] + - ccfits # [not arm64] + - wcslib # [not arm64] host: - python @@ -25,10 +25,10 @@ requirements: - numpy - pyyaml>=5.1 - pandas>=0.23 - - cfitsio - - ccfits - - wcslib - - xspec-modelsonly + - cfitsio # [not arm64] + - ccfits # [not arm64] + - wcslib # [not arm64] + - xspec-modelsonly # [not arm64] - future - numba>=0.54 - h5py @@ -46,9 +46,9 @@ requirements: - pytables - pandas>=0.23 - dill - - cfitsio - - ccfits - - wcslib + - cfitsio # [not arm64] + - ccfits # [not arm64] + - wcslib # [not arm64] - future - numba>=0.54 - h5py