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

Commit

Permalink
Updated this branch with the restructured Python module taken from th…
Browse files Browse the repository at this point in the history
…e OOPrestructure branch
  • Loading branch information
daminton committed Jul 2, 2021
1 parent 1ee39a0 commit bbd5bc1
Show file tree
Hide file tree
Showing 43 changed files with 2,701 additions and 2,622 deletions.
116 changes: 116 additions & 0 deletions examples/symba_chambers2013/aescattermovie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import swiftest.io as swio
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
import matplotlib.colors as mcolors

radscale = 20
xmin = 1.0
xmax = 10.0
ymin = 1e-6
ymax = 1.0

class AnimatedScatter(object):
"""An animated scatter plot using matplotlib.animations.FuncAnimation."""
def __init__(self, ds, param):
#outf = 'aescatter.mp4'

frame = 0
nframes = ds['time'].size
self.ds = ds
self.param = param
self.ds['Mass'] = self.ds['Mass'] / param['GU']
self.ds['radmarker'] = self.ds['Radius'].fillna(0)
self.ds['radmarker'] = self.ds['radmarker'] / self.ds['radmarker'].max() * radscale

self.clist = {'Initial conditions' : 'xkcd:faded blue',
'Disruption' : 'xkcd:marigold',
'Supercatastrophic' : 'xkcd:shocking pink',
'Hit and run fragment' : 'xkcd:baby poop green'}

self.stream = self.data_stream(frame)
# Setup the figure and axes...
self.fig, self.ax = plt.subplots(figsize=(8,4.5))
# Then setup FuncAnimation.
self.ani = animation.FuncAnimation(self.fig, self.update, interval=1, frames=nframes,
init_func=self.setup_plot, blit=True)
self.ani.save('aescatter.mp4', fps=60, dpi=300,
extra_args=['-vcodec', 'libx264'])
print('Finished writing aescattter.mp4')

def scatters(self, pl, radmarker, origin):
scat = []
for key, value in self.clist.items():
idx = origin == value
s = self.ax.scatter(pl[idx, 0], pl[idx, 1], marker='o', s=radmarker[idx], c=value, alpha=0.25, label=key)
scat.append(s)
return scat

def setup_plot(self):
# First frame
"""Initial drawing of the scatter plot."""
t, name, Mass, Radius, npl, pl, radmarker, origin = next(self.data_stream(0))

# set up the figure
self.ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax))
self.ax.margins(x=10, y=1)
self.ax.set_xlabel('Semi Major Axis (AU)', fontsize='16', labelpad=1)
self.ax.set_ylabel('Eccentricity', fontsize='16', labelpad=1)
self.ax.set_yscale('log')

self.title = self.ax.text(0.50, 1.05, "", bbox={'facecolor': 'w', 'alpha': 0.5, 'pad': 5}, transform=self.ax.transAxes,
ha="center")

self.title.set_text(f'Time = ${t / 24 / 3600:4.1f}$ days with ${npl:f}$ particles')
slist = self.scatters(pl, radmarker, origin)
self.s0 = slist[0]
self.s1 = slist[1]
self.s2 = slist[2]
self.s3 = slist[3]
self.ax.legend(loc='upper right')
return self.s0, self.s1, self.s2, self.s3, self.title

def data_stream(self, frame=0):
while True:
d = self.ds.isel(time=frame)
Radius = d['radmarker'].values
Mass = d['Mass'].values
a = d['a'].values
e = d['e'].values
name = d['id'].values
npl = d['npl'].values
radmarker = d['radmarker']
origin = d['origin_type']

t = self.ds.coords['time'].values[frame]

frame += 1
yield t, name, Mass, Radius, npl, np.c_[a, e], radmarker, origin

def update(self,frame):
"""Update the scatter plot."""
t, name, Mass, Radius, npl, pl, radmarker, origin = next(self.data_stream(frame))

self.title.set_text(f'Time = ${t / 24 / 3600:4.1f}$ days with ${npl:4.0f}$ particles')

# We need to return the updated artist for FuncAnimation to draw..
# Note that it expects a sequence of artists, thus the trailing comma.
s = [self.s0, self.s1, self.s2, self.s3]
for i, (key, value) in enumerate(self.clist.items()):
idx = origin == key
s[i].set_sizes(radmarker[idx])
s[i].set_offsets(pl[idx,:])
s[i].set_facecolor(value)

self.s0 = s[0]
self.s1 = s[1]
self.s2 = s[2]
self.s3 = s[3]
return self.s0, self.s1, self.s2, self.s3, self.title,


