gridlib.io package

Subpackages

Submodules

gridlib.io.fit_results module

Module with functions to read and write fit results.

gridlib.io.fit_results.read_data_grid_resampling(path: str) Tuple[Dict[str, Union[ndarray, float]], List[Dict[str, Union[ndarray, float]]]][source]

Function loads and parses the resampling data from GRID.

Parameters

path (str) – Path to the file with all the resampling data

Returns

  • fit_result_full (Dict[str, Union[np.ndarray, float]]) –

    Dictionary with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: final cost value

  • fit_results_resampled (List[Dict[str, Union[np.ndarray, float]]]) –

    List of dictionaries with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: final cost value

    Every dictionary entry in the list contains the results of one data resample.

gridlib.io.fit_results.read_data_grid_resampling_trackit(path: str) Tuple[Dict[str, Union[ndarray, float]], List[Dict[str, Union[ndarray, float]]]][source]

Function loads and parses the resampling data from GRID.

Parameters

path (str) – Path to the file with all the resampling data

Returns

  • fit_result_full (Dict[str, Union[np.ndarray, float]]) –

    Dictionary with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: np.NaN (since this is not provided by TrackIt resampling data)

  • fit_results_resampled (List[Dict[str, Union[np.ndarray, float]]]) –

    List of dictionaries with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: np.NaN (since this is not provided by TrackIt resampling data)

    Every dictionary entry in the list contains the results of one data resample.

gridlib.io.fit_results.read_fit_results(path: Union[str, Path]) Dict[str, Dict[str, Union[ndarray, float]]][source]

Function reads the fit results from a .mat file.

Parameters

path (Union[str, pathlib.Path]) – The file path to read the fit results from.

Returns

fit_results – A dictionary containing the fit results, where the keys are the names of the fit results and the values are dictionaries. The dictionaries have keys ‘grid’ or f”{n}-exp”, where n is the number of exponentials, and values that are either numpy arrays or floats.

Return type

Dict[str, Dict[str, Union[np.ndarray, float]]]

Examples

>>> fit_results = read_fit_results("/path/to/file.mat")
>>> {'grid': {'k': np.array([1.0e-03, ..., 10.0]), 's': np.array([1.000e-03, ..., 2.500e-03]), 'a': 0.022, 'loss': 0.0047}, '1-exp': {'k': array([0.02563639]), 's': array([1.]), 'a': 0.08514936433699753, 'loss': 1.2825570522448484}}
gridlib.io.fit_results.read_fit_results_trackit(path: Union[str, Path]) Dict[str, Dict[str, Union[ndarray, float]]][source]

Function loads and parses the fit results from the original GRID package, which saves the data in a different data structure, so hence there is some extra parsing involved.

gridlib.io.fit_results.write_data_grid_resampling(path: Union[str, Path], fit_result_full: Tuple[Dict[str, Union[ndarray, float]]], fit_results_resampled: List[Dict[str, Union[ndarray, float]]])[source]

Function writes the resampling results to a .mat file.

gridlib.io.fit_results.write_fit_results(path: Union[str, Path], fit_results: Dict[str, Dict[str, Union[ndarray, float]]]) None[source]

Write fit results to a .mat file.

Parameters
  • path (Union[str, pathlib.Path]) – The file path to write the fit results to.

  • fit_results (Dict[str, Dict[str, Union[np.ndarray, float]]]) – A dictionary containing the fit results, where the keys are the names of the fit results and the values are dictionaries. The dictionaries have keys ‘grid’ or f”{n}-exp”, where n is the number of exponentials, and values that are either numpy arrays or floats.

Return type

None

Examples

>>> fit_results = {'grid': {'k': np.array([1.0e-03, ..., 10.0]),
... 's': np.array([1.000e-03, ..., 2.500e-03]), 'a': 0.022, 'loss': 0.0047},
... '1-exp': {'k': array([0.02563639]), 's': array([1.]), 'a': 0.08514936433699753,
... 'loss': 1.2825570522448484}}
>>> write_fit_results("/path/to/file.mat", fit_results)

Fit results are saved in “/path/to/file.mat”.

gridlib.io.survival_function module

gridlib.io.survival_function.read_data_survival_function(path: Union[str, Path]) Dict[str, Dict[str, ndarray]][source]

Function reads survival function from csv file.

Parameters

path (str or pathlib.Path) – Path to the location of the .csv file containing the survival time distributions.

Returns

data – Data of the survival function to write to a csv file. The dictionary structure is as follows: {

f”{t_tl}”: {

“time”: np.ndarray with the time points, “value”: np.ndarray with the survival function values,

}

}

