Skip to content

Commit da58fed

Browse files
authored
Merge pull request #140 from migueldvb/spec_v0.1
Follow the general guidelines in spectroscopy
2 parents df41612 + fd066d4 commit da58fed

File tree

1 file changed

+64
-53
lines changed

1 file changed

+64
-53
lines changed

sbpy/spectroscopy/core.py

Lines changed: 64 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from astroquery.jplspec import JPLSpec
1414
from astroquery.jplhorizons import Horizons, conf
1515
from ..bib import register
16+
from ..data import Phys
1617

1718
conf.horizons_server = 'https://ssd.jpl.nasa.gov/horizons_batch.cgi'
1819

@@ -26,20 +27,20 @@ def molecular_data(temp_estimate, transition_freq, mol_tag):
2627
2728
Parameters
2829
----------
29-
transition_freq : `~astropy.units.Quantity`
30-
Transition frequency in MHz
31-
3230
temp_estimate : `~astropy.units.Quantity`
3331
Estimated temperature in Kelvins
3432
33+
transition_freq : `~astropy.units.Quantity`
34+
Transition frequency in MHz
35+
3536
mol_tag : int or str
3637
Molecule identifier. Make sure it is an exclusive identifier.
3738
3839
Returns
3940
-------
40-
Molecular data : list
41-
List of constants in the following order:
42-
| Transtion frequency
41+
Molecular data : `~sbpy.data.Phys` instance
42+
Quantities in the following order:
43+
| Transition frequency
4344
| Temperature
4445
| Integrated line intensity at 300 K
4546
| Partition function at 300 K
@@ -95,12 +96,17 @@ def molecular_data(temp_estimate, transition_freq, mol_tag):
9596
energy_J = energy.to(u.J, equivalencies=u.spectral())
9697
elo_J = elo.to(u.J, equivalencies=u.spectral())
9798

98-
result = []
99-
100-
result.append(t_freq)
101-
102-
result.extend((temp, lgint, part300, partition, gu, energy_J,
103-
elo_J, df))
99+
quantities = [t_freq, temp, lgint, part300, partition, gu, energy_J, elo_J, df]
100+
names = ('Transition frequency',
101+
'Temperature',
102+
'Integrated line intensity at 300 K',
103+
'Partition function at 300 K',
104+
'Partition function at designated temperature',
105+
'Upper state degeneracy',
106+
'Upper level energy in Joules',
107+
'Lower level energy in Joules',
108+
'Degrees of freedom')
109+
result = Phys.from_array(quantities, names)
104110

105111
return result
106112

@@ -129,15 +135,15 @@ def intensity_conversion(temp_estimate, transition_freq, mol_tag):
129135

130136
mol_data = molecular_data(temp_estimate, transition_freq, mol_tag)
131137

132-
temp = mol_data[1]
133-
lgint = mol_data[2]
134-
part300 = mol_data[3]
135-
partition = mol_data[4]
136-
energy_J = mol_data[6]
137-
elo_J = mol_data[7]
138-
df = mol_data[8]
138+
temp = mol_data[0][1]
139+
lgint = mol_data[0][2]
140+
part300 = mol_data[0][3]
141+
partition = mol_data[0][4]
142+
energy_J = mol_data[0][6]
143+
elo_J = mol_data[0][7]
144+
df = mol_data[0][8]
139145

140-
k = con.k_B.to('J/K') # boltzman constant
146+
k = con.k_B.to('J/K') # Boltzmann constant
141147

142148
if (((energy_J - elo_J).value / (k * temp).value) and
143149
((energy_J - elo_J).value / (k * 300 * u.K).value) < 1):
@@ -185,18 +191,18 @@ def einstein_coeff(temp_estimate, transition_freq, mol_tag):
185191

186192
mol_data = molecular_data(temp_estimate, transition_freq, mol_tag)
187193

188-
t_freq = mol_data[0]
189-
temp = mol_data[1]
190-
lgint = mol_data[2]
191-
part300 = mol_data[3]
192-
partition = mol_data[4]
193-
gu = mol_data[5]
194-
energy_J = mol_data[6]
195-
elo_J = mol_data[7]
194+
t_freq = mol_data[0][0]
195+
temp = mol_data[0][1]
196+
lgint = mol_data[0][2]
197+
part300 = mol_data[0][3]
198+
partition = mol_data[0][4]
199+
gu = mol_data[0][5]
200+
energy_J = mol_data[0][6]
201+
elo_J = mol_data[0][7]
196202

197-
h = con.h.to('J*s') # planck constant
203+
h = con.h.to('J*s') # Planck constant
198204

199-
k = con.k_B.to('J/K') # boltzman constant
205+
k = con.k_B.to('J/K') # Boltzmann constant
200206

