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

Commit

Permalink
Browse files Browse the repository at this point in the history
 into IO
  • Loading branch information
daminton committed Aug 27, 2021
2 parents 0d836c5 + 74fd250 commit d24f2bf
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 29 deletions.
18 changes: 9 additions & 9 deletions examples/whm_gr_test/pl.swifter.in
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
9
1 39.476926408897626
0 39.476926408897626
0.0 0.0 0.0
0.0 0.0 0.0
2 6.5537098095653139645e-06 0.001475126151488013514
1 6.553709809565314146e-06 0.0014751261514880139061
1.6306381826061645943e-05
-0.29510017042975300594 -0.34346884022084378518 -0.000997917547895216684
5.709185893355676925 -6.2220892824670268354 -1.0321515701207669188
3 9.663313399581537916e-05 0.006759061578633709628
2 9.6633133995815381836e-05 0.006759061578633710828
4.0453784346544178454e-05
-0.21096294566811030213 -0.6945147553261317164 0.0026420019351886940041
7.0187176732445560167 -2.1783670470162428854 -0.43491289164169576724
4 0.000120026935827952453094 0.010044949983771722159
3 0.000120026935827952456416 0.010044949983771724966
4.25875607065040958e-05
0.905522725638602366 -0.44829515638659761523 1.8122901980659660508e-05
2.685845700565266851 5.6080546137104218133 -0.00027833838024725729542
5 1.2739802010675941456e-05 0.0072465915674003775008
4 1.2739802010675941808e-05 0.0072465915674003790445
2.265740805092889601e-05
-1.6511945936824949932 0.1180803833522415941 0.042978148735422203042
-0.17443328105136805607 -4.661619009141641736 -0.09341597039948347882
6 0.037692251088985676735 0.3552713110772063034
5 0.03769225108898567778 0.3552713110772063853
0.00046732617030490929307
4.2381319671740662614 -2.694827110197309139 -0.08362807329786287047
1.44742540330701551 2.4581907268113588696 -0.042593445938391914576
7 0.011285899820091272997 0.43766359903328559694
6 0.01128589982009127331 0.4376635990332856823
0.00038925687730393611812
6.4776155764849425722 -7.5454781609219372385 -0.12660625214421539209
1.4343694668413992401 1.3251694474665614901 -0.08010594537316981756
8 0.0017236589478267730203 0.4696622419824256353
7 0.001723658947826773068 0.46966224198242572768
0.00016953449859497231466
14.737783583010530819 13.132284780084109599 -0.14218874866247160904
-0.96494157148906816704 1.0080364706941240677 0.016191990849809560611
9 0.0020336100526728302319 0.781439451609552476
8 0.0020336100526728302882 0.7814394516095526881
0.000164587904124493665
29.578253698940308425 -4.488584904681241383 -0.58928426126360722304
0.16609282485651713797 1.143247554888599065 -0.027336661118935745503
16 changes: 8 additions & 8 deletions examples/whm_gr_test/pl.swiftest.in
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
8
Mercury 6.5537098095653139645e-06 0.001475126151488013514
Mercury 6.553709809565314146e-06 0.0014751261514880139061
1.6306381826061645943e-05
0.38709861919270799335 0.20562987442219879397 7.0036598799530471737
48.303764444546942514 29.187012577257871015 139.02452846395490837
Venus 9.663313399581537916e-05 0.006759061578633709628
Venus 9.6633133995815381836e-05 0.006759061578633710828
4.0453784346544178454e-05
0.72332350338494522113 0.0067851993472706276234 3.3945100118236060105
76.62172575937908903 55.11451498626085055 120.69543184874230235
Earth 0.000120026935827952453094 0.010044949983771722159
Earth 0.000120026935827952456416 0.010044949983771724966
4.25875607065040958e-05
1.000022414803547921 0.016679693167334301573 0.002750719340522077977
175.59912721852418827 287.3487256951211748 232.20474506920808722
Mars 1.2739802010675941456e-05 0.0072465915674003775008
Mars 1.2739802010675941808e-05 0.0072465915674003790445
2.265740805092889601e-05
1.5237056817307590428 0.09335454089002033495 1.8479086301002540793
49.490790672135332784 286.7030449733272235 203.56009534652309867
Jupiter 0.037692251088985676735 0.3552713110772063034
Jupiter 0.03769225108898567778 0.3552713110772063853
0.00046732617030490929307
5.203524963998765074 0.048518619089771883313 1.3035691332389880426
100.516740776557597314 273.38311024861741316 317.57998688455870706
Saturn 0.011285899820091272997 0.43766359903328559694
Saturn 0.01128589982009127331 0.4376635990332856823
0.00038925687730393611812
9.581861578191695372 0.05220296447788015659 2.4862598063103709123
113.59526938704850352 335.69019804854252698 225.44748806008931297
Uranus 0.0017236589478267730203 0.4696622419824256353
Uranus 0.001723658947826773068 0.46966224198242572768
0.00016953449859497231466
19.23638216159032055 0.04433184777155944195 0.7703424893861580136
74.09557761028084144 95.84993853316392176 235.82773290830229485
Neptune 0.0020336100526728302319 0.781439451609552476
Neptune 0.0020336100526728302882 0.7814394516095526881
0.000164587904124493665
30.289653279202511271 0.013458737599393380546 1.769000156955224945
131.74519418988560915 245.79890439350270981 334.51418242279709148
16 changes: 10 additions & 6 deletions python/swiftest/swiftest/init_cond.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def solar_system_horizons(plname, idval, param, ephemerides_start_date, ds):
rotcb = solarpole.cartesian * solarrot
Ipsun = np.array([0.0, 0.0, planetIpz['Sun']])