param = swio.read_swiftest_param("param.in")
marsdisk = swio.swiftest2xr(param)
print('Making animation')
anim = AnimatedScatter(marsdisk,param)
print('Animation finished')
116 changes: 116 additions & 0 deletions examples/symba_clement2018/aescattermovie.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
import swiftest.io as swio
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
import matplotlib.colors as mcolors

radscale = 20
xmin = 1.0
xmax = 10.0
ymin = 1e-6
ymax = 1.0

class AnimatedScatter(object):
"""An animated scatter plot using matplotlib.animations.FuncAnimation."""
def __init__(self, ds, param):
#outf = 'aescatter.mp4'

frame = 0
nframes = ds['time'].size
self.ds = ds
self.param = param
self.ds['Mass'] = self.ds['Mass'] / param['GU']
self.ds['radmarker'] = self.ds['Radius'].fillna(0)
self.ds['radmarker'] = self.ds['radmarker'] / self.ds['radmarker'].max() * radscale

self.clist = {'Initial conditions' : 'xkcd:faded blue',
'Disruption' : 'xkcd:marigold',
'Supercatastrophic' : 'xkcd:shocking pink',
'Hit and run fragment' : 'xkcd:baby poop green'}

self.stream = self.data_stream(frame)
# Setup the figure and axes...
self.fig, self.ax = plt.subplots(figsize=(8,4.5))
# Then setup FuncAnimation.
self.ani = animation.FuncAnimation(self.fig, self.update, interval=1, frames=nframes,
init_func=self.setup_plot, blit=True)
self.ani.save('aescatter.mp4', fps=60, dpi=300,
extra_args=['-vcodec', 'libx264'])
print('Finished writing aescattter.mp4')

def scatters(self, pl, radmarker, origin):
scat = []
for key, value in self.clist.items():
idx = origin == value
s = self.ax.scatter(pl[idx, 0], pl[idx, 1], marker='o', s=radmarker[idx], c=value, alpha=0.25, label=key)
scat.append(s)
return scat

def setup_plot(self):
# First frame
"""Initial drawing of the scatter plot."""
t, name, Mass, Radius, npl, pl, radmarker, origin = next(self.data_stream(0))

# set up the figure
self.ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax))
self.ax.margins(x=10, y=1)
self.ax.set_xlabel('Semi Major Axis (AU)', fontsize='16', labelpad=1)
self.ax.set_ylabel('Eccentricity', fontsize='16', labelpad=1)
self.ax.set_yscale('log')

self.title = self.ax.text(0.50, 1.05, "", bbox={'facecolor': 'w', 'alpha': 0.5, 'pad': 5}, transform=self.ax.transAxes,
ha="center")

self.title.set_text(f'Time = ${t / 24 / 3600:4.1f}$ days with ${npl:f}$ particles')
slist = self.scatters(pl, radmarker, origin)
self.s0 = slist[0]
self.s1 = slist[1]
self.s2 = slist[2]
self.s3 = slist[3]
self.ax.legend(loc='upper right')
return self.s0, self.s1, self.s2, self.s3, self.title

def data_stream(self, frame=0):
while True:
d = self.ds.isel(time=frame)
Radius = d['radmarker'].values
Mass = d['Mass'].values
a = d['a'].values
e = d['e'].values
name = d['id'].values
npl = d['npl'].values
radmarker = d['radmarker']
origin = d['origin_type']

t = self.ds.coords['time'].values[frame]

frame += 1
yield t, name, Mass, Radius, npl, np.c_[a, e], radmarker, origin

def update(self,frame):
"""Update the scatter plot."""
t, name, Mass, Radius, npl, pl, radmarker, origin = next(self.data_stream(frame))

self.title.set_text(f'Time = ${t / 24 / 3600:4.1f}$ days with ${npl:4.0f}$ particles')

# We need to return the updated artist for FuncAnimation to draw..
# Note that it expects a sequence of artists, thus the trailing comma.
s = [self.s0, self.s1, self.s2, self.s3]
for i, (key, value) in enumerate(self.clist.items()):
idx = origin == key
s[i].set_sizes(radmarker[idx])
s[i].set_offsets(pl[idx,:])
s[i].set_facecolor(value)

self.s0 = s[0]
self.s1 = s[1]
self.s2 = s[2]
self.s3 = s[3]
return self.s0, self.s1, self.s2, self.s3, self.title,


