Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skew-T log-p diagrams #75

Merged
merged 22 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
1eb7c0e
Start porting https://github.com/rsobash/d3-skewt/ to solidjs
Peter9192 Oct 29, 2024
8bc1154
Make axis ticks and tick format settable + polish code
Peter9192 Oct 29, 2024
ab9cf48
Oopsie messed up ticks on profile
Peter9192 Oct 29, 2024
fdd4606
Add and plot dummy data, looks like a real sounding now
Peter9192 Oct 29, 2024
b914dfd
Add title to card and rename to thermodynamic diagram
Peter9192 Oct 29, 2024
8d66cc6
Change soundingdata format
Peter9192 Nov 12, 2024
39a137e
Convert CLASS output to soundingdata format (proof of concept)
Peter9192 Nov 12, 2024
8eff1c7
Split skewT background from lines
Peter9192 Nov 12, 2024
e356a6c
Plot thermodynamic diagrams for all experiments/permutations
Peter9192 Nov 12, 2024
d5af833
Highlight lines on hover using either tailwind or solid event
Peter9192 Nov 12, 2024
212164d
Change size of lineplots
Peter9192 Nov 25, 2024
8897702
Merge remote-tracking branch 'origin/main' into skewtlogp
Peter9192 Nov 25, 2024
d8b1420
Fix formatting
Peter9192 Nov 25, 2024
8504f82
Consistent font
Peter9192 Nov 25, 2024
6c9e68c
Move legend out of lineplot
Peter9192 Nov 25, 2024
e14f8b6
Reuse legend component in thermodynamic diagram
Peter9192 Nov 25, 2024
b144988
Make sure all plots share same margins etc. + enable axis labels on s…
Peter9192 Nov 25, 2024
34e651e
Use analysis also in index.tsx, and turn off final height for production
Peter9192 Nov 25, 2024
75874d4
Start refactoring plotting code
Peter9192 Nov 25, 2024
6067f62
formatting
Peter9192 Nov 25, 2024
ab23007
disable failing test as final height is no longer available
Peter9192 Nov 25, 2024
666dde0
formatting
Peter9192 Nov 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 53 additions & 9 deletions apps/class-solid/src/components/Analysis.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { For, Match, Show, Switch, createMemo, createUniqueId } from "solid-js";
import { getVerticalProfiles } from "~/lib/profiles";
import { getThermodynamicProfiles, getVerticalProfiles } from "~/lib/profiles";
import { type Analysis, deleteAnalysis, experiments } from "~/lib/store";
import LinePlot from "./LinePlot";
import { MdiCog, MdiContentCopy, MdiDelete, MdiDownload } from "./icons";
import LinePlot from "./plots/LinePlot";
import { SkewTPlot } from "./plots/skewTlogP";
import { Button } from "./ui/button";
import { Card, CardContent, CardHeader, CardTitle } from "./ui/card";

Expand Down Expand Up @@ -37,19 +38,25 @@ export function TimeSeriesPlot() {
.map((perm, j) => {
return {
label: `${e.name}/${perm.name}`,
y: perm.output?.h ?? [],
x: perm.output?.t ?? [],
color: colors[(j + 1) % 10],
linestyle: linestyles[i % 5],
data:
perm.output?.t.map((tVal, i) => ({
x: tVal,
y: perm.output?.h[i] || Number.NaN,
})) || [],
};
});
return [
{
y: experimentOutput?.h ?? [],
x: experimentOutput?.t ?? [],
label: e.name,
color: colors[0],
linestyle: linestyles[i],
data:
experimentOutput?.t.map((tVal, i) => ({
x: tVal,
y: experimentOutput?.h[i] || Number.NaN,
})) || [],
},
...permutationRuns,
];
Expand Down Expand Up @@ -79,7 +86,7 @@ export function VerticalProfilePlot() {
color: colors[(j + 1) % 10],
linestyle: linestyles[i % 5],
label: `${e.name}/${p.name}`,
...getVerticalProfiles(p.output, p.config, variable, time),
data: getVerticalProfiles(p.output, p.config, variable, time),
};
});

