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

Commit

Permalink
Merge branch 'encounter_storage' into debug
Browse files Browse the repository at this point in the history
  • Loading branch information
daminton committed Dec 6, 2022
2 parents acff2c9 + d06b7da commit 9c329fd
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions examples/Fragmentation/Fragmentation_Movie.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,14 @@
class AnimatedScatter(object):
"""An animated scatter plot using matplotlib.animations.FuncAnimation."""

def __init__(self, sim, animfile, title, nskip=1):
tgood = sim.enc.where(sim.enc['Gmass'] > 9e-8).time
self.ds = sim.enc.sel(time=tgood)
def __init__(self, sim, animfile, title, style, nskip=1):
if style == "disruption_headon" or style == "hitandrun":
tgood = sim.enc.where(sim.enc['Gmass'] > 0.8 * body_Gmass[style][0]).time
else:
tgood = sim.enc.where(sim.enc['Gmass'] > 0.01 * body_Gmass[style][1]).time

self.ds = sim.enc[['rh','vh','Gmass','radius']].sel(time=tgood).load().interpolate_na(dim="time")

nframes = int(self.ds['time'].size)
self.sim = sim
self.title = title
Expand Down Expand Up @@ -134,13 +139,12 @@ def center(Gmass, x, y):
x = x[~np.isnan(x)]
y = y[~np.isnan(y)]
Gmass = Gmass[~np.isnan(Gmass)]
x = x[Gmass]
x_com = np.sum(Gmass * x) / np.sum(Gmass)
y_com = #np.sum(Gmass * y) / np.sum(Gmass)
y_com = np.sum(Gmass * y) / np.sum(Gmass)
return x_com, y_com

Gmass, rh, point_rad = next(self.data_stream(frame))
#x_com, y_com = center(Gmass, rh[:,0], rh[:,1])
x_com, y_com = center(Gmass, rh[:,0], rh[:,1])
self.scatter_artist.set_offsets(np.c_[rh[:,0] - x_com, rh[:,1] - y_com])
self.scatter_artist.set_sizes(point_rad**2)
return self.scatter_artist,
Expand Down Expand Up @@ -183,4 +187,4 @@ def data_stream(self, frame=0):
sim.set_parameter(fragmentation=True, fragmentation_save="TRAJECTORY", gmtiny=gmtiny, minimum_fragment_gmass=minimum_fragment_gmass, verbose=False)
sim.run(dt=1e-4, tstop=2.0e-3, istep_out=1, dump_cadence=0)

anim = AnimatedScatter(sim,movie_filename,movie_titles[style],nskip=1)
anim = AnimatedScatter(sim,movie_filename,movie_titles[style],style,nskip=1)

0 comments on commit 9c329fd

Please sign in to comment.