Skip to content

Instantly share code, notes, and snippets.

@pordyna
Last active June 13, 2023 09:17
Show Gist options
  • Select an option

  • Save pordyna/2c0afec7207260e46ca32ceb60fba0df to your computer and use it in GitHub Desktop.

Select an option

Save pordyna/2c0afec7207260e46ca32ceb60fba0df to your computer and use it in GitHub Desktop.
import ipywidgets as widgets
import openpmd_api as io
from pint import UnitRegistry
ureg = UnitRegistry()
class IterationSlider:
def __init__(self, series):
iterations = list(series.iterations)
times = [series.iterations[it].time_unit_SI
* series.iterations[it].time for it in iterations]
times *= ureg.second
# print iteration index with time in a compact unit
# (choose automaticaly between s,ps,fs,...)
# with 6 significant digits
options = [(f"{it}: {time.to_compact():.6g~P}", (it, time))
for it, time in zip(iterations, times)]
selection_range_slider = widgets.SelectionSlider(
options=options,
description='Iterations',
orientation='horizontal',
layout={'width': '500px'})
def get_iteration(it):
return it
self.slider = widgets.interactive(
get_iteration,
it=selection_range_slider)
self.times = times
@property
def iteration_index(self):
return self.slider.result[0]
@property
def time(self):
return self.slider.result[1]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment