-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreddening.py
72 lines (51 loc) · 1.77 KB
/
reddening.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# -*- coding: utf-8 -*-
# future import statements
from __future__ import print_function
from __future__ import division
# version information
__project__ = "EXPLORE"
__author__ = "ACRI-ST"
__license__ = '$Apache 2.0 $'
import numpy as np
import scipy.interpolate as spi
from astropy import units as u
from astropy.coordinates import SkyCoord
def reddening(sc, cube, axes, max_axes, step_pc=5):
"""Calculate Extinction versus distance from Sun.
Args:
sc: SkyCoord object
Kwargs:
step_pc (int): Incremental distance in parsec
Returns:
array: Parsec values.
array: Extinction A(5500) value obtained with integral of linear extrapolation.
"""
sc1=SkyCoord(sc, distance = 1 * u.pc)
coords_xyz = sc1.transform_to('galactic').represent_as('cartesian').get_xyz().value
# Find the number of parsec I can calculate before go out the cube
# (exclude divide by 0)
not0 = np.where(coords_xyz != 0)
max_pc = np.amin(
np.abs( np.take(max_axes, not0) / np.take(coords_xyz, not0) ) )
# Calculate all coordinates to interpolate (use step_pc)
distances = np.arange(0, max_pc, step_pc)
sc2 = SkyCoord(
sc,
distance=distances)
sc2 = sc2.transform_to('galactic').represent_as('cartesian')
coords_xyz = np.array([coord.get_xyz().value for coord in sc2])
# linear interpolation with coordinates
interpolation = spi.interpn(
axes,
cube,
coords_xyz,
method='linear'
)
xvalues = np.arange(0, len(interpolation) * step_pc, step_pc)
yvalues_cumul = np.nancumsum(interpolation) * step_pc
yvalues = interpolation
return (
xvalues,
np.around(yvalues_cumul, decimals=5),
np.around(yvalues, decimals=5)
)