Skip to content
This repository was archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
Fixed issues that were causing the horizons initial conditions genera…
Browse files Browse the repository at this point in the history
…tor to fail if a valid body could not be identified.
  • Loading branch information
MintoDA1 authored and MintoDA1 committed Aug 2, 2023
1 parent a136e95 commit 517a2f4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
13 changes: 8 additions & 5 deletions python/swiftest/swiftest/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ def get_altid(errstr,exclude_spacecraft=True):
altname =[jpl.table['targetname'][0]]
except Exception as e:
altid,altname = get_altid(str(e))
if altid is not None: # Return the first matching id
if altid is not None and len(altid) >0: # Return the first matching id
id = altid[0]
jpl = Horizons(id=id, location='@sun',
epochs={'start': ephemerides_start_date, 'stop': ephemerides_end_date,
Expand Down Expand Up @@ -340,9 +340,12 @@ def solar_system_horizons(name: str,
print(f"Fetching ephemerides data for {ephemeris_id} from JPL/Horizons")

jpl,altid,altname = horizons_query(ephemeris_id,ephemerides_start_date)
print(f"Found ephemerides data for {altname[0]} ({altid[0]}) from JPL/Horizons")
if name == None:
name = altname[0]
if jpl is not None:
print(f"Found ephemerides data for {altname[0]} ({altid[0]}) from JPL/Horizons")
if name == None:
name = altname[0]
else:
return None

if param['IN_FORM'] == 'XV':
rx = jpl.vectors()['x'][0] * DCONV
Expand Down Expand Up @@ -380,7 +383,7 @@ def solar_system_horizons(name: str,

# Generate planet value vectors
if (param['RHILL_PRESENT']):
rhill = jpl.elements()['a'][0] * DCONV * (3 * MSun_over_Mpl[name]) ** (-THIRDLONG)
rhill = jpl.elements()['a'][0] * DCONV * (3 * Gmass / GMcb) ** (-THIRDLONG)

if (param['ROTATION']):
rot *= param['TU2S']
Expand Down
9 changes: 7 additions & 2 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -2232,10 +2232,15 @@ def add_solar_system_body(self,

body_list = []
for i,n in enumerate(name):
body_list.append(init_cond.solar_system_horizons(n, self.param, date, ephemeris_id=ephemeris_id[i]))
body = init_cond.solar_system_horizons(n, self.param, date, ephemeris_id=ephemeris_id[i])
if body is not None:
body_list.append(body)

#Convert the list receieved from the solar_system_horizons output and turn it into arguments to vec2xr
if len(body_list) == 1:
if len(body_list) == 0:
print("No valid bodies found")
return
elif len(body_list) == 1:
values = list(np.hsplit(np.array(body_list[0],dtype=np.dtype(object)),17))
else:
values = list(np.squeeze(np.hsplit(np.array(body_list,np.dtype(object)),17)))
Expand Down

0 comments on commit 517a2f4

Please sign in to comment.