gelles-brandeis / tapqir

Bayesian analysis of co-localization single-molecule microscopy image data.
Apache License 2.0
4 stars 0 forks source link

How to read .pkl files (produced by tapqir) in matlab #416

Closed ordabayevy closed 1 year ago

ordabayevy commented 1 year ago

Discussed in https://github.com/gelles-brandeis/tapqir/discussions/415

Originally posted by **gelles-brandeis** February 8, 2023 This is a kludge, maybe someone has a better way? 1. pick a compatible version of python from https://www.mathworks.com/support/requirements/python-compatibility.html 2022b <--> 3.10 2. install that version of python from python.org (if not already installed) 3. make sure that the directories containing the python executable and scripts are at the top of your windows path (in settings/system/about/advanced system settings/environment variables (in my case: C:\Users\gelles\AppData\Local\Programs\Python\Python310 and C:\Users\gelles\AppData\Local\Programs\Python\Python310\Scripts) 4. from a windows terminal run: python -m pip install pandas 5. **close and reopen Matlab** 6. after I did all that I was able to depickle a tapqir file in matlab (based on https://xcorr.net/2013/06/12/load-pickle-files-in-matlab/) with the following matlab commands: >> pyenv % just checking that matlab is connected to python ans = PythonEnvironment with properties: Version: "3.10" Executable: "C:\Users\gelles\AppData\Local\Programs\Python\Python310\python.EXE" Library: "C:\Users\gelles\AppData\Local\Programs\Python\Python310\python310.dll" Home: "C:\Users\gelles\AppData\Local\Programs\Python\Python310" Status: NotLoaded ExecutionMode: InProcess >> fn = "C:\Users\gelles\Downloads\cosmos+hmm_dwelltime-intervals-channel0.pkl" fn = "C:\Users\gelles\Downloads\cosmos+hmm_dwelltime-intervals-channel0.pkl" >> fid = py.open(fn,'rb'); >> py.pickle.load(fid) ans = Python DataFrame with properties: T: [1×1 py.pandas.core.frame.DataFrame] at: [1×1 py.pandas.core.indexing._AtIndexer] attrs: [1×1 py.dict] axes: [1×2 py.list] columns: [1×1 py.pandas.core.indexes.base.Index] dtypes: [1×1 py.pandas.core.series.Series] empty: 0 flags: [1×1 py.pandas.core.flags.Flags] iat: [1×1 py.pandas.core.indexing._iAtIndexer] iloc: [1×1 py.pandas.core.indexing._iLocIndexer] index: [1×1 py.pandas.core.indexes.range.RangeIndex] loc: [1×1 py.pandas.core.indexing._LocIndexer] ndim: [1×1 py.int] shape: [1×2 py.tuple] size: [1×1 py.numpy.int32] values: [1×1 py.numpy.ndarray] posterior_sample aoi start_frame ... dwell_time low_or_high z 0 0 0 0 ... 944 2 0 1 0 1 0 ... 289 -2 0 2 0 1 289 ... 3 1 1 3 0 1 292 ... 652 2 0 4 0 2 0 ... 115 -2 0 ... ... ... ... ... ... ... .. 958887 499 262 514 ... 49 0 0 958888 499 262 563 ... 16 1 1 958889 499 262 579 ... 20 0 0 958890 499 262 599 ... 2 1 1 958891 499 262 601 ... 343 2 0 [958892 rows x 7 columns] >> a = ans >>py.pandas.DataFrame(a).to_csv('csvout.csv') % makes a csv output file that can be read by matlab import data tool or excel