Skip to content

Commit 66e502d

Browse files
authored
Merge pull request #446 from NASA-IMPACT/develop
Release 1.8.0
2 parents e87316b + bee5be9 commit 66e502d

23 files changed

+137
-675
lines changed
Lines changed: 19 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import get from 'lodash.get';
1+
import defaultsDeep from 'lodash.defaultsdeep';
22

33
import no2 from './layer-no2';
44
import no2Diff from './layer-no2-diff';
@@ -18,7 +18,7 @@ import waterGlSpm from './layer-wq-gl-spm';
1818
import detectionPlane from './layer-detection-plane';
1919
import agTogo from './layer-togo-ag';
2020

21-
const layers = [
21+
const layerOverrides = [
2222
no2,
2323
no2Diff,
2424
co2,
@@ -38,196 +38,30 @@ const layers = [
3838
agTogo
3939
];
4040

41-
export default layers;
42-
43-
const layersBySpotlight = {
44-
be: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'recovery', 'detection-plane'],
45-
du: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'recovery'],
46-
gh: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'recovery'],
47-
la: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'agriculture', 'slowdown', 'detection-ship', 'detection-plane', 'recovery'],
48-
sf: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'agriculture', 'slowdown', 'recovery', 'detection-ship', 'detection-plane', 'water-chlorophyll', 'water-spm'],
49-
tk: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'recovery', 'detection-plane'],
50-
ny: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'detection-ship', 'detection-plane', 'water-chlorophyll', 'water-spm', 'recovery'],
51-
togo: ['togo-ag'],
52-
wble: ['water-wq-gl-chl', 'water-wq-gl-spm']
53-
};
54-
55-
const layerOverridesBySpotlight = {
56-
be: {
57-
'nightlights-viirs': handleNightlightsViirs,
58-
'detection-plane': (l, spotlightId) =>
59-
handleInferenceTimeseries(l, spotlightId, {
60-
domain: ['2020-01-09', '2020-01-12', '2020-01-14', '2020-02-10', '2020-02-18', '2020-03-12', '2020-03-13', '2020-03-19', '2020-04-11', '2020-05-05', '2020-05-14']
61-
})
62-
63-
},
64-
du: {
65-
'nightlights-viirs': handleNightlightsViirs
66-
},
67-
gh: {
68-
'nightlights-viirs': handleNightlightsViirs
69-
},
70-
la: {
71-
'nightlights-viirs': handleNightlightsViirs,
72-
'detection-multi': (l, spotlightId) =>
73-
handleInferenceTimeseries(l, spotlightId, {
74-
domain: ['2020-01-02', '2020-02-13']
75-
}),
76-
'detection-ship': (l, spotlightId) =>
77-
handleInferenceTimeseries(l, spotlightId, {
78-
domain: ['2020-01-01', '2020-01-06', '2020-01-07', '2020-01-09', '2020-01-10', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-17', '2020-01-18', '2020-01-19', '2020-01-22', '2020-01-23', '2020-01-24', '2020-01-27', '2020-01-28', '2020-01-29', '2020-01-30', '2020-01-31', '2020-02-02', '2020-02-03', '2020-02-27', '2020-02-29', '2020-03-03', '2020-03-08', '2020-03-15', '2020-03-21', '2020-03-22', '2020-03-27', '2020-04-23', '2020-04-24', '2020-05-01', '2020-05-02', '2020-05-03', '2020-05-04', '2020-05-05', '2020-05-06', '2020-05-07', '2020-05-08', '2020-05-09', '2020-05-11', '2020-05-12', '2020-05-13', '2020-05-14', '2020-05-15', '2020-05-16', '2020-05-17', '2020-05-19', '2020-05-20', '2020-05-21']
79-
}),
80-
'detection-plane': (l, spotlightId) =>
81-
handleInferenceTimeseries(l, spotlightId, {
82-
domain: ['2020-01-10', '2020-01-14', '2020-02-01', '2020-02-03', '2020-03-22', '2020-04-15', '2020-04-21', '2020-05-04', '2020-05-05']
83-
})
84-
},
85-
sf: {
86-
'nightlights-viirs': handleNightlightsViirs,
87-
'detection-ship': (l, spotlightId) =>
88-
handleInferenceTimeseries(l, spotlightId, {
89-
domain: ['2020-01-02', '2020-01-03', '2020-01-05', '2020-01-07', '2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-17', '2020-01-18', '2020-01-23', '2020-01-27', '2020-01-30', '2020-01-31', '2020-05-01', '2020-05-03', '2020-05-04', '2020-05-05', '2020-05-06', '2020-05-07', '2020-05-08', '2020-01-02', '2020-01-03', '2020-01-05', '2020-01-07', '2020-01-10', '2020-01-11', '2020-01-12', '2020-01-13', '2020-01-14', '2020-01-17', '2020-01-18', '2020-01-22', '2020-01-23', '2020-01-27', '2020-01-30', '2020-01-31', '2020-02-03', '2020-02-27', '2020-02-29', '2020-03-03', '2020-03-08', '2020-03-10', '2020-03-11', '2020-04-21', '2020-05-01', '2020-05-03', '2020-05-04', '2020-05-05', '2020-05-06', '2020-05-07', '2020-05-08', '2020-05-09', '2020-05-15', '2020-05-16', '2020-05-17', '2020-05-19', '2020-05-20', '2020-05-21']
90-
}),
91-
'water-chlorophyll': (l, spotlightId) => {
92-
return {
93-
...l,
94-
domain: ['2020-03-02', '2020-04-03', '2020-04-19', '2020-05-04', '2020-05-05', '2020-05-19', '2020-05-21', '2020-05-24', '2020-06-01', '2020-06-03', '2020-06-06', '2020-06-13', '2020-06-18', '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-26', '2020-06-28', '2020-07-01', '2020-07-03', '2020-07-06', '2020-07-08', '2020-07-13']
95-
};
96-
},
97-
'water-spm': (l, spotlightId) => {
98-
return {
99-
...l,
100-
domain: ['2020-03-02', '2020-04-03', '2020-04-19', '2020-05-04', '2020-05-05', '2020-05-21', '2020-05-24', '2020-05-28', '2020-06-01', '2020-06-03', '2020-06-06', '2020-06-13', '2020-06-21', '2020-06-22', '2020-06-23', '2020-06-25', '2020-06-28', '2020-07-01', '2020-07-03']
101-
};
102-
},
103-
'detection-plane': (l, spotlightId) =>
104-
handleInferenceTimeseries(l, spotlightId, {
105-
domain: ['2020-01-11', '2020-01-12', '2020-01-13', '2020-02-06', '2020-02-07', '2020-02-10', '2020-02-15', '2020-02-18', '2020-02-20', '2020-03-09', '2020-03-10', '2020-03-12', '2020-03-19', '2020-04-02', '2020-04-03', '2020-04-07', '2020-04-15', '2020-04-22', '2020-05-04', '2020-05-05', '2020-05-07', '2020-05-19']
106-
})
107-
},
108-
tk: {
109-
'nightlights-viirs': handleNightlightsViirs,
110-
'water-chlorophyll': (l, spotlightId) => {
111-
return {
112-
...l,
113-
domain: ['2018-01-03', '2018-01-10', '2018-01-17', '2018-01-24', '2018-01-31', '2018-02-14', '2018-02-21', '2018-03-07', '2018-03-14', '2018-03-28', '2018-04-04', '2018-04-11', '2018-04-18', '2018-04-25', '2018-05-02', '2018-05-09', '2018-05-16', '2018-05-30', '2018-06-20', '2018-06-27', '2018-07-04', '2018-07-11', '2018-07-18', '2018-07-25', '2018-08-01', '2018-08-08', '2018-08-22', '2018-09-05', '2018-09-12', '2018-09-19', '2018-09-26', '2018-10-03', '2018-10-17', '2018-10-24', '2018-11-07', '2018-11-14', '2018-11-21', '2018-11-28', '2018-12-12', '2018-12-19', '2018-12-26', '2019-01-02', '2019-01-09', '2019-01-16', '2019-01-23', '2019-01-30', '2019-02-13', '2019-02-27', '2019-03-06', '2019-03-13', '2019-03-20', '2019-03-27', '2019-04-03', '2019-04-10', '2019-05-08', '2019-05-15', '2019-05-22', '2019-05-29', '2019-06-12', '2019-06-19', '2019-07-24', '2019-07-31', '2019-08-07', '2019-08-14', '2019-08-21', '2019-08-28', '2019-09-04', '2019-09-11', '2019-09-25', '2019-10-02', '2019-10-09', '2019-10-23', '2019-10-30', '2019-11-06', '2019-11-13', '2019-11-20', '2019-11-27', '2019-12-11', '2019-12-18', '2019-12-25', '2020-01-01', '2020-01-08', '2020-01-15', '2020-01-29', '2020-02-05', '2020-02-19', '2020-02-26', '2020-03-04', '2020-03-18', '2020-03-25', '2020-04-01', '2020-04-08', '2020-04-15', '2020-04-29', '2020-05-06', '2020-05-13', '2020-05-20', '2020-06-03', '2020-06-10', '2020-06-13', '2020-07-25', '2020-08-01', '2020-08-08', '2020-08-15'],
114-
source: {
115-
...l.source,
116-
tiles: l.source.tiles.map(t => t.replace('&rescale=-100%2C100', ''))
117-
}
118-
};
119-
},
120-
'detection-plane': (l, spotlightId) =>
121-
handleInferenceTimeseries(l, spotlightId, {
122-
domain: ['2020-01-19', '2020-02-01', '2020-02-05', '2020-03-18', '2020-03-19', '2020-04-09', '2020-04-10', '2020-05-02']
123-
})
124-
},
125-
ny: {
126-
'nightlights-viirs': handleNightlightsViirs,
127-
'water-chlorophyll': (l, spotlightId) => {
128-
return {
129-
...l,
130-
domain: ['2020-01-01', '2020-01-08', '2020-01-15', '2020-01-22', '2020-01-29', '2020-02-05', '2020-02-12', '2020-02-19', '2020-02-26', '2020-03-04', '2020-03-11', '2020-03-18', '2020-03-25', '2020-04-01', '2020-04-08', '2020-04-15', '2020-04-22', '2020-04-29', '2020-05-06', '2020-05-13', '2020-05-20', '2020-05-27', '2020-06-03', '2020-06-10', '2020-06-17', '2020-06-24', '2020-07-01', '2020-07-08', '2020-07-15', '2020-07-22', '2020-07-29', '2020-08-05', '2020-08-12', '2020-09-02', '2020-09-09', '2020-09-16', '2020-09-23', '2020-09-30']
131-
};
132-
},
133-
'detection-ship': (l, spotlightId) =>
134-
handleInferenceTimeseries(l, spotlightId, {
135-
domain: ['2020-01-02', '2020-01-09', '2020-01-11', '2020-01-16', '2020-01-17', '2020-01-19', '2020-01-23', '2020-01-24', '2020-01-30', '2020-05-02', '2020-05-05', '2020-01-02', '2020-01-09', '2020-01-11', '2020-01-16', '2020-01-17', '2020-01-19', '2020-01-20', '2020-01-21', '2020-01-22', '2020-01-23', '2020-01-24', '2020-01-30', '2020-02-02', '2020-02-03', '2020-02-29', '2020-03-08', '2020-03-18', '2020-03-22', '2020-03-27', '2020-05-02', '2020-05-05', '2020-05-09', '2020-05-10', '2020-05-13', '2020-05-14', '2020-05-16', '2020-05-19', '2020-05-20', '2020-05-21']
136-
}),
137-
'water-spm': (l, spotlightId) => {
138-
return {
139-
...l,
140-
domain: ['2020-01-01', '2020-01-08', '2020-01-15', '2020-01-22', '2020-01-29', '2020-02-05', '2020-02-12', '2020-02-19', '2020-02-26', '2020-03-04', '2020-03-11', '2020-03-18', '2020-03-25', '2020-04-01', '2020-04-08', '2020-04-15', '2020-04-22', '2020-04-29', '2020-05-06', '2020-05-13', '2020-05-20', '2020-05-27', '2020-06-03', '2020-06-10', '2020-06-17', '2020-06-24', '2020-07-01', '2020-07-08', '2020-07-15', '2020-07-22', '2020-07-29', '2020-08-05', '2020-08-12', '2020-09-02', '2020-09-09', '2020-09-16', '2020-09-23', '2020-09-30']
141-
};
142-
},
143-
'nightlights-hd': (l, spotlightId) => {
144-
return {
145-
...l,
146-
// For NY, nightlights goes till June
147-
domain: [l.domain[0], '2020-06-01']
148-
};
149-
},
150-
'detection-plane': (l, spotlightId) =>
151-
handleInferenceTimeseries(l, spotlightId, {
152-
domain: ['2020-01-16', '2020-01-20', '2020-02-17', '2020-02-19', '2020-03-09', '2020-03-15', '2020-04-06', '2020-04-15', '2020-05-05', '2020-05-14']
153-
})
154-
}
155-
};
41+
// Store the layer data.
42+
const layersDataBySpotlight = {};
15643

15744
export function getSpotlightLayers (spotlightId) {
158-
const layersToUse = layersBySpotlight[spotlightId] || [];
159-
160-
// Filter by the layers to include &
161-
// Replace the {site} property on the layers
162-
return layers
163-
.filter((l) => layersToUse.includes(l.id))
164-
.map((layer) => {
165-
let l = handleSpotlightId(layer, spotlightId);
166-
167-
// Apply override function if it exists
168-
const overrideFn = get(layerOverridesBySpotlight, [spotlightId, l.id]);
169-
l = overrideFn ? overrideFn(l, spotlightId) : l;
170-
171-
return l;
172-
});
45+
return layersDataBySpotlight[spotlightId];
17346
}
17447

17548
export function getGlobalLayers () {
176-
const layersToUse = ['no2', 'no2-diff', 'co2', 'co2-diff', 'gibs-population', 'agriculture'];
177-
return layers.filter((l) => layersToUse.includes(l.id));
49+
return layersDataBySpotlight.global;
17850
}
17951

180-
// // // // // // // // // // // // // // // // // // // // // // // // // // //
181-
// // // // // // // // // // // // // // // // // // // // // // // // // // //
182-
// Layer helper functions below.
183-
184-
function handleSpotlightId (l, spotlightId) {
185-
// If we're dealing with a layer with a standard source, replace the
186-
// spotlightId in the source tiles. Other layers will be handled by the
187-
// override functions.
188-
const tiles = get(l, 'source.tiles');
189-
return tiles
190-
? {
191-
...l,
192-
source: {
193-
...l.source,
194-
tiles: tiles.map((t) => t.replace('{spotlightId}', spotlightId))
195-
}
196-
}
197-
: l;
198-
}
52+
export const storeSpotlightLayers = (spotlightId, layers) => {
53+
if (spotlightId === 'global') {
54+
layersDataBySpotlight[spotlightId] = layers;
55+
return;
56+
}
19957

200-
function handleNightlightsViirs (l, spotlightId) {
201-
const spotlightName = spotlightId === 'du' || spotlightId === 'gh'
202-
? 'EUPorts'
203-
: spotlightId;
58+
// Overrides to the layer settings.
59+
const spotLayers = layers
60+
.map((layer) => {
61+
const overrides = layerOverrides.find(l => l.id === layer.id) || {};
20462

205-
return {
206-
...l,
207-
source: {
208-
...l.source,
209-
tiles: l.source.tiles.map((t) =>
210-
t.replace('{spotlightName}', spotlightName)
211-
)
212-
}
213-
};
214-
}
63+
return defaultsDeep(layer, overrides);
64+
});
21565

216-
function handleInferenceTimeseries (l, spotlightId, options) {
217-
return {
218-
...l,
219-
domain: options.domain,
220-
source: {
221-
...l.source,
222-
vector: {
223-
...l.source.vector,
224-
data: l.source.vector.data.replace('{spotlightId}', spotlightId)
225-
},
226-
raster: {
227-
...l.source.raster,
228-
tiles: l.source.raster.tiles
229-
.map(t => t.replace('{spotlightId}', spotlightId))
230-
}
231-
}
232-
};
233-
}
66+
layersDataBySpotlight[spotlightId] = spotLayers;
67+
};
Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,6 @@
1-
import config from '../../../config';
2-
3-
import { indicatorGroupColors } from '../../../styles/theme/theme.js';
4-
51
export default {
62
id: 'agriculture',
7-
name: 'Agriculture',
8-
type: 'raster-timeseries',
9-
timeUnit: 'day',
10-
domain: [
11-
'2020-01-28', '2020-02-28', '2020-03-28', '2020-04-28', '2020-05-28', '2020-06-28', '2020-07-28', '2020-08-28', '2020-09-28'
12-
],
13-
source: {
14-
type: 'raster',
15-
tiles: [
16-
`${config.api}/{z}/{x}/{y}@1x?url=s3://covid-eo-data/agriculture/CropMonitor_{date}.tif&resampling_method=nearest&bidx=1&color_map=custom_cropmonitor`
17-
]
18-
},
193
exclusiveWith: ['no2', 'co2', 'co2-diff', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-ship', 'detection-multi', 'water-chlorophyll', 'water-spm'],
204
enabled: false,
21-
swatch: indicatorGroupColors.economic,
22-
legend: {
23-
type: 'categorical',
24-
stops: [
25-
{ color: '#3C8EC4', label: 'Exceptional' },
26-
{ color: '#6ECC51', label: 'Favourable' },
27-
{ color: '#F3EF4F', label: 'Watch' },
28-
{ color: '#DF6335', label: 'Poor' },
29-
{ color: '#7E170E', label: 'Failure' },
30-
{ color: '#777879', label: 'Out of season' },
31-
{ color: '#794416', label: 'No data' }
32-
]
33-
},
345
info: null
356
};
Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,6 @@
1-
import config from '../../../config';
2-
3-
import { indicatorGroupColors } from '../../../styles/theme/theme.js';
4-
51
export default {
62
id: 'co2-diff',
7-
name: 'CO\u2082 (Diff)',
8-
type: 'raster-timeseries',
9-
timeUnit: 'day',
10-
domain: [
11-
'2020-01-01',
12-
'2020-07-16'
13-
],
14-
source: {
15-
type: 'raster',
16-
tiles: [
17-
`${config.api}/{z}/{x}/{y}@1x?url=s3://covid-eo-data/xco2-diff/xco2_16day_diff.{date}.tif&resampling_method=bilinear&bidx=1&rescale=-0.000001%2C0.000001&color_map=rdbu_r`
18-
]
19-
},
203
exclusiveWith: ['agriculture', 'no2', 'no2-diff', 'co2', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-ship', 'detection-multi', 'water-chlorophyll', 'water-spm'],
214
enabled: false,
22-
swatch: indicatorGroupColors['greenhouse-gas'],
23-
legend: {
24-
type: 'gradient',
25-
min: '< -1 ppm',
26-
max: '> 1 ppm',
27-
stops: [
28-
'#3A88BD',
29-
'#C9E0ED',
30-
'#E4EEF3',
31-
'#FDDCC9',
32-
'#DD7059'
33-
]
34-
},
355
info: 'This layer shows changes in carbon dioxide (CO₂) levels during coronavirus lockdowns versus previous years. Redder colors indicate increases in CO₂. Bluer colors indicate lower levels of CO₂.'
366
};

app/assets/scripts/components/common/layers/layer-co2.js

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,8 @@ import { format } from 'date-fns';
22

33
import config from '../../../config';
44

5-
import { indicatorGroupColors } from '../../../styles/theme/theme.js';
6-
75
export default {
86
id: 'co2',
9-
name: 'CO\u2082 (Avg)',
10-
type: 'raster-timeseries',
11-
timeUnit: 'day',
12-
domain: [
13-
'2020-01-01',
14-
'2020-07-16'
15-
],
16-
source: {
17-
type: 'raster',
18-
tiles: [
19-
`${config.api}/{z}/{x}/{y}@1x?url=s3://covid-eo-data/xco2-mean/xco2_16day_mean.{date}.tif&resampling_method=bilinear&bidx=1&rescale=0.000408%2C0.000419&color_map=rdylbu_r&color_formula=gamma r {gamma}`
20-
21-
]
22-
},
237
exclusiveWith: ['agriculture', 'no2', 'co2-diff', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-ship', 'detection-multi', 'water-chlorophyll', 'water-spm'],
248
enabled: false,
259
compare: {
@@ -34,21 +18,5 @@ export default {
3418
]
3519
}
3620
},
37-
38-
swatch: indicatorGroupColors['greenhouse-gas'],
39-
legend: {
40-
type: 'gradient-adjustable',
41-
min: '< 408 ppm',
42-
max: '> 419 ppm',
43-
stops: [
44-
'#313695',
45-
'#588cbf',
46-
'#a3d2e5',
47-
'#e8f6e8',
48-
'#fee89c',
49-
'#fba55c',
50-
'#e24932'
51-
]
52-
},
5321
info: 'This layer shows the average background concentration of carbon dioxide (CO₂) in our atmosphere for 2020. Redder colors indicate more CO₂. Whiter colors indicate less CO₂.'
5422
};
Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,6 @@
1-
import config from '../../../config';
2-
import { indicatorGroupColors } from '../../../styles/theme/theme';
3-
41
export default {
52
id: 'detection-plane',
6-
name: 'Planes',
7-
type: 'inference-timeseries',
8-
domain: [
9-
'2020-01-01',
10-
'2020-04-30'
11-
],
12-
source: {
13-
vector: {
14-
type: 'geojson',
15-
data: `${config.api}/detections/plane/{spotlightId}/{date}.geojson`
16-
},
17-
raster: {
18-
type: 'raster',
19-
tiles: [
20-
`${config.api}/planet/{z}/{x}/{y}?date={date}&site={spotlightId}`
21-
]
22-
}
23-
},
243
exclusiveWith: ['agriculture', 'no2', 'no2-diff', 'co2-diff', 'co2', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-multi', 'water-chlorophyll', 'water-spm'],
254
enabled: false,
26-
swatch: indicatorGroupColors.economic,
27-
timeUnit: 'day',
285
info: 'Planes detected each day in PlanetScope imagery are shown in red.'
296
};

0 commit comments

Comments
 (0)