icecube.dataio
– python bindings to Data I/O utilities¶
- class icecube.dataio.I3File
Simple sequential reader/writer of
.i3
files.- frameno
The current frame number. Read-only member.
- mode
Used to indicate the mode with which to open a file. Possible values are
Write/Append
,Write/Create
,Write/Truncate
, andRead
. Read-only parameter.
- path
Path to the file. Read-only member.
- size
Size of the file in frames. Does not include unread frames. Read-only member.
- stream
Indicates the
Stream
type, also called a Stop. Possible values includeI3Frame::None
,I3Frame::Geometry
,I3Frame::Calibration
,I3Frame::DetectorStatus
,I3Frame::Simulation
,I3Frame::DAQ
,I3Frame::Physics
, andI3Frame::TrayInfo
. Read-only parameter.
- type
Used to indicate the type of file. Possible values are
Closed
,Stream
,Empty
, andFile
. Read-only parameter.
- close()
Close the file.
- get_current_frame_and_deps()
Gets the current frame, and the frames it depends on. Returns a list of I3Frames [parent … current].
- get_mixed_frames()
Gets the frames that the current frame depends on. Returns a list of I3Frames.
- more()
Returns true if there are more frames available. This prints all the event ids in a file:
i3f = I3File("mydata.i3") while i3f.more(): phys = i3f.pop_frame() print phys['I3EventHeader'].EventID
You can also use the iterator interface rather than writing an explicit loop.
- pop_daq()
Shorthand for:
pop_frame(icetray.I3Frame.DAQ)
- pop_frame()
Return the next frame of any type from the file:
frame = i3file.pop_frame() print frame
- pop_frame(stream)
Return the next frame of with stream type stream from the file:
frame = i3file.pop_frame(icetray.I3Frame.Geometry) print frame
- pop_physics()
Shorthand for:
pop_frame(icetray.I3Frame.Physics)
- push(frame)
Push frame onto file (file must be open for writing):
frame = icetray.I3Frame(icetray.I3Frame.Physics) i3file = I3File("generated.i3.gz", I3File.Writing) i3file.push(frame)
- rewind()
Close and reopen the file to the beginning.
- seek(frame_number)
Seek to specific frame number.
- I3File()
Create an I3File object w/o an actual associated file:
# not very useful f = I3File()
- I3File(path, mode=I3File.Reading)
Create an I3File, then call:
self.open_file(path, mode)
- __iter__()
Return an iterator to the I3File of type I3FileIterator, which supports standard python iteration. This means you can use the I3File in looping contexts:
i3f = I3File("mydata.i3") for frame in i3f: print frame
or minus the intermediate variable
i3f
:for frame in I3File('mydata.i3'): print frame
and list comprehensions. For instance this gets the EventID of all physics frames in the file
mydata.i3
:eventids = [frame['I3EventHeader'].EventId for frame in I3File('mydata.i3') if frame.GetStop() == icetray.I3Frame.Physics]
- __len__()
Returns the size of the I3File in number of frames.
- __exit__()
Exit context and close I3File
- __enter__()
Enter context and open I3File
- class icecube.dataio.I3FileIterator
Simple iterator for the frames contained in an I3File
- __next__()
Same as next()
- next()
Returns the next frame, if available, else throws StopIteration. This is part of the python ‘iterator protocol’; this function gets you iteration in loops and list comprehensions (see __iter__() above):
- __iter__()
Return an iterator to the I3File of type I3FileIterator, which supports standard python iteration. This means you can use the I3File in looping contexts:
i3f = I3File("mydata.i3") for frame in i3f: print frame
or minus the intermediate variable
i3f
:for frame in I3File('mydata.i3'): print frame
and list comprehensions. For instance this gets the EventID of all physics frames in the file
mydata.i3
:eventids = [frame['I3EventHeader'].EventId for frame in I3File('mydata.i3') if frame.GetStop() == icetray.I3Frame.Physics]
- class icecube.dataio.I3FileStager
A base class interface for staging files to local storage from remote locations
This class is supposed to handle copying files to local storage for reading, and copying local files to remote storage for writing.
- ReadSchemes()
Returns the URI scheme this stager can read. (i.e. the in a URL before the colon, e.g. “http”, “ftp”, “gsiftp”, …)
- WriteSchemes()
Returns the URI scheme this stager can write
- CanStageIn(url)
Returns True if url matches any of the URI schemes this stager can read
- CanStageOut()
Returns True if url matches any of the URI schemes this stager can write
- GetReadablePath()
Returns a readable local file handle for a remote URI
- GetWriteablePath()
Returns a writeable local file handle for a remote URI
- class icecube.dataio.I3FileStagerCollection
A subclass of I3FileStager for staging multiple files
- __init__(pointer)
Initializes an instance of I3FileStagerCollection from an I3FileStagerCollectionPointer
- class icecube.dataio.I3TrivialFileStager
A subclass of I3FileStager with no remote capability
- __init__(pointer)
Initializes an instance of I3TrivialFileStager from an I3TrivialFileStagerPointer
- class icecube.dataio.I3FrameSequence
A class to easily access multiple I3Files as if they were one large sequence of frames. Only supports read access.
- __init__()¶
- __init__(frame_sequence)
Copy constructor
- __init__(file_names, cache_size)
Create and open an I3FrameSequence
- close()
Close the files
- add_file(file_name)
Add a file
- close_last_file()
Close the last file
- more()
Test if there is another frame
- rewind()
Return to the beginning of the sequence of files/frames.
- pop_daq()
Return the next DAQ frame from the file, skipping frames on other streams.
- pop_physics()
Return the next physics frame from the file, skipping frames on other streams.
- seek(number)
Seek to a specific frame number
- get_mixed_frames()
Returns the frames that are mixed into the current frame.
- paths
Contains the paths to the files in the frame sequence
- frameno
Contains the next frame number
- size
Contains the total number of frames across all files in the I3FrameSequence
- cur_size
Contains the current size of the frame sequence