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

Dev #214

Merged
merged 18 commits into from
Feb 1, 2025
Merged

Dev #214

Show file tree
Hide file tree
Changes from all commits
Commits
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
62 changes: 26 additions & 36 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 13 additions & 22 deletions .github/workflows/test_and_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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: |
Expand Down Expand Up @@ -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
Expand Down
13 changes: 7 additions & 6 deletions astromodels/functions/function.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion astromodels/functions/functions_1D/extinction.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion astromodels/functions/template_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion astromodels/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand Down
3 changes: 2 additions & 1 deletion astromodels/xspec/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
27 changes: 27 additions & 0 deletions ci/environment_noxspec.yml
Original file line number Diff line number Diff line change
@@ -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
22 changes: 11 additions & 11 deletions conda-dist/recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
Loading