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

Mag vs dm #188

Merged
merged 17 commits into from
Oct 21, 2024
85 changes: 85 additions & 0 deletions .github/ci_orig_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: CI Tests

on:
push:
branches:
- master
tags:
pull_request:

env:
SETUP_XVFB: True # avoid issues if mpl tries to open a GUI window

jobs:
ci-tests:
name: Python-${{ matrix.python }}, deps=${{ matrix.deps }}
runs-on: ${{ matrix.os }}
if: "!(contains(github.event.head_commit.message, '[skip ci]') || contains(github.event.head_commit.message, '[ci skip]'))"

strategy:
matrix:
os: [ubuntu-latest]
python: ['3.11', '3.12']
deps: [current, numpy211, astropydev, numpydev, astropydev-numpydev]

steps:
- name: Check out repository
uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python }}
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
- name: Test with numpy = 2.1.1
if: "contains(matrix.deps, 'numpy211')"
run: |
python -m pip install numpy==2.1.1
- name: Test with dev version of numpy
if: "contains(matrix.deps, 'numpydev')"
run: |
python -m pip install git+https://github.com/numpy/numpy.git#egg=numpy
- name: Test with dev version astropy
if: "contains(matrix.deps, 'astropydev')"
run: |
python -m pip install git+https://github.com/astropy/astropy.git#egg=astropy
- name: Install frb requirements
run: |
python -m pip install wheel scipy IPython
python -m pip install git+https://github.com/FRBs/ne2001.git#egg=ne2001
python -m pip install git+https://github.com/FRBs/astropath.git#egg=astropath
python -m pip install git+https://github.com/linetools/linetools#egg=linetools
python -m pip install -r frb/requirements.txt
- name: Install numba
run: |
python -m pip install numba
- name: Install astroquery
run: |
python -m pip install astroquery
- name: Print Python, pip, astropy, numpy, and setuptools versions
run: |
python -c "import sys; print(f'Python {sys.version}')"
python -c "import pip; print(f'pip {pip.__version__}')"
python -c "import astropy; print(f'astropy {astropy.__version__}')"
python -c "import numpy; print(f'numpy {numpy.__version__}')"
python -c "import setuptools; print(f'setuptools {setuptools.__version__}')"
- name: Run tests
run: tox -e ${{ matrix.python }}-${{ matrix.toxenv }}

codestyle:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v2
- name: Python codestyle check
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pycodestyle
- name: Check for runtime errors using pycodestyle
run: |
pycodestyle frb --count --select=E9
65 changes: 8 additions & 57 deletions .github/workflows/ci_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,82 +4,33 @@ on:
push:
branches:
- master
tags:
pull_request:

env:
SETUP_XVFB: True # avoid issues if mpl tries to open a GUI window
SETUP_XVFB: True # avoid issues if something tries to open a GUI window

jobs:
ci-tests:
name: Python-${{ matrix.python }}, deps=${{ matrix.deps }}
name: Tox env ${{ matrix.python }}-${{ matrix.toxenv }}
runs-on: ${{ matrix.os }}
if: "!(contains(github.event.head_commit.message, '[skip ci]') || contains(github.event.head_commit.message, '[ci skip]'))"

strategy:
matrix:
os: [ubuntu-latest]
python: ['3.11', '3.12']
deps: [current, numpy211, astropydev, numpydev, astropydev-numpydev]

toxenv: [test, test-astropydev]
steps:
- name: Check out repository
uses: actions/checkout@v2
uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v2
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
- name: Test with numpy = 2.1.1
if: "contains(matrix.deps, 'numpy211')"
run: |
python -m pip install numpy==2.1.1
- name: Test with dev version of numpy
if: "contains(matrix.deps, 'numpydev')"
run: |
python -m pip install git+https://github.com/numpy/numpy.git#egg=numpy
- name: Test with dev version astropy
if: "contains(matrix.deps, 'astropydev')"
run: |
python -m pip install git+https://github.com/astropy/astropy.git#egg=astropy
- name: Install frb requirements
run: |
python -m pip install wheel scipy IPython
python -m pip install -r frb/requirements.txt --upgrade pip tox
python -m pip install git+https://github.com/FRBs/ne2001.git#egg=ne2001
python -m pip install git+https://github.com/FRBs/astropath.git#egg=astropath
python -m pip install git+https://github.com/linetools/linetools#egg=linetools
python -m pip install -r frb/requirements.txt
- name: Install numba
run: |
python -m pip install numba
- name: Install astroquery
run: |
python -m pip install astroquery
- name: Print Python, pip, astropy, numpy, and setuptools versions
run: |
python -c "import sys; print(f'Python {sys.version}')"
python -c "import pip; print(f'pip {pip.__version__}')"
python -c "import astropy; print(f'astropy {astropy.__version__}')"
python -c "import numpy; print(f'numpy {numpy.__version__}')"
python -c "import setuptools; print(f'setuptools {setuptools.__version__}')"
- name: Run tests
run: python setup.py test