Expand All @@ -88,7 +95,7 @@ export function VerticalProfilePlot() {
label: e.name,
color: colors[0],
linestyle: linestyles[i],
...getVerticalProfiles(
data: getVerticalProfiles(
e.reference.output ?? {
t: [],
h: [],
Expand All @@ -113,6 +120,39 @@ export function VerticalProfilePlot() {
);
}

export function ThermodynamicPlot() {
const time = -1;
const skewTData = createMemo(() => {
return experiments.flatMap((e, i) => {
const permutations = e.permutations.map((p, j) => {
// TODO get additional config info from reference
// permutations probably usually don't have gammaq/gammatetha set?
return {
color: colors[(j + 1) % 10],
linestyle: linestyles[i % 5],
label: `${e.name}/${p.name}`,
data: getThermodynamicProfiles(p.output, p.config, time),
};
});

return [
{
label: e.name,
color: colors[0],
linestyle: linestyles[i],
data: getThermodynamicProfiles(
e.reference.output,
e.reference.config,
time,
),
},
...permutations,
];
});
});
return <SkewTPlot data={skewTData} />;
}

/** Simply show the final height for each experiment that has output */
function FinalHeights() {
return (
Expand Down Expand Up @@ -154,7 +194,7 @@ function FinalHeights() {
export function AnalysisCard(analysis: Analysis) {
const id = createUniqueId();
return (
<Card class="w-[500px]" role="article" aria-labelledby={id}>
<Card class="min-w-[500px]" role="article" aria-labelledby={id}>
<CardHeader class="flex-row items-center justify-between py-2 pb-6">
{/* TODO: make name & description editable */}
<CardTitle id={id}>{analysis.name}</CardTitle>
Expand Down Expand Up @@ -183,6 +223,7 @@ export function AnalysisCard(analysis: Analysis) {
</CardHeader>
<CardContent class="min-h-[450px]">
<Switch fallback={<p>Unknown analysis type</p>}>
{/* @ts-ignore: kept for developers, but not included in production */}
<Match when={analysis.type === "finalheight"}>
<FinalHeights />
</Match>
Expand All @@ -192,6 +233,9 @@ export function AnalysisCard(analysis: Analysis) {
<Match when={analysis.type === "profiles"}>
<VerticalProfilePlot />
</Match>
<Match when={analysis.type === "skewT"}>
<ThermodynamicPlot />
</Match>
</Switch>
</CardContent>
</Card>
Expand Down
126 changes: 0 additions & 126 deletions apps/class-solid/src/components/LinePlot.tsx

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,26 @@ interface AxisProps {
transform?: string;
tickCount?: number;
label?: string;
tickValues?: number[];
tickFormat?: (n: number | { valueOf(): number }) => string;
decreasing?: boolean;
}

export const AxisBottom = (props: AxisProps) => {
const ticks = () => {
const domain = props.scale.domain();
const tickCount = props.tickCount || 5;
const ticks = (props: AxisProps) => {
const domain = props.scale.domain();
const generateTicks = (domain = [0, 1], tickCount = 5) => {
const step = (domain[1] - domain[0]) / (tickCount - 1);

return [...Array(tickCount).keys()].map((i) => {
const value = domain[0] + i * step;
return {
value,
position: props.scale(value),
};
});
return [...Array(10).keys()].map((i) => domain[0] + i * step);
};

const values = props.tickValues
? props.tickValues.filter((x) => x >= domain[0] && x <= domain[1])
: generateTicks(domain, props.tickCount);
return values.map((value) => ({ value, position: props.scale(value) }));
};

export const AxisBottom = (props: AxisProps) => {
const format = props.tickFormat ? props.tickFormat : d3.format(".3g");
return (
<g transform={props.transform}>
<line
Expand All @@ -35,12 +38,12 @@ export const AxisBottom = (props: AxisProps) => {
y2="0"
stroke="currentColor"
/>
<For each={ticks()}>
<For each={ticks(props)}>
{(tick) => (
<g transform={`translate(${tick.position}, 0)`}>
<line y2="6" stroke="currentColor" />
<text y="9" dy="0.71em" text-anchor="middle">
{d3.format(".3g")(tick.value)}
{format(tick.value)}
</text>
</g>
)}
Expand All @@ -53,21 +56,8 @@ export const AxisBottom = (props: AxisProps) => {
};

export const AxisLeft = (props: AxisProps) => {
const ticks = () => {
const domain = props.scale.domain();
const tickCount = props.tickCount || 5;
const step = (domain[1] - domain[0]) / (tickCount - 1);

return [...Array(tickCount).keys()].map((i) => {
const value = domain[0] + i * step;
return {
value,
position: props.scale(value),
};
});
};

const labelpos = props.scale.range().reduce((a, b) => a + b) / 2;
const format = props.tickFormat ? props.tickFormat : d3.format(".0f");
const yAnchor = props.decreasing ? 0 : 1;
return (
<g transform={props.transform}>
<line
Expand All @@ -77,23 +67,39 @@ export const AxisLeft = (props: AxisProps) => {
y2={props.scale.range()[1]}
stroke="currentColor"
/>
<For each={ticks()}>
<For each={ticks(props)}>
{(tick) => (
<g transform={`translate(0, ${tick.position})`}>
<line x2="-6" stroke="currentColor" />
<text x="-9" dy="0.32em" text-anchor="end">
{tick.value.toFixed()}
{format(tick.value)}
</text>
</g>
)}
</For>
<text
y={props.scale.range()[1]}
y={props.scale.range()[yAnchor]}
text-anchor="end"
transform="translate(-65, 20) rotate(-90)"
transform="translate(-45, 0) rotate(-90)"
>
{props.label}
</text>
</g>
);
};

/**
* Calculate a "nice" step size by rounding up to the nearest power of 10
* Snap the min and max to the nearest multiple of step
*/
export function getNiceAxisLimits(data: number[]): [number, number] {
const max = Math.max(...data);
const min = Math.min(...data);
const range = max - min;
const step = 10 ** Math.floor(Math.log10(range));

const niceMin = Math.floor(min / step) * step;
const niceMax = Math.ceil(max / step) * step;

return [niceMin, niceMax];
}
9 changes: 9 additions & 0 deletions apps/class-solid/src/components/plots/Base.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export interface ChartData<T> {
label: string;
color: string;
linestyle: string;
data: T[];
}

// TODO: would be nice to create a chartContainer/context that manages logic like
// width/height/margins etc. that should be consistent across different plots.
Loading