Skip to content

Commit

Permalink
Move PWSExperimentPath and PWSImagePath in __init__ to be individuall…
Browse files Browse the repository at this point in the history
…y defined in each example for better usability.
  • Loading branch information
nicholas.anthony@northwestern.edu committed Feb 5, 2022
1 parent f3829b3 commit 071ba50
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 53 deletions.
5 changes: 4 additions & 1 deletion examples/ROItoReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import pwspy.dataTypes as pwsdt
import matplotlib.pyplot as plt
import numpy as np
from examples import PWSImagePath

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

plt.ion()
a = pwsdt.Acquisition(PWSImagePath).pws.toDataClass() # Load a measurement from file.
Expand Down
5 changes: 0 additions & 5 deletions examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,5 @@
opdExampleScript
positionTransformation
"""
import pathlib as pl

# Set this to a folder containing multiple "Cell{x}" acquisition folders. Some examples will use this.
PWSExperimentPath = pl.Path(__file__).parent.parent / 'tests' / 'resources' / 'test_data' / 'sequencer'

# Set this to the "Cell{X}" folder of a PWS acquisition. Most of the examples will then refer to this file.
PWSImagePath = PWSExperimentPath / 'Cell1'
6 changes: 5 additions & 1 deletion examples/compileResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
"""
import pandas
from pwspy.analysis.compilation import PWSRoiCompiler, PWSCompilerSettings
from examples import PWSExperimentPath
import pwspy.dataTypes as pwsdt

### 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'`
######################


tmpList = []
compiler = PWSRoiCompiler(PWSCompilerSettings(reflectance=True, rms=True))

Expand Down
4 changes: 2 additions & 2 deletions examples/limitedOPDSigma.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
The phantom has a strong thin-film spectrum. This script is meant to filter out the thin film components
of the fourier transfrom and extract RMS from what is left.
"""
from pwspy.dataTypes import CameraCorrection, Acquisition, Roi, PwsCube, KCube
from pwspy.dataTypes import CameraCorrection, Acquisition, PwsCube, KCube
import matplotlib.pyplot as plt
import scipy.signal as sps
import os
Expand All @@ -36,7 +36,7 @@
maskSuffix = 'resin'

# identify the depth in um to which the OPD spectra need to be integrated
integrationDepth = 2.0 ## in um
integrationDepth = 2.0 # in um
isHannWindow = True # Should Hann windowing be applied to eliminate edge artifacts?
subtractResinOpd = True
resetResinMasks = False
Expand Down
7 changes: 5 additions & 2 deletions examples/opdExampleScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@
"""

import pwspy.dataTypes as pwsdt
from mpl_qt_viz.visualizers import PlotNd
from examples import PWSImagePath
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

### User Variables ###
PWSImagePath = ... # 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.
plt.figure()

