PyRate icon indicating copy to clipboard operation
PyRate copied to clipboard

NameError: free variable 'L_tbl' referenced before assignment in enclosing scope

Open JoukjeKloosterman opened this issue 1 year ago • 5 comments

Hi,

I am new to PyRate, and I am rerunning an analysis by Fabien Condamine: https://www.nature.com/articles/s41467-021-23754-0.pdf

I am running some commands with the latest version of PyRate, and I get the following error:

python3 PyRate.py -plot2 ../pyrate_mcmc_logs/ -tag Hadrosauridae -b 100

Module FastPyRateC was loaded.
0
FILE STEM: Hadrosauridae Hadrosauridae
found 1 log files...

determining min age... .Min root age: 90
89 0

combining all files... Hadrosauridae_2_BDMCMC_G_marginal_rates
.skipping file: ../pyrate_mcmc_logs/Hadrosauridae_2_BDMCMC_G_marginal_rates.log

calculating HPDs... .Traceback (most recent call last):
  File "/home/jkloosterman/project_dino_decline/condamine_paper/PyRate/PyRate.py", line 5054, in <module>
    plot_RTT(path_dir_log_files, burnin, file_stem,one_file,root_plot,plot_type)
  File "/home/jkloosterman/project_dino_decline/condamine_paper/PyRate/PyRate.py", line 481, in plot_RTT
    hpds95 =  np.array(get_HPD(threshold=.95))
  File "/home/jkloosterman/project_dino_decline/condamine_paper/PyRate/PyRate.py", line 440, in get_HPD
    for time_ind in range(shape(L_tbl)[1]):
NameError: free variable 'L_tbl' referenced before assignment in enclosing scope

Any idea what the error means and how I can fix it?

JoukjeKloosterman avatar Apr 04 '24 11:04 JoukjeKloosterman

Hi,

This error occurs when you set the burnin -b to a higher value than the number of MCMC samples in the marginal rates file. Either you run the analysis longer (as in the paper) or if you only want to experiment with the commands you decrease -b to e.g. 1.

Best, Torsten

thauffe avatar Apr 08 '24 17:04 thauffe

@thauffe What do you mean by running it longer? I have rerun the commands with the parameters as written in the paper, and it still happens...

JoukjeKloosterman avatar Apr 09 '24 09:04 JoukjeKloosterman

Hi,

When you aim to exclude the first 100 sampled MCMC iterations (with -b 100), you need to make sure to have at least 103 rows in you marginal_rates.log file. Otherwise, you need to increase the value of -n in your PyRate command, which means running the analysis longer.

This command from the original paper is fine: python3.8 PyRate.py ./Datasets/Dinosauria/Hadrosauridae_PyRate.py —A 2 -mG -j [set a replicate number between 1 and 100] -n 5000000 -p 5000 -s 5000 -wd Dinosauria/Hadrosauridae/BDMCMC -log_marginal_rates 1 -out _BDMCMC

It provides1000 MCMC samples in the marginal_rates.log file (i.e. n/s 5000000/5000), from which 100 are excluded as burnin when using the -plot2.

If this does not fix the plotting issue, please upload your PyRate output files and I will have a look.

Best, Torsten

thauffe avatar Apr 09 '24 14:04 thauffe

Thank you very much @thauffe

I ran the command you posted, and it does work now. I do not know why it did not work the first time.

I do have another error now, when running -plot2 :

generating R file... ..
An R script with the source for the RTT plot was saved as: Hadrosauridae_2_BDMCMC_G_marginal_rates_RTT.r
(in .)
Error in library(scales) : there is no package called ‘scales’
Execution halted
done

JoukjeKloosterman avatar Apr 10 '24 13:04 JoukjeKloosterman

Awesome that this is working now!

You need to install the missing R package. Just open your terminal or e.g, RStudio and enter install.packages("scales")

thauffe avatar Apr 10 '24 13:04 thauffe