Skip to content

Commit

Permalink
Save some basic metadata in Ephem tables.
Browse files Browse the repository at this point in the history
  • Loading branch information
mkelley committed Sep 1, 2024
1 parent 9c629f7 commit b6429ab
Showing 1 changed file with 34 additions and 5 deletions.
39 changes: 34 additions & 5 deletions sbpy/data/ephem.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,9 @@ def from_horizons(
'lat': location.lat.deg,
'elevation': location.height.to('km')}

# append ephemerides table for each targetid
# append ephemerides table for each targetid, collect all URLs
all_eph = None
urls = []
for targetid in targetids:

# load ephemerides using astroquery.jplhorizons
Expand All @@ -224,6 +225,8 @@ def from_horizons(
'The following query was attempted: {:s}').format(
str(e), obj.uri))

urls.append(obj.uri)

if _sorted:
# restore user's original order
eph = eph[_unsort]
Expand Down Expand Up @@ -273,7 +276,12 @@ def from_horizons(
all_eph['locapp_hourangle'] = u.Quantity(Angle(
all_eph['locapp_hourangle'], 'hr'), u.hourangle)

return cls.from_table(all_eph)
meta = {
"targetids": targetids,
"location": location,
"urls": urls,
}
return cls.from_table(all_eph, meta=meta)

@classmethod
@requires("astroquery")
Expand Down Expand Up @@ -447,8 +455,9 @@ def from_mpc(cls, targetids, epochs=None, location='500', ra_format=None,
else:
raise ValueError('Invalid `epochs` parameter')

# append ephemerides table for each targetid
# append ephemerides table for each targetid and collect URLs
all_eph = None
urls = []
for targetid in targetids:
try:
# get ephemeris
Expand All @@ -461,12 +470,14 @@ def from_mpc(cls, targetids, epochs=None, location='500', ra_format=None,
number=1, **kwargs)
e['Date'] = e['Date'].iso # for vstack to work
eph.append(e)
urls.append(e.uri)
eph = QTable(vstack(eph))
eph['Date'] = Time(eph['Date'], scale='utc')
else:
eph = MPC.get_ephemeris(targetid, location=location,
start=start, step=step,
number=number, **kwargs)
urls.append(e.uri)
except InvalidQueryError as e:
raise QueryError(
'Error raised by astroquery.mpc: {:s}'.format(str(e)))
Expand All @@ -492,7 +503,12 @@ def from_mpc(cls, targetids, epochs=None, location='500', ra_format=None,
if dec_format is not None:
all_eph['Dec'].info.format = lambda x: x.to_string(**dec_format)

return cls.from_table(all_eph)
meta = {
"targetids": targetids,
"location": location,
"urls": urls,
}
return cls.from_table(all_eph, meta=meta)

@classmethod
@requires("astroquery")
Expand Down Expand Up @@ -627,6 +643,7 @@ def from_miriade(cls, targetids, objtype='asteroid',

# append ephemerides table for each targetid
all_eph = None
urls = []
for targetid in targetids:
query = Miriade()
try:
Expand All @@ -638,6 +655,7 @@ def from_miriade(cls, targetids, objtype='asteroid',
location=location,
epoch=_epochs['start'],
**kwargs)
urls.append(eph.uri)
else:
# multiple epochs
eph = []
Expand All @@ -650,6 +668,7 @@ def from_miriade(cls, targetids, objtype='asteroid',
**kwargs
)
eph.append(e)
urls.append(eph.uri)
eph = vstack(eph)
else:
# dictionary
Expand All @@ -659,6 +678,7 @@ def from_miriade(cls, targetids, objtype='asteroid',
epoch_step=_epochs['step'],
epoch_nsteps=_epochs['number'],
**kwargs)
urls.append(eph.uri)
except RuntimeError as e:
raise QueryError(
('Error raised by astroquery.imcce: {:s}\n'
Expand All @@ -672,7 +692,12 @@ def from_miriade(cls, targetids, objtype='asteroid',

all_eph = QTable(all_eph)
all_eph['epoch'] = Time(all_eph['epoch'], scale='utc', format='jd')
return cls.from_table(all_eph)
meta = {
"targetids": targetids,
"location": location,
"urls": urls,
}
return cls.from_table(all_eph, meta=meta)

@classmethod
@requires("pyoorb")
Expand Down Expand Up @@ -885,6 +910,10 @@ def from_oo(cls, orbit, epochs=None, location='500', scope='full',
ephem.table['epoch'].format = 'jd'
ephem.table.remove_column('MJD')

ephem.meta["location"] = location
ephem.meta["ephfile"] = ephfile
ephem.meta["dynmodel"] = dynmodel

return ephem


Expand Down

0 comments on commit b6429ab

Please sign in to comment.