Skip to content

Commit

Permalink
fix detector not changing
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Dec 5, 2023
1 parent 85c378b commit 2ce3b0c
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 138 deletions.
6 changes: 3 additions & 3 deletions src/data-entry/beamProperties.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ export default function BeampropertiesDataEntry() {
value={beamlineConfig.cameraLength ?? ""}
InputProps={{
inputProps: {
max: beamlineConfig.maxCameraLength,
min: beamlineConfig.minCameraLength,
step: beamlineConfig.cameraLengthStep,
max: beamlineConfig.maxCameraLength.toNumber(),
min: beamlineConfig.minCameraLength.toNumber(),
step: beamlineConfig.cameraLengthStep.toNumber(),
},
}}
onChange={handleCameraLength}
Expand Down
2 changes: 1 addition & 1 deletion src/data-entry/dataSideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default function DataSideBar(): JSX.Element {
{DistanceUnits.millimetre} x {DistanceUnits.millimetre}
</MenuItem>
<MenuItem value={DistanceUnits.micrometre}>
{DistanceUnits.micrometre} x {DistanceUnits.micrometre}
{"\u03BC" + "m"} x {"\u03BC" + "m"}
</MenuItem>
</Select>
</FormControl>
Expand Down
2 changes: 1 addition & 1 deletion src/data-entry/detectorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const useDetectorStore = create<DetectorStore>((set) => ({
detectorList: detectorList,
updateDetector: (newDetector: string) =>
set((state) => ({
current: state.detectorList[newDetector],
...state.detectorList[newDetector],
name: newDetector,
})),
updatePixelUnits: (newUnits: DistanceUnits) =>
Expand Down
52 changes: 29 additions & 23 deletions src/plot/centrePlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,10 @@ import { useDetectorStore } from "../data-entry/detectorStore";
import { useCameraTubeStore } from "../data-entry/cameraTubeStore";
import {
UnitVector,
createPlotEllipse,
createPlotEllipseClearance,
createPlotRange,
createPlotRectangle,
Plotter,
getDomains,
} from "./plotUtils";
import { usePlotStore } from "./plotStore";
import { PlotAxes, usePlotStore } from "./plotStore";

Check failure on line 20 in src/plot/centrePlot.tsx

View workflow job for this annotation

GitHub Actions / deploy

'PlotAxes' is defined but never used
import {
BeamlineConfig,
Beamstop,
Expand Down Expand Up @@ -74,6 +71,15 @@ export default function CentrePlot(): JSX.Element {
return { centre: state.centre, diameter: state.diameter };
});


const scaleFactor: mathjs.Unit | null = null;
if (
beamlineConfig.cameraLength &&
beamlineConfig.wavelength
) {
const scaleFactor = mathjs.divide(2e-12 * Math.PI, mathjs.multiply(mathjs.unit(beamlineConfig.cameraLength, "m"), beamlineConfig.wavelength));

Check failure on line 80 in src/plot/centrePlot.tsx

View workflow job for this annotation

GitHub Actions / deploy

'scaleFactor' is assigned a value but never used
}

// evil :( :( :( :()
/* eslint-disable */
if (mathjs.Unit.UNITS.xpixel) {
Expand All @@ -90,6 +96,7 @@ export default function CentrePlot(): JSX.Element {
mathjs.createUnit("xpixel", detector.pixelSize.width.toString());
mathjs.createUnit("ypixel", detector.pixelSize.height.toString());


const { ptMin, ptMax, visibleQRange, fullQRange } = computeQrange(
detector,
beamstop,
Expand Down Expand Up @@ -121,35 +128,31 @@ export default function CentrePlot(): JSX.Element {
y: mathjs.unit(cameraTube.centre.y ?? NaN, "ypixel")
}

const plotBeamstop = createPlotEllipse(
const plotter = new Plotter(plotConfig.plotAxes, scaleFactor)

const plotBeamstop = plotter.createPlotEllipse(
beamstopCentre,
beamstop.diameter,
plotConfig.plotAxes,
beamstop.diameter
);

const plotCameraTube = createPlotEllipse(
const plotCameraTube = plotter.createPlotEllipse(
cameraTubeCentre,
cameraTube.diameter,
plotConfig.plotAxes,
cameraTube.diameter
);

const plotClearance = createPlotEllipseClearance(
const plotClearance = plotter.createPlotEllipseClearance(
beamstopCentre,
beamstop.diameter,
beamstop.clearance ?? 0,
plotConfig.plotAxes,
beamstop.clearance ?? 0
);

const plotDetector = createPlotRectangle(
new Vector3(0, 0),
const plotDetector = plotter.createPlotRectangle(
detector.resolution,
plotConfig.plotAxes,
);

const plotVisibleRange = createPlotRange(
const plotVisibleRange = plotter.createPlotRange(
minPoint,
maxPoint,
plotConfig.plotAxes,
);

// I am up to here
Expand Down Expand Up @@ -180,13 +183,15 @@ export default function CentrePlot(): JSX.Element {
)
});


let plotRequestedRange = {
start: new Vector3(0, 0),
end: new Vector3(0, 0),
};
if (
requestedRange &&
beamlineConfig.cameraLength
beamlineConfig.cameraLength &&
beamlineConfig.wavelength
) {
const requestedMaxPt = getPointForQ(
requestedRange.max,
Expand All @@ -202,13 +207,14 @@ export default function CentrePlot(): JSX.Element {
beamlineConfig.wavelength,
beamstopCentre,
);
plotRequestedRange = createPlotRange(
plotRequestedRange = plotter.createPlotRange(
requestedMinPt,
requestedMaxPt,
plotConfig.plotAxes,
requestedMaxPt
);
}



const domains = getDomains(plotDetector, plotConfig.plotAxes);

return (
Expand Down
8 changes: 4 additions & 4 deletions src/plot/plotStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { create } from "zustand";
export enum PlotAxes {
milimeter = "mm",
pixel = "pixel",
reciprocal = "reciprocal",
reciprocal = "mm^-1",
}

export interface PlotConfig {
Expand Down Expand Up @@ -34,13 +34,13 @@ export const usePlotStore = create<PlotConfig>((set) => ({
cameraTube: true,
cameraTubeColor: { r: 80, g: 227, b: 194, a: 0.4 },
visibleRange: true,
visibleColor: { r: 208, g: 2, b: 27, a: 1 },
visibleColor: { r: 245, g: 166, b: 35, a: 1 },
requestedRange: true,
requestedRangeColor: { r: 65, g: 117, b: 5, a: 1 },
clearance: true,
clearanceColor: { r: 0, g: 0, b: 0, a: 0.2 },
inaccessibleRange: false,
inaccessibleRangeColor: { r: 245, g: 166, b: 35, a: 1 },
inaccessibleRange: true,
inaccessibleRangeColor: { r: 208, g: 2, b: 27, a: 1 },
plotAxes: PlotAxes.milimeter,
update: (newConfig) => {
set({ ...newConfig });
Expand Down
171 changes: 78 additions & 93 deletions src/plot/plotUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,113 +43,98 @@ export interface UnitVector {
y: math.Unit
}

export const createPlotEllipse = (
centre: UnitVector,
diameter: math.Unit,
plotAxes: PlotAxes,
): PlotEllipse => {
let xunit = plotAxes as string;
let yunit = plotAxes as string;

if (plotAxes === PlotAxes.pixel) {
xunit = "xpixel";
yunit = "ypixel";
}

const centreVec = new Vector3(
centre.x.to(xunit).toNumber(),
centre.y.to(yunit).toNumber(),
);

return {
centre: centreVec,
endPointX: new Vector3(
centreVec.x + mathjs.divide(diameter, 2).to(xunit).toNumber(),
centreVec.y,
),
endPointY: new Vector3(
centreVec.x,
centreVec.y + mathjs.divide(diameter, 2).to(yunit).toNumber(),
),
};
};

export const createPlotEllipseClearance = (
centre: UnitVector,
diameter: math.Unit,
clearance: number,
plotAxes: PlotAxes,
): PlotEllipse => {
let xunit = plotAxes as string;
let yunit = plotAxes as string;

if (plotAxes === PlotAxes.pixel) {
xunit = "xpixel";
yunit = "ypixel";
}

const centreVec = new Vector3(
centre.x.to(xunit).toNumber(),
centre.y.to(yunit).toNumber(),
);

return {
centre: centreVec,
endPointX: new Vector3(
centreVec.x + mathjs.divide(diameter, 2).to(xunit).toNumber() + mathjs.unit(clearance, "xpixel").to(xunit).toNumber(),
centreVec.y,
),
endPointY: new Vector3(
centreVec.x,
centreVec.y + mathjs.divide(diameter, 2).to(yunit).toNumber() + mathjs.unit(clearance, "ypixel").to(yunit).toNumber(),
),
};
};


export interface PlotRectangle {
upperBound: Vector3;
lowerBound: Vector3;
}

export const createPlotRectangle = (
pinnedCorner: Vector3,
resolution: { height: number; width: number },
plotAxes: PlotAxes,
): PlotRectangle => {
let xunit = plotAxes as string;
let yunit = plotAxes as string;
if (plotAxes === PlotAxes.pixel) {
xunit = "xpixel";
yunit = "ypixel";
}


return {
lowerBound: pinnedCorner,
upperBound: new Vector3(mathjs.unit(resolution.width, "xpixel").to(xunit).toNumber(), mathjs.unit(resolution.height, "ypixel").to(yunit).toNumber()),
};
};

export interface PlotRange {
start: Vector3;
end: Vector3;
}

export const createPlotRange = (
startPoint: UnitVector,
endPoint: UnitVector,
plotAxes: PlotAxes,
): PlotRange => {
let xunit = plotAxes as string;
let yunit = plotAxes as string;
if (plotAxes === PlotAxes.pixel) {
xunit = "xpixel";
yunit = "ypixel";
export class Plotter {
plotAxes: PlotAxes;
private xunit: string;
private yunit: string;
private scaleFactor: mathjs.Unit | null;
constructor(plotAxes: PlotAxes, scaleFactor: mathjs.Unit | null) {
this.xunit = plotAxes as string;
this.yunit = plotAxes as string;
this.plotAxes = plotAxes;
this.scaleFactor = scaleFactor;
if (plotAxes === PlotAxes.pixel) {
this.xunit = "xpixel";
this.yunit = "ypixel";
}
}

return {
start: new Vector3(startPoint.x.to(xunit).toNumber(), startPoint.y.to(yunit).toNumber()),
end: new Vector3(endPoint.x.to(xunit).toNumber(), endPoint.y.to(yunit).toNumber()),
createPlotEllipse(
centre: UnitVector,
diameter: math.Unit,
): PlotEllipse {
const centreVec = new Vector3(
centre.x.to(this.xunit).toNumber(),
centre.y.to(this.yunit).toNumber(),
);

return {
centre: centreVec,
endPointX: new Vector3(
centreVec.x + mathjs.divide(diameter, 2).to(this.xunit).toNumber(),
centreVec.y,
),
endPointY: new Vector3(
centreVec.x,
centreVec.y + mathjs.divide(diameter, 2).to(this.yunit).toNumber(),
),
};
};

Check failure on line 95 in src/plot/plotUtils.ts

View workflow job for this annotation

GitHub Actions / deploy

Unnecessary semicolon

createPlotEllipseClearance = (
centre: UnitVector,
diameter: math.Unit,
clearance: number,
): PlotEllipse => {

const centreVec = new Vector3(
centre.x.to(this.xunit).toNumber(),
centre.y.to(this.yunit).toNumber(),
);

return {
centre: centreVec,
endPointX: new Vector3(
centreVec.x + mathjs.divide(diameter, 2).to(this.xunit).toNumber() + mathjs.unit(clearance, "xpixel").to(this.xunit).toNumber(),
centreVec.y,
),
endPointY: new Vector3(
centreVec.x,
centreVec.y + mathjs.divide(diameter, 2).to(this.yunit).toNumber() + mathjs.unit(clearance, "ypixel").to(this.yunit).toNumber(),
),
};
};

createPlotRectangle(
resolution: { height: number; width: number },
): PlotRectangle {
return {
lowerBound: new Vector3(0, 0),
upperBound: new Vector3(mathjs.unit(resolution.width, "xpixel").to(this.xunit).toNumber(), mathjs.unit(resolution.height, "ypixel").to(this.yunit).toNumber()),
};
};

Check failure on line 128 in src/plot/plotUtils.ts

View workflow job for this annotation

GitHub Actions / deploy

Unnecessary semicolon

createPlotRange = (
startPoint: UnitVector,
endPoint: UnitVector,
): PlotRange => {
return {
start: new Vector3(startPoint.x.to(this.xunit).toNumber(), startPoint.y.to(this.yunit).toNumber()),
end: new Vector3(endPoint.x.to(this.xunit).toNumber(), endPoint.y.to(this.yunit).toNumber()),
};
};
};

Check failure on line 139 in src/plot/plotUtils.ts

View workflow job for this annotation

GitHub Actions / deploy

Unnecessary semicolon

8 changes: 4 additions & 4 deletions src/presets/presetConfigs.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"diameter": 310
},
"angle": 1.57,
"angle": 90,
"wavelength": null,
"cameraLength": 1.9,
"minWavelength": 0.062,
Expand All @@ -42,13 +42,13 @@
},
"diameter": 310
},
"angle": 1.57,
"angle": 90,
"wavelength": null,
"cameraLength": 1.9,
"minWavelength": 6.2e-2,
"minWavelength": 0.062,
"maxWavelength": 0.335,
"minCameraLength": 1.9,
"maxCameraLength": 9.9,
"cameraLengthStep": 2
}
}
}
Loading

0 comments on commit 2ce3b0c

Please sign in to comment.