Skip to content

Commit

Permalink
Add group3 config filter
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jul 10, 2024
1 parent 13d16fd commit 0826b77
Show file tree
Hide file tree
Showing 13 changed files with 83 additions and 49 deletions.
2 changes: 1 addition & 1 deletion app/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const initConfig = () => {
simulation_round: 'ISIMIP3a',
sectors: [],
groups: [],
scenarios: []
group3: false
}

return {...defaultConfig, ...getConfig(), ...parseLocation()}
Expand Down
28 changes: 21 additions & 7 deletions app/src/components/Config.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,27 @@ const Config = ({ definitions, config, actions }) => {
const id = 'control-simulation-round-' + row.specifier

return (
<div className="form-check" key={index}>
<input className="form-check-input" type="radio" id={id}
value={row.specifier}
checked={row.specifier == config.simulation_round}
onChange={(event) => actions.changeSimulationRound(event.target.value)} />
<label className="form-check-label" htmlFor={id}>{row.title}</label>
</div>
<React.Fragment key={index}>
<div className="form-check">
{
row.specifier.endsWith('b') && (
<div className="float-right">
<input className="form-check-input" type="checkbox" id="control-group3"
checked={config.group3}
onChange={(event) => actions.toggleGroup3()} />
<label className="form-check-label" htmlFor="control-group3">
<span className="badge badge-info">only Group III</span>
</label>
</div>
)
}
<input className="form-check-input" type="radio" id={id}
value={row.specifier}
checked={row.specifier == config.simulation_round}
onChange={(event) => actions.changeSimulationRound(event.target.value)} />
<label className="form-check-label" htmlFor={id}>{row.title}</label>
</div>
</React.Fragment>
)
})
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/components/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ const Table = ({ definitions, config, identifier, caption, actions }) => {
case 'river_basin':
return <RiverBasinTable config={config} caption={caption} rows={rows} actions={actions} />
case 'sens_scenario':
return <ScenarioTable config={config} caption={caption} rows={rows} actions={actions} />
return <ScenarioTable config={config} caption={caption} rows={rows} actions={actions} group3={true} />
case 'soc_dataset':
return <InputDatasetTable config={config} caption={caption} rows={rows} groups={groups} actions={actions}/>
return <InputDatasetTable config={config} caption={caption} rows={rows} groups={groups} actions={actions} group3={true} />
case 'soc_scenario':
return <ScenarioTable config={config} caption={caption} rows={rows} actions={actions} />
return <ScenarioTable config={config} caption={caption} rows={rows} actions={actions} group3={true} />
case 'species':
return <SpeciesTable config={config} caption={caption} rows={rows} actions={actions} />
case 'upstream_variable':
Expand Down
3 changes: 3 additions & 0 deletions app/src/components/Title.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const Title = ({ definitions, config }) => {
return (
<div className="title">
<SimulationRounds config={config} /> protocol for <Sectors config={config} sectors={null} />
{
config.simulation_round.endsWith('b') && config.group3 && <span className="badge badge-info">only Group III</span>
}
</div>
)
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/tables/ExperimentsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Sectors from '../badges/Sectors'
import { filterRows } from '../../utils'

const ExperimentsTable = function({ definitions, config, caption, rows, actions }) {
const filteredRows = filterRows(config, rows)
const filteredRows = filterRows(config, rows, true)
const climateScenarios = Object.fromEntries(filterRows(config, definitions.climate_scenario).map(scenario => {
return [scenario.specifier, scenario.description]
}))
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/tables/ForcingDataTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SocForcing from '../badges/SocForcing'
import { GroupToggleLink, filterGroups, filterField, toggleGroups } from '../../utils'

const ForcingTable = function({ config, caption, rows, groups, actions }) {
const filteredGroups = filterGroups(config, rows, groups, actions)
const filteredGroups = filterGroups(config, rows, groups, actions, true)
const empty = (filteredGroups.length == 0)
const allOpen = filteredGroups.every(group => !group.closed)
const allToggle = () => toggleGroups(filteredGroups, allOpen)
Expand Down
28 changes: 20 additions & 8 deletions app/src/components/tables/InputDatasetTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import Sectors from '../badges/Sectors'
import { GroupToggleLink, filterGroups, filterField, toggleGroups } from '../../utils'


const InputDatasetTable = function({ config, caption, rows, groups, actions }) {
const filteredGroups = filterGroups(config, rows, groups, actions)
const InputDatasetTable = function({ config, caption, rows, groups, actions, group3 }) {
const filteredGroups = filterGroups(config, rows, groups, actions, group3)
const empty = (filteredGroups.length == 0)
const allOpen = filteredGroups.every(group => !group.closed)
const allToggle = () => toggleGroups(filteredGroups, allOpen)
Expand Down Expand Up @@ -70,11 +70,22 @@ const InputDatasetTable = function({ config, caption, rows, groups, actions }) {
<tr>
<td rowSpan={row.variables.length + 1}>
<p>{row.title || row.specifier }</p>
{row.mandatory && <p>
<span className="badge badge-info badge-mandatory" title="If your models uses input data of this kind, we require to use the specified dataset. Please see the note above.">
mandatory
</span>
</p>}
{
(row.mandatory || row.group3) && (
<p>
{
row.group3 && <span className="badge badge-info">Group III</span>
}
{
row.mandatory && (
<span className="badge badge-info badge-mandatory" title="If your models uses input data of this kind, we require to use the specified dataset. Please see the note above.">
mandatory
</span>
)
}
</p>
)
}
</td>
<td colSpan="4" className="nowrap">
<div>
Expand Down Expand Up @@ -148,7 +159,8 @@ InputDatasetTable.propTypes = {
caption: PropTypes.string.isRequired,
rows: PropTypes.array.isRequired,
groups: PropTypes.array.isRequired,
actions: PropTypes.object.isRequired
actions: PropTypes.object.isRequired,
group3: PropTypes.bool
}

export default InputDatasetTable
7 changes: 4 additions & 3 deletions app/src/components/tables/ScenarioTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Status from '../badges/Status'
import { filterRows } from '../../utils'


const ScenarioTable = function({ config, caption, rows }) {
const ScenarioTable = function({ config, caption, rows, group3 }) {
return (
<table className="table table-bordered table-fixed">
<caption>
Expand All @@ -23,7 +23,7 @@ const ScenarioTable = function({ config, caption, rows }) {
</thead>
<tbody>
{
filterRows(config, rows).map((row, index) => {
filterRows(config, rows, group3).map((row, index) => {
return (
<tr key={row.specifier}>
<td>
Expand Down Expand Up @@ -52,7 +52,8 @@ const ScenarioTable = function({ config, caption, rows }) {
ScenarioTable.propTypes = {
config: PropTypes.object.isRequired,
caption: PropTypes.string.isRequired,
rows: PropTypes.array.isRequired
rows: PropTypes.array.isRequired,
group3: PropTypes.bool
}

export default ScenarioTable
18 changes: 4 additions & 14 deletions app/src/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ const actions = {
toggleGroup: function(value) {
return { type: 'toggleGroup', value }
},
toggleScenario: function(value) {
return { type: 'toggleScenario', value }
toggleGroup3: function() {
return { type: 'toggleGroup3' }
}
}

Expand Down Expand Up @@ -44,18 +44,8 @@ function reducer(state, action) {
}
}
}
case 'toggleScenario': {
if (state.config.scenarios.find((scenario) => scenario === action.value)) {
return {
...state,
config: { ...state.config, scenarios: state.config.scenarios.filter((scenario) => scenario !== action.value) }
}
} else {
return {
...state,
config: { ...state.config, scenarios: [...state.config.scenarios, action.value] }
}
}
case 'toggleGroup3': {
return { ...state, config: { ...state.config, group3: !state.config.group3 }}
}
default:
return state
Expand Down
8 changes: 5 additions & 3 deletions app/src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const GroupToggleLink = ({ closed, toggle, all, label }) => {
}
}

const filterRows = (config, rows) => {
const filterRows = (config, rows, group3) => {
if (Array.isArray(rows)) {
return rows.filter(row => {
if (row.simulation_rounds === undefined || row.simulation_rounds.includes(config.simulation_round)) {
Expand All @@ -41,6 +41,8 @@ const filterRows = (config, rows) => {
return false
}).filter(row => {
return row.hidden != true
}).filter(row => {
return config.simulation_round.endsWith('a') || !group3 || !config.group3 || row.group3
})
} else {
return []
Expand Down Expand Up @@ -76,9 +78,9 @@ const filterField = (config, field) => {
}
}

const filterGroups = (config, rows, groups, actions) => {
const filterGroups = (config, rows, groups, actions, group3) => {
return groups.map(group => {
group.rows = filterRows(config, rows).filter(row => row.group == group.specifier)
group.rows = filterRows(config, rows, group3).filter(row => row.group == group.specifier)
group.closed = !config.groups.includes(group.specifier)
group.toggle = () => actions.toggleGroup(group.specifier)
return group
Expand Down
9 changes: 2 additions & 7 deletions app/src/utils/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,7 @@ const getConfig = () => {
config.groups = groups
}

const scenarios = ls.get('scenarios') ? JSON.parse(ls.get('scenarios')) : []
if ([
...definitions.climate_scenario, ...definitions.soc_scenario, ...definitions.sens_scenario
].some((scenario) => scenarios.includes(scenario.specifier))) {
config.scenarios = scenarios
}
config.group3 = ls.get('group3') ? JSON.parse(ls.get('group3')) : false

return config
}
Expand All @@ -34,7 +29,7 @@ const updateConfig = (config) => {
ls.set('simulation_round', config.simulation_round)
ls.set('sectors', JSON.stringify(config.sectors))
ls.set('groups', JSON.stringify(config.groups))
ls.set('scenarios', JSON.stringify(config.scenarios))
ls.set('group3', JSON.stringify(config.group3))
}

export { getConfig, updateConfig }
2 changes: 1 addition & 1 deletion assets/app.js

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions definitions/soc_dataset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
title: Landuse totals
group: landuse
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -68,6 +69,7 @@
title: Downscaling to 5 crops
group: landuse
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -149,6 +151,7 @@
title: Downscaling to 15 crops
group: landuse
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -293,6 +296,7 @@
title: Managed pastures and rangeland
group: landuse
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -350,6 +354,7 @@
title: Urban areas
group: landuse
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -405,6 +410,7 @@
title: Forests and natural vegetation
group: landuse
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -475,6 +481,7 @@
title: Nitrogen deposited by fertilizers on croplands
group: n-fertilizer
mandatory: true
group3: true
frequency: annual (growing season)
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -541,6 +548,7 @@
group: n-deposition
frequency: monthly
resolution: 0.5° grid
group3: true
path:
ISIMIP3a:
- ISIMIP3a/InputData/socioeconomic/n-deposition/histsoc/ndep-nhx_histsoc_annual_<start>_<end>.nc
Expand Down Expand Up @@ -593,6 +601,7 @@
group: n-deposition
frequency: monthly
resolution: 0.5° grid
group3: true
path:
ISIMIP3a:
- ISIMIP3a/InputData/socioeconomic/n-deposition/histsoc/ndep-nhy_histsoc_annual_<start>_<end>.nc
Expand Down Expand Up @@ -680,6 +689,7 @@
frequency: annual
resolution: 0.5° grid
mandatory: true
group3: true
path:
- ISIMIP3b/InputData/socioeconomic/crop_calendar/histsoc/ggcmi-crop-calendar_<soc_scenario>_<crop>_<irrigation>.nc
- ISIMIP3b/InputData/socioeconomic/crop_calendar/ssp126soc-adapt/ggcmi-crop-calendar_<climate-forcing>_ssp126_<crop>-<irrigation>.nc
Expand Down Expand Up @@ -1062,6 +1072,7 @@
resolution:
- 0.5° grid
- national
group3: true
path:
ISIMIP3a:
- ISIMIP3a/InputData/socioeconomic/wood_harvesting/histsoc/<variable>_histsoc_annual_<start>_<end>.nc
Expand Down Expand Up @@ -1142,6 +1153,7 @@
group: land-transformation
frequency: annual
resolution: 0.5° grid
group3: true
path:
ISIMIP3a:
- ISIMIP3a/InputData/socioeconomic/land-transformation/histsoc/land-transformation_histsoc_annual_<start>_<end>.nc
Expand Down Expand Up @@ -1194,6 +1206,7 @@
group: irrigation-techniques-shares
frequency: annual
resolution: 0.5° grid
group3: true
path:
ISIMIP3b:
- ISIMIP3b/InputData/socioeconomic/irrigation-techniques/ssp126soc-noadapt/irrigation-techniques-15crops_magpie_ssp126_annual_2015_2100.nc
Expand Down Expand Up @@ -1508,6 +1521,7 @@
title: Population (gridded)
group: population
mandatory: true
group3: true
frequency: annual
resolution: 0.5° grid
path:
Expand Down Expand Up @@ -1548,6 +1562,7 @@
title: Population (country-level)
group: population
mandatory: true
group3: true
frequency: annual
resolution: national
path:
Expand Down Expand Up @@ -1581,6 +1596,7 @@
title: GDP PPP
group: gdp
mandatory: true
group3: true
frequency: annual
resolution: country-level
path:
Expand Down Expand Up @@ -1613,6 +1629,7 @@
title: GDP MER
group: gdp
mandatory: true
group3: true
frequency: annual
resolution: country-level
path:
Expand Down

0 comments on commit 0826b77

Please sign in to comment.