Skip to content

Commit 79bd9b3

Browse files
authored
Merge pull request #141 from gianninapr/specinputfix
Fixed input to production rate functions so as to follow sbpy rules
2 parents da58fed + 0061bed commit 79bd9b3

File tree

3 files changed

+67
-115
lines changed

3 files changed

+67
-115
lines changed

docs/sbpy/spectroscopy.rst

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ JPLSpec Constants and Line Intensity Integral Conversion
1414
`sbpy.spectroscopy` has a function called ``molecular_data`` which takes care of
1515
querying the JPL Molecular Spectral Catalog through the use of
1616
`astroquery.jplspec` and calculates all the necessary constants needed for both
17-
production rate and Einstein coefficient calculations. The function
18-
``intensity_conversion`` takes care of converting the intensity line integral at
19-
300 K found in JPL Spec catalog and convert it closer to the temperature given
20-
by the user.
17+
production rate and Einstein coefficient calculations. ``molecular_data``
18+
returns an `sbpy.data.phys` instance with quantities in the order of: Transition
19+
Frequency, Temperature, Integrated line intensity at 300 K, and Partition
20+
function at 300 K. The function ``intensity_conversion`` takes care of
21+
converting the intensity line integral at 300 K found in JPL Spec catalog and
22+
convert it closer to the temperature given by the user.
2123

2224
.. code-block:: python
2325
@@ -82,18 +84,21 @@ section.
8284
.. code-block:: python
8385
8486
>>> from sbpy.spectroscopy import prodrate_np
87+
>>> from astropy.time import Time
88+
>>> from sbpy.data import Ephem
8589
>>> temp_estimate = 33. * u.K
86-
>>> target = '900918'
90+
>>> target = '103P'
8791
>>> vgas = 0.8 * u.km / u.s
8892
>>> aper = 30 * u.m
8993
>>> b = 1.13
9094
>>> mol_tag = 27001
9195
>>> transition_freq = 265.886434 * u.MHz
9296
>>> spectra = 1.22 * u.K * u.km / u.s
93-
>>> time = '2010-11-3 00:48:06'
97+
>>> time = Time('2010-11-3 00:48:06', format='iso')
98+
>>> ephemobj = Ephem(target, epochs=time.jd, id_type='id')
9499
>>> q = prodrate_np(spectra, temp_estimate, transition_freq,
95-
mol_tag, time, target, vgas, aper,
96-
b=b, id_type='id')
100+
mol_tag, ephemobj, vgas, aper,
101+
b=b)
97102
98103
>>> q
99104
<Quantity 1.0432591198553935e+25 1 / s>
@@ -113,6 +118,8 @@ model does account for the effects of photolysis.
113118
.. code-block:: python
114119
115120
>>> from sbpy.activity.gas import Haser
121+
>>> from astropy.time import Time
122+
>>> from sbpy.data import Ephem
116123
>>> coma = Haser(Q, v, parent)
117124
>>> Q = spec.production_rate(coma, molecule='H2O')
118125
@@ -126,14 +133,15 @@ model does account for the effects of photolysis.
126133
>>> vgas = 0.5 * u.km / u.s
127134
128135
>>> time = '2017-12-22 05:24:20'
136+
>>> ephemobj = Ephem(target, epochs=time.jd)
129137
>>> spectra = 0.26 * u.K * u.km / u.s
130138
131139
>>> parent = photo_timescale('CO') * vgas
132140
133141
>>> coma = Haser(Q_estimate, vgas, parent)
134142
135143
>>> Q = spec.production_rate(coma, spectra, temp_estimate,
136-
transition_freq, mol_tag, time, target,
144+
transition_freq, mol_tag, ephemobj,
137145
aper=aper, b=b)
138146
139147
>>> print(Q)
@@ -169,7 +177,7 @@ The names of the built-in sources are stored as an internal array. They can be
169177

170178
>>> from sbpy.spectroscopy import Sun
171179
>>> Sun.show_builtin()
172-
name description
180+
name description
173181
------------ -----------------------------------------------------------------
174182
E490_2014 E490-00a (2014) reference solar spectrum (Table 3)
175183
E490_2014LR E490-00a (2014) low resolution reference solar spectrum (Table 4)