param = swio.read_swiftest_param("param.in")
marsdisk = swio.swiftest2xr(param)
print('Making animation')
anim = AnimatedScatter(marsdisk,param)
print('Animation finished')
26 changes: 13 additions & 13 deletions examples/symba_mars_disk/aescattermovie.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import swiftestio as swio
import swiftest.io as swio
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import animation
Expand All @@ -13,15 +13,15 @@

class AnimatedScatter(object):
"""An animated scatter plot using matplotlib.animations.FuncAnimation."""
def __init__(self, ds, config):
def __init__(self, ds, param):
#outf = 'aescatter.mp4'

frame = 0
nframes = ds['time'].size
self.ds = ds
self.config = config
self.ds['mass'] = self.ds['mass'] / config['GU']
self.ds['radmarker'] = self.ds['radius'].fillna(0)
self.param = param
self.ds['Mass'] = self.ds['Mass'] / param['GU']
self.ds['radmarker'] = self.ds['Radius'].fillna(0)
self.ds['radmarker'] = self.ds['radmarker'] / self.ds['radmarker'].max() * radscale

self.clist = {'Initial conditions' : 'xkcd:faded blue',
Expand Down Expand Up @@ -50,7 +50,7 @@ def scatters(self, pl, radmarker, origin):
def setup_plot(self):
# First frame
"""Initial drawing of the scatter plot."""
t, name, mass, radius, npl, pl, radmarker, origin = next(self.data_stream(0))
t, name, Mass, Radius, npl, pl, radmarker, origin = next(self.data_stream(0))

# set up the figure
self.ax = plt.axes(xlim=(xmin, xmax), ylim=(ymin, ymax))
Expand All @@ -74,8 +74,8 @@ def setup_plot(self):
def data_stream(self, frame=0):
while True:
d = self.ds.isel(time=frame)
radius = d['radmarker'].values
mass = d['mass'].values
Radius = d['radmarker'].values
Mass = d['Mass'].values
a = d['a'].values / RMars
e = d['e'].values
name = d['id'].values
Expand All @@ -86,11 +86,11 @@ def data_stream(self, frame=0):
t = self.ds.coords['time'].values[frame]

frame += 1
yield t, name, mass, radius, npl, np.c_[a, e], radmarker, origin
yield t, name, Mass, Radius, npl, np.c_[a, e], radmarker, origin

def update(self,frame):
"""Update the scatter plot."""
t, name, mass, radius, npl, pl, radmarker, origin = next(self.data_stream(frame))
t, name, Mass, Radius, npl, pl, radmarker, origin = next(self.data_stream(frame))

self.title.set_text(f'Time = ${t / 24 / 3600:4.1f}$ days with ${npl:4.0f}$ particles')

Expand All @@ -110,8 +110,8 @@ def update(self,frame):
return self.s0, self.s1, self.s2, self.s3, self.title,


config = swio.read_swiftest_config("param.in")
marsdisk = swio.swiftest2xr(config)
param = swio.read_swiftest_param("param.in")
marsdisk = swio.swiftest2xr(param)
print('Making animation')
anim = AnimatedScatter(marsdisk,config)
anim = AnimatedScatter(marsdisk,param)
print('Animation finished')
Binary file removed python/.DS_Store
Binary file not shown.
3 changes: 3 additions & 0 deletions python/swiftest/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions python/swiftest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
swiftest
Documentation TBD
86 changes: 86 additions & 0 deletions python/swiftest/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
argon2-cffi @ file:///tmp/build/80754af9/argon2-cffi_1613036642480/work
astropy==4.2.1
astroquery==0.4.2
async-generator==1.10
attrs @ file:///tmp/build/80754af9/attrs_1620827162558/work
backcall @ file:///home/ktietz/src/ci/backcall_1611930011877/work
beautifulsoup4==4.9.3
bleach @ file:///tmp/build/80754af9/bleach_1612211392645/work
certifi==2021.5.30
cffi @ file:///tmp/build/80754af9/cffi_1613246939562/work
chardet==4.0.0
cryptography==3.4.7
cycler==0.10.0
decorator @ file:///tmp/build/80754af9/decorator_1621259047763/work
defusedxml @ file:///tmp/build/80754af9/defusedxml_1615228127516/work
entrypoints==0.3
html5lib==1.1
idna==2.10
importlib-metadata==4.5.0
ipykernel==5.5.5
ipython @ file:///tmp/build/80754af9/ipython_1617118429768/work
ipython-genutils @ file:///tmp/build/80754af9/ipython_genutils_1606773439826/work
ipywidgets @ file:///tmp/build/80754af9/ipywidgets_1610481889018/work
jedi==0.17.0
jeepney==0.6.0
Jinja2 @ file:///tmp/build/80754af9/jinja2_1621238361758/work
jsonschema @ file:///tmp/build/80754af9/jsonschema_1602607155483/work
jupyter==1.0.0
jupyter-client @ file:///tmp/build/80754af9/jupyter_client_1616770841739/work
jupyter-console @ file:///tmp/build/80754af9/jupyter_console_1616615302928/work
jupyter-core @ file:///tmp/build/80754af9/jupyter_core_1612213308260/work
jupyterlab-pygments @ file:///tmp/build/80754af9/jupyterlab_pygments_1601490720602/work
jupyterlab-widgets @ file:///tmp/build/80754af9/jupyterlab_widgets_1609884341231/work
keyring==23.0.1
kiwisolver @ file:///tmp/build/80754af9/kiwisolver_1612282414123/work
MarkupSafe @ file:///tmp/build/80754af9/markupsafe_1621528142364/work
matplotlib==3.4.2
mistune @ file:///tmp/build/80754af9/mistune_1594373098390/work
mkl-random @ file:///tmp/build/80754af9/mkl_random_1618853974840/work
mkl-service==2.3.0
nbclient @ file:///tmp/build/80754af9/nbclient_1614364831625/work
nbconvert @ file:///tmp/build/80754af9/nbconvert_1601914821128/work
nbformat @ file:///tmp/build/80754af9/nbformat_1617383369282/work
nest-asyncio @ file:///tmp/build/80754af9/nest-asyncio_1613680548246/work
notebook @ file:///tmp/build/80754af9/notebook_1621523661196/work
numpy==1.20.3
olefile==0.46
packaging @ file:///tmp/build/80754af9/packaging_1611952188834/work
pandas==1.2.4
pandocfilters @ file:///tmp/build/80754af9/pandocfilters_1605120451932/work
parso @ file:///tmp/build/80754af9/parso_1617223946239/work
pexpect @ file:///tmp/build/80754af9/pexpect_1605563209008/work
pickleshare @ file:///tmp/build/80754af9/pickleshare_1606932040724/work
Pillow @ file:///tmp/build/80754af9/pillow_1617386154241/work
prometheus-client @ file:///tmp/build/80754af9/prometheus_client_1623189609245/work
prompt-toolkit @ file:///tmp/build/80754af9/prompt-toolkit_1616415428029/work
ptyprocess @ file:///tmp/build/80754af9/ptyprocess_1609355006118/work/dist/ptyprocess-0.7.0-py2.py3-none-any.whl
pycparser @ file:///tmp/build/80754af9/pycparser_1594388511720/work
pyerfa==2.0.0
Pygments @ file:///tmp/build/80754af9/pygments_1621606182707/work
pyparsing @ file:///home/linux1/recipes/ci/pyparsing_1610983426697/work
pyrsistent @ file:///tmp/build/80754af9/pyrsistent_1600141707582/work
pySLALIB==1.0.4
python-dateutil @ file:///home/ktietz/src/ci/python-dateutil_1611928101742/work
pytz @ file:///tmp/build/80754af9/pytz_1612215392582/work
pyvo==1.1
pyzmq==20.0.0
qtconsole @ file:///tmp/build/80754af9/qtconsole_1623278325812/work
QtPy==1.9.0
requests==2.25.1
scipy==1.6.3
Send2Trash @ file:///tmp/build/80754af9/send2trash_1607525499227/work
six @ file:///tmp/build/80754af9/six_1623709665295/work
soupsieve==2.2.1
-e git+https://github.itap.purdue.edu/MintonGroup/swiftest.git@19f9e7d0b735f38b5b2e0f5d21fe9b4fb2b79838#egg=swiftest&subdirectory=python/swiftest
terminado==0.9.4
testpath @ file:///home/ktietz/src/ci/testpath_1611930608132/work
tornado @ file:///tmp/build/80754af9/tornado_1606942283357/work
traitlets @ file:///home/ktietz/src/ci/traitlets_1611929699868/work
typing-extensions==3.10.0.0
urllib3==1.26.5
wcwidth @ file:///tmp/build/80754af9/wcwidth_1593447189090/work
webencodings==0.5.1
widgetsnbextension==3.5.1
xarray==0.18.2
zipp @ file:///tmp/build/80754af9/zipp_1615904174917/work
Loading

0 comments on commit bbd5bc1

Please sign in to comment.