Skip to content

Commit

Permalink
Merge pull request #8 from nanthony21/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
nanthony21 authored Oct 14, 2021
2 parents 22d9c22 + 660ae05 commit 2051262
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 24 deletions.
4 changes: 2 additions & 2 deletions conda.recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ requirements:
- google-auth-httplib2
- google-auth-oauthlib
- pyqt =5
- pwspy >=0.2.4 # Core pws package, available on backmanlab anaconda cloud account.
- mpl_qt_viz >=1.0.7 # Plotting package available on PyPi and the backmanlab anaconda cloud account. Written for this project by Nick Anthony
- pwspy >=0.2.8 # Core pws package, available on backmanlab anaconda cloud account.
- mpl_qt_viz >=1.0.9 # Plotting package available on PyPi and the backmanlab anaconda cloud account and conda-forge. Written for this project by Nick Anthony
- descartes
- cachetools >=4
app:
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
'google-auth-httplib2',
'google-auth-oauthlib',
'PyQt5',
'pwspy>=0.2.4', # Core pws package, available on backmanlab anaconda cloud account.
'mpl_qt_viz>=1.0.7', # Plotting package available on PyPi and the backmanlab anaconda cloud account. Written for this project by Nick Anthony
'pwspy>=0.2.8', # Core pws package, available on backmanlab anaconda cloud account.
'mpl_qt_viz>=1.0.9', # Plotting package available on PyPi and the backmanlab anaconda cloud account. Written for this project by Nick Anthony
'descartes',
'cachetools>=4'],
package_dir={'': 'src'},
Expand Down
13 changes: 3 additions & 10 deletions src/pwspy_gui/ExtraReflectanceCreator/ERWorkFlow.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def deleteFigures(self):
def loadCubes(self, includeSettings: t_.List[str], binning: int, parallelProcessing: bool):
self.dataprovider.loadCubes(includeSettings, binning, parallelProcessing)

def plot(self, includeSettings: t_.List[str], binning: int, parallelProcessing: bool, numericalAperture: float, saveToPdf: bool = False, saveDir: str = None):
def plot(self, includeSettings: t_.List[str], binning: int, parallelProcessing: bool, numericalAperture: float):
self.loadIfNeeded(includeSettings, binning, parallelProcessing)
cubes = self.dataprovider.getCubes()
materials = set(cubes['material'])
Expand All @@ -183,12 +183,6 @@ def plot(self, includeSettings: t_.List[str], binning: int, parallelProcessing:
roi = cubes['cube'].sample(n=1).iloc[0].selectLassoROI() # Select an ROI to analyze
cubeDict = cubes.groupby('setting').apply(lambda df: df.groupby('material')['cube'].apply(list).to_dict()).to_dict() # Transform data frame to a dict of dicts of lists for input to `plot`
self.figs.extend(er.plotExtraReflection(cubeDict, theoryR, matCombos, numericalAperture, roi))
if saveToPdf:
with PdfPages(os.path.join(saveDir, f"fig_{datetime.strftime(datetime.now(), '%d-%m-%Y %HH%MM%SS')}.pdf")) as pp:
for i in plt.get_fignums():
f = plt.figure(i)
f.set_size_inches(9, 9)
pp.savefig(f)

def save(self, includeSettings: t_.List[str], binning: int, parallelProcessing: bool, numericalAperture: float, parentWidget: QWidget):
self.loadIfNeeded(includeSettings, binning, parallelProcessing)
Expand Down Expand Up @@ -256,8 +250,7 @@ def compareDates(self, includeSettings: t_.List[str], binning: int, parallelProc
anis = []
figs = [] # These lists just maintain references to matplotlib figures to keep them responsive.
cubes = self.dataprovider.getCubes()
verts = cubes['cube'].sample(n=1).iloc[0].selectLassoROI() # Select a random of the selected cubes and use it to prompt the user for an analysis ROI
mask = Roi.fromVerts(verts=verts, dataShape=cubes['cube'].sample(n=1).iloc[0].data.shape[:-1])
roi = cubes['cube'].sample(n=1).iloc[0].selectLassoROI() # Select a random of the selected cubes and use it to prompt the user for an analysis ROI
for mat in set(cubes['material']):
c = cubes[cubes['material'] == mat]
fig, ax = plt.subplots()
Expand All @@ -270,7 +263,7 @@ def compareDates(self, includeSettings: t_.List[str], binning: int, parallelProc
anims = []
for i, row in c.iterrows():
im = row['cube']
spectra = im.getMeanSpectra(mask)[0]
spectra = im.getMeanSpectra(roi)[0]
ax.plot(im.wavelengths, spectra, label=row['setting'])
anims.append((ax2.imshow(im.data.mean(axis=2), animated=True,
clim=[np.percentile(im.data, .5), np.percentile(im.data, 99.5)]),
Expand Down
7 changes: 1 addition & 6 deletions src/pwspy_gui/ExtraReflectanceCreator/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,7 @@ def connectWindowToWorkflow(self):
self.window.checkedSettings,
self.window.binning,
self.window.parallelProcessing,
self.window.numericalAperture.value(),
saveToPdf=True,
saveDir=self.figsDir)))
self.window.numericalAperture.value())))

def checkDataDir(self):
self.homeDir = os.path.join(appPath, 'ExtraReflectanceCreatorData')
Expand All @@ -76,9 +74,6 @@ def checkDataDir(self):
self.gDriveDir = os.path.join(self.homeDir, 'GoogleDriveData')
if not os.path.exists(self.gDriveDir):
os.mkdir(self.gDriveDir)
self.figsDir = os.path.join(self.homeDir, 'Plots')
if not os.path.exists(self.figsDir):
os.mkdir(self.figsDir)

def _cb(self, func):
"""Return a wrapped function with extra gui stuff."""
Expand Down
4 changes: 2 additions & 2 deletions src/pwspy_gui/ExtraReflectanceCreator/examples/4waycalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ def processIm(im):
theoryR = er.getTheoreticalReflectances(list(zip(*materials))[1], cubes['cube'][0].wavelengths, 0.52)
matCombos = er.generateMaterialCombos(list(zip(*materials))[1], excludedCombos=exclude)
if plotResults:
mask = random.choice(cubes['cube']).selectLassoRoi()
er.plotExtraReflection(cubes, theoryR, matCombos, 0.52, mask, plotReflectionImages=False)
roi = random.choice(cubes['cube']).selectLassoRoi()
er.plotExtraReflection(cubes, theoryR, matCombos, 0.52, roi, plotReflectionImages=False)
with PdfPages(os.path.join(rootDir, "figs.pdf")) as pp:
for i in plt.get_fignums():
f = plt.figure(i)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ def processIm(im):
theoryR = er.getTheoreticalReflectances(list(zip(*materials))[1], df['cube'][0].wavelengths, numericalAperture=na)
matCombos = er.generateMaterialCombos(list(zip(*materials))[1])
if plotResults:
verts = random.choice(df['cube']).selectLassoROI()
roi = Roi.fromVerts(verts, df['cube'][0].data.shape[:2])
roi = random.choice(df['cube']).selectLassoROI()
er.plotExtraReflection(df, theoryR, matCombos, na, roi, plotReflectionImages=False)
with PdfPages(os.path.join(rootDir, "figs.pdf")) as pp:
for i in plt.get_fignums():
Expand Down

0 comments on commit 2051262

Please sign in to comment.