-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontend): aggregated risk map layer (risk hotspots)
New raster layer showing aggregated risk values for: - variables: "total value", "economic use", "population use", "total risk", EAD, EAEL. - hazards: "none", cyclone, "all flooding". Includes: - New aggregated risk map layer and params in `src/state/layers/risks`, `src/state/risks` and `src/state/risk-mapping`. - New config in `src/config/risks`. - New sidebar controls in `src/sidebar/risks`. - New legends and tooltips in `src/map/legend` and `src/map/tooltip`.
- Loading branch information
1 parent
a1fdaff
commit 0a1dada
Showing
24 changed files
with
423 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { DataParamGroupConfig } from 'lib/controls/data-params'; | ||
|
||
export interface RiskParams { | ||
riskSource?: string; | ||
returnPeriod: number; | ||
epoch: number; | ||
rcp: string; | ||
confidence: string | number; | ||
} | ||
|
||
export const RISK_DOMAINS: Record<string, DataParamGroupConfig<RiskParams>> = { | ||
none: { | ||
paramDomains: { | ||
returnPeriod: [0], | ||
epoch: [2010], | ||
rcp: ['baseline'], | ||
confidence: ['None'], | ||
}, | ||
paramDefaults: { | ||
returnPeriod: 0, | ||
epoch: 2010, | ||
rcp: 'baseline', | ||
confidence: 'None', | ||
}, | ||
}, | ||
fluvial: { | ||
paramDomains: { | ||
returnPeriod: [100], | ||
rcp: ['baseline'], | ||
epoch: [2010], | ||
confidence: ['None'], | ||
}, | ||
paramDefaults: { | ||
returnPeriod: 100, | ||
rcp: 'baseline', | ||
epoch: 2010, | ||
confidence: 'None', | ||
}, | ||
paramDependencies: { | ||
rcp: ({ epoch }) => { | ||
if (epoch === 2010) return ['baseline']; | ||
else if (epoch === 2050 || epoch === 2080) return ['2.6', '4.5', '8.5']; | ||
return []; | ||
}, | ||
}, | ||
}, | ||
cyclone: { | ||
paramDomains: { | ||
returnPeriod: [100], | ||
epoch: [2010], | ||
rcp: ['baseline'], | ||
confidence: [5, 50, 95], | ||
}, | ||
paramDefaults: { | ||
returnPeriod: 100, | ||
epoch: 2010, | ||
rcp: 'baseline', | ||
confidence: 50, | ||
}, | ||
paramDependencies: { | ||
rcp: ({ epoch }) => { | ||
if (epoch === 2010) return ['baseline']; | ||
if (epoch === 2050 || epoch === 2100) return ['4.5', '8.5']; | ||
return []; | ||
}, | ||
}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export const HAZARDS_METADATA = { | ||
none: { label: 'None' }, | ||
cyclone: { label: 'Cyclone' }, | ||
fluvial: { label: 'All Flooding' }, | ||
}; | ||
|
||
export const HAZARDS = Object.keys(HAZARDS_METADATA); | ||
|
||
export const RISKS_METADATA = { | ||
totalValue: { | ||
label: 'Total value', | ||
dataUnit: '', | ||
}, | ||
economicUse: { | ||
label: 'Economic use', | ||
dataUnit: '', | ||
}, | ||
populationUse: { | ||
label: 'Population use', | ||
dataUnit: '', | ||
}, | ||
totalRisk: { | ||
label: 'Total risk', | ||
dataUnit: '', | ||
}, | ||
ead: { | ||
label: 'Expected Annual Damages (EAD)', | ||
dataUnit: '', | ||
}, | ||
eael: { | ||
label: 'Expected Annual Economic Losses (EAEL)', | ||
dataUnit: '', | ||
}, | ||
}; | ||
|
||
export const RISKS = Object.keys(RISKS_METADATA); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import GL from '@luma.gl/constants'; | ||
import { RiskParams } from 'config/risks/domains'; | ||
|
||
import { rasterTileLayer } from 'lib/deck/layers/raster-tile-layer'; | ||
import { ViewLayer } from 'lib/data-map/view-layers'; | ||
|
||
import { RASTER_COLOR_MAPS } from '../color-maps'; | ||
import { RISK_SOURCE } from './source'; | ||
|
||
export function getRiskId< | ||
F extends string, //'fluvial' | 'surface' | 'coastal' | 'cyclone', | ||
RP extends number, | ||
RCP extends string, | ||
E extends number, | ||
C extends number | string, | ||
>({ | ||
riskType, | ||
riskSource, | ||
returnPeriod, | ||
rcp, | ||
epoch, | ||
confidence, | ||
}: { | ||
riskType: F; | ||
riskSource: string; | ||
returnPeriod: RP; | ||
rcp: RCP; | ||
epoch: E; | ||
confidence: C; | ||
}) { | ||
return `${riskType}__${riskSource}__rp_${returnPeriod}__rcp_${rcp}__epoch_${epoch}__conf_${confidence}` as const; | ||
} | ||
|
||
export function riskViewLayer(riskType: string, riskParams: RiskParams): ViewLayer { | ||
const { riskSource, returnPeriod, rcp, epoch, confidence } = riskParams; | ||
|
||
const deckId = getRiskId({ riskType, riskSource, returnPeriod, rcp, epoch, confidence }); | ||
|
||
return { | ||
id: riskType, | ||
group: 'risks', | ||
spatialType: 'raster', | ||
interactionGroup: 'risks', | ||
params: { riskType, riskParams }, | ||
fn: ({ deckProps }) => { | ||
const { scheme, range } = RASTER_COLOR_MAPS[riskType]; | ||
const dataURL = RISK_SOURCE.getDataUrl( | ||
{ | ||
riskType, | ||
riskParams: { riskSource, returnPeriod, rcp, epoch, confidence }, | ||
}, | ||
{ scheme, range }, | ||
); | ||
|
||
return rasterTileLayer( | ||
{ | ||
textureParameters: { | ||
[GL.TEXTURE_MAG_FILTER]: GL.LINEAR, | ||
// [GL.TEXTURE_MAG_FILTER]: zoom < 12 ? GL.NEAREST : GL.NEAREST_MIPMAP_LINEAR, | ||
}, | ||
opacity: riskType === 'cyclone' ? 0.6 : 1, | ||
}, | ||
deckProps, | ||
{ | ||
id: `${riskType}@${deckId}`, // follow the convention viewLayerId@deckLayerId | ||
data: dataURL, | ||
refinementStrategy: 'no-overlap', | ||
}, | ||
); | ||
}, | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const RISK_SOURCE = { | ||
getDataUrl( | ||
{ riskType, riskParams: { riskSource, returnPeriod, rcp, epoch, confidence } }, | ||
{ scheme, range }, | ||
) { | ||
const sanitisedRcp = rcp?.replace('.', 'x'); | ||
|
||
return `/raster/singleband/${riskType}/${riskSource}/${returnPeriod}/${sanitisedRcp}/${epoch}/${confidence}/{z}/{x}/{y}.png?colormap=${scheme}&stretch_range=[${range[0]},${range[1]}]`; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.