cbid = np.array([1])
cbid = np.array([0])
cvec = np.vstack([GMcb, Rcb, J2RP2, J4RP4])
if param['ROTATION'] == 'YES':
cvec = np.vstack([cvec, Ipsun[0], Ipsun[1], Ipsun[2], rotcb.x, rotcb.y, rotcb.z])
Expand Down Expand Up @@ -264,9 +264,9 @@ def solar_system_horizons(plname, idval, param, ephemerides_start_date, ds):
plab = tlab.copy()

if idval is None:
plid = np.array([planetid[key]], dtype=int) + 1
plid = np.array([planetid[key]], dtype=int)
else:
plid = np.array([idval]+1, dtype=int)
plid = np.array([idval], dtype=int)

# Prepare frames by adding an extra axis for the time coordinate
plframe = np.expand_dims(pvec.T, axis=0)
Expand All @@ -277,7 +277,7 @@ def solar_system_horizons(plname, idval, param, ephemerides_start_date, ds):

return ds

def vec2xr(param, names, idvals, v1, v2, v3, v4, v5, v6, GMpl=None, Rpl=None, rhill=None, Ip1=None, Ip2=None, Ip3=None, rotx=None, roty=None, rotz=None, t=0.0):
def vec2xr(param, idvals, namevals, v1, v2, v3, v4, v5, v6, GMpl=None, Rpl=None, rhill=None, Ip1=None, Ip2=None, Ip3=None, rotx=None, roty=None, rotz=None, t=0.0):

if param['ROTATION'] == 'YES':
if Ip1 is None:
Expand Down Expand Up @@ -305,8 +305,12 @@ def vec2xr(param, names, idvals, v1, v2, v3, v4, v5, v6, GMpl=None, Rpl=None, rh
if ispl and rhill is None and param['RHILL_PRESENT'] == 'YES':
print("rhill is required.")
return None


# Be sure we use the correct input format
old_out_form = param['OUT_FORM']
param['OUT_FORM'] = param['IN_FORM']
clab, plab, tlab = swiftest.io.make_swiftest_labels(param)
param['OUT_FORM'] = old_out_form
vec = np.vstack([v1, v2, v3, v4, v5, v6])
if ispl:
vec = np.vstack([vec, GMpl, Rpl])
Expand All @@ -320,7 +324,7 @@ def vec2xr(param, names, idvals, v1, v2, v3, v4, v5, v6, GMpl=None, Rpl=None, rh
else:
bodyxr = xr.DataArray(bodyframe, dims=dims, coords={'time': [t], 'id': idvals, 'vec': tlab})

bodyxr = bodyxr.assign_coords(name=('id', names))
bodyxr = bodyxr.assign_coords(name=('id', namevals))

ds = bodyxr.to_dataset(dim='vec')
return ds
8 changes: 4 additions & 4 deletions python/swiftest/swiftest/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,8 +806,8 @@ def swiftest_xr2infile(ds, param, framenum=-1):
A set of three input files for a Swiftest run
"""
frame = ds.isel(time=framenum)
cb = frame.where(frame.id == 1, drop=True)
pl = frame.where(frame.id > 1, drop=True)
cb = frame.where(frame.id == 0, drop=True)
pl = frame.where(frame.id > 0, drop=True)
pl = pl.where(np.invert(np.isnan(pl['Gmass'])), drop=True).drop_vars(['J_2', 'J_4'])
tp = frame.where(np.isnan(frame['Gmass']), drop=True).drop_vars(['Gmass', 'radius', 'J_2', 'J_4'])

Expand Down Expand Up @@ -984,8 +984,8 @@ def swifter_xr2infile(ds, param, framenum=-1):
A set of input files for a Swifter run
"""
frame = ds.isel(time=framenum)
cb = frame.where(frame.id == 1, drop=True)
pl = frame.where(frame.id > 1, drop=True)
cb = frame.where(frame.id == 0, drop=True)
pl = frame.where(frame.id > 0, drop=True)
pl = pl.where(np.invert(np.isnan(pl['Gmass'])), drop=True).drop_vars(['J_2', 'J_4'])
tp = frame.where(np.isnan(frame['Gmass']), drop=True).drop_vars(['Gmass', 'radius', 'J_2', 'J_4'])

Expand Down
4 changes: 2 additions & 2 deletions python/swiftest/swiftest/simulation_class.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def add(self, plname, date=date.today().isoformat(), idval=None):
return


def addp(self, idvals, t1, t2, t3, t4, t5, t6, GMpl=None, Rpl=None, rhill=None, Ip1=None, Ip2=None, Ip3=None, rotx=None, roty=None, rotz=None):
def addp(self, idvals, namevals, t1, t2, t3, t4, t5, t6, GMpl=None, Rpl=None, rhill=None, Ip1=None, Ip2=None, Ip3=None, rotx=None, roty=None, rotz=None):
"""
Adds a body (test particle or massive body) to the internal DataSet given a set up 6 vectors (orbital elements
or cartesian state vectors, depending on the value of self.param). Input all angles in degress
Expand All @@ -99,7 +99,7 @@ def addp(self, idvals, t1, t2, t3, t4, t5, t6, GMpl=None, Rpl=None, rhill=None,
"""
t = self.param['T0']

dsnew = init_cond.vec2xr(self.param, idvals, t1, t2, t3, t4, t5, t6, GMpl, Rpl, rhill, Ip1, Ip2, Ip3, rotx, roty, rotz, t)
dsnew = init_cond.vec2xr(self.param, idvals, namevals, t1, t2, t3, t4, t5, t6, GMpl, Rpl, rhill, Ip1, Ip2, Ip3, rotx, roty, rotz, t)
if dsnew is not None:
self.ds = xr.combine_by_coords([self.ds, dsnew])
return
Expand Down

0 comments on commit d24f2bf

Please sign in to comment.