Skip to content

Commit

Permalink
Merge pull request #2 from norrisryan/master
Browse files Browse the repository at this point in the history
Ported to Julia 0.7+
  • Loading branch information
giordano authored Mar 2, 2019
2 parents 1ecc697 + e29243c commit 3650993
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 34 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: julia
julia:
- 0.4
- 0.5
- 1.0
- nightly
notifications:
email: false
Expand Down
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
DustExtinction.jl
=================
# DustExtinction.jl

[![Build Status](https://img.shields.io/travis/JuliaAstro/DustExtinction.jl.svg?style=flat-square)](https://travis-ci.org/JuliaAstro/DustExtinction.jl)


Tools for interstellar dust extinction in astronomy

Install
-------
## Install

```julia
julia> Pkg.add("DustExtinction")
```
From package manager (``` ]``` key)

``` add DustExtinction```

Usage
-----
Expand Down
5 changes: 2 additions & 3 deletions REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
julia 0.4
FITSIO 0.8.1
Compat 0.8.6
julia 1.0
FITSIO 0.13.0
27 changes: 13 additions & 14 deletions src/DustExtinction.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
module DustExtinction

using FITSIO # for SFD98 dust maps
using Compat

import Base: show

Expand Down Expand Up @@ -97,11 +96,11 @@ od94(w::Real, r_v) = ccm89like(w, r_v, od94_ca, od94_cb)
# Vectorized versions (vectorized on wavelength only)
for f = (:ccm89, :od94)
@eval begin
($f){T<:Real}(w::AbstractArray{T,1}, r_v) =
($f)(w::AbstractArray{T,1}, r_v) where T<:Real =
[ ($f)(w[i], r_v) for i=1:length(w) ]
($f){T<:Real}(w::AbstractArray{T,2}, r_v) =
($f)(w::AbstractArray{T,2}, r_v) where T<:Real =
[ ($f)(w[i,j], r_v) for i=1:size(w,1), j=1:size(w,2) ]
($f){T<:Real}(w::AbstractArray{T}, r_v) =
($f)(w::AbstractArray{T}, r_v) where T<:Real =
reshape([ ($f)(w[i], r_v) for i=1:length(w) ], size(w))
end
end
Expand Down Expand Up @@ -150,8 +149,8 @@ directory containing the two FITS files defining the map,
the FITS files defining the map open, speeding up repeated queries
for E(B-V) values.
"""
type SFD98Map
mapdir::Compat.UTF8String
mutable struct SFD98Map
mapdir::String
ngp::ImageHDU
ngp_size::Tuple{Int, Int}
ngp_crpix1::Float64
Expand Down Expand Up @@ -240,29 +239,29 @@ function ebv_galactic(dustmap::SFD98Map, l::Real, b::Real)
# the image bounds, but not both.
if x0 == 0
data = read(hdu, 1, y0:y0+1)
val = (1. - yw) * data[1] + yw * data[2]
val = (1 - yw) * data[1] + yw * data[2]
elseif x0 == xsize
data = read(hdu, xsize, y0:y0+1)
val = (1. - yw) * data[1] + yw * data[2]
val = (1 - yw) * data[1] + yw * data[2]
elseif y0 == 0
data = read(hdu, x0:x0+1, 1)
val = (1. - xw) * data[1] + xw * data[2]
val = (1 - xw) * data[1] + xw * data[2]
elseif y0 == ysize
data = read(hdu, x0:x0+1, xsize)
val = (1. - xw) * data[1] + xw * data[2]
val = (1 - xw) * data[1] + xw * data[2]
else
data = read(hdu, x0:x0+1, y0:y0+1)
val = ((1.-xw) * (1.-yw) * data[1, 1] +
xw * (1.-yw) * data[2, 1] +
(1.-xw) * yw * data[1, 2] +
val = ((1 -xw) * (1 -yw) * data[1, 1] +
xw * (1 -yw) * data[2, 1] +
(1 -xw) * yw * data[1, 2] +
xw * yw * data[2, 2])
end

return convert(Float64, val)
end

# array version
function ebv_galactic{T <: Real}(dustmap::SFD98Map, l::Vector{T}, b::Vector{T})
function ebv_galactic(dustmap::SFD98Map, l::Vector{T}, b::Vector{T}) where T <: Real
m = length(l)
length(b) == m || error("length of l and b must match")
result = Array(Float64, m)
Expand Down
16 changes: 8 additions & 8 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using DustExtinction
using Base.Test
using Test

# =============================================================================
# ccm89
Expand All @@ -11,7 +11,7 @@ using Base.Test
# Note that a and b can be obtained with:
# b = ccm89(wave, 0.)
# a = ccm89(wave, 1.) - b
#
#
# These differ from the values tablulated in the original paper.
# Could be due to floating point errors in the original paper?

Expand All @@ -23,7 +23,7 @@ wave = 1.e4 ./ x_inv_microns
ref_values = [1.569, 1.337, 1.000, 0.751, 0.479, 0.282, 0.190, 0.114]

for i=1:length(wave)
@test_approx_eq_eps ccm89(wave[i], 3.1) ref_values[i] 0.016*ref_values[i]
@test ccm89(wave[i], 3.1) ref_values[i] rtol=0.016
end

# =============================================================================
Expand All @@ -39,12 +39,12 @@ end

# This is tested by evaluating the extinction curve at a (given)
# effective wavelength, since these effective wavelengths:
# "... represent(s) that wavelength on the extinction curve
# "... represent(s) that wavelength on the extinction curve
# with the same extinction as the full passband."

# The test does not include UKIRT L' (which, at 3.8 microns) is
# The test does not include UKIRT L' (which, at 3.8 microns) is
# beyond the range of wavelengths allowed by the function
# or the APM b_J filter which is defined in a non-standard way.
# or the APM b_J filter which is defined in a non-standard way.

# The SFD98 tabulated values go to 1e-3, so we should be able to match at
# that level.
Expand Down Expand Up @@ -74,7 +74,7 @@ ref_values = [1.664, 1.321, 1.015, 0.819, 0.594,
1.197, 0.811, 0.580]

for i=1:length(wave)
@test_approx_eq_eps od94(wave[i], 3.1) ref_values[i] 0.0051*ref_values[i]
@test od94(wave[i], 3.1) ref_values[i] rtol=0.0051
end


Expand Down Expand Up @@ -115,7 +115,7 @@ if haskey(ENV, "SFD98_DIR")
dustmap = SFD98Map()
for i=1:length(refcoords)
l, b = refcoords[i]
@test_approx_eq_eps ebv_galactic(dustmap, l, b) refebv[i] 0.02*refebv[i]
@test ebv_galactic(dustmap, l, b) refebv[i] rtol=0.02
end
else
println("Skipping SFD98Map test because \$SFD98_DIR not defined.")
Expand Down

0 comments on commit 3650993

Please sign in to comment.