Skip to content

Commit

Permalink
rearrange example doc page. Minor fixes to various examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
nanthony21 committed Mar 3, 2022
1 parent 2db1113 commit 908323f
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 19 deletions.
24 changes: 13 additions & 11 deletions docs/source/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,25 @@ Examples
If you don't have PWS experimental data to run these examples with you can find a dataset that is used for automated testing
on Zenodo here: https://zenodo.org/record/5976039#.Yf6aPt_MJPY

Performing FFT on the raw data to get a view of the estimated depth of cell features
--------------------------------------------------------------------------------------
.. literalinclude:: ../../examples/opdExampleScript.py
Running basic PWS analysis on a single image.
-----------------------------------------------------------------------------------------
This example runs the PWS analysis on a single measurement. The results of the analysis will be saved alongside the raw data
under the `analyses` folder. Running this example may be required in order for other examples which require that analysis results
already be available.

.. literalinclude:: ../../examples/runPWSAnalysis.py
:language: python
:linenos:

.. image:: ../resources/opdExample.gif


Brief example of basic PWS analysis to produce Sigma, Reflectance, Ld, and other images.
-----------------------------------------------------------------------------------------
.. literalinclude:: ../../examples/runPWSAnalysis.py
Performing FFT to visualize the estimated depth of cell features
--------------------------------------------------------------------------------------
.. literalinclude:: ../../examples/opdExampleScript.py
:language: python
:linenos:

.. image:: ../resources/opdExample.gif

Use the `compilation` functionality to reduce analysis results to a table of values of average values within an ROI
Compile analysis results to a table of average values within each ROI
----------------------------------------------------------------------------------------------------------------------
.. literalinclude:: ../../examples/compileResults.py
:language: python
Expand Down Expand Up @@ -54,4 +56,4 @@ Generating new position lists to enable colocalized measurements on multiple sys
--------------------------------------------------------------
.. literalinclude:: ../../examples/positionTransformation.py
:language: python
:linenos:
:linenos:
3 changes: 2 additions & 1 deletion examples/ROItoReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@
import pwspy.dataTypes as pwsdt
import matplotlib.pyplot as plt
import numpy as np
import pathlib as pl

### User Variables ###
PWSImagePath = ... # Set this to the path of a "Cell{X}" folder of a PWS acquisition.
PWSImagePath: pl.Path = ... # Set this to the path of a "Cell{X}" folder of a PWS acquisition.
######################

plt.ion()
Expand Down
3 changes: 2 additions & 1 deletion examples/compileResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import pandas
from pwspy.analysis.compilation import PWSRoiCompiler, PWSCompilerSettings
import pwspy.dataTypes as pwsdt
import pathlib as pl

### User Variables ###
PWSExperimentPath = ... # Set this to a folder containing multiple "Cell{x}" acquisition folders. If you have downloaded the test dataset you can use `pl.Path(__file__).parent.parent / 'tests' / 'resources' / 'test_data' / 'sequencer'`
PWSExperimentPath: pl.Path = ... # Set this to a folder containing multiple "Cell{x}" acquisition folders. If you have downloaded the test dataset you can use `pl.Path(__file__).parent.parent / 'tests' / 'resources' / 'test_data' / 'sequencer'`
######################


Expand Down
8 changes: 5 additions & 3 deletions examples/limitedOPDSigma.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
import scipy.signal as sps
import os
import numpy as np
import pathlib as pl

'''User Input'''
path = r'2_7_2019 11.07'
refName = 'Cell999' # This is an PwsCube of glass, used for normalization.
path: pl.Path = ...
refName = 'Cell3' # This is an PwsCube of glass, used for normalization.
cellNames = ['Cell1', 'Cell2'] # , 'Cell3', 'Cell4','Cell5']
maskSuffix = 'resin'

Expand Down Expand Up @@ -71,7 +72,7 @@
if resetResinMasks:
[resin.metadata.acquisitionDirectory.deleteRoi(name, num) for name, num, fformat in resin.metadata.acquisitionDirectory.getRois() if name == maskSuffix]
if maskSuffix in [name for name, number, fformat in resin.metadata.acquisitionDirectory.getRois()]:
resinRoi = resin.metadata.acquisitionDirectory.loadRoi(maskSuffix, 1)
resinRoi = resin.metadata.acquisitionDirectory.loadRoi(maskSuffix, 1).getRoi()
else:
print('Select a region containing only resin.')
resinRoi = resin.selectLassoROI()
Expand All @@ -86,6 +87,7 @@
ax.legend()
plt.pause(0.2)

print("Beginning processing.")
rmses = {} # Store the rms maps for later saving
for cellName in cellNames:
cube = PwsCube.fromMetadata(Acquisition(os.path.join(path, cellName)).pws)
Expand Down
6 changes: 5 additions & 1 deletion examples/opdExampleScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import pwspy.dataTypes as pwsdt
from mpl_qt_viz.visualizers import PlotNd # The mpl_qt_viz library is not a dependency of PWSpy and will need to be installed separately. It can be found on Conda-Forge (conda install -c conda-forge mpl_qt_viz) or on PyPi (pip install mpl_qt_viz)
import matplotlib.pyplot as plt
import pathlib as pl
from PyQt5.QtWidgets import QApplication

### User Variables ###
PWSImagePath = ... # Set this to the path of a "Cell{X}" folder of a PWS acquisition.
PWSImagePath: pl.Path = ... # Set this to the path of a "Cell{X}" folder of a PWS acquisition.
######################

plt.ion() # Without this we will get a crash when trying to open the PlotNd window because a Qt application loop must be running.
Expand All @@ -47,5 +49,7 @@
ri = 1.37 # Estimated RI of livecell chromatin
opdValues = opdValues / (2 * ri)

app = QApplication([]) # Start a QApplication instance to run the PlotNd qwidget
plotWindow = PlotNd(opd, names=('y', 'x', 'depth'),
indices=(None, None, opdValues), title="Estimated Depth")
app.exec()
5 changes: 4 additions & 1 deletion examples/runPWSAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@

from pwspy import analysis
from pwspy import dataTypes as pwsdt
import pathlib as pl

### User Variables ###
PWSExperimentPath = ... # Set this to a folder containing multiple "Cell{x}" acquisition folders. If you have downloaded the test dataset you can use `pl.Path(__file__).parent.parent / 'tests' / 'resources' / 'test_data' / 'sequencer'`
PWSExperimentPath: pl.Path = ... # Set this to a folder containing multiple "Cell{x}" acquisition folders. If you have downloaded the test dataset you can use `pl.Path(__file__).parent.parent / 'tests' / 'resources' / 'test_data' / 'sequencer'`
######################

settings = analysis.pws.PWSAnalysisSettings.loadDefaultSettings("Recommended")
Expand All @@ -42,3 +43,5 @@
acq.pws.saveAnalysis(results, 'myAnalysis', overwrite=True) # Save our analysis results to file in the default location alongside the raw data under the `analyses` folder.

loadedResults = acq.pws.loadAnalysis('myAnalysis') # This is just going to be a copy of `results`, loaded from file.

print(f"Saved anlysis `myAnalysis` to {acq.filePath}")
1 change: 0 additions & 1 deletion examples/syntheticReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
"""

import copy

import matplotlib.pyplot as plt
import pwspy.dataTypes as pwsdt

Expand Down

0 comments on commit 908323f

Please sign in to comment.