tritemio / mcdepi2018-paper-analysis

Analsys notebooks for the MC-DEPI 2018 paper.
https://doi.org/10.1101/385252
MIT License
0 stars 0 forks source link

Notebook Burst Analysis-DEPI-sim2-E_nanotime.ipynb #2

Open fabiotrovato opened 5 years ago

fabiotrovato commented 5 years ago

Hi,

I am trying to execute the notebook Burst Analysis-DEPI-sim2-E_nanotime.ipynb, but I get the following error at: rg = RandomGenerator(Xoroshiro128(1)) burstsph_sim = depi.recolor_burstsph(burstsph_sel.loc[Dex, 'timestamp'], rg=rg, **params)

Any idea how I could solve this issue? Thank you, Fabio

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-44-57fe7470d820> in <module>
      1 rg = RandomGenerator(Xoroshiro128(1))
----> 2 burstsph_sim = depi.recolor_burstsph(burstsph_sel.loc[Dex, 'timestamp'], rg=rg, **params)

~/anaconda2/envs/mc-depi/lib/python3.7/site-packages/depi/depi.py in recolor_burstsph(timestamps, R0, τ_relax, δt, τ_D, τ_A, D_fract, A_fract, bg_rate_d, bg_rate_a, ts_unit, tcspc_range, prob_A_dark, τ_A_dark, gamma, lk, dir_ex_t, rg, chunk_size, α, ndt, **dd_model)
    163         prob_A_dark=prob_A_dark, τ_A_dark=τ_A_dark,
    164         bg_rate_d=bg_rate_d, bg_rate_a=bg_rate_a, ts_unit=ts_unit, tcspc_range=tcspc_range,
--> 165         rg=rg, chunk_size=chunk_size, α=α, ndt=ndt, dd_params=dd_model)
    166 
    167 

~/anaconda2/envs/mc-depi/lib/python3.7/site-packages/depi/depi.py in recolor_burstsph_OU_gauss_R(timestamps, R0, gamma, lk, dir_ex_t, τ_relax, dd_params, δt, τ_D, τ_A, D_fract, A_fract, bg_rate_d, bg_rate_a, ts_unit, tcspc_range, prob_A_dark, τ_A_dark, rg, chunk_size, α, ndt, cdf)
    259     burstsph, bg = _select_background(burstsph_all, bg_rate_d=bg_rate_d, bg_rate_a=bg_rate_a,
    260                                       ts_unit=ts_unit, tcspc_range=tcspc_range, rg=rg)
--> 261     burstsph = _color_photons(burstsph, R0, gamma=gamma, lk=lk, dir_ex_t=dir_ex_t, rg=rg)
    262     burstsph = _recolor_A_blinking(burstsph, prob_A_dark, τ_A_dark, lk, τ_D, D_fract, rg)
    263     burstsph = _add_acceptor_nanotime(burstsph, τ_A, A_fract, rg)

~/anaconda2/envs/mc-depi/lib/python3.7/site-packages/depi/depi.py in _color_photons(df, R0, gamma, lk, dir_ex_t, rg)
    400     assert D_em.sum() == ND
    401     df['A_ch'] = A_em
--> 402     df = _set_ph_stream_column(df, A_em)
    403     # These values are shot-noise free
    404     ND_theor = num_ph * (1 - Eraw)

~/anaconda2/envs/mc-depi/lib/python3.7/site-packages/depi/depi.py in _set_ph_stream_column(df, A_ch)
    385 
    386 def _set_ph_stream_column(df, A_ch):
--> 387     df['stream'] = pd.Categorical.from_codes(A_ch, categories=["DexDem", "DexAem"])
    388     return df
    389 

~/anaconda2/envs/mc-depi/lib/python3.7/site-packages/pandas/core/arrays/categorical.py in from_codes(cls, codes, categories, ordered, dtype)
    663                           "raise a ValueError"), FutureWarning, stacklevel=2)
    664             if msg:
--> 665                 raise ValueError(msg)
    666 
    667         if len(codes) and (

ValueError: codes need to be array-like integers
tritemio commented 5 years ago

It is likely an error with newer version of pandas. Unless you are using a very old pandas version, the problem is here:

387     df['stream'] = pd.Categorical.from_codes(A_ch, categories=["DexDem", "DexAem"])

pandas does not like the argument A_ch, probably a bool array. Try to change it to A_ch.astype('uint8') or to something that pandas accepts.

fabiotrovato commented 5 years ago

I am not sure what you're suggesting. Are you suggesting to hack your code and add A_ch.astype('uint8') somewhere? Which pandas version was used to test the notebook? My pandas version is pandas==0.24.1. I followed the instructions for installing depi, to meet the various dependencies (pandas >= 0.22).

fabiotrovato commented 5 years ago

If I add A_ch.astype('uint8') in _set_ph_stream_column(df, A_ch) of depi.py I still get the same error. Thanks.

tritemio commented 5 years ago

Yes, this software served to demonstrate the idea of the DEPI paper. I don't have the resources to support it with evolving versions of the python ecosystems. You can find the original environment here:

https://github.com/tritemio/mcdepi2018-paper-analysis/blob/master/binder/environment.yml

it says that pandas 0.22 was used, so there must be a breaking change in pandas 0.24.

Everything here is opensource, all the versions of the packages used at that time are captured in the environment file and data files are available on figshare. You can even run the analysis online by clicking on the mybinder button!

Feel free to take the source and develop/fix it in any direction may fits you, follow the MIT license (acknowledge original author) and please share back.