Return type

Dict[str, Dict[str, np.ndarray]]

Raises
  • ValueError – If the path suffix does not end with .csv

  • FileNotFoundError – If the file is not present at path.

Notes

The .csv file with the surivival time distributions should look like this (without the header):

time-lapse 1, value, time-lapse 2, value, …

Delta t_1,f1(Delta t_1), Delta t_2, f2(Delta t_2)

2*Delta t_1,f1(2*Delta t_1), 2*Delta t_2, f2(2*Delta t_2)

3*Delta t_1,f1(3*Delta t_1), 3*Delta t_2, f2(3*Delta t_2)

…, …, …, …

gridlib.io.survival_function.write_data_survival_function(path: Union[str, Path], data: Dict[str, Dict[str, ndarray]])[source]

Function writes the survival function data to a csv file.

Parameters
  • path (str or pathlib.Path) – Path to the location of the file, where to save to. If the file does not exist, it will be created.

  • data (Dict[str, Dict[str, np.ndarray]]) –

    Data of the survival function to write to a csv file. The dictionary structure is as follows: {

    f”{t_tl}”: {

    “time”: np.ndarray with the time points, “value”: np.ndarray with the survival function values,

    }

    }

Return type

None

Raises

ValueError – If the path suffix does not end with .csv

Notes

The .csv file with the survival time distributions will looks as follows (without the header):

time-lapse 1, value, time-lapse 2, value, …

Delta t_1,f1(Delta t_1), Delta t_2, f2(Delta t_2)

2*Delta t_1,f1(2*Delta t_1), 2*Delta t_2, f2(2*Delta t_2)

3*Delta t_1,f1(3*Delta t_1), 3*Delta t_2, f2(3*Delta t_2)

…, …, …, …

Module contents

gridlib.io.read_data_grid_resampling(path: str) Tuple[Dict[str, Union[ndarray, float]], List[Dict[str, Union[ndarray, float]]]][source]

Function loads and parses the resampling data from GRID.

Parameters

path (str) – Path to the file with all the resampling data

Returns

  • fit_result_full (Dict[str, Union[np.ndarray, float]]) –

    Dictionary with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: final cost value

  • fit_results_resampled (List[Dict[str, Union[np.ndarray, float]]]) –

    List of dictionaries with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: final cost value

    Every dictionary entry in the list contains the results of one data resample.

gridlib.io.read_data_grid_resampling_trackit(path: str) Tuple[Dict[str, Union[ndarray, float]], List[Dict[str, Union[ndarray, float]]]][source]

Function loads and parses the resampling data from GRID.

Parameters

path (str) – Path to the file with all the resampling data

Returns

  • fit_result_full (Dict[str, Union[np.ndarray, float]]) –

    Dictionary with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: np.NaN (since this is not provided by TrackIt resampling data)

  • fit_results_resampled (List[Dict[str, Union[np.ndarray, float]]]) –

    List of dictionaries with the following key-value pairs:

    ”k”: np.ndarray with the dissociation rates “s”: np.ndarray with the corresponding weights “a”: bleaching number (a = kb * t_int) “loss”: np.NaN (since this is not provided by TrackIt resampling data)

    Every dictionary entry in the list contains the results of one data resample.

gridlib.io.read_data_survival_function(path: Union[str, Path]) Dict[str, Dict[str, ndarray]][source]

Function reads survival function from csv file.

Parameters

path (str or pathlib.Path) – Path to the location of the .csv file containing the survival time distributions.

Returns

data – Data of the survival function to write to a csv file. The dictionary structure is as follows: {

f”{t_tl}”: {

“time”: np.ndarray with the time points, “value”: np.ndarray with the survival function values,

}

}

Return type

Dict[str, Dict[str, np.ndarray]]

Raises
  • ValueError – If the path suffix does not end with .csv

  • FileNotFoundError – If the file is not present at path.

Notes

The .csv file with the surivival time distributions should look like this (without the header):

time-lapse 1, value, time-lapse 2, value, …

Delta t_1,f1(Delta t_1), Delta t_2, f2(Delta t_2)

2*Delta t_1,f1(2*Delta t_1), 2*Delta t_2, f2(2*Delta t_2)

3*Delta t_1,f1(3*Delta t_1), 3*Delta t_2, f2(3*Delta t_2)

…, …, …, …

gridlib.io.read_fit_results(path: Union[str, Path]) Dict[str, Dict[str, Union[ndarray, float]]][source]

