Skip to content

Commit

Permalink
Merge pull request #446 from NASA-IMPACT/develop
Browse files Browse the repository at this point in the history
Release 1.8.0
  • Loading branch information
drewbo authored Nov 11, 2020
2 parents e87316b + bee5be9 commit 66e502d
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 675 deletions.
204 changes: 19 additions & 185 deletions app/assets/scripts/components/common/layers/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import get from 'lodash.get';
import defaultsDeep from 'lodash.defaultsdeep';

import no2 from './layer-no2';
import no2Diff from './layer-no2-diff';
Expand All @@ -18,7 +18,7 @@ import waterGlSpm from './layer-wq-gl-spm';
import detectionPlane from './layer-detection-plane';
import agTogo from './layer-togo-ag';

const layers = [
const layerOverrides = [
no2,
no2Diff,
co2,
Expand All @@ -38,196 +38,30 @@ const layers = [
agTogo
];

export default layers;

const layersBySpotlight = {
be: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'recovery', 'detection-plane'],
du: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'recovery'],
gh: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'recovery'],
la: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'agriculture', 'slowdown', 'detection-ship', 'detection-plane', 'recovery'],
sf: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'agriculture', 'slowdown', 'recovery', 'detection-ship', 'detection-plane', 'water-chlorophyll', 'water-spm'],
tk: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'recovery', 'detection-plane'],
ny: ['no2', 'no2-diff', 'co2', 'co2-diff', 'nightlights-hd', 'nightlights-viirs', 'slowdown', 'detection-ship', 'detection-plane', 'water-chlorophyll', 'water-spm', 'recovery'],
togo: ['togo-ag'],
wble: ['water-wq-gl-chl', 'water-wq-gl-spm']
};

const layerOverridesBySpotlight = {
be: {
'nightlights-viirs': handleNightlightsViirs,
'detection-plane': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
})

},
du: {
'nightlights-viirs': handleNightlightsViirs
},
gh: {
'nightlights-viirs': handleNightlightsViirs
},
la: {
'nightlights-viirs': handleNightlightsViirs,
'detection-multi': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
domain: ['2020-01-02', '2020-02-13']
}),
'detection-ship': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
}),
'detection-plane': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
})
},
sf: {
'nightlights-viirs': handleNightlightsViirs,
'detection-ship': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
}),
'water-chlorophyll': (l, spotlightId) => {
return {
...l,
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']
};
},
'water-spm': (l, spotlightId) => {
return {
...l,
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']
};
},
'detection-plane': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
})
},
tk: {
'nightlights-viirs': handleNightlightsViirs,
'water-chlorophyll': (l, spotlightId) => {
return {
...l,
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'],
source: {
...l.source,
tiles: l.source.tiles.map(t => t.replace('&rescale=-100%2C100', ''))
}
};
},
'detection-plane': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
})
},
ny: {
'nightlights-viirs': handleNightlightsViirs,
'water-chlorophyll': (l, spotlightId) => {
return {
...l,
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']
};
},
'detection-ship': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
}),
'water-spm': (l, spotlightId) => {
return {
...l,
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']
};
},
'nightlights-hd': (l, spotlightId) => {
return {
...l,
// For NY, nightlights goes till June
domain: [l.domain[0], '2020-06-01']
};
},
'detection-plane': (l, spotlightId) =>
handleInferenceTimeseries(l, spotlightId, {
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']
})
}
};
// Store the layer data.
const layersDataBySpotlight = {};

export function getSpotlightLayers (spotlightId) {
const layersToUse = layersBySpotlight[spotlightId] || [];

// Filter by the layers to include &
// Replace the {site} property on the layers
return layers
.filter((l) => layersToUse.includes(l.id))
.map((layer) => {
let l = handleSpotlightId(layer, spotlightId);

// Apply override function if it exists
const overrideFn = get(layerOverridesBySpotlight, [spotlightId, l.id]);
l = overrideFn ? overrideFn(l, spotlightId) : l;

return l;
});
return layersDataBySpotlight[spotlightId];
}

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

// // // // // // // // // // // // // // // // // // // // // // // // // // //
// // // // // // // // // // // // // // // // // // // // // // // // // // //
// Layer helper functions below.

function handleSpotlightId (l, spotlightId) {
// If we're dealing with a layer with a standard source, replace the
// spotlightId in the source tiles. Other layers will be handled by the
// override functions.
const tiles = get(l, 'source.tiles');
return tiles
? {
...l,
source: {
...l.source,
tiles: tiles.map((t) => t.replace('{spotlightId}', spotlightId))
}
}
: l;
}
export const storeSpotlightLayers = (spotlightId, layers) => {
if (spotlightId === 'global') {
layersDataBySpotlight[spotlightId] = layers;
return;
}

function handleNightlightsViirs (l, spotlightId) {
const spotlightName = spotlightId === 'du' || spotlightId === 'gh'
? 'EUPorts'
: spotlightId;
// Overrides to the layer settings.
const spotLayers = layers
.map((layer) => {
const overrides = layerOverrides.find(l => l.id === layer.id) || {};

return {
...l,
source: {
...l.source,
tiles: l.source.tiles.map((t) =>
t.replace('{spotlightName}', spotlightName)
)
}
};
}
return defaultsDeep(layer, overrides);
});

function handleInferenceTimeseries (l, spotlightId, options) {
return {
...l,
domain: options.domain,
source: {
...l.source,
vector: {
...l.source.vector,
data: l.source.vector.data.replace('{spotlightId}', spotlightId)
},
raster: {
...l.source.raster,
tiles: l.source.raster.tiles
.map(t => t.replace('{spotlightId}', spotlightId))
}
}
};
}
layersDataBySpotlight[spotlightId] = spotLayers;
};
29 changes: 0 additions & 29 deletions app/assets/scripts/components/common/layers/layer-agriculture.js
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
import config from '../../../config';

import { indicatorGroupColors } from '../../../styles/theme/theme.js';

export default {
id: 'agriculture',
name: 'Agriculture',
type: 'raster-timeseries',
timeUnit: 'day',
domain: [
'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'
],
source: {
type: 'raster',
tiles: [
`${config.api}/{z}/{x}/{y}@1x?url=s3://covid-eo-data/agriculture/CropMonitor_{date}.tif&resampling_method=nearest&bidx=1&color_map=custom_cropmonitor`
]
},
exclusiveWith: ['no2', 'co2', 'co2-diff', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-ship', 'detection-multi', 'water-chlorophyll', 'water-spm'],
enabled: false,
swatch: indicatorGroupColors.economic,
legend: {
type: 'categorical',
stops: [
{ color: '#3C8EC4', label: 'Exceptional' },
{ color: '#6ECC51', label: 'Favourable' },
{ color: '#F3EF4F', label: 'Watch' },
{ color: '#DF6335', label: 'Poor' },
{ color: '#7E170E', label: 'Failure' },
{ color: '#777879', label: 'Out of season' },
{ color: '#794416', label: 'No data' }
]
},
info: null
};
30 changes: 0 additions & 30 deletions app/assets/scripts/components/common/layers/layer-co2-diff.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
import config from '../../../config';

import { indicatorGroupColors } from '../../../styles/theme/theme.js';

export default {
id: 'co2-diff',
name: 'CO\u2082 (Diff)',
type: 'raster-timeseries',
timeUnit: 'day',
domain: [
'2020-01-01',
'2020-07-16'
],
source: {
type: 'raster',
tiles: [
`${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`
]
},
exclusiveWith: ['agriculture', 'no2', 'no2-diff', 'co2', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-ship', 'detection-multi', 'water-chlorophyll', 'water-spm'],
enabled: false,
swatch: indicatorGroupColors['greenhouse-gas'],
legend: {
type: 'gradient',
min: '< -1 ppm',
max: '> 1 ppm',
stops: [
'#3A88BD',
'#C9E0ED',
'#E4EEF3',
'#FDDCC9',
'#DD7059'
]
},
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₂.'
};
32 changes: 0 additions & 32 deletions app/assets/scripts/components/common/layers/layer-co2.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,8 @@ import { format } from 'date-fns';

import config from '../../../config';

import { indicatorGroupColors } from '../../../styles/theme/theme.js';

export default {
id: 'co2',
name: 'CO\u2082 (Avg)',
type: 'raster-timeseries',
timeUnit: 'day',
domain: [
'2020-01-01',
'2020-07-16'
],
source: {
type: 'raster',
tiles: [
`${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}`

]
},
exclusiveWith: ['agriculture', 'no2', 'co2-diff', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-ship', 'detection-multi', 'water-chlorophyll', 'water-spm'],
enabled: false,
compare: {
Expand All @@ -34,21 +18,5 @@ export default {
]
}
},

swatch: indicatorGroupColors['greenhouse-gas'],
legend: {
type: 'gradient-adjustable',
min: '< 408 ppm',
max: '> 419 ppm',
stops: [
'#313695',
'#588cbf',
'#a3d2e5',
'#e8f6e8',
'#fee89c',
'#fba55c',
'#e24932'
]
},
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₂.'
};
Original file line number Diff line number Diff line change
@@ -1,29 +1,6 @@
import config from '../../../config';
import { indicatorGroupColors } from '../../../styles/theme/theme';

export default {
id: 'detection-plane',
name: 'Planes',
type: 'inference-timeseries',
domain: [
'2020-01-01',
'2020-04-30'
],
source: {
vector: {
type: 'geojson',
data: `${config.api}/detections/plane/{spotlightId}/{date}.geojson`
},
raster: {
type: 'raster',
tiles: [
`${config.api}/planet/{z}/{x}/{y}?date={date}&site={spotlightId}`
]
}
},
exclusiveWith: ['agriculture', 'no2', 'no2-diff', 'co2-diff', 'co2', 'gibs-population', 'car-count', 'nightlights-viirs', 'nightlights-hd', 'detection-multi', 'water-chlorophyll', 'water-spm'],
enabled: false,
swatch: indicatorGroupColors.economic,
timeUnit: 'day',
info: 'Planes detected each day in PlanetScope imagery are shown in red.'
};
Loading

0 comments on commit 66e502d

Please sign in to comment.