Expand Down
70 changes: 34 additions & 36 deletions examples/positionTransformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,39 +26,37 @@
@author: Nick Anthony
"""

if __name__ == '__main__':

import pathlib as pl
import matplotlib.pyplot as plt
from skimage.transform import AffineTransform
import numpy as np

plt.ion()
NCPath = pl.Path(r'Z:\Nick\NU-NC_EtOH fixation comparison\NC\Buccal cell')
NUPath = pl.Path(r'Z:\Nick\NU-NC_EtOH fixation comparison\NU\Buccal')

# Load the position list of the coverslip corners taken at the beginning of the experiment.
preTreatRefPositions = PositionList.fromNanoMatFile(NCPath / 'corners_list2.mat', 'TIXYDrive')
# Load the position list of the coverslip corners after placing the dish back on the microscope after treatment.
postTreatRefPositions = PositionList.fromPropertyMap(PropertyMap.loadFromFile(NUPath / 'corners.pos'))
# Generate an affine transform describing the difference between the two position lists.
transformMatrix = preTreatRefPositions.getAffineTransform(postTreatRefPositions)
# Load the positions of the cells we are measuring before the dish was removed.
preTreatCellPositions = PositionList.fromNanoMatFile(NCPath / 'cell_list.mat', 'TIXYDrive')
# Transform the cell positions to the new expected locations.
postTreatCellPositions = preTreatCellPositions.applyAffineTransform(transformMatrix)
# Save the new positions to a file that can be loaded by Micro-Manager.
postTreatCellPositions.toPropertyMap().saveToFile(NUPath / 'transformedPositions.pos')

# Plot the reference and cell positions before treatment
fig, ax = plt.subplots()
preTreatRefPositions.plot(fig, ax)
preTreatCellPositions.plot(fig, ax)

# Plot the reference and cell positions after treatment
fig2, ax2 = plt.subplots()
postTreatRefPositions.plot(fig2, ax2)
postTreatCellPositions.plot(fig2, ax2)

af = AffineTransform(np.vstack([transformMatrix, [0, 0, 1]]))
print(f"Scale: {af.scale}, Shear: {af.shear}, Rotation: {af.rotation / (2*np.pi) * 360}, Translation: {af.translation}")
import pathlib as pl
import matplotlib.pyplot as plt
from skimage.transform import AffineTransform
import numpy as np

plt.ion()
NCPath = pl.Path(r'Z:\Nick\NU-NC_EtOH fixation comparison\NC\Buccal cell')
NUPath = pl.Path(r'Z:\Nick\NU-NC_EtOH fixation comparison\NU\Buccal')

# Load the position list of the coverslip corners taken at the beginning of the experiment.
preTreatRefPositions = PositionList.fromNanoMatFile(NCPath / 'corners_list2.mat', 'TIXYDrive')
# Load the position list of the coverslip corners after placing the dish back on the microscope after treatment.
postTreatRefPositions = PositionList.fromPropertyMap(PropertyMap.loadFromFile(NUPath / 'corners.pos'))
# Generate an affine transform describing the difference between the two position lists.
transformMatrix = preTreatRefPositions.getAffineTransform(postTreatRefPositions)
# Load the positions of the cells we are measuring before the dish was removed.
preTreatCellPositions = PositionList.fromNanoMatFile(NCPath / 'cell_list.mat', 'TIXYDrive')
# Transform the cell positions to the new expected locations.
postTreatCellPositions = preTreatCellPositions.applyAffineTransform(transformMatrix)
# Save the new positions to a file that can be loaded by Micro-Manager.
postTreatCellPositions.toPropertyMap().saveToFile(NUPath / 'transformedPositions.pos')

# Plot the reference and cell positions before treatment
fig, ax = plt.subplots()
preTreatRefPositions.plot(fig, ax)
preTreatCellPositions.plot(fig, ax)

# Plot the reference and cell positions after treatment
fig2, ax2 = plt.subplots()
postTreatRefPositions.plot(fig2, ax2)
postTreatCellPositions.plot(fig2, ax2)

af = AffineTransform(np.vstack([transformMatrix, [0, 0, 1]]))
print(f"Scale: {af.scale}, Shear: {af.shear}, Rotation: {af.rotation / (2*np.pi) * 360}, Translation: {af.translation}")
12 changes: 8 additions & 4 deletions examples/roiUsageExample.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,15 @@
import matplotlib.pyplot as plt
import pathlib
import numpy as np
from examples import PWSExperimentPath
plt.ion()

workingDirectory = PWSExperimentPath # The folder that all your acquisitions are saved under.

### 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'`
analysisName = 'script' # This will often be "p0"
######################

plt.ion()


def plotHist(roi, rms):
"""
Expand All @@ -44,7 +48,7 @@ def plotHist(roi, rms):
plt.hist(vals) # Plot a histogram


cellFolderIterator = pathlib.Path(workingDirectory).glob("Cell[0-9]") # An iterator for all folders that are below workingDirectory and match the "regex" pattern "Cell[0-9]"
cellFolderIterator = pathlib.Path(PWSExperimentPath).glob("Cell[0-9]") # An iterator for all folders that are below workingDirectory and match the "regex" pattern "Cell[0-9]"
for folder in cellFolderIterator:
acq = pwsdt.Acquisition(folder) # An object handling the contents of a single "Cell{X}" folder

Expand Down
5 changes: 4 additions & 1 deletion examples/runPWSAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@

from pwspy import analysis
from pwspy import dataTypes as pwsdt
from examples import PWSExperimentPath

### 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'`
######################

settings = analysis.pws.PWSAnalysisSettings.loadDefaultSettings("Recommended")

Expand Down
5 changes: 4 additions & 1 deletion examples/syntheticReference.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@

import matplotlib.pyplot as plt
import pwspy.dataTypes as pwsdt
from examples import PWSImagePath

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

plt.ion()

Expand Down

0 comments on commit 071ba50

Please sign in to comment.