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

Update min python to 3.9 and min sunpy to 4 #318

Merged
merged 4 commits into from
Feb 12, 2023
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/end2end_run.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.8"]
python-version: ["3.9"]

steps:
- name: Checkout github repo (+ download lfs dependencies)
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ repos:
args: ['--in-place', '--remove-all-unused-imports', '--remove-unused-variable']
exclude: ".*(.fits|.fts|.fit|.txt|tca.*|extern.*|.rst|.md|__init__.py|docs/conf.py)$"
- repo: https://github.com/timothycrosley/isort
rev: 5.6.4
rev: 5.12.0
hooks:
- id: isort
args: ['--sp','setup.cfg']
Expand Down
6 changes: 5 additions & 1 deletion .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ submodules:
# Optionally build your docs in additional formats such as PDF and ePub
formats: []

build:
os: ubuntu-22.04
tools:
python: "3.9"

# Optionally set the version of Python and requirements required to build your docs
python:
version: 3.7
install:
- method: pip
path: .
Expand Down
20 changes: 10 additions & 10 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ variables:
CI_NAME: Azure Pipelines
CI_BUILD_ID: $(Build.BuildId)
CI_BUILD_URL: "https://dev.azure.com/https://github.com/i4Ds/STIXCore.git/_build/results?buildId=$(Build.BuildId)"
CIBW_BUILD: cp37-* cp38-* cp39-*
CIBW_BUILD: cp39-* cp310-* cp311-*
CIBW_SKIP: "*-win32 *-manylinux1_i686"

resources:
Expand Down Expand Up @@ -36,14 +36,14 @@ jobs:
submodules: true
coverage: codecov
envs:
- macos: py37
name: py37_mac
- macos: py39
name: py39_mac

- windows: py37
name: py37_win
- windows: py39
name: py39_win

- linux: py37
name: py37_linux
- linux: py39
name: py39_linux

- linux: codestyle
name: codestyle
Expand All @@ -65,6 +65,6 @@ jobs:
# - wheels_macos
- sdist
dependsOn:
- py36_test
- py37_test
- py38_test
- py39_test
- py310_test
- py311_test
20 changes: 11 additions & 9 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,23 @@ long_description = file: README.rst
include_package_data = True
zip_safe = False
packages = find:
python_requires = >=3.7
python_requires = >=3.9
setup_requires = setuptools_scm
install_requires =
sunpy>=3.0.1
numpy
spiceypy
bitstring
roentgen
watchdog
pyyaml
intervaltree
hissw
polling2
intervaltree
numpy
matplotlib
paramiko
polling2
python-dateutil
pyyaml
roentgen
scp
spiceypy
sunpy>=4.0.1
watchdog



Expand Down
21 changes: 2 additions & 19 deletions stixcore/calibration/tests/test_transmission.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,10 @@

import numpy as np
import pytest
from numpy.testing import assert_allclose

import astropy.units as u

from stixcore.calibration.transmission import Transmission


def test_transmission_create_material():
hydrogen = Transmission.create_material(name='hydrogen', fractional_masses={'H': 1.0},
thickness=1*u.cm, density=8.375e-05*u.g/u.cm**3)

assert hydrogen.name == 'hydrogen'
assert hydrogen.thickness == 1.0 * u.cm
assert hydrogen.density == 8.375e-05*u.g/u.cm**3
# taken from https://physics.nist.gov/PhysRefData/XrayMassCoef/ElemTab/z01.html
ref_attenuation_coefficient = [7.217E+00, 2.944E-01, 3.254E-02] * u.cm**2/u.g
attenuation_coefficient = hydrogen.mass_attenuation_coefficient.func([1e-3, 1e-1, 1e+1] * u.MeV)
assert np.allclose(attenuation_coefficient, ref_attenuation_coefficient)
transmission = np.exp(-hydrogen.density*hydrogen.thickness*attenuation_coefficient)
assert np.allclose(transmission, hydrogen.transmission([1e-3, 1e-1, 1e+1] * u.MeV))


@pytest.mark.skip('Changes to transmission data')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to investigate the change of transmission values.

def test_transmission_get_transmission():
# test_materials = OrderedDict([('test1', [('al', 1 * u.mm), ('be', 2*u.mm)]),
# ('test2', [('be', 1*u.mm)])])
Expand Down
55 changes: 9 additions & 46 deletions stixcore/calibration/transmission.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from pathlib import Path
from functools import partial
from collections import OrderedDict

import numpy as np
from roentgen.absorption.material import Compound, MassAttenuationCoefficient, Material
from roentgen.absorption.material import Material, Stack

import astropy.units as u
from astropy.table.table import Table
Expand Down Expand Up @@ -81,9 +80,10 @@ def __init__(self, solarblack='solarblack_carbon'):
if material == 'solarblack':
material = self.solarblack
mass_frac, den = MATERIALS[material]
parts.append(self.create_material(name=material, fractional_masses=mass_frac,
thickness=thickness, density=den))
self.components[name] = Compound(parts)
mat = Material(mass_frac, thickness=thickness, density=den)
mat.name = name
parts.append(mat)
self.components[name] = Stack(parts)

def get_transmission(self, energies=None, attenuator=False):
"""
Expand Down Expand Up @@ -113,10 +113,10 @@ def get_transmission(self, energies=None, attenuator=False):
if attenuator:
base_comps.append(self.components['attenuator'])

base = Compound(base_comps)
base = Stack(base_comps)
base_trans = base.transmission(energies)

fine = Compound(base_comps + [self.components['grid_covers']])
fine = Stack(base_comps + [self.components['grid_covers']])
fine_trans = fine.transmission(energies)

# TODO need to move to configuration db
Expand Down Expand Up @@ -167,49 +167,12 @@ def get_transmission_by_material(self):
res = {}
for name, thickness in material_thickness.items():
frac_mass, density = self.materials[name]
mat = self.create_material(name=name, fractional_masses=frac_mass,
density=density, thickness=thickness)
mat = Material(frac_mass, density=density, thickness=thickness)
mat.name = name
res[name] = mat

return res

@classmethod
def create_material(cls, name=None, fractional_masses=None, thickness=None, density=None):
"""
Create a new material given the composition and fractional masses.
Parameters
----------
name : `str`
Name of the meterial
fractional_masses : `dict`
The element and fractional masses of the material e.g. `{'H': 0.031, 'O': 0.969}`
thickness : `astropy.units.Quantity`
Thickness of the material
density : `astropy.units.Quantity`
Density of the material
Returns
-------
`roentgen.absorption.material.Material`
The material
"""
material = Material('h', thickness, density)
material.name = name
# probably don't need this
material.density = density

# TODO remove in favour of upstream fix when completed
# see https://github.com/ehsteve/roentgen/issues/26
def func(composition, e):
return sum([MassAttenuationCoefficient(element).func(e) * frac_mass
for element, frac_mass in composition.items()])

material_func = partial(func, fractional_masses)

material.mass_attenuation_coefficient.func = material_func
return material


def generate_transmission_tables():
from datetime import datetime
Expand Down
4 changes: 2 additions & 2 deletions stixcore/time/tests/test_datetime.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def test_time_eq():
def test_time_broadcast():
t = SCETime(0, 0)
t1 = t + np.arange(100) * u.s
t2 = SCETime(np.arange(100, dtype=np.int), 0)
t3 = SCETime(0, np.arange(100, dtype=np.int))
t2 = SCETime(np.arange(100, dtype=int), 0)
t3 = SCETime(0, np.arange(100, dtype=int))
assert t1.shape == (100,)
assert t2.shape == (100,)
assert t3.shape == (100,)
Expand Down