hestia-earth-models 0.73.0__py3-none-any.whl → 0.73.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hestia_earth/models/akagiEtAl2011/utils.py +4 -2
- hestia_earth/models/aware/scarcityWeightedWaterUse.py +8 -7
- hestia_earth/models/cache_sites.py +8 -4
- hestia_earth/models/chaudharyBrooks2018/damageToTerrestrialEcosystemsLandTransformation.py +14 -11
- hestia_earth/models/chaudharyBrooks2018/utils.py +4 -2
- hestia_earth/models/config/Cycle.json +35 -37
- hestia_earth/models/config/Site.json +26 -24
- hestia_earth/models/cycle/completeness/electricityFuel.py +1 -1
- hestia_earth/models/cycle/completeness/freshForage.py +1 -1
- hestia_earth/models/cycle/input/hestiaAggregatedData.py +1 -2
- hestia_earth/models/cycle/product/economicValueShare.py +1 -1
- hestia_earth/models/environmentalFootprintV3_1/environmentalFootprintSingleOverallScore.py +1 -1
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandOccupation.py +11 -11
- hestia_earth/models/environmentalFootprintV3_1/soilQualityIndexLandTransformation.py +14 -11
- hestia_earth/models/faostat2018/utils.py +26 -13
- hestia_earth/models/geospatialDatabase/utils.py +13 -10
- hestia_earth/models/hestia/aboveGroundCropResidue.py +6 -5
- hestia_earth/models/hestia/cropResidueManagement.py +3 -2
- hestia_earth/models/hestia/default_emissions.py +1 -1
- hestia_earth/models/hestia/default_resourceUse.py +1 -1
- hestia_earth/models/hestia/excretaKgMass.py +7 -9
- hestia_earth/models/hestia/seed_emissions.py +1 -1
- hestia_earth/models/hestia/stockingDensityAnimalHousingAverage.py +1 -1
- hestia_earth/models/hestia/waterSalinity.py +1 -1
- hestia_earth/models/ipcc2019/aboveGroundBiomass.py +2 -4
- hestia_earth/models/ipcc2019/belowGroundBiomass.py +2 -4
- hestia_earth/models/ipcc2019/biomass_utils.py +1 -1
- hestia_earth/models/ipcc2019/ch4ToAirAquacultureSystems.py +1 -1
- hestia_earth/models/ipcc2019/ch4ToAirOrganicSoilCultivation.py +3 -4
- hestia_earth/models/ipcc2019/co2ToAirCarbonStockChange_utils.py +2 -4
- hestia_earth/models/ipcc2019/co2ToAirOrganicSoilCultivation.py +2 -3
- hestia_earth/models/ipcc2019/n2OToAirCropResidueBurningDirect.py +1 -1
- hestia_earth/models/ipcc2019/nonCo2EmissionsToAirNaturalVegetationBurning.py +2 -3
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_1.py +2 -3
- hestia_earth/models/ipcc2019/organicCarbonPerHa_tier_2.py +3 -4
- hestia_earth/models/ipcc2019/organicCarbonPerHa_utils.py +2 -3
- hestia_earth/models/mocking/search-results.json +1582 -1582
- hestia_earth/models/pooreNemecek2018/freshwaterWithdrawalsDuringCycle.py +43 -5
- hestia_earth/models/site/grouped_measurement.py +1 -1
- hestia_earth/models/utils/background_emissions.py +1 -1
- hestia_earth/models/utils/impact_assessment.py +29 -14
- hestia_earth/models/utils/lookup.py +5 -1
- hestia_earth/models/utils/measurement.py +0 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/METADATA +3 -2
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/RECORD +54 -59
- tests/models/geospatialDatabase/test_utils.py +12 -1
- tests/models/ipcc2019/test_organicCarbonPerHa_tier_2.py +1 -1
- tests/models/pooreNemecek2018/test_freshwaterWithdrawalsDuringCycle.py +12 -0
- tests/models/utils/test_array_builders.py +1 -1
- tests/models/utils/test_impact_assessment.py +29 -13
- hestia_earth/models/utils/array_builders.py +0 -590
- hestia_earth/models/utils/descriptive_stats.py +0 -49
- hestia_earth/models/utils/stats.py +0 -429
- tests/models/utils/test_descriptive_stats.py +0 -50
- tests/models/utils/test_stats.py +0 -186
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.73.0.dist-info → hestia_earth_models-0.73.2.dist-info}/top_level.txt +0 -0
tests/models/utils/test_stats.py
DELETED
@@ -1,186 +0,0 @@
|
|
1
|
-
from numpy import inf, sqrt
|
2
|
-
from numpy.testing import assert_almost_equal
|
3
|
-
from pytest import mark
|
4
|
-
|
5
|
-
from hestia_earth.models.utils.stats import (
|
6
|
-
_calc_confidence_level, add_normal_distributions, calc_confidence_level_monte_carlo, calc_precision_monte_carlo,
|
7
|
-
calc_required_iterations_monte_carlo, calc_z_critical, lerp_normal_distributions, subtract_normal_distributions
|
8
|
-
)
|
9
|
-
|
10
|
-
|
11
|
-
# confidence_level, n_sided, z_critical
|
12
|
-
CONFIDENCE_INTERVAL_PARAMS = [
|
13
|
-
# 1 sided
|
14
|
-
(0, 1, -inf),
|
15
|
-
(50, 1, 0),
|
16
|
-
(80, 1, 0.8416),
|
17
|
-
(90, 1, 1.2816),
|
18
|
-
(95, 1, 1.6449),
|
19
|
-
(99, 1, 2.3263),
|
20
|
-
(100, 1, inf),
|
21
|
-
# 2 sided
|
22
|
-
(0, 2, 0),
|
23
|
-
(50, 2, 0.6745),
|
24
|
-
(80, 2, 1.2816),
|
25
|
-
(90, 2, 1.6449),
|
26
|
-
(95, 2, 1.9600),
|
27
|
-
(99, 2, 2.5758),
|
28
|
-
(100, 2, inf)
|
29
|
-
]
|
30
|
-
|
31
|
-
|
32
|
-
@mark.parametrize(
|
33
|
-
"confidence_level, n_sided, z_critical",
|
34
|
-
CONFIDENCE_INTERVAL_PARAMS,
|
35
|
-
ids=[f"z={z}, n={n}" for _, n, z in CONFIDENCE_INTERVAL_PARAMS]
|
36
|
-
)
|
37
|
-
def test_calc_confidence_level(confidence_level, n_sided, z_critical):
|
38
|
-
result = _calc_confidence_level(z_critical, n_sided=n_sided)
|
39
|
-
assert_almost_equal(result, confidence_level, decimal=2)
|
40
|
-
|
41
|
-
|
42
|
-
@mark.parametrize(
|
43
|
-
"confidence_level, n_sided, z_critical",
|
44
|
-
CONFIDENCE_INTERVAL_PARAMS,
|
45
|
-
ids=[f"conf={conf}, n={n}" for conf, n, _ in CONFIDENCE_INTERVAL_PARAMS]
|
46
|
-
)
|
47
|
-
def test_calc_z_critical(confidence_level, n_sided, z_critical):
|
48
|
-
result = calc_z_critical(confidence_level, n_sided=n_sided)
|
49
|
-
assert_almost_equal(result, z_critical, decimal=4)
|
50
|
-
|
51
|
-
|
52
|
-
# confidence_level, n_iterations, precision, sd
|
53
|
-
MONTE_CARLO_PARAMS = [
|
54
|
-
(95, 80767, 0.01, 1.45),
|
55
|
-
(95, 1110, 0.01, 0.17),
|
56
|
-
(99, 1917, 0.01, 0.17),
|
57
|
-
(50, 102, 100.18, 1500)
|
58
|
-
]
|
59
|
-
|
60
|
-
|
61
|
-
@mark.parametrize(
|
62
|
-
"confidence_level, n_iterations, precision, sd",
|
63
|
-
MONTE_CARLO_PARAMS,
|
64
|
-
ids=[f"n={n}, prec={prec}, sd={sd}" for _, n, prec, sd in MONTE_CARLO_PARAMS]
|
65
|
-
)
|
66
|
-
def test_calc_confidence_level_monte_carlo(confidence_level, n_iterations, precision, sd):
|
67
|
-
result = calc_confidence_level_monte_carlo(n_iterations, precision, sd,)
|
68
|
-
assert_almost_equal(result, confidence_level, decimal=2)
|
69
|
-
|
70
|
-
|
71
|
-
@mark.parametrize(
|
72
|
-
"confidence_level, n_iterations, precision, sd",
|
73
|
-
MONTE_CARLO_PARAMS,
|
74
|
-
ids=[f"conf={conf}, prec={prec}, sd={sd}" for conf, _, prec, sd in MONTE_CARLO_PARAMS]
|
75
|
-
)
|
76
|
-
def test_calc_required_iterations_monte_carlo(confidence_level, n_iterations, precision, sd):
|
77
|
-
result = calc_required_iterations_monte_carlo(confidence_level, precision, sd)
|
78
|
-
assert result == n_iterations
|
79
|
-
|
80
|
-
|
81
|
-
@mark.parametrize(
|
82
|
-
"confidence_level, n_iterations, precision, sd",
|
83
|
-
MONTE_CARLO_PARAMS,
|
84
|
-
ids=[f"conf={conf}, n={n}, sd={sd}" for conf, n, _, sd in MONTE_CARLO_PARAMS]
|
85
|
-
)
|
86
|
-
def test_calc_precision_monte_carlo(confidence_level, n_iterations, precision, sd):
|
87
|
-
result = calc_precision_monte_carlo(confidence_level, n_iterations, sd)
|
88
|
-
assert_almost_equal(result, precision, decimal=2)
|
89
|
-
|
90
|
-
|
91
|
-
# mu_1, sigma_1, mu_2, sigma_2, rho, sum_mean, sum_sigma, diff_mean, diff_sigma
|
92
|
-
PARAMS_NORMAL_DIST = [
|
93
|
-
# 2 standard normal distributions, perfectly negative correlation
|
94
|
-
(0, 1, 0, 1, -1, 0, 0, 0, 2),
|
95
|
-
# 2 standard normal distributions, negative correlation
|
96
|
-
(0, 1, 0, 1, -0.5, 0, 1, 0, sqrt(3)),
|
97
|
-
# 2 standard normal distributions, no correlation
|
98
|
-
(0, 1, 0, 1, 0, 0, sqrt(2), 0, sqrt(2)),
|
99
|
-
# 2 standard normal distributions, positive correlation
|
100
|
-
(0, 1, 0, 1, 0.5, 0, sqrt(3), 0, 1),
|
101
|
-
# 2 standard normal distributions, perfectly positive correlation
|
102
|
-
(0, 1, 0, 1, 1, 0, 2, 0, 0),
|
103
|
-
# different normal distributions, perfectly negative correlation
|
104
|
-
(50000, 3000, 45000, 9000, -1, 95000, 6000, 5000, 12000),
|
105
|
-
# different normal distributions, no correlation
|
106
|
-
(50000, 3000, 45000, 9000, 0, 95000, sqrt(90000000), 5000, sqrt(90000000)),
|
107
|
-
# different normal distributions, perfectly positive correlation
|
108
|
-
(50000, 3000, 45000, 9000, 1, 95000, 12000, 5000, 6000)
|
109
|
-
]
|
110
|
-
IDS_ADD_NORMAL_DIST = [
|
111
|
-
f"N({mu_1}, {sigma_1}^2) + N({mu_2}, {sigma_2}^2), rho: {rho}"
|
112
|
-
for mu_1, sigma_1, mu_2, sigma_2, rho, *_ in PARAMS_NORMAL_DIST
|
113
|
-
]
|
114
|
-
IDS_SUBTRACT_DIST = [
|
115
|
-
f"N({mu_1}, {sigma_1}^2) - N({mu_2}, {sigma_2}^2), rho: {rho}"
|
116
|
-
for mu_1, sigma_1, mu_2, sigma_2, rho, *_ in PARAMS_NORMAL_DIST
|
117
|
-
]
|
118
|
-
|
119
|
-
|
120
|
-
@mark.parametrize(
|
121
|
-
"mu_1, sigma_1, mu_2, sigma_2, rho, sum_mean, sum_sigma, _diff_mean, _diff_sigma",
|
122
|
-
PARAMS_NORMAL_DIST,
|
123
|
-
ids=IDS_ADD_NORMAL_DIST
|
124
|
-
)
|
125
|
-
def test_add_normal_distributions(mu_1, sigma_1, mu_2, sigma_2, rho, sum_mean, sum_sigma, _diff_mean, _diff_sigma):
|
126
|
-
result = add_normal_distributions(mu_1, sigma_1, mu_2, sigma_2, rho)
|
127
|
-
assert result == (sum_mean, sum_sigma)
|
128
|
-
|
129
|
-
|
130
|
-
@mark.parametrize(
|
131
|
-
"mu_1, sigma_1, mu_2, sigma_2, rho, _sum_mean, _sum_sigma, diff_mean, diff_sigma",
|
132
|
-
PARAMS_NORMAL_DIST,
|
133
|
-
ids=IDS_SUBTRACT_DIST
|
134
|
-
)
|
135
|
-
def test_subtract_normal_distributions(mu_1, sigma_1, mu_2, sigma_2, rho, _sum_mean, _sum_sigma, diff_mean, diff_sigma):
|
136
|
-
result = subtract_normal_distributions(mu_1, sigma_1, mu_2, sigma_2, rho)
|
137
|
-
assert result == (diff_mean, diff_sigma)
|
138
|
-
|
139
|
-
|
140
|
-
# mu_1, sigma_1, mu_2, sigma_2, alpha, rho, Z_mean, Z_sigma
|
141
|
-
PARAMS_LERP_NORMAL_DIST = [
|
142
|
-
# 2 standard normal distributions, perfectly negative correlation
|
143
|
-
(0, 1, 0, 1, 0, -1, 0, 1),
|
144
|
-
(0, 1, 0, 1, 0.5, -1, 0, 0),
|
145
|
-
(0, 1, 0, 1, 1, -1, 0, 1),
|
146
|
-
# 2 standard normal distributions, no correlation
|
147
|
-
(0, 1, 0, 1, 0, 0, 0, 1),
|
148
|
-
(0, 1, 0, 1, 0.5, 0, 0, sqrt(0.5)),
|
149
|
-
(0, 1, 0, 1, 1, 0, 0, 1),
|
150
|
-
# 2 standard normal distributions, perfectly positive correlation
|
151
|
-
(0, 1, 0, 1, 0, 1, 0, 1),
|
152
|
-
(0, 1, 0, 1, 0.5, 1, 0, 1),
|
153
|
-
(0, 1, 0, 1, 1, 1, 0, 1),
|
154
|
-
# different normal distributions, perfectly negative correlation
|
155
|
-
(10000, 3000, 5000, 2500, -0.5, -1, 12500, 5750),
|
156
|
-
(10000, 3000, 5000, 2500, 0, -1, 10000, 3000),
|
157
|
-
(10000, 3000, 5000, 2500, 0.5, -1, 7500, 250),
|
158
|
-
(10000, 3000, 5000, 2500, 1, -1, 5000, 2500),
|
159
|
-
(10000, 3000, 5000, 2500, 1.5, -1, 2500, 5250),
|
160
|
-
# different normal distributions, no correlation
|
161
|
-
(10000, 3000, 5000, 2500, -0.5, 0, 12500, sqrt(21812500)),
|
162
|
-
(10000, 3000, 5000, 2500, 0, 0, 10000, 3000),
|
163
|
-
(10000, 3000, 5000, 2500, 0.5, 0, 7500, sqrt(3812500)),
|
164
|
-
(10000, 3000, 5000, 2500, 1, 0, 5000, 2500),
|
165
|
-
(10000, 3000, 5000, 2500, 1.5, 0, 2500, sqrt(16312500)),
|
166
|
-
# different normal distributions, perfectly positive correlation
|
167
|
-
(10000, 3000, 5000, 2500, -0.5, 1, 12500, 3250),
|
168
|
-
(10000, 3000, 5000, 2500, 0, 1, 10000, 3000),
|
169
|
-
(10000, 3000, 5000, 2500, 0.5, 1, 7500, 2750.0),
|
170
|
-
(10000, 3000, 5000, 2500, 1, 1, 5000, 2500),
|
171
|
-
(10000, 3000, 5000, 2500, 1.5, 1, 2500, 2250)
|
172
|
-
]
|
173
|
-
IDS_LERP_NORMAL_DIST = [
|
174
|
-
f"N({mu_1}, {sigma_1}^2) - N({mu_2}, {sigma_2}^2), alpha: {alpha}, rho: {rho}"
|
175
|
-
for mu_1, sigma_1, mu_2, sigma_2, alpha, rho, *_ in PARAMS_LERP_NORMAL_DIST
|
176
|
-
]
|
177
|
-
|
178
|
-
|
179
|
-
@mark.parametrize(
|
180
|
-
"mu_1, sigma_1, mu_2, sigma_2, alpha, rho, Z_mean, Z_sigma",
|
181
|
-
PARAMS_LERP_NORMAL_DIST,
|
182
|
-
ids=IDS_LERP_NORMAL_DIST
|
183
|
-
)
|
184
|
-
def test_lerp_normal_distributions(mu_1, sigma_1, mu_2, sigma_2, alpha, rho, Z_mean, Z_sigma):
|
185
|
-
result = lerp_normal_distributions(mu_1, sigma_1, mu_2, sigma_2, alpha, rho)
|
186
|
-
assert result == (Z_mean, Z_sigma)
|
File without changes
|
File without changes
|
File without changes
|