Skip to content

Added an [-x FILE] option to igorpackedexperiment.py. #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bin/igorpackedexperiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,12 @@ def _run(self, args):
f.close()
if args.verbose > 0:
pprint.pprint(filesystem)
walk(filesystem, self._plot_wave_callback)
walk(filesystem, self._plot_wave_and_execute_callback)

def _plot_wave_callback(self, dirpath, key, value):
def _plot_wave_and_execute_callback(self, dirpath, key, value):
if isinstance(value, WaveRecord):
self.plot_wave(self.args, value.wave, title=dirpath + [key])
self.execute(self.args, value.wave, dirpath + [key])


s = PackedScript(
Expand Down
16 changes: 16 additions & 0 deletions igor/script.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ def __init__(self, description=None, filetype='IGOR Binary Wave (.ibw) file'):
self.parser.add_argument(
'-V', '--verbose', action='count', default=0,
help='increment verbosity')
self.parser.add_argument(
'-x', '--execute', metavar='FILE', default='-',
help=('Path to a custom Python script, which will be executed on '
'every wave file. The script can access the wave and the '
'corresponding path through the global variables wave and '
'dirpath.')
)
self._num_plots = 0

def run(self, *args, **kwargs):
Expand Down Expand Up @@ -86,6 +93,15 @@ def plot_wave(self, args, wave, title=None):
pass
self._num_plots += 1

def execute(self, args, wave, dirpath):
if args.execute == '-':
return # no-op
try:
exec(open(args.execute).read(), {"wave": wave, "dirpath": dirpath})
except Exception as e:
_LOG.error('error executing on wave {} {}'.format(dirpath, e))
raise

def display_plots(self):
if self._num_plots:
_matplotlib_pyplot.show()