-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add gcp.ARCFile class analogous to core.G3File (#74)
Optional `extract` keyword argument to also run `gcp.ARCExtract` on each frame. Also, add a `core.InjectFrame` utility function for injecting arbitrary frames into a pipeline, used with `ARCFile(..., extract=True)`.
- Loading branch information
Showing
3 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from spt3g.gcp import ARCFileReader, ARCExtract | ||
|
||
class ARCFile(object): | ||
'''Iterable class for ARC files, as created by GCP. Loop through frames by doing something like: | ||
f = gcp.ARCFile('/path/to/arc.dat') | ||
for frame in f: | ||
print( frame ) | ||
An entire file can also be read into an indexable list by doing: | ||
f = list(gcp.ARCFile('/path/to/arc.dat')) | ||
''' | ||
def __init__(self, path, extract=False): | ||
self.reader = ARCFileReader(path) | ||
self.extract = extract | ||
|
||
def __iter__(self): | ||
return self | ||
|
||
def next(self): | ||
frames = self.reader.Process(None) | ||
if len(frames) == 0: | ||
raise StopIteration('No more frames in file') | ||
if len(frames) > 1: | ||
raise ValueError('Too many frames returned by reader') | ||
frame = frames[0] | ||
|
||
if self.extract: | ||
# calibrate and parse arc frames | ||
from spt3g.core import G3Pipeline, G3InfiniteSource, InjectFrame | ||
|
||
pipe = G3Pipeline() | ||
pipe.Add(G3InfiniteSource, n=1) | ||
pipe.Add(InjectFrame, frame=frame) | ||
pipe.Add(ARCExtract) | ||
pipe.Run() | ||
|
||
return frame | ||
|
||
__next__ = next |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters