Skip to content

Commit

Permalink
New keyword for saving methods
Browse files Browse the repository at this point in the history
  • Loading branch information
ayshih committed Nov 29, 2016
1 parent 713d9d2 commit 39d32d0
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
26 changes: 20 additions & 6 deletions gripspy/science/bgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def append(self, other):
self.clock_source = np.hstack([self.clock_source, other.clock_source])
self.clock_synced = np.hstack([self.clock_synced, other.clock_synced])

def save(self, save_file=None):
def save(self, save_file=None, use_current_directory=False):
"""Save the parsed data for future reloading.
The data is stored in gzip-compressed binary pickle format.
Expand All @@ -121,14 +121,21 @@ def save(self, save_file=None):
The name of the save file to create. If none is provided, the default is the name of
the telemetry file with the extension ".bgoe.pgz" appended if a single telemetry file
is the source.
use_current_directory : bool
If True, remove any directory specification from `save_file`
"""
if save_file is None:
if type(self.filename) == str:
save_file = self.filename + ".bgoe.pgz"
to_save = self.filename + ".bgoe.pgz"
else:
raise RuntimeError("The name for the save file needs to be explicitly specified here")
else:
to_save = save_file

if use_current_directory:
to_save = os.path.basename(to_save)

with gzip.open(save_file, 'wb') as f:
with gzip.open(to_save, 'wb') as f:
pickle.dump({'filename' : self.filename,
'event_time' : self.event_time,
'channel' : self.channel,
Expand Down Expand Up @@ -257,7 +264,7 @@ def append(self, other):
self.channel_count = np.vstack([self.channel_count, other.channel_count])
self.veto_count = np.hstack([self.veto_count, other.veto_count])

def save(self, save_file=None):
def save(self, save_file=None, use_current_directory=False):
"""Save the parsed data for future reloading.
The data is stored in gzip-compressed binary pickle format.
Expand All @@ -267,14 +274,21 @@ def save(self, save_file=None):
The name of the save file to create. If none is provided, the default is the name of
the telemetry file with the extension ".bgoc.pgz" appended if a single telemetry file
is the source.
use_current_directory : bool
If True, remove any directory specification from `save_file`
"""
if save_file is None:
if type(self.filename) == str:
save_file = self.filename + ".bgoc.pgz"
to_save = self.filename + ".bgoc.pgz"
else:
raise RuntimeError("The name for the save file needs to be explicitly specified here")
else:
to_save = save_file

if use_current_directory:
to_save = os.path.basename(to_save)

with gzip.open(save_file, 'wb') as f:
with gzip.open(to_save, 'wb') as f:
pickle.dump({'filename' : self.filename,
'counter_time' : self.counter_time,
'total_livetime' : self.total_livetime,
Expand Down
14 changes: 10 additions & 4 deletions gripspy/science/ge.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def append(self, other):

self._process_single_triggers()

def save(self, save_file=None):
def save(self, save_file=None, use_current_directory=False):
"""Save the parsed data for future reloading.
The data is stored in gzip-compressed binary pickle format.
Expand All @@ -131,15 +131,21 @@ def save(self, save_file=None):
The name of the save file to create. If none is provided, the default is the name of
the telemetry file with the extension ".ge?.pgz" appended if a single telemetry file
is the source.
use_current_directory : bool
If True, remove any directory specification from `save_file`
"""
if save_file is None:
if type(self.filename) == str:
save_file = self.filename + ".ge{0}.pgz".format(self.detector)
to_save = self.filename + ".ge{0}.pgz".format(self.detector)
else:
raise RuntimeError("The name for the save file needs to be explicitly specified here")
else:
to_save = save_file

if use_current_directory:
to_save = os.path.basename(to_save)

with gzip.open(save_file, 'wb') as f:
with gzip.open(to_save, 'wb') as f:
pickle.dump({'filename' : self.filename,
'adc' : self.adc,
'cms' : self.cms,
Expand Down

0 comments on commit 39d32d0

Please sign in to comment.