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

Bugfix: snapshot units should now display correctly #468

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 7 additions & 1 deletion app/javascript/projects/analysis_panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,13 @@ const ChartLegend = ({ chartData, sourceType, props }: ChartLegendProps) => {
<input
disabled
type="text"
value={(key === "sum" && props && props.unit) ? `${NumStats[key]} ${props.unit}` : NumStats[key]}
value={NumStats[key]}
/>
<input
type='text'
value={ key === "sum" ? (props?.unit ? props.unit : "No unit") : ((props?.unit && props?.area) ? `${props.unit}/${props.area}` : "No unit") }
style={{ width: 70, textAlign: 'center' }}
disabled
/>
</div>
))
Expand Down
13 changes: 10 additions & 3 deletions app/javascript/projects/analysis_panel_tools/subsection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export function extentToChartData(colors: Color[] | undefined, model: BooleanTil
let counts = new Map<any, number>()
let color = new Map<any, [number, number, number, number]>()
let numeric_stats: NumericStats | undefined
const cellSize = getMedianCellSize(model).area / 1000000
const cellSize = getMedianCellSize(model).area

for (let x = outputTileRange.minX; x <= outputTileRange.maxX; x++) {
for (let y = outputTileRange.minY; y <= outputTileRange.maxY; y++) {
Expand All @@ -195,7 +195,7 @@ export function extentToChartData(colors: Color[] | undefined, model: BooleanTil

const count = counts.get(value) || 0

counts.set(value, count + cellSize)
counts.set(value, count + 1)

if (colors && model instanceof BooleanTileGrid) {
const col_value = colors[value ? 1 : 0]
Expand Down Expand Up @@ -227,7 +227,7 @@ export function extentToChartData(colors: Color[] | undefined, model: BooleanTil
const range = max - min
const step = range / bins

const _sum = sum(mapEntries.map((x) => x[1] * x[0])) * unitsAdjustmentFactor(model.properties.area, model)
let _sum = sum(mapEntries.map((x) => x[1] * x[0]))
const total_entries = mapEntries.reduce((acc, cur) => acc + cur[1], 0)

const _mean = _sum / total_entries
Expand All @@ -237,6 +237,9 @@ export function extentToChartData(colors: Color[] | undefined, model: BooleanTil
return current[1] > max[1] ? current : max
}, mapEntries[0])[0]

// adjust the sum based on the area
_sum = _sum * unitsAdjustmentFactor(model.properties.area, model)

counts = new Map()
const fillMap = fillType ? getColorStops((fillType == "greyscale" ? "greys" : (fillType === "heatmap" ? "jet" : fillType)), 40).reverse() : undefined
const [ds_min, ds_max] = [model.getStats().min, model.getStats().max]
Expand All @@ -259,6 +262,10 @@ export function extentToChartData(colors: Color[] | undefined, model: BooleanTil
}
}

counts.forEach((value, key) => {
counts.set(key, ((value as number) * cellSize) / (1000 ** 2)) // convert from n cells to km²
})

numeric_stats = {
sum: _sum,
min,
Expand Down
Loading