-
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/modules/risks`. - New config in `src/config/risks`. Parameters defined in `src/config/risks/domains`. - New sidebar controls in `src/sidebar/risks`. - New legends and tooltips in `src/config/risks`.
- Loading branch information
1 parent
8782508
commit e3867a3
Showing
17 changed files
with
406 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { FC } from 'react'; | ||
|
||
import { RasterHoverDescription } from 'lib/data-map/types'; | ||
import { RasterHoverDescription as RasterTooltip } from 'app/map/tooltip/content/RasterHoverDescription'; | ||
|
||
import * as RISKS_COLOR_MAPS from './color-maps'; | ||
import { RISKS_METADATA } from './metadata'; | ||
|
||
export const RiskHoverDescription: FC<RasterHoverDescription> = ({ target, viewLayer }) => { | ||
const { label, dataUnit } = RISKS_METADATA[viewLayer.id]; | ||
const { scheme, range } = RISKS_COLOR_MAPS[viewLayer.id]; | ||
return ( | ||
<RasterTooltip | ||
color={target.color} | ||
label={label} | ||
dataUnit={dataUnit} | ||
scheme={scheme} | ||
range={range} | ||
/> | ||
); | ||
}; |
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,14 @@ | ||
import { FC } from 'react'; | ||
|
||
import { RasterLegend } from 'app/map/legend/RasterLegend'; | ||
import { ViewLayer } from 'lib/data-map/view-layers'; | ||
|
||
import * as RISKS_COLOR_MAPS from './color-maps'; | ||
import { RISKS_METADATA } from './metadata'; | ||
|
||
export const RiskLegend: FC<{ viewLayer: ViewLayer }> = ({ viewLayer }) => { | ||
const { id } = viewLayer; | ||
const { label, dataUnit } = RISKS_METADATA[id]; | ||
const { scheme, range } = RISKS_COLOR_MAPS[id]; | ||
return <RasterLegend label={label} dataUnit={dataUnit} scheme={scheme} range={range} />; | ||
}; |
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,28 @@ | ||
export const totalValue = { | ||
scheme: 'reds', | ||
range: [0, 10], | ||
}; | ||
export const economicUse = { | ||
scheme: 'blues', | ||
range: [0, 10], | ||
}; | ||
|
||
export const populationUse = { | ||
scheme: 'purples', | ||
range: [0, 10], | ||
}; | ||
|
||
export const totalRisk = { | ||
scheme: 'greens', | ||
range: [0, 10], | ||
}; | ||
|
||
export const ead = { | ||
scheme: 'oranges', | ||
range: [0, 10], | ||
}; | ||
|
||
export const eael = { | ||
scheme: 'purples', | ||
range: [0, 10], | ||
}; |
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,66 @@ | ||
import { DataParamGroupConfig } from 'lib/controls/data-params'; | ||
|
||
export interface RiskParams { | ||
hazard: string; | ||
returnPeriod: number; | ||
epoch: number; | ||
rcp: string; | ||
confidence: string | number; | ||
} | ||
|
||
/* | ||
Default parameter ranges for each hazard type. | ||
These are used to define ranges for input controls in the sidebar. | ||
*/ | ||
const hazardParamDomains = { | ||
none: { | ||
returnPeriod: [0], | ||
epoch: [2010], | ||
rcp: ['baseline'], | ||
confidence: ['None'], | ||
}, | ||
cyclone: { | ||
returnPeriod: [0], | ||
epoch: [2010], | ||
rcp: ['baseline'], | ||
confidence: ['None'], | ||
}, | ||
fluvial: { | ||
returnPeriod: [0], | ||
epoch: [2010], | ||
rcp: ['baseline'], | ||
confidence: ['None'], | ||
}, | ||
}; | ||
|
||
export const RISK_DOMAINS: DataParamGroupConfig<RiskParams> = { | ||
/* | ||
Default parameter ranges for each risk type. | ||
*/ | ||
paramDomains: { | ||
hazard: ['none', 'cyclone', 'fluvial'], | ||
returnPeriod: [0], | ||
epoch: [2010], | ||
rcp: ['baseline'], | ||
confidence: ['None'], | ||
}, | ||
/* | ||
Default parameter values for each risk type. | ||
*/ | ||
paramDefaults: { | ||
hazard: 'none', | ||
returnPeriod: 0, | ||
epoch: 2010, | ||
rcp: 'baseline', | ||
confidence: 'None', | ||
}, | ||
/* | ||
Callback functions to define custom parameter ranges based on selected hazard etc. | ||
*/ | ||
paramDependencies: { | ||
rcp: ({ hazard }) => hazardParamDomains[hazard].rcp, | ||
epoch: ({ hazard }) => hazardParamDomains[hazard].epoch, | ||
returnPeriod: ({ hazard }) => hazardParamDomains[hazard].returnPeriod, | ||
confidence: ({ hazard }) => hazardParamDomains[hazard].confidence, | ||
}, | ||
}; |
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,85 @@ | ||
import { createElement } from 'react'; | ||
import GL from '@luma.gl/constants'; | ||
import { RiskParams } from './domains'; | ||
|
||
import { rasterTileLayer } from 'lib/deck/layers/raster-tile-layer'; | ||
import { ViewLayer } from 'lib/data-map/view-layers'; | ||
import { RasterTarget } from 'lib/data-map/types'; | ||
|
||
import { RiskLegend } from './RiskLegend'; | ||
import { RiskHoverDescription } from './RiskHoverDescription'; | ||
import * as RISKS_COLOR_MAPS from './color-maps'; | ||
import { RISK_SOURCE } from './source'; | ||
|
||
export function getRiskId< | ||
F extends string, // risk variable | ||
RP extends number, | ||
RCP extends string, | ||
E extends number, | ||
C extends number | string, | ||
>({ | ||
riskType, | ||
hazard, | ||
returnPeriod, | ||
rcp, | ||
epoch, | ||
confidence, | ||
}: { | ||
riskType: F; | ||
hazard: string; | ||
returnPeriod: RP; | ||
rcp: RCP; | ||
epoch: E; | ||
confidence: C; | ||
}) { | ||
return `${riskType}__${hazard}__rp_${returnPeriod}__rcp_${rcp}__epoch_${epoch}__conf_${confidence}` as const; | ||
} | ||
|
||
export function riskViewLayer(riskType: string, riskParams: RiskParams): ViewLayer { | ||
const { hazard, returnPeriod, rcp, epoch, confidence } = riskParams; | ||
|
||
const deckId = getRiskId({ riskType, hazard, returnPeriod, rcp, epoch, confidence }); | ||
|
||
return { | ||
id: riskType, | ||
group: 'risks', | ||
spatialType: 'raster', | ||
interactionGroup: 'risks', | ||
params: { riskType, riskParams }, | ||
fn: ({ deckProps }) => { | ||
const { scheme, range } = RISKS_COLOR_MAPS[riskType]; | ||
const dataURL = RISK_SOURCE.getDataUrl( | ||
{ | ||
riskType, | ||
riskParams: { hazard, 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', | ||
}, | ||
); | ||
}, | ||
renderLegend() { | ||
return createElement(RiskLegend, { | ||
key: riskType, | ||
viewLayer: this, | ||
}); | ||
}, | ||
renderTooltip({ target }: { target: RasterTarget }) { | ||
return createElement(RiskHoverDescription, { key: this.id, target, viewLayer: this }); | ||
}, | ||
}; | ||
} |
Oops, something went wrong.