Function reads the fit results from a .mat file.

Parameters

path (Union[str, pathlib.Path]) – The file path to read the fit results from.

Returns

fit_results – A dictionary containing the fit results, where the keys are the names of the fit results and the values are dictionaries. The dictionaries have keys ‘grid’ or f”{n}-exp”, where n is the number of exponentials, and values that are either numpy arrays or floats.

Return type

Dict[str, Dict[str, Union[np.ndarray, float]]]

Examples

>>> fit_results = read_fit_results("/path/to/file.mat")
>>> {'grid': {'k': np.array([1.0e-03, ..., 10.0]), 's': np.array([1.000e-03, ..., 2.500e-03]), 'a': 0.022, 'loss': 0.0047}, '1-exp': {'k': array([0.02563639]), 's': array([1.]), 'a': 0.08514936433699753, 'loss': 1.2825570522448484}}
gridlib.io.read_fit_results_trackit(path: Union[str, Path]) Dict[str, Dict[str, Union[ndarray, float]]][source]

Function loads and parses the fit results from the original GRID package, which saves the data in a different data structure, so hence there is some extra parsing involved.

gridlib.io.read_track_file_csv(path: Union[str, Path]) List[Tuple][source]

Function reads track data from a .csv file that has the data format of track files created by the TrackIt framework and returns the data.

Parameters

path (str or pathlib.Path) – Path to the file with track information.

Returns

data – List with tuples, where every tuple contains the information of one part of a track. Every tuple has the following structure: (f, t, x, y, track_id, disp, intensity, sigma, fit_error).

f (int): frame number t (float): time x (float): x-coordinate in um y (float): y-coordinate in um track_id (int): id of the track disp (float): displacement in um between current localization of track and previous one.

The value is -1 if it is the first localization of the track.

intensity (float): TODO is from SOS sigma (float): TODO is from SOS fit_error (float): TODO is from SOS

Return type

list of tuples

Raises
  • ValueError – If the path suffix does not end with .csv

  • FileNotFoundError – If the file is not present at path.

gridlib.io.write_data_grid_resampling(path: Union[str, Path], fit_result_full: Tuple[Dict[str, Union[ndarray, float]]], fit_results_resampled: List[Dict[str, Union[ndarray, float]]])[source]

Function writes the resampling results to a .mat file.

gridlib.io.write_data_survival_function(path: Union[str, Path], data: Dict[str, Dict[str, ndarray]])[source]

Function writes the survival function data to a csv file.

Parameters
  • path (str or pathlib.Path) – Path to the location of the file, where to save to. If the file does not exist, it will be created.

  • data (Dict[str, Dict[str, np.ndarray]]) –

    Data of the survival function to write to a csv file. The dictionary structure is as follows: {

    f”{t_tl}”: {

    “time”: np.ndarray with the time points, “value”: np.ndarray with the survival function values,

    }

    }

Return type

None

Raises

ValueError – If the path suffix does not end with .csv

Notes

The .csv file with the survival time distributions will looks as follows (without the header):

time-lapse 1, value, time-lapse 2, value, …

Delta t_1,f1(Delta t_1), Delta t_2, f2(Delta t_2)

2*Delta t_1,f1(2*Delta t_1), 2*Delta t_2, f2(2*Delta t_2)

3*Delta t_1,f1(3*Delta t_1), 3*Delta t_2, f2(3*Delta t_2)

…, …, …, …

gridlib.io.write_fit_results(path: Union[str, Path], fit_results: Dict[str, Dict[str, Union[ndarray, float]]]) None[source]

Write fit results to a .mat file.

Parameters
  • path (Union[str, pathlib.Path]) – The file path to write the fit results to.

  • fit_results (Dict[str, Dict[str, Union[np.ndarray, float]]]) – A dictionary containing the fit results, where the keys are the names of the fit results and the values are dictionaries. The dictionaries have keys ‘grid’ or f”{n}-exp”, where n is the number of exponentials, and values that are either numpy arrays or floats.

Return type

None

Examples

>>> fit_results = {'grid': {'k': np.array([1.0e-03, ..., 10.0]),
... 's': np.array([1.000e-03, ..., 2.500e-03]), 'a': 0.022, 'loss': 0.0047},
... '1-exp': {'k': array([0.02563639]), 's': array([1.]), 'a': 0.08514936433699753,
... 'loss': 1.2825570522448484}}
>>> write_fit_results("/path/to/file.mat", fit_results)

Fit results are saved in “/path/to/file.mat”.