sbpy/spectroscopy/core.py

Lines changed: 38 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,17 @@ def einstein_coeff(temp_estimate, transition_freq, mol_tag):
222222
return au / u.s
223223

224224

225-
def photod_rate(time, time_scale, target, id_type, observatory, time_format,
226-
mol_tag):
225+
def photod_rate(ephemobj, mol_tag):
227226
# imported here to avoid circular dependency with activity.gas
228227
from ..activity.gas import photo_timescale
228+
from ..data import Ephem
229229

230-
epoch = Time(time, scale=time_scale, format=time_format)
231-
obj = Horizons(id=target, epochs=epoch.jd, location=observatory,
232-
id_type=id_type)
230+
if not isinstance(ephemobj, Ephem):
231+
raise ValueError('ephemobj must be a `sbpy.data.ephem` instance.')
233232

234-
try:
235-
orb = obj.ephemerides()
236-
237-
except ValueError:
238-
239-
raise
240-
241-
delta = (orb['delta'].data * u.au).to('m')
242-
r = (orb['r'].data)
233+
orb = ephemobj
234+
delta = (orb['delta']).to('m')
235+
r = (orb['r'])
243236
cat = JPLSpec.get_species_table()
244237
mol = cat[cat['TAG'] == mol_tag]
245238
name = mol['NAME'].data[0]
@@ -258,8 +251,7 @@ def photod_rate(time, time_scale, target, id_type, observatory, time_format,
258251

259252

260253
def total_number(integrated_line, temp_estimate, transition_freq, mol_tag,
261-
aper, b, time, target, time_scale, id_type, observatory,
262-
time_format):
254+
aper, b, ephemobj):
263255
"""
264256
Basic equation relating number of molecules with observed integrated flux.
265257
This is given by equation 10 in
@@ -285,8 +277,8 @@ def total_number(integrated_line, temp_estimate, transition_freq, mol_tag,
285277
transition_freq,
286278
mol_tag))).decompose()
287279

288-
photod = photod_rate(time, time_scale, target, id_type, observatory,
289-
time_format, mol_tag)
280+
photod = photod_rate(ephemobj, mol_tag)
281+
290282
beta = photod["beta"]
291283

292284
sigma = (1./2. * beta * b * con.c / (transition_freq * aper)).value
@@ -456,10 +448,8 @@ def fit(self, spec):
456448
"""
457449

