Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #385 from kruzaeva/FEMGUI
Fluctuation EM GUI
- Loading branch information
Showing
6 changed files
with
170 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import * as React from "react"; | ||
import { useState } from "react"; | ||
import { useDispatch } from "react-redux"; | ||
import { defaultDebounce } from "../../helpers"; | ||
import ResultList from "../../job/components/ResultList"; | ||
import { AnalysisTypes } from "../../messages"; | ||
import { cbToRadius, inRectConstraint, riConstraint, roConstraints } from "../../widgets/constraints"; | ||
import DraggableHandle from "../../widgets/DraggableHandle"; | ||
import Ring from "../../widgets/Ring"; | ||
import { HandleRenderFunction } from "../../widgets/types"; | ||
import * as analysisActions from "../actions"; | ||
import { AnalysisProps } from "../types"; | ||
import AnalysisLayoutTwoCol from "./AnalysisLayoutTwoCol"; | ||
import useDefaultFrameView from "./DefaultFrameView"; | ||
import Toolbar from "./Toolbar"; | ||
|
||
const FEMAnalysis: React.SFC<AnalysisProps> = ({ analysis, dataset }) => { | ||
const { shape } = dataset.params; | ||
const [scanHeight, scanWidth, imageHeight, imageWidth] = shape; | ||
const minLength = Math.min(imageWidth, imageHeight); | ||
|
||
const [cx, setCx] = useState(imageWidth / 2); | ||
const [cy, setCy] = useState(imageHeight / 2); | ||
const [ri, setRi] = useState(minLength / 4); | ||
const [ro, setRo] = useState(minLength / 2); | ||
|
||
const riHandle = { | ||
x: cx - ri, | ||
y: cy, | ||
} | ||
const roHandle = { | ||
x: cx - ro, | ||
y: cy, | ||
} | ||
|
||
const handleCenterChange = defaultDebounce((newCx: number, newCy: number) => { | ||
setCx(newCx); | ||
setCy(newCy); | ||
}); | ||
const handleRIChange = defaultDebounce(setRi); | ||
const handleROChange = defaultDebounce(setRo); | ||
|
||
const frameViewHandles: HandleRenderFunction = (handleDragStart, handleDrop) => (<> | ||
<DraggableHandle x={cx} y={cy} | ||
imageWidth={imageWidth} | ||
onDragMove={handleCenterChange} | ||
parentOnDrop={handleDrop} | ||
parentOnDragStart={handleDragStart} | ||
constraint={inRectConstraint(imageWidth, imageHeight)} /> | ||
<DraggableHandle x={roHandle.x} y={roHandle.y} | ||
imageWidth={imageWidth} | ||
onDragMove={cbToRadius(cx, cy, handleROChange)} | ||
parentOnDrop={handleDrop} | ||
parentOnDragStart={handleDragStart} | ||
constraint={roConstraints(riHandle.x, cy)} /> | ||
<DraggableHandle x={riHandle.x} y={riHandle.y} | ||
imageWidth={imageWidth} | ||
parentOnDrop={handleDrop} | ||
parentOnDragStart={handleDragStart} | ||
onDragMove={cbToRadius(cx, cy, handleRIChange)} | ||
constraint={riConstraint(roHandle.x, cy)} /> | ||
</>); | ||
|
||
const frameViewWidgets = ( | ||
<Ring cx={cx} cy={cy} ri={ri} ro={ro} | ||
imageWidth={imageWidth} /> | ||
) | ||
|
||
const dispatch = useDispatch(); | ||
|
||
const runAnalysis = () => { | ||
dispatch(analysisActions.Actions.run(analysis.id, 1, { | ||
type: AnalysisTypes.FEM, | ||
parameters: { | ||
shape: "ring", | ||
cx, cy, ri, ro, | ||
} | ||
})); | ||
}; | ||
|
||
const { | ||
frameViewTitle, frameModeSelector, | ||
handles: resultHandles, | ||
widgets: resultWidgets, | ||
} = useDefaultFrameView({ | ||
scanWidth, | ||
scanHeight, | ||
analysisId: analysis.id, | ||
}) | ||
|
||
const subtitle = ( | ||
<>{frameViewTitle} Ring: center=(x={cx.toFixed(2)}, y={cy.toFixed(2)}), ri={ri.toFixed(2)}, ro={ro.toFixed(2)}</> | ||
) | ||
|
||
const toolbar = <Toolbar analysis={analysis} onApply={runAnalysis} busyIdxs={[1]} /> | ||
|
||
return ( | ||
<AnalysisLayoutTwoCol | ||
title="Fluctuation EM (SD over Ring analysis)" subtitle={subtitle} | ||
left={<> | ||
<ResultList | ||
extraHandles={frameViewHandles} extraWidgets={frameViewWidgets} | ||
jobIndex={0} analysis={analysis.id} | ||
width={imageWidth} height={imageHeight} | ||
selectors={frameModeSelector} | ||
/> | ||
</>} | ||
right={<> | ||
<ResultList | ||
jobIndex={1} analysis={analysis.id} | ||
width={scanWidth} height={scanHeight} | ||
extraHandles={resultHandles} | ||
extraWidgets={resultWidgets} | ||
/> | ||
</>} | ||
toolbar={toolbar} | ||
/> | ||
); | ||
} | ||
|
||
export default FEMAnalysis; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from libertem.viz import visualize_simple | ||
|
||
from .base import BaseAnalysis, AnalysisResult, AnalysisResultSet | ||
|
||
import libertem.udf.FEM as FEM | ||
|
||
|
||
class FEMAnalysis(BaseAnalysis): | ||
TYPE = "UDF" | ||
|
||
def get_udf(self): | ||
center = (self.parameters["cy"], self.parameters["cx"]) | ||
rad_in = self.parameters["ri"] | ||
rad_out = self.parameters["ro"] | ||
return FEM.FEMUDF(center=center, rad_in=rad_in, rad_out=rad_out) | ||
|
||
def get_udf_results(self, udf_results): | ||
|
||
return AnalysisResultSet([ | ||
AnalysisResult(raw_data=udf_results.intensity, | ||
visualized=visualize_simple( | ||
udf_results.intensity.reshape(self.dataset.shape.nav)), | ||
key="intensity", title="intensity", | ||
desc="result from SD calculation over ring"), | ||
]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters