Skip to content

Commit

Permalink
update beamline config store type
Browse files Browse the repository at this point in the history
  • Loading branch information
tizayi committed Dec 5, 2023
1 parent 2161791 commit 9b3df9d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 53 deletions.
5 changes: 3 additions & 2 deletions src/basicAppBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export default function BasicAppBar(): JSX.Element {
setState({ menuOpen: open });
};

const preset = useBeamlineConfigStore((state) => state.preset);
const beamlineConfig = useBeamlineConfigStore();

const updateBeamstop = useBeamstopStore((state) => state.updateBeamstop);
const updateCameraTube = useCameraTubeStore(
(state) => state.updateCameraTube,
Expand Down Expand Up @@ -73,7 +74,7 @@ export default function BasicAppBar(): JSX.Element {
disablePortal
id="combo-box-demo"
options={Object.keys(presetList)}
value={preset}
value={beamlineConfig.preset}
sx={{ width: 300, color: "white" }}
renderInput={(params) => (
<TextField
Expand Down
4 changes: 2 additions & 2 deletions src/data-entry/beamlineconfigStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface BeamlineConfigStore extends BeamlineConfig {
updateWavelengthUnits: (newUnits: WavelengthUnits) => void;
updateEnergy: (newEnergy: number | null, newUnits: EnergyUnits) => void;
updateEnergyUnits: (newUnits: EnergyUnits) => void;
update: (newConfig: Partial<BeamlineConfig>) => void;
update: (newConfig: Partial<BeamlineConfigStore>) => void;
}

export const useBeamlineConfigStore = create<BeamlineConfigStore>((set) => ({
Expand Down Expand Up @@ -69,5 +69,5 @@ export const useBeamlineConfigStore = create<BeamlineConfigStore>((set) => ({
energy: state.energy.to(newUnits),
userEnergy: state.energy.to(newUnits).toNumber(),
})),
update: (newConfig: Partial<BeamlineConfig>) => set({ ...newConfig }),
update: (newConfig: Partial<BeamlineConfigStore>) => set({ ...newConfig }),
}));
87 changes: 46 additions & 41 deletions src/plot/plotUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ export const getDomains = (
? detector.upperBound.x
: detector.upperBound.y;

const minAxis =
detector.lowerBound.x > detector.lowerBound.y
? detector.lowerBound.x
: detector.lowerBound.y;

return {
xAxis: new NumericRange(Math.round(-offset), Math.round(maxAxis + offset)),
yAxis: new NumericRange(Math.round(-offset), Math.round(maxAxis + offset)),
xAxis: new NumericRange(Math.round(minAxis - offset), Math.round(maxAxis + offset)),
yAxis: new NumericRange(Math.round(minAxis - offset), Math.round(maxAxis + offset)),
};
};

Expand Down Expand Up @@ -110,19 +115,19 @@ export class Plotter {
centre: newcentreVec,
endPointX: new Vector3(
newcentreVec.x +
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.xunit)
.toNumber(),
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.xunit)
.toNumber(),
newcentreVec.y,
),
endPointY: new Vector3(
newcentreVec.x,
newcentreVec.y +
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.yunit)
.toNumber(),
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.yunit)
.toNumber(),
),
};
}
Expand All @@ -142,15 +147,15 @@ export class Plotter {
centre: centreVec,
endPointX: new Vector3(
centreVec.x +
mathjs.divide(diameter, 2).to(this.xunit).toNumber() +
mathjs.unit(clearance, "xpixel").to(this.xunit).toNumber(),
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(),
mathjs.divide(diameter, 2).to(this.yunit).toNumber() +
mathjs.unit(clearance, "ypixel").to(this.yunit).toNumber(),
),
};
}
Expand All @@ -172,27 +177,27 @@ export class Plotter {
centre: newcentreVec,
endPointX: new Vector3(
newcentreVec.x +
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.xunit)
.toNumber() +
mathjs
.multiply(mathjs.unit(clearance, "xpixel"), this.scaleFactor)
.to(this.xunit)
.toNumber(),
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.xunit)
.toNumber() +
mathjs
.multiply(mathjs.unit(clearance, "xpixel"), this.scaleFactor)
.to(this.xunit)
.toNumber(),
newcentreVec.y,
),
endPointY: new Vector3(
newcentreVec.x,
newcentreVec.y +
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.yunit)
.toNumber() +
mathjs
.multiply(mathjs.unit(clearance, "ypixel"), this.scaleFactor)
.to(this.yunit)
.toNumber(),
mathjs
.multiply(mathjs.divide(diameter, 2), this.scaleFactor)
.to(this.yunit)
.toNumber() +
mathjs
.multiply(mathjs.unit(clearance, "ypixel"), this.scaleFactor)
.to(this.yunit)
.toNumber(),
),
};
};
Expand Down Expand Up @@ -228,18 +233,18 @@ export class Plotter {
),
upperBound: new Vector3(
lowerBound.x.to(this.xunit).toNumber() +
mathjs
.multiply(mathjs.unit(resolution.width, "xpixel"), this.scaleFactor)
.to(this.xunit)
.toNumber(),
mathjs
.multiply(mathjs.unit(resolution.width, "xpixel"), this.scaleFactor)
.to(this.xunit)
.toNumber(),
lowerBound.y.to(this.yunit).toNumber() +
mathjs
.multiply(
mathjs.unit(resolution.height, "ypixel"),
this.scaleFactor,
)
.to(this.yunit)
.toNumber(),
mathjs
.multiply(
mathjs.unit(resolution.height, "ypixel"),
this.scaleFactor,
)
.to(this.yunit)
.toNumber(),
),
};
}
Expand Down
14 changes: 6 additions & 8 deletions src/utils/units.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as math from "mathjs";
import * as mathjs from "mathjs";

export const CSPEED = math.unit(299792458, "m/s");
export const PLANCK = math.unit(6.62607015e-34, "J s");
export const CSPEED = mathjs.unit(299792458, "m/s");
export const PLANCK = mathjs.unit(6.62607015e-34, "J s");

export enum DistanceUnits {
millimetre = "mm",
Expand Down Expand Up @@ -46,7 +46,7 @@ export interface UnitConfig {
* @returns - wavelength in nm
*/
export const energy2WavelengthConverter = (energy: math.Unit): math.Unit => {
const result = math.divide(math.multiply(PLANCK, CSPEED), energy.toSI());
const result = mathjs.divide(mathjs.multiply(PLANCK, CSPEED), energy.toSI());

if (typeof result == "number" || !("units" in result)) {
throw TypeError("units for constants h and c are wrong");
Expand All @@ -62,7 +62,7 @@ export const energy2WavelengthConverter = (energy: math.Unit): math.Unit => {
export const wavelength2EnergyConverter = (
wavelength: math.Unit,
): math.Unit => {
const result = math.divide(math.multiply(PLANCK, CSPEED), wavelength.toSI());
const result = mathjs.divide(mathjs.multiply(PLANCK, CSPEED), wavelength.toSI());
if (typeof result == "number" || !("units" in result)) {
throw TypeError("units for constants h and c are wrong");
}
Expand Down Expand Up @@ -95,9 +95,7 @@ export const enforceRangeLimits = (
max: number,
value: number,
): number => {
if (value > max) {
return max;
}
if (value > max) return max;
if (value < min) return min;
return value;
};

0 comments on commit 9b3df9d

Please sign in to comment.