Skip to content

Commit

Permalink
updating examples.
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Anthony committed Oct 13, 2021
1 parent dde2b43 commit 31e8102
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 292 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ buildScripts/pyInstaller/dist/
.idea/
src/pwspy/_version
*.orig
tests/resources/test_data/
5 changes: 3 additions & 2 deletions src/pwspy/dataTypes/_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def index(self) -> t_.Tuple[float, ...]:
"""
return self._index


def plotMean(self) -> t_.Tuple[plt.Figure, plt.Axes]:
"""
Expand Down Expand Up @@ -107,7 +108,7 @@ def getMeanSpectra(self, mask: t_.Optional[t_.Union[_other.Roi, np.ndarray]] = N
std = self.data[mask].std(axis=0)
return mean, std

def selectLassoROI(self, displayIndex: t_.Optional[int] = None, clim: t_.Sequence = None) -> np.ndarray:
def selectLassoROI(self, displayIndex: t_.Optional[int] = None, clim: t_.Sequence = None) -> _other.Roi:
"""
Allow the user to draw a `freehand` ROI on an image of the acquisition.
Expand All @@ -134,7 +135,7 @@ def onSelect(verts):
fig.show()
while plt.fignum_exists(fig.number):
fig.canvas.flush_events()
return np.array(Verts[0])
return _other.Roi.fromVerts(np.array(Verts[0]), self.data.shape[:2])

def selectRectangleROI(self, displayIndex: t_.Optional[int] = None) -> np.ndarray:
"""
Expand Down
15 changes: 9 additions & 6 deletions src/pwspy/examples/ROItoMirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,27 @@

# -*- coding: utf-8 -*-
"""
This script Allows the user to select a region of an PwsCube. the spectra of this
This script allows the user to select a region of an PwsCube. the spectra of this
region is then averaged over the X and Y dimensions. This spectra is then saved
as a reference dataTypes with the same initial dimensions.
Can help to make a reference when you don't actually have one for some reason
"""

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

if __name__ == '__main__':
a = PwsCube.loadAny(PWSImagePath)
plt.ion()
a = pwsdt.Acquisition(PWSImagePath).pws.toDataClass()

mask = a.selectLassoROI()
spec, std = a.getMeanSpectra(mask)
roi = a.selectLassoROI()
spec, std = a.getMeanSpectra(mask=roi)
newData = np.zeros(a.data.shape)
newData[:, :, :] = spec[np.newaxis, np.newaxis, :]
ref = PwsCube(newData, a.metadata)
ref = pwsdt.PwsCube(newData, a.metadata)

plt.plot(a.wavelengths, spec)

a = 1
4 changes: 4 additions & 0 deletions src/pwspy/examples/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,8 @@
opdExampleScript
"""

# Set this to a folder containing multiple "Cell{x}" acquisition folders. Some examples will use this.
PWSExperimentPath = r"C:\Users\backman05\Documents\Bitbucket\pwspython\tests\resources\seqTest"

# Set this to the "Cell{X}" folder of a PWS acquisition. Most of the examples will then refer to this file.
PWSImagePath = r'\\backmanlabnas.myqnapcloud.com\home\Year2\canvassing\Cell868'
135 changes: 0 additions & 135 deletions src/pwspy/examples/flatFieldVisualizer.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/pwspy/examples/limitedOPDSigma.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
resinRoi = resin.metadata.acquisitionDirectory.loadRoi(maskSuffix, 1)
else:
print('Select a region containing only resin.')
resinRoi = Roi.fromVerts(resin.selectLassoROI(), resin.data.shape[:2])
resinRoi = resin.selectLassoROI()
resin.metadata.acquisitionDirectory.saveRoi(maskSuffix, 1, resinRoi)
resin.data -= resin.data.mean(axis=2)[:, :, np.newaxis]
opdResin, xvals = resin.getOpd(isHannWindow, indexOpdStop=None, mask=resinRoi.mask)
Expand Down
22 changes: 14 additions & 8 deletions src/pwspy/examples/opdExampleScript.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,28 @@

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

imageDirectory = r'\\backmanlabnas.myqnapcloud.com\home\Year3\ethanolTimeSeries\LTL20l_Pure\Track_3hrs\Cell3'
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()

acquisition = pwsdt.Acquisition(imageDirectory)
acquisition = pwsdt.Acquisition(PWSImagePath)

roiSpecs = acquisition.getRois()
print("ROIs:\n", roiSpecs)

PwsCube = acquisition.pws.toDataClass()
kCube = pwsdt.KCube.fromPwsCube(PwsCube)
del PwsCube
analysis = acquisition.pws.loadAnalysis(acquisition.pws.getAnalyses()[0]) # Load a reference to an analysis file.
kCube = analysis.reflectance # Load the processed `reflectance` array from the analysis file.

opd, opdValues = kCube.getOpd(useHannWindow= False, indexOpdStop = 50)
opd, opdValues = kCube.getOpd(useHannWindow=False, indexOpdStop=50) # Use FFT to transform the reflectance array to OPD

ri = 1.37
# Scale the opdValues to give estimated depth instead of raw OPD. Factor of 2 because light is making a round-trip.
ri = 1.37 # Estimated RI of livecell chromatin
opdValues = opdValues / (2 * ri)

plotWindow = PlotNd(opd, names=('y', 'x', 'depth'),
indices=(None, None, opdValues), title="Estimated Depth")
indices=(None, None, opdValues), title="Estimated Depth")

a = 1
a = 1
2 changes: 1 addition & 1 deletion src/pwspy/examples/plotITOThinFilmCalibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def proc(im: PwsCube):
return im, ref

if __name__ == '__main__':
subDir = r'J:\Calibrations\ITOThinFilm\LCPWS1' # Use '*' to include all subdirectories
subDir = r'J:\Calibrations\ITOThinFilm\LCPWS1' # Use '*' to include all subdirectories
dateStart = '1-16-2020'
dateEnd = None
templateName = '1_16_2020'
Expand Down
126 changes: 0 additions & 126 deletions src/pwspy/examples/pwsAnalysis.py

This file was deleted.

Loading

0 comments on commit 31e8102

Please sign in to comment.