pyjacket.filetools

class pyjacket.filetools.FileManager(src_root: str = None, dst_root: str = None, rel_path: str = '', base: str = '', CSV_SEP: str = ';')[source]

Bases: object

Make it easy to read/write files

abs_path(dst: bool, filename: str = '', folder: str = '')[source]
delete(filename: str, folder: str = '', dst: bool = True, verbose=True)[source]
property dst_folder
dst_path(filename: str = '', folder: str = '')[source]

Absolute path to a file in the dst directory

static ensure_endswith(s: str, extension: str, **kwargs)[source]
static ensure_exists(path: str, verbose=True, **kwargs)[source]
exists(filename: str, folder: str = '', dst: bool = False)[source]
static explode(path: str, sep='/', **kwargs)[source]
static handle_extension(filename: str, valid_extensions: list, **kwargs)[source]
iter_dir(folder: str = '', ext: str = None, dst=False, nat=True, exclude: set = None, **kwargs)[source]

Obtain files/folders in the <root>/<rel_path>/<folder>

ext: types of files to return
  • None: yield all file types

  • ‘/’: yield directories only

  • ‘.png’: yield only png.

list_dir(folder='', ext: str = None, dst=False, nat=True, exclude: set = None, **kwargs)[source]
read(filename: str, *args, folder: str = '', dst: bool = False, **kwargs)[source]

Read files of a standard format such as .txt

read_before(filename: str, folder: str, dst: bool, valid_extensions: list)[source]

Prepare the filepath for reading a file

filename: str

folder: str

dst: bool

valid_extensions: list

the first element of this list will be used as default.

read_csv(filename: str, folder: str = '', dst: bool = False, **kwargs) DataFrame[source]

Read csv data into a pandas dataframe

read_img(filename: str, folder='', dst=False, **kwargs)[source]

Read image data into a numpy.ndarray of shape: (frames, t, y, x, channels)

read_img_meta(filename: str, folder='', dst_folder=False)[source]

Get the Exif (meta)data for an image file. This contains various acquisition details such as exposure time

read_json(filename: str, folder='', dst=False, **kwargs)[source]
read_pickle(filename: str, folder: str = '', dst: bool = False, **kwargs)[source]

Read a python object from a pickle file.

dst_folder: bool

read a file in the dst path rather than the src path

read_txt(filename: str, folder: str = '', dst=False, **kwargs)[source]
savefig(filename, handle=None, folder='', close=True, **kwargs)[source]

Called ‘save’ rather than ‘write’ because the original data cannot be retrieved from the file.

property src_folder
src_path(filename: str = '', folder: str = '')[source]

Absolute path to a file in the src directory

walk(folder: str = '', ext: str = None, depth: int = None, dst=False, **kwargs)[source]
write(filename: str, data: Writeable, *args, folder: str = '', **kwargs)[source]

Writes any object that implements a write function

write_after(filepath)[source]

write_before(filename: str, folder: str, valid_extensions: list)[source]

Finds the absolute path and creates folders when necessary

write_csv(filename: str, data: DataFrame, folder: str = '', **kwargs)[source]

Save a csv data to a csv file

write_img(filename: str, data: ndarray, folder: str = '', **kwargs)[source]

Write numpy.ndarray data to img file format

TODO: allow log scale display

write_json(filename: str, data: dict, folder: str = '', **kwargs)[source]
write_pickle(filename: str, data: object, *args, folder: str = '', **kwargs)[source]

Write a python object to a pickle file.

write_txt(filename: str, data: dict, folder: str = '', mode='a+', **kwargs)[source]