codestyle:
runs-on: ubuntu-latest
if: "!contains(github.event.head_commit.message, '[ci skip]')"
steps:
- uses: actions/checkout@v2
- name: Python codestyle check
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Install base dependencies
run: |
python -m pip install --upgrade pip
python -m pip install pycodestyle
- name: Check for runtime errors using pycodestyle
- name: Test with tox
run: |
pycodestyle frb --count --select=E9
tox -e ${{ matrix.python }}-${{ matrix.toxenv }}
16 changes: 0 additions & 16 deletions bin/frb_mag_limit

This file was deleted.

16 changes: 0 additions & 16 deletions bin/frb_pz_dm

This file was deleted.

2 changes: 1 addition & 1 deletion docs/installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ to install and/or update these packages.
* `healpy <https://healpy.readthedocs.io/en/latest/index.html>`_ version 1.15 or later
* `pandas <https://pandas.pydata.org/>`_ version 1.5 or later
* `requests <https://pillow.readthedocs.io/en/5.3.x/>`_ version 2.18 or later
* `extinction <https://extinction.readthedocs.io/en/latest/>`_ version 0.4.6 or greater
* `dust_extinction <https://dust-extinction.readthedocs.io/en/latest/>`_
* `matplotlib <https://matplotlib.org/>`_ version 3.7 or greater
* `linetools <https://github.com/linetools/linetools>`_ version 0.3 or later
* `astropath <https://github.com/FRBs/astropath>`_ version 0.1 or later
Expand Down
17 changes: 4 additions & 13 deletions frb/builds/build_hosts.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@
except:
print('WARNING: ppxf not installed')
from frb.galaxies import nebular
from frb.galaxies import utils as galaxy_utils
from frb.galaxies import hosts
from frb.galaxies import defs as galaxy_defs
from frb.surveys import survey_utils
from frb import utils
import pandas

try:
import extinction
except ImportError:
print("extinction package not loaded. Extinction corrections will fail")

