Skip to content
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

Feature/reduce recording #297

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2dd4c67
initial work on reduce recording for interactive save/restore
Aug 23, 2021
38c559c
updates for wavecal/fit1d interactive record/replay
Aug 24, 2021
886ce15
code commenting for record/replay functionality
Aug 24, 2021
386ea45
Apertures interactive record/load functionality
Aug 25, 2021
5cde230
more fixes to record/restore logic and side effects in the turbo tabs
Aug 25, 2021
ea0530e
added mask encoding/decoding simple version to compress the json a bit
Aug 26, 2021
5e6a07b
Stop replaying saved values if a user modifies one of the interactive…
Aug 30, 2021
67f2b4a
detect changes during replay, alert user and continue without the fur…
Aug 31, 2021
e47b5c2
record/replay via .fits file output, different unique suffix for outp…
Sep 1, 2021
e21e994
manually checking for --replay so I can support a .fits argument
Sep 1, 2021
cc17e34
switching to hasattr for record field check
Sep 1, 2021
09a2a57
layered in None check for record
Sep 1, 2021
c2399fa
consolidating if, trying to trigger Jenkins tests
Sep 2, 2021
194f5a9
merging in latest from master
Oct 28, 2021
c4acf75
Merge branch 'master' into feature/reduce_recording
Dec 17, 2021
4ca2a8f
merging latest from master
Feb 12, 2022
f70d789
Merge branch 'master' into feature/reduce_recording
Mar 30, 2022
ff3b1a9
adding docs for record/replay
Mar 31, 2022
8264576
Merge branch 'master' into feature/reduce_recording
Apr 11, 2022
bd76980
properly strip datalab extension that contain a number like -QL-2D. …
KathleenLabrie May 2, 2022
e878ec3
Merge branch 'master' of github.com:GeminiDRSoftware/DRAGONS
May 20, 2022
ae3ef6b
Revert "properly strip datalab extension that contain a number like -…
May 20, 2022
4cd13e2
Merge branch 'master' of github.com:GeminiDRSoftware/DRAGONS
May 23, 2022
33a4107
Merge branch 'master' of github.com:GeminiDRSoftware/DRAGONS
May 23, 2022
f807c36
Merge branch 'master' of github.com:GeminiDRSoftware/DRAGONS
May 31, 2022
a83a8e2
Merge branch 'master' into feature/reduce_recording
May 31, 2022
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
Prev Previous commit
Next Next commit
code commenting for record/replay functionality
  • Loading branch information
Oliver committed Aug 24, 2021
commit 886ce15f368b50b3bba16482bbec939009e69f64
22 changes: 22 additions & 0 deletions geminidr/interactive/fit/fit1d.py
Original file line number Diff line number Diff line change
@@ -1039,12 +1039,34 @@ def _point_mask_handler(self, x, y, mult, action):
self.model.perform_fit()

def record(self):
"""
Record the state of this tab into a dictionary.

This call returns a dictionary representation of the state of this tab interface.
This dictionary can be sent back in to the :meth:`load` method to restore the state
at a later time.

Returns
-------
dict : Dictionary describing the state of the user interface
"""
return {
"mask": self.model.data.data['mask'],
"params": self.model.fit.extract_params()
}

def load(self, record):
"""
Load the state of this tab from a dictionary.

This call loads the state of the interface tab from a previously saved dictionary
from :meth:`record`.

Parameters
----------
record : dict
Dictionary of saved state from :meth:`record`
"""
self.model.data.data['mask'] = record["mask"]
if "regions" in record["params"]:
region_tuples = cartesian_regions_to_slices(record["params"]["regions"])
52 changes: 52 additions & 0 deletions recipe_system/utils/reduce_recorder.py
Original file line number Diff line number Diff line change
@@ -18,6 +18,17 @@


def init_reduce_recorder(filename):
"""
Setup the reduce job to record interactive parameters to the named file.

This call sets up the reduce job to save each interactive session to a
json file for future reuse.

Parameters
----------
filename : str
Name of the file to save the state in
"""
global reduce_recorder
global reduce_filename
reduce_recorder = {
@@ -29,19 +40,47 @@ def init_reduce_recorder(filename):


def record_interactive(record):
"""
Add a json record to the record to be saved for this reduce job.

This call takes a single dictionary of state representing the current interactive
tool's state and adds it to the set to be saved for this session overall.

Parameters
----------
record : dict
Dictionary describing the state of the current interactive tool
"""
global reduce_recorder
if reduce_recorder is not None:
reduce_recorder["interactive"].append(record)


def record_reduction():
"""
Save a record of this reduction session to the json file.

This call writes all of the information needed for this reduce session,
including the interactive tools, to a json file.
"""
if reduce_recorder is not None:
with open(reduce_filename, 'w') as reduce_file:
output = json.dumps(reduce_recorder, indent=4)
reduce_file.write(f"{output}")


def load_reduce_record(filename):
"""
Load the reduce session from the given save file.

This call opens a previously saved reduce session from a json file
and prepares it for use by the current reduce.

Parameters
----------
filename : str
Name of the json file to read
"""
with open(filename, 'r') as record_file:
global replay_record
replay_record = json.loads(record_file.read())
@@ -52,6 +91,19 @@ def load_reduce_record(filename):


def load_replay_interactive_settings(visualizer):
"""
Load the current interactive tool state from the record.

This call initializes an interactive tool based on the current
step in the loaded json file. Each time an interface is loaded,
the system advances to the next saved interactive state to use for
the next tool.

Parameters
----------
visualizer : :class:`~geminidr.interactive.PrimitiveVisualizer`
visualizer to be initialized
"""
global replay_step
if replay_record and replay_step < len(replay_record["interactive"]):
retval = replay_record["interactive"][replay_step]