-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07 Decompose exposure effect
82 lines (65 loc) · 3.03 KB
/
07 Decompose exposure effect
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var geometry = ee.FeatureCollection("projects/heatwave0214/assets/basicpolygon/Chinaregion_NOTW")
// .filter(ee.Filter.eq('zone', 'Central China'))
.geometry();
var basePath = "projects/heatwave0214/assets/";
var datasets = [
{path: "Age_pop_exposure_TM_SSP585/", variable: "TM_SSP585"},
{path: "Age_pop_exposure_TM_SSP245/", variable: "TM_SSP245"},
// {path: "Age_pop_exposure_TX_SSP245/", variable: "TX_SSP245"}
];
var years = [];
for (var i = 2041; i <= 2100; i++) {
years.push( i.toString() );
}
// Function to calculate effects for a single dataset
function calculateEffectsForDataset(dataset) {
var effectsList = years.map(function(year) {
var heatwave_base = ee.Image("projects/heatwave0214/assets/Age_pop_exposure_TM_historical/Interpolation_Agepop_exposure_TM_historical_2001").select("HWF");
var heatwave_future = ee.Image(basePath + dataset.path + "Interpolation_agepop_exposure_" + dataset.variable + "_withoutsum_" + year).select("HWF");
var population_base = ee.Image("projects/heatwave0214/assets/Age_pop_exposure_TM_historical/Interpolation_Agepop_exposure_TM_historical_2001").select("age_pop");
var population_future = ee.Image(basePath + dataset.path + "Interpolation_agepop_exposure_" + dataset.variable + "_withoutsum_" + year).select("age_pop");
var delta_heatwave = heatwave_future.subtract(heatwave_base);
var delta_population = population_future.subtract(population_base);
var climate_effect = population_base.multiply(delta_heatwave).rename("climate_effect");
var population_effect = heatwave_base.multiply(delta_population).rename("population_effect");
var combined_effect = delta_population.multiply(delta_heatwave).rename("combined_effect");
var climate_effect_sum = climate_effect.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: geometry,
scale: 11132,
maxPixels: 1e9
});
var population_effect_sum = population_effect.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: geometry,
scale: 11132,
maxPixels: 1e9
});
var combined_effect_sum = combined_effect.reduceRegion({
reducer: ee.Reducer.sum(),
geometry: geometry,
scale: 11132,
maxPixels: 1e9
});
return ee.Feature(null, {
'year': year,
'variable': dataset.variable,
'climate_effect': climate_effect_sum.get('climate_effect'),
'population_effect': population_effect_sum.get('population_effect'),
'combined_effect': combined_effect_sum.get('combined_effect')
});
});
return ee.FeatureCollection(effectsList);
}
// Calculate effects for all datasets
var allDatasetsEffects = datasets.map(calculateEffectsForDataset);
// Combine all dataset effects into a single FeatureCollection
var combinedEffects = ee.FeatureCollection(allDatasetsEffects).flatten();
// print("combinedEffects:",combinedEffects)
// Export the results as a CSV file
Export.table.toDrive({
collection: combinedEffects,
description: 'Decompose_effects_summary_2001base',
fileFormat: 'CSV',
folder: 'futureheatwave-batch-change1'
});