BackmanLab / PWSpy

A Python library dedicated to the analysis of Partial Wave Microscopy (PWS) data.
GNU General Public License v3.0
4 stars 3 forks source link

trouble running examples #18

Closed pr4deepr closed 2 years ago

pr4deepr commented 2 years ago

Hi @nanthony21 I have been getting issues running examples:

For example, when I run https://github.com/BackmanLab/PWSpy/blob/master/examples/compileResults.py

Whenver I get to using:

acquisition.pws.getAnalyses() I get an empty array.

I got the same issue with first example here: https://pwspy.readthedocs.io/en/dev/examples.html#performing-fft-on-the-raw-data-to-get-a-view-of-the-estimated-depth-of-cell-features

Im this example, I get the ROIs:

ROIs:
 [('nuc', 0, <FileFormats.HDF2: 3>), ('nuc', 1, <FileFormats.HDF2: 3>), ('nuc', 2, <FileFormats.HDF2: 3>), 
('nuc', 3, <FileFormats.HDF2: 3>), ('nuc', 4, <FileFormats.HDF2: 3>)]

But, then I get an error when running

analysis = acquisition.pws.loadAnalysis(acquisition.pws.getAnalyses()[0])

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-28-739ef9b45b48> in <module>
      8 print("ROIs:\n", roiSpecs)
      9 
---> 10 analysis = acquisition.pws.loadAnalysis(acquisition.pws.getAnalyses()[0])
     11 kCube = analysis.reflectance
     12 opd, opdValues = kCube.getOpd(useHannWindow=False, indexOpdStop=50)

IndexError: list index out of range

I am using Windows 10 and installed PWSpy in development mode.

Cheers Pradeep

pr4deepr commented 2 years ago

I had a detailed look at your code. From what I understand when calling getAnalyses or getAnalysesAtPath, it looks for a folder called analyses within specified file path. From your example data provided, I couldn't find any folders with the name `analyses'. Am I missing something?

nanthony21 commented 2 years ago

Sorry for the confusion, in order for these examples to work properly they need to be able to find cached analysis results. The test dataset does not include analysis results (part of the testing is to make sure that they can be properly generated.)

In order to generate analysis results for raw data you can use the runPWSAnalysis.py script (also found here). This will save an analysis result file under the name myAnalysis. Then if you run https://github.com/BackmanLab/PWSpy/blob/master/examples/compileResults.py you should see something like this:

   cellNumber       rms  reflectance  roiNum roiName
0           1  0.088394     1.078946       0     nuc
1           1  0.072542     0.993344       1     nuc
2           1  0.066166     1.047874       2     nuc
3           1  0.077311     1.012409       5    test
4           1  0.063230     1.026144       6    test
5           1  0.012438     1.000989       7    test
6           1  0.072001     1.022854       8    test

In practice most people wanting to do custom scripted data analysis in PWSpy would have already generated cached analysis results for their dataset using PWSpy_gui

pr4deepr commented 2 years ago

Ahh, that makes sense. I know the test data is for testing, but it serves as a really good purpose for trying the examples too. BTW, I can run all the tests without any errors..

Is it possible to make it obvious that the analysis needs to be run using the script in the "Examples page" before trying it on some data: https://pwspy.readthedocs.io/en/dev/examples.html ? This script brief example of PWS Analysis should be your first example then.

Another recommendation is to perhaps print a warning to the user if the "analyses" folder is not found here maybe: https://github.com/BackmanLab/PWSpy/blob/1d8bd63dc745746da6ab6abcf2f8efea6878c47c/src/pwspy/dataTypes/_metadata.py#L205-L209

You already have this in an example actually:

https://github.com/BackmanLab/PWSpy/blob/1d8bd63dc745746da6ab6abcf2f8efea6878c47c/examples/roiUsageExample.py#L55-L59


Problems or suggestions with other examples:

When running from a terminal, the plot exits before even it updated. I added lines from the example in mpl_qt_viz, specifically the QtWidget lines for graph to persist after plotting:

from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
#plot command
sys.exit(app.exec_())

It works after this update. Had to do the same thing for this example: ROItoReference


pr4deepr commented 2 years ago

When I run the example https://github.com/BackmanLab/PWSpy/blob/master/examples/limitedOPDSigma.py on the folder test_data/dynamics

User input I used:

path = "E:\\Python_Repos\\PWSpy\\tests\\resources\\test_data\\dynamics\\"
refName = 'Cell999'  # This is an PwsCube of glass, used for normalization.
cellNames = ['Cell1']  # , 'Cell3', 'Cell4','Cell5']
maskSuffix = 'resin'

I get the following error:

opdResin, xvals = resin.getOpd(isHannWindow, indexOpdStop=None, mask=resinRoi.mask)
AttributeError: 'RoiFile' object has no attribute 'mask'
nanthony21 commented 2 years ago

Thanks for the feedback. Many of the examples were written for earlier versions of the library and it looks like over time some of them have had issues appear as PWSpy has evolved. I have just pushed a commit which should address the issues you've run into. 908323ff114297d8083e32c12dc2444b6ffc84ee