try:
from frb.galaxies import cigale
except ModuleNotFoundError:
Expand Down Expand Up @@ -386,14 +382,9 @@ def run(host_input:pandas.core.series.Series,
# Correct for Galactic extinction
ebv = float(nebular.get_ebv(Host.coord)['meanValue'])
print(f'Correcting the spectrum for Galactic extinction with reddening E(B-V)={ebv}')
AV = ebv * 3.1 # RV
Al = extinction.ccm89(spectrum.wavelength.value, AV, 3.1)
# New spec
new_flux = spectrum.flux * 10**(Al/2.5)
new_sig = spectrum.sig * 10**(Al/2.5)
new_spec = XSpectrum1D.from_tuple((spectrum.wavelength, new_flux, new_sig))

#
new_spec = galaxy_utils.deredden_spec(spectrum, ebv)

# Run it
ppxf.run(new_spec, R, host_input.z,
results_file=ppxf_results_file,
spec_fit=spec_file,
Expand Down
Binary file added frb/data/DM/CHIME_pzdm_repeaters.npz
Binary file not shown.
Binary file added frb/data/DM/CRAFT_ICS_1300_pzdm.npz
Binary file not shown.
Binary file added frb/data/DM/CRAFT_ICS_1632_pzdm.npz
Binary file not shown.
Binary file added frb/data/DM/CRAFT_ICS_892_pzdm.npz
Binary file not shown.
Binary file added frb/data/DM/CRAFT_class_I_and_II_pzdm.npz
Binary file not shown.
Binary file added frb/data/DM/DSA_pzdm.npz
Binary file not shown.
Binary file added frb/data/DM/FAST_pzdm.npz
Binary file not shown.
36 changes: 36 additions & 0 deletions frb/data/DM/convert_npy_to_npz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
""" Simple script to convert .npy files to .npz files. """

import numpy as np

from frb.dm import prob_dmz

def main():

npy_files = ['DSA_pzdm.npy',
'parkes_mb_class_I_and_II_pzdm.npy',
'CRAFT_class_I_and_II_pzdm.npy',
'CRAFT_ICS_1300_pzdm.npy',
'CRAFT_ICS_892_pzdm.npy',
'CRAFT_ICS_1632_pzdm.npy',
'FAST_pzdm.npy']

# Load of z, DM_EG from CHIME
chime_dict = prob_dmz.grab_repo_grid(prob_dmz.telescope_dict['CHIME'])

# Parse
z = chime_dict['z']
DM = chime_dict['DM']

# Loop on the files
for npy_file in npy_files:
# Load
pzdm = prob_dmz.grab_repo_grid(npy_file)
# Save
npz_file = npy_file.replace('.npy', '.npz')
np.savez(npz_file, pzdm=pzdm, z=z, DM=DM)
# Report
print(f"Wrote: {npz_file}")

# Command line execution
if __name__ == '__main__':
main()
Binary file added frb/data/DM/parkes_mb_class_I_and_II_pzdm.npz
Binary file not shown.
14 changes: 14 additions & 0 deletions frb/dm/prob_dmz.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,20 @@

from IPython import embed

# Dict to resolve telescope/survey into the appropriate grid filename
telescope_dict = {
'CHIME_repeaters': 'CHIME_pzdm_repeaters.npz',
'CHIME': 'CHIME_pzdm.npz',
'DSA': 'DSA_pzdm.npz',
'Parkes': 'parkes_mb_class_I_and_II_pzdm.npz',
'CRAFT': 'CRAFT_class_I_and_II_pzdm.npz',
'CRAFT_ICS_1300': 'CRAFT_ICS_1300_pzdm.npz',
'CRAFT_ICS_892': 'CRAFT_ICS_892_pzdm.npz',
'CRAFT_ICS_1632': 'CRAFT_ICS_1632_pzdm.npz',
'FAST': 'FAST_pzdm.npz',
'perfect': 'PDM_z.npz'
}

class P_DM_z(object):
pass

Expand Down
19 changes: 11 additions & 8 deletions frb/galaxies/nebular.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
from astropy.table import Table
from astropy import units

try:
import extinction
except ImportError:
warnings.warn("extinction package not loaded. Extinction corrections will fail")
import dust_extinction

try:
from linetools.lists import linelist
Expand All @@ -33,7 +30,7 @@ def calc_dust_extinct(neb_lines, method):
"""
Estimate the Visual extinction A_V based on input nebular emission lines

Uses the Fitzpatrick & Massa (2007) extinction law
Uses the Gordon 2024

Args:
neb_lines (dict): Line fluxes
Expand Down Expand Up @@ -71,8 +68,11 @@ def calc_dust_extinct(neb_lines, method):
raise IOError("Not ready for this mode")

# Extinction
a1AV = extinction.fm07(np.atleast_1d(wave1), 1.0)[0]
a2AV = extinction.fm07(np.atleast_1d(wave2), 1.0)[0]
#a1AV = extinction.fm07(np.atleast_1d(wave1), 1.0)[0]
#a2AV = extinction.fm07(np.atleast_1d(wave2), 1.0)[0]
extmod = dust_extinction.parameter_averages.G23(Rv=3.1)
a1AV = extmod(np.atleast_1d(wave1*units.AA)) # *units.AA)
a2AV = extmod(np.atleast_1d(wave2*units.AA)) # *units.AA)

# Observed ratio
fratio_obs = F1_obs/F2_obs
Expand Down Expand Up @@ -153,7 +153,10 @@ def calc_lum(neb_lines, line, z, cosmo, AV=None):

# Dust correct?
if AV is not None:
al = extinction.fm07(np.atleast_1d(wave.to('Angstrom').value), AV)[0]
#al = extinction.fm07(np.atleast_1d(wave.to('Angstrom').value), AV)[0]
extmod = dust_extinction.parameter_averages.G23(Rv=3.1)
AlAV = extmod(np.atleast_1d(wave)*units.AA)[0]
al = AlAV * AV
else:
al = 0.

Expand Down
Loading
Loading