201207
intl = intensity_conversion(temp_estimate, transition_freq, mol_tag)
202208

@@ -246,7 +252,9 @@ def photod_rate(time, time_scale, target, id_type, observatory, time_format,
246252

247253
beta = (timescale) * r**2
248254

249-
return beta, delta
255+
result = Phys.from_array((beta, delta), ('beta', 'delta'))
256+
257+
return result
250258

251259

252260
def total_number(integrated_line, temp_estimate, transition_freq, mol_tag,
@@ -277,10 +285,11 @@ def total_number(integrated_line, temp_estimate, transition_freq, mol_tag,
277285
transition_freq,
278286
mol_tag))).decompose()
279287

280-
delta, beta = photod_rate(time, time_scale, target, id_type, observatory,
281-
time_format, mol_tag)
288+
photod = photod_rate(time, time_scale, target, id_type, observatory,
289+
time_format, mol_tag)
290+
beta = photod["beta"]
282291

283-
sigma = (1./2. * delta * b * con.c / (transition_freq * aper)).value
292+
sigma = (1./2. * beta * b * con.c / (transition_freq * aper)).value
284293

285294
total_number = cdensity.decompose() * sigma * u.m * u.m / np.sqrt(np.log(2))
286295

@@ -517,7 +526,7 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
517526
518527
Returns
519528
-------
520-
q : list
529+
q : `~astropy.units.Quantity`
521530
Production rate, not including photodissociation
522531
523532
Examples
@@ -588,8 +597,8 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
588597
gu_list = []
589598
energy_J_list = []
590599
au_list = []
591-
h = con.h.to('J*s') # planck constant
592-
k = con.k_B.to('J/K') # boltzman constant
600+
h = con.h.to('J*s') # Planck constant
601+
k = con.k_B.to('J/K') # Boltzmann constant
593602
c = con.c.to('m/s') # speed of light
594603
vgas = vgas.to('m/s')
595604

@@ -600,11 +609,11 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
600609
mol_data = molecular_data(temp_estimate, transition_freq[i],
601610
mol_tag)
602611

603-
t_freq = mol_data[0]
604-
temp = mol_data[1]
605-
partition = mol_data[4]
606-
gu = mol_data[5]
607-
energy_J = mol_data[6]
612+
t_freq = mol_data[0][0]
613+
temp = mol_data[0][1]
614+
partition = mol_data[0][4]
615+
gu = mol_data[0][5]
616+
energy_J = mol_data[0][6]
608617

609618
au = einstein_coeff(temp_estimate, transition_freq[i], mol_tag)
610619

@@ -622,8 +631,9 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
622631
gu = sum(gu_list) / float(len(gu_list))
623632
energy_J = sum(energy_J_list) / float(len(energy_J_list))
624633

625-
beta, delta = photod_rate(time, time_scale, target, id_type,
626-
observatory, time_format, mol_tag)
634+
photod = photod_rate(time, time_scale, target, id_type, observatory,
635+
time_format, mol_tag)
636+
delta = photod["delta"]
627637

628638
calc = ((16*np.pi*k*t_freq.decompose() *
629639
partition*vgas) / (np.sqrt(np.pi*np.log(2))
@@ -640,20 +650,21 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
640650

641651
mol_data = molecular_data(temp_estimate, transition_freq, mol_tag)
642652

643-
t_freq = mol_data[0]
644-
temp = mol_data[1]
645-
partition = mol_data[4]
646-
gu = mol_data[5]
647-
energy_J = mol_data[6]
648-
h = con.h.to('J*s') # planck constant
649-
k = con.k_B.to('J/K') # boltzman constant
653+
t_freq = mol_data[0][0]
654+
temp = mol_data[0][1]
655+
partition = mol_data[0][4]
656+
gu = mol_data[0][5]
657+
energy_J = mol_data[0][6]
658+
h = con.h.to('J*s') # Planck constant
659+
k = con.k_B.to('J/K') # Boltzmann constant
650660
c = con.c.to('m/s') # speed of light
651661
vgas = vgas.to('m/s')
652662

653663
au = einstein_coeff(temp_estimate, transition_freq, mol_tag)
654664

655-
beta, delta = photod_rate(time, time_scale, target, id_type,
656-
observatory, time_format, mol_tag)
665+
photod = photod_rate(time, time_scale, target, id_type, observatory,
666+
time_format, mol_tag)
667+
delta = photod["delta"]
657668

658669
calc = ((16*np.pi*k*t_freq.decompose() *
659670
partition*vgas) / (np.sqrt(np.pi*np.log(2))

0 commit comments

Comments
 (0)