Skip to content

Commit

Permalink
Add units, change to absorbance mode
Browse files Browse the repository at this point in the history
  • Loading branch information
suzil committed Oct 13, 2021
1 parent 410fe56 commit 4fc24b9
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 49 deletions.
10 changes: 9 additions & 1 deletion lib/radis-lambda/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,15 @@ def lambda_handler(event, context):

return {
"statusCode": 200,
"body": json.dumps({"data": {"x": list(x), "y": list(y)}}),
"body": json.dumps(
{
"data": {
"x": list(x),
"y": list(y),
"units": spectrum.units[payload["mode"]],
},
}
),
"headers": {
"Content-Type": "application/json",
"Access-Control-Allow-Origin": "*",
Expand Down
4 changes: 3 additions & 1 deletion website/src/components/CalcSpectrum.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const CalcSpectrum: React.FC = () => {
pressure: 1.01325,
path_length: 1,
simulate_slit: false,
mode: "radiance_noslit",
mode: "absorbance",
});
const [validationErrors, setValidationErrors] = useState<ValidationErrors>({
molecule: [],
Expand Down Expand Up @@ -95,6 +95,7 @@ export const CalcSpectrum: React.FC = () => {
species: params.species.map((species) => ({ ...species })),
minWavenumber: params.min_wavenumber_range,
maxWavenumber: params.max_wavenumber_range,
mode: params.mode,
});

import(/* webpackIgnore: true */ "./config.js").then(async (module) => {
Expand Down Expand Up @@ -328,6 +329,7 @@ export const CalcSpectrum: React.FC = () => {
species={plotData.species}
minWavenumberRange={plotData.minWavenumber}
maxWavenumberRange={plotData.maxWavenumber}
mode={plotData.mode}
/>
)
)}
Expand Down
107 changes: 63 additions & 44 deletions website/src/components/CalcSpectrumPlot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,75 @@ interface CalcSpectrumPlotProps {
species: Species[];
minWavenumberRange: number;
maxWavenumberRange: number;
mode: string;
}

export const CalcSpectrumPlot: React.FC<CalcSpectrumPlotProps> = ({
data,
species,
minWavenumberRange,
maxWavenumberRange,
}) => (
<Plot
className="Plot"
data={[
{
x: data.x,
y: data.y,
type: "scatter",
marker: { color: palette.secondary.main },
},
]}
layout={{
width: 800,
height: 600,
title: `Spectrum for ${species
.map(({ molecule, mole_fraction }) => {
const moleculeWithSubscripts = addSubscriptsToMolecule(
molecule || ""
);
return `${moleculeWithSubscripts}${moleculeWithSubscripts.sub()} = ${
mole_fraction as number
})`;
})
.join(", ")}`,
font: { family: "Roboto", color: "#000" },
xaxis: {
range: [minWavenumberRange, maxWavenumberRange],
title: { text: "Wavenumber (cm⁻¹)" },
rangeslider: {
// TODO: Update typing in DefinitelyTyped
// @ts-ignore
mode,
}) => {
let modeLabel;
if (mode === "absorbance") {
modeLabel = "Absorbance";
} else if (mode === "transmittance_noslit") {
modeLabel = "Transmittance";
} else if (mode === "radiance_noslit") {
modeLabel = "Radiance";
} else {
throw new Error("Invalid mode");
}
console.log(`Units: "${data.units}"`);
return (
<Plot
className="Plot"
data={[
{
x: data.x,
y: data.y,
type: "scatter",
marker: { color: palette.secondary.main },
},
]}
layout={{
width: 800,
height: 600,
title: `Spectrum for ${species
.map(({ molecule, mole_fraction }) => {
const moleculeWithSubscripts = addSubscriptsToMolecule(
molecule || ""
);
return `${moleculeWithSubscripts}${moleculeWithSubscripts.sub()} = ${
mole_fraction as number
})`;
})
.join(", ")}`,
font: { family: "Roboto", color: "#000" },
xaxis: {
range: [minWavenumberRange, maxWavenumberRange],
title: { text: "Wavenumber (cm⁻¹)" },
rangeslider: {
// TODO: Update typing in DefinitelyTyped
// @ts-ignore
autorange: true,
// @ts-ignore
yaxis: { rangemode: "auto" },
},
type: "linear",
},
yaxis: {
autorange: true,
// @ts-ignore
yaxis: { rangemode: "auto" },
title: {
text: `${modeLabel}${
data.units.length ? " (" + data.units + ")" : ""
}`,
},
type: "linear",
fixedrange: false,
},
type: "linear",
},
yaxis: {
autorange: true,
title: { text: "Radiance (mW/cm²/sr/nm)" },
type: "linear",
fixedrange: false,
},
}}
/>
);
}}
/>
);
};
4 changes: 2 additions & 2 deletions website/src/components/fields/Mode.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export const Mode: React.FC<ModeProps> = ({ params, setParams }) => (
mode: event.target.value as
| "radiance_noslit"
| "transmittance_noslit"
| "abscoeff",
| "absorbance",
})
}
>
<MenuItem value={"absorbance"}>Absorbance</MenuItem>
<MenuItem value={"radiance_noslit"}>Radiance</MenuItem>
<MenuItem value={"transmittance_noslit"}>Transmittance</MenuItem>
<MenuItem value={"abscoeff"}>Absorption Coefficient</MenuItem>
</Select>
</FormControl>
);
4 changes: 3 additions & 1 deletion website/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ export interface CalcSpectrumParams {
pressure: number;
path_length: number;
simulate_slit: boolean;
mode: "radiance_noslit" | "transmittance_noslit" | "abscoeff";
mode: "radiance_noslit" | "transmittance_noslit" | "absorbance";
}

export interface CalcSpectrumResponseData {
x: number[];
y: number[];
units: string;
}

export const palette = {
Expand Down Expand Up @@ -50,4 +51,5 @@ export interface CalcSpectrumPlotData {
species: Species[];
minWavenumber: number;
maxWavenumber: number;
mode: string;
}

0 comments on commit 4fc24b9

Please sign in to comment.