imaginglss.utils.filehandler module¶
Python code to read and write “filehander files”, which are simply directories with files in them for each “keyword”.
-
imaginglss.utils.filehandler.
format_filename
(key, data_or_dtype)[source]¶ Generate a filename from base name for data
Parameters: data_or_dtype : array_like or dtype
Must be 1d or 2d array. For 2d array, the shape of the last dimension is used as the size of the vector. Or a dtype with shape
key: string
key
Returns: filename : string
key.vectorsize.datatype
-
imaginglss.utils.filehandler.
parse_filename
(filename)[source]¶ parse a single file name
Parameters: filename : string
filename
Returns: key: string
key of the
dtype: dtype
dtype
-
imaginglss.utils.filehandler.
read
(fname, keys=None, offset=0, count=None)[source]¶ Reads a specificed list of “keys” in a “file” of name fname.
Parameters: fname : string
location to look for the data columns
keys : list or None
list of the keys; all if keys==None.
offset : int
offset to start reading, in unit of items
count : int
total number to read. None for read to the end of the file
Returns: data : dict
a dictionary of NumPy arrays.
Notes
Does minimal checking, assuming you know what you’re doing. The on-disk representation is always in ‘<’. We swap native endianness, on the fly if it differ from the native endianness.
-
imaginglss.utils.filehandler.
write
(fname, data, mode='w', offset=None)[source]¶ Writes the dictionary, data, which is meant to contain only NumPy arrays, to a “file” of name fname. The file is always written with ‘<’ endian.
Parameters: fname : string
location where the files will be written
data : dict alike
key and array pairs. Each item must be a numerical numpy array
mode : string
‘w’ for writing or ‘a’ for appending, or ‘r+’ for writing at offset.
offset : int or None
if the mode is ‘r+’, offset in a file for the write operation, in units of items. None to append to the end.
Notes
Does minimal checking, assuming you know what you’re doing.