Skip to content

Commit

Permalink
black formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
armantekinalp committed Oct 31, 2020
1 parent a72cce9 commit e9e4d9a
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 46 deletions.
2 changes: 1 addition & 1 deletion elastica/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
try:
import numba

if 'IMPORT_TEST_NUMPY' in os.environ:
if "IMPORT_TEST_NUMPY" in os.environ:
# This is used to test if numpy version of classes can be imported.
raise ImportError

Expand Down
2 changes: 0 additions & 2 deletions elastica/_elastica_numba/_timestepper/_explicit_steppers.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,3 @@ def _first_stage(self, System, Memory, time, dt):
def _first_update(self, System, Memory, time, dt):
System.state += dt * System(time, dt)
return time + dt


2 changes: 0 additions & 2 deletions elastica/timestepper/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,3 @@
extend_stepper_interface,
integrate,
)


1 change: 0 additions & 1 deletion elastica/timestepper/explicit_steppers.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,6 @@ def n_stages(self):
)



class StatefulRungeKutta4(_StatefulStepper):
"""
Stores all states of Rk within the time-stepper. Works as long as the states
Expand Down
2 changes: 0 additions & 2 deletions elastica/timestepper/symplectic_steppers.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,5 +200,3 @@ def n_stages(self):
PositionVerlet,
PEFRL,
)


Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ class SnakeSimulator(BaseSystemCollection, Constraints, Forcing, CallBacks):
pass


def run_snake(
b_coeff, SAVE_RESULTS=False
):
def run_snake(b_coeff, SAVE_RESULTS=False):

snake_sim = SnakeSimulator()

Expand Down Expand Up @@ -153,8 +151,6 @@ def make_callback(self, system, time, current_step: int):
t_coeff_optimized = np.array([17.4, 48.5, 5.4, 14.7, 0.97])

# run the simulation
pp_list = run_snake(
t_coeff_optimized, SAVE_RESULTS
)
pp_list = run_snake(t_coeff_optimized, SAVE_RESULTS)

print("Datafile Created")
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@
location=[15.0, 10.5, -15.0],
angle=30,
look_at=[4.0, 2.7, 2.0],
name='diag'
name="diag",
)
stages.add_camera(
# Add top viewpoint
location=[0, 15, 3],
angle=30,
look_at=[0.0, 0, 3],
sky=[-1, 0, 0],
name='top'
name="top",
)
stages.add_light(
# Sun light
position=[1500, 2500, -1000],
color='White',
color="White",
camera_id=-1,
)
stages.add_light(
Expand All @@ -75,7 +75,7 @@
# Externally Including Files (USER DEFINE)
# If user wants to include other POVray objects such as grid or coordinate axes,
# objects can be defined externally and included separately.
included = ['../default.inc']
included = ["../default.inc"]

# Multiprocessing Configuration (USER DEFINE)
MULTIPROCESSING = True
Expand Down Expand Up @@ -122,10 +122,10 @@
# Rendering
# For each frame, a 'pov' script file is generated in OUTPUT_IMAGE_DIR directory.
batch = []
for view_name in stage_scripts.keys(): # Make Directory
for view_name in stage_scripts.keys(): # Make Directory
output_path = os.path.join(OUTPUT_IMAGES_DIR, view_name)
os.makedirs(output_path, exist_ok=True)
for frame_number in tqdm(range(total_frame), desc='Scripting'):
for frame_number in tqdm(range(total_frame), desc="Scripting"):
for view_name, stage_script in stage_scripts.items():
output_path = os.path.join(OUTPUT_IMAGES_DIR, view_name)

Expand All @@ -139,31 +139,31 @@
rod_object = pyelastica_rod(
x=xs[frame_number],
r=base_radius[frame_number],
color='rgb<0.45,0.39,1>'
color="rgb<0.45,0.39,1>",
)
script.append(rod_object)
pov_script = "\n".join(script)

# Write .pov script file
file_path = os.path.join(output_path, "frame_{:04d}".format(frame_number))
with open(file_path+'.pov', "w+") as f:
with open(file_path + ".pov", "w+") as f:
f.write(pov_script)
batch.append(file_path)

# Process POVray
# For each frames, a 'png' image file is generated in OUTPUT_IMAGE_DIR directory.
pbar = tqdm(total=len(batch), desc='Rendering') # Progress Bar
pbar = tqdm(total=len(batch), desc="Rendering") # Progress Bar
if MULTIPROCESSING:
func = partial(
render,
width=WIDTH,
height=HEIGHT,
display=DISPLAY_FRAMES,
pov_thread=THREAD_PER_AGENT
)
render,
width=WIDTH,
height=HEIGHT,
display=DISPLAY_FRAMES,
pov_thread=THREAD_PER_AGENT,
)
with Pool(NUM_AGENT) as p:
for message in p.imap_unordered(func, batch):
#(TODO) POVray error within child process could be an issue
# (TODO) POVray error within child process could be an issue
pbar.update()
else:
for filename in batch:
Expand All @@ -172,16 +172,19 @@
width=WIDTH,
height=HEIGHT,
display=DISPLAY_FRAMES,
pov_thread=multiprocessing.cpu_count()
pov_thread=multiprocessing.cpu_count(),
)
pbar.update()

# Create Video using moviepy
for view_name in stage_scripts.keys():
imageset_path = os.path.join(OUTPUT_IMAGES_DIR, view_name)
imageset = [os.path.join(imageset_path, path)
for path in os.listdir(imageset_path) if path[-3:]=='png']
imageset = [
os.path.join(imageset_path, path)
for path in os.listdir(imageset_path)
if path[-3:] == "png"
]
imageset.sort()
filename = OUTPUT_FILENAME + '_' + view_name + '.mp4'
filename = OUTPUT_FILENAME + "_" + view_name + ".mp4"
clip = ImageSequenceClip(imageset, fps=FPS)
clip.write_videofile(filename, fps=FPS)
18 changes: 6 additions & 12 deletions examples/Visualization/_povmacros.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
def pyelastica_rod(
x,
r,
color='rgb<0.45,0.39,1>',
color="rgb<0.45,0.39,1>",
transmit=0.0,
interpolation="linear_spline",
deform=None,
Expand Down Expand Up @@ -73,13 +73,7 @@ def pyelastica_rod(


def render(
filename,
width,
height,
antialias="on",
quality=11,
display="Off",
pov_thread=4
filename, width, height, antialias="on", quality=11, display="Off", pov_thread=4
):
"""Rendering frame
Expand Down Expand Up @@ -115,8 +109,8 @@ def render(
"""

# Define script path and image path
script_file = filename + '.pov'
image_file = filename + '.png'
script_file = filename + ".pov"
image_file = filename + ".png"

# Run Povray as subprocess
cmds = [
Expand All @@ -128,7 +122,7 @@ def render(
f"Work_Threads={pov_thread}",
f"Antialias={antialias}",
f"Quality={quality}",
f"Display={display}"
f"Display={display}",
]
process = subprocess.Popen(
cmds, stderr=subprocess.PIPE, stdin=subprocess.PIPE, stdout=subprocess.PIPE
Expand Down Expand Up @@ -266,7 +260,7 @@ class StageObject:
"""

def __init__(self):
self.str = ''
self.str = ""
self.update_script()

def update_script(self):
Expand Down

0 comments on commit e9e4d9a

Please sign in to comment.