458450
def prodrate_np(self, spectra, temp_estimate, transition_freq,
459-
mol_tag, time, target, vgas=1 * u.km/u.s,
460-
aper=25 * u.m, observatory='500', b=1.2,
461-
time_format='iso', time_scale='utc',
462-
id_type='designation'):
451+
mol_tag, ephemobj, vgas=1 * u.km/u.s,
452+
aper=25 * u.m, b=1.2):
463453
"""
464454
| Returns production rate based on Drahus 2012 model referenced. Includes
465455
| no photodissociation
@@ -485,14 +475,8 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
485475
temp_estimate : `~astropy.units.Quantity`
486476
Estimated temperature in Kelvins
487477
488-
time : str
489-
Time of observation of any format supported by `~astropy.time`
490-
491-
target : str
492-
| Target designation, if there is more than one aparition you
493-
| will be prompted to pick a more specific identifier from a
494-
| displayed table and change the parameter id_type to 'id'.
495-
| Look at `~astroquery.jplhorizons` for more information.
478+
ephemobj: `~sbpy.data.Ephem` object
479+
An `~sbpy.data.Ephem` object that holds ephemerides information
496480
497481
mol_tag : int or str
498482
Molecule identifier. Make sure it is an exclusive identifier.
@@ -503,27 +487,11 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
503487
aper : `~astropy.units.Quantity`
504488
Telescope aperture in meters. Default is 25 m
505489
506-
observatory : str
507-
| Observatory identifier as per `~astroquery.jplhorizons`
508-
| Default is geocentric ('500')
509-
510490
b : int
511491
| Dimensionless factor intrinsic to every antenna. Typical
512492
| value, and the default for this model, is 1.22. See
513493
| references for more information on this parameter.
514494
515-
time_format : str
516-
| Time format, see `~astropy.time` for more information
517-
| Default is 'iso' which corresponds to 'YYYY-MM-DD HH:MM:SS'
518-
519-
time_scale : str
520-
| Time scale, see `~astropy.time` for mor information.
521-
| Default is 'utc'
522-
523-
id_type : str
524-
| ID type for target. See `~astroquery.jplhorizons` for more.
525-
| Default is 'designation'
526-
527495
Returns
528496
-------
529497
q : `~astropy.units.Quantity`
@@ -533,11 +501,15 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
533501
--------
534502
>>> import astropy.units as u # doctest: +SKIP
535503
504+
>>> from astropy.time import Time # doctest: +SKIP
505+
506+
>>> from sbpy.data import Ephem # doctest: +SKIP
507+
536508
>>> from sbpy.spectroscopy import prodrate_np # doctest: +SKIP
537509
538510
>>> temp_estimate = 33. * u.K # doctest: +SKIP
539511
540-
>>> target = '900918' # doctest: +SKIP
512+
>>> target = '103P' # doctest: +SKIP
541513
542514
>>> vgas = 0.8 * u.km / u.s # doctest: +SKIP
543515
@@ -551,11 +523,12 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
551523
552524
>>> spectra = 1.22 * u.K * u.km / u.s # doctest: +SKIP
553525
554-
>>> time = '2010-11-3 00:48:06' # doctest: +SKIP
526+
>>> time = Time('2010-11-3 00:48:06', format='iso') # doctest: +SKIP
527+
528+
>>> ephemobj = Ephem(target, epochs=time.jd, id_type='id') # doctest: +SKIP
555529
556530
>>> q = prodrate_np(spectra, temp_estimate, transition_freq, # doctest: +SKIP
557-
mol_tag, time, target, vgas, aper,
558-
b=b, id_type='id')
531+
mol_tag, ephemobj, vgas, aper, b=b)
559532
560533
>>> q # doctest: +SKIP
561534
<Quantity 1.0432591198553935e+25 1 / s>
@@ -577,17 +550,6 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
577550
assert isinstance(vgas, u.Quantity)
578551
assert isinstance(aper, u.Quantity)
579552
assert isinstance(spectra, u.Quantity) # K * km / s
580-
assert isinstance(time, str), "Input time as string, i.e. '2018-05-14'"
581-
assert isinstance(time_scale, str), "Input time scale as string, i.e.\
582-
'utc' see astropy.time.Time for \
583-
more info"
584-
assert isinstance(target, str), "Object name should be a string and\
585-
should be identifiable through \
586-
astroquery.jplhorizons"
587-
assert isinstance(observatory, str), "Observatory should be a string\
588-
and identified through \
589-
astroquery.jplhorizons,\
590-
i.e. '500' (geocentric)"
591553

592554
if type(transition_freq) == list:
593555

@@ -631,8 +593,8 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
631593
gu = sum(gu_list) / float(len(gu_list))
632594
energy_J = sum(energy_J_list) / float(len(energy_J_list))
633595

634-
photod = photod_rate(time, time_scale, target, id_type, observatory,
635-
time_format, mol_tag)
596+
photod = photod_rate(ephemobj, mol_tag)
597+
636598
delta = photod["delta"]
637599

638600
calc = ((16*np.pi*k*t_freq.decompose() *
@@ -662,8 +624,8 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
662624

663625
au = einstein_coeff(temp_estimate, transition_freq, mol_tag)
664626

665-
photod = photod_rate(time, time_scale, target, id_type, observatory,
666-
time_format, mol_tag)
627+
photod = photod_rate(ephemobj, mol_tag)
628+
667629
delta = photod["delta"]
668630

669631
calc = ((16*np.pi*k*t_freq.decompose() *
@@ -678,10 +640,8 @@ def prodrate_np(self, spectra, temp_estimate, transition_freq,
678640
return q
679641

680642
def production_rate(self, coma, integrated_line, temp_estimate,
681-
transition_freq, mol_tag, time, target,
682-
aper=25 * u.m, observatory='500', b=1.2,
683-
time_format='iso', time_scale='utc',
684-
id_type='designation'):
643+
transition_freq, mol_tag, ephemobj,
644+
aper=25 * u.m, b=1.2):
685645
"""
686646
Calculate production rate for `GasComa`
687647
@@ -702,39 +662,17 @@ def production_rate(self, coma, integrated_line, temp_estimate,
702662
mol_tag : int or str
703663
Molecule identifier. Make sure it is an exclusive identifier.
704664
705-
time : str
706-
Time of observation of any format supported by `~astropy.time`
707-
708-
target : str
709-
| Target designation, if there is more than one aparition you
710-
| will be prompted to pick a more specific identifier from a
711-
| displayed table and change the parameter id_type to 'id'.
712-
| Look at `~astroquery.jplhorizons` for more information.
665+
ephemobj: `~sbpy.data.Ephem` object
666+
An `~sbpy.data.Ephem` object that holds ephemerides information
713667
714668
aper : `~astropy.units.Quantity`
715669
Telescope aperture in meters. Default is 25 m
716670
717-
observatory : str
718-
| Observatory identifier as per `~astroquery.jplhorizons`
719-
| Default is geocentric ('500')
720-
721671
b : int
722672
| Dimensionless factor intrinsic to every antenna. Typical
723673
| value, and the default for this model, is 1.22. See
724674
| references for more information on this parameter.
725675
726-
time_format : str
727-
| Time format, see `~astropy.time` for more information
728-
| Default is 'iso' which corresponds to 'YYYY-MM-DD HH:MM:SS'
729-
730-
time_scale : str
731-
| Time scale, see `~astropy.time` for mor information.
732-
| Default is 'utc'
733-
734-
id_type : str
735-
| ID type for target. See `~astroquery.jplhorizons` for more.
736-
| Default is 'designation'
737-
738676
Returns
739677
-------
740678
Q : `~astropy.units.Quantity`
@@ -743,6 +681,9 @@ def production_rate(self, coma, integrated_line, temp_estimate,
743681
Examples
744682
--------
745683
>>> from sbpy.activity.gas import Haser # doctest: +SKIP
684+
>>> from sbpy.data import Ephem # doctest: +SKIP
685+
>>> from astropy.time import Time # doctest: +SKIP
686+
746687
>>> coma = Haser(Q, v, parent) # doctest: +SKIP
747688
>>> Q = spec.production_rate(coma, molecule='H2O') # doctest: +SKIP
748689
@@ -755,15 +696,16 @@ def production_rate(self, coma, integrated_line, temp_estimate,
755696
>>> b = 0.74 # doctest: +SKIP
756697
>>> vgas = 0.5 * u.km / u.s # doctest: +SKIP
757698
758-
>>> time = '2017-12-22 05:24:20' # doctest: +SKIP
699+
>>> time = Time('2017-12-22 05:24:20', format = 'iso') # doctest: +SKIP
700+
>>> ephemobj = Ephem(target, epochs=time.jd) # doctest: +SKIP
759701
>>> spectra = 0.26 * u.K * u.km / u.s # doctest: +SKIP
760702
761703
>>> parent = photo_timescale('CO') * vgas # doctest: +SKIP
762704
763705
>>> coma = Haser(Q_estimate, vgas, parent) # doctest: +SKIP
764706
765707
>>> Q = spec.production_rate(coma, spectra, temp_estimate, # doctest: +SKIP
766-
transition_freq, mol_tag, time, target,
708+
transition_freq, mol_tag, ephemobj,
767709
aper=aper, b=b) # doctest: +SKIP
768710
769711
>>> print(Q) # doctest: +SKIP
@@ -785,8 +727,7 @@ def production_rate(self, coma, integrated_line, temp_estimate,
785727
# integrated_line = self.integrated_flux(transition_freq) - not yet implemented
786728

787729
molecules = total_number(integrated_line, temp_estimate,
788-
transition_freq, mol_tag, aper, b, time, target,
789-
time_scale, id_type, observatory, time_format)
730+
transition_freq, mol_tag, aper, b, ephemobj)
790731

791732
model_molecules = coma.total_number(aper)
792733

0 commit comments

Comments
 (0)