hestia-earth-models 0.58.0__py3-none-any.whl → 0.59.0__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.
Potentially problematic release.
This version of hestia-earth-models might be problematic. Click here for more details.
- hestia_earth/models/cycle/{irrigated.py → irrigatedTypeUnspecified.py} +4 -4
- hestia_earth/models/cycle/residueIncorporated.py +1 -1
- hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +2 -2
- hestia_earth/models/geospatialDatabase/clayContent.py +17 -4
- hestia_earth/models/geospatialDatabase/sandContent.py +17 -4
- hestia_earth/models/impact_assessment/irrigated.py +0 -3
- hestia_earth/models/ipcc2019/co2ToAirSoilCarbonStockChangeManagementChange.py +10 -9
- hestia_earth/models/ipcc2019/n2OToAirCropResidueDecompositionDirect.py +4 -51
- hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +104 -0
- hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserDirect.py +105 -0
- hestia_earth/models/ipcc2019/organicCarbonPerHa.py +1059 -1220
- hestia_earth/models/ipcc2019/utils.py +82 -1
- hestia_earth/models/mocking/search-results.json +161 -87
- hestia_earth/models/site/management.py +12 -9
- hestia_earth/models/site/organicCarbonPerHa.py +251 -89
- hestia_earth/models/utils/blank_node.py +157 -34
- hestia_earth/models/utils/cycle.py +6 -3
- hestia_earth/models/utils/measurement.py +1 -1
- hestia_earth/models/utils/term.py +46 -1
- hestia_earth/models/version.py +1 -1
- {hestia_earth_models-0.58.0.dist-info → hestia_earth_models-0.59.0.dist-info}/METADATA +4 -8
- {hestia_earth_models-0.58.0.dist-info → hestia_earth_models-0.59.0.dist-info}/RECORD +34 -30
- tests/models/cycle/{test_irrigated.py → test_irrigatedTypeUnspecified.py} +1 -1
- tests/models/geospatialDatabase/test_clayContent.py +9 -3
- tests/models/geospatialDatabase/test_sandContent.py +9 -3
- tests/models/ipcc2019/test_n2OToAirInorganicFertiliserDirect.py +74 -0
- tests/models/ipcc2019/test_n2OToAirOrganicFertiliserDirect.py +74 -0
- tests/models/ipcc2019/test_organicCarbonPerHa.py +303 -1044
- tests/models/site/test_organicCarbonPerHa.py +51 -5
- tests/models/utils/test_blank_node.py +102 -42
- tests/models/utils/test_term.py +17 -3
- {hestia_earth_models-0.58.0.dist-info → hestia_earth_models-0.59.0.dist-info}/LICENSE +0 -0
- {hestia_earth_models-0.58.0.dist-info → hestia_earth_models-0.59.0.dist-info}/WHEEL +0 -0
- {hestia_earth_models-0.58.0.dist-info → hestia_earth_models-0.59.0.dist-info}/top_level.txt +0 -0
|
@@ -5,13 +5,19 @@ from unittest.mock import patch
|
|
|
5
5
|
from tests.utils import fixtures_path, fake_new_measurement
|
|
6
6
|
|
|
7
7
|
from hestia_earth.models.site.organicCarbonPerHa import (
|
|
8
|
-
MODEL, TERM_ID, run, _cdf, _c_to_depth, _get_last_date,
|
|
8
|
+
MODEL, TERM_ID, run, _cdf, _c_to_depth, _get_most_relevant_soc_node, _get_last_date, _should_run_calculation_group
|
|
9
9
|
)
|
|
10
10
|
|
|
11
11
|
class_path = f"hestia_earth.models.{MODEL}.{TERM_ID}"
|
|
12
12
|
fixtures_folder = f"{fixtures_path}/{MODEL}/{TERM_ID}"
|
|
13
13
|
|
|
14
|
-
SUBFOLDERS = [
|
|
14
|
+
SUBFOLDERS = [
|
|
15
|
+
"calculate-single",
|
|
16
|
+
"calculate-multiple",
|
|
17
|
+
"rescale-single",
|
|
18
|
+
"rescale-multiple",
|
|
19
|
+
"calculate-and-rescale"
|
|
20
|
+
]
|
|
15
21
|
|
|
16
22
|
|
|
17
23
|
@mark.parametrize("depth, expected", [(0, 0), (1, 10.41666666666667)], ids=["0m", "1m"])
|
|
@@ -36,21 +42,55 @@ def test_cdf(depth_upper, depth_lower, expected):
|
|
|
36
42
|
(["2020-01-01", "2020-02-28"], "2020-02-28"),
|
|
37
43
|
([], None)
|
|
38
44
|
],
|
|
39
|
-
ids=["YYYY", "YYYY-MM", "YYYY-MM-DD", "
|
|
45
|
+
ids=["YYYY", "YYYY-MM", "YYYY-MM-DD", "empty-list"]
|
|
40
46
|
)
|
|
41
47
|
def test_get_node_date(dates, expected):
|
|
42
48
|
assert _get_last_date(dates) == expected
|
|
43
49
|
|
|
44
50
|
|
|
51
|
+
@mark.parametrize(
|
|
52
|
+
"nodes, expected_id",
|
|
53
|
+
[
|
|
54
|
+
(
|
|
55
|
+
[
|
|
56
|
+
{"@id": "1", "depthUpper": 0, "depthLower": 10},
|
|
57
|
+
{"@id": "2", "depthUpper": 0, "depthLower": 40},
|
|
58
|
+
{"@id": "3", "depthUpper": 0, "depthLower": 100}
|
|
59
|
+
],
|
|
60
|
+
"2"
|
|
61
|
+
),
|
|
62
|
+
(
|
|
63
|
+
[
|
|
64
|
+
{"@id": "1", "depthUpper": 0, "depthLower": 5},
|
|
65
|
+
{"@id": "2", "depthUpper": 0, "depthLower": 10},
|
|
66
|
+
{"@id": "3", "depthUpper": 0, "depthLower": 20}
|
|
67
|
+
],
|
|
68
|
+
"3"
|
|
69
|
+
),
|
|
70
|
+
(
|
|
71
|
+
[
|
|
72
|
+
{"@id": "1", "depthUpper": 0, "depthLower": 20},
|
|
73
|
+
{"@id": "2", "depthUpper": 0, "depthLower": 40},
|
|
74
|
+
{"@id": "3", "depthUpper": 0, "depthLower": 100}
|
|
75
|
+
],
|
|
76
|
+
"2"
|
|
77
|
+
)
|
|
78
|
+
],
|
|
79
|
+
ids=["simple", "no-priority", "tie"]
|
|
80
|
+
)
|
|
81
|
+
def test_get_most_relevant_soc_node(nodes, expected_id):
|
|
82
|
+
assert _get_most_relevant_soc_node(nodes).get("@id") == expected_id
|
|
83
|
+
|
|
84
|
+
|
|
45
85
|
@patch(f"{class_path}.find_term_match")
|
|
46
86
|
def test_should_run_measurements(mock_find):
|
|
47
87
|
# no measurement => no run
|
|
48
88
|
mock_find.return_value = {}
|
|
49
|
-
assert
|
|
89
|
+
assert _should_run_calculation_group([]) is False
|
|
50
90
|
|
|
51
91
|
# with measurement => run
|
|
52
92
|
mock_find.return_value = {'value': [10], 'depthUpper': 0, 'depthLower': 10}
|
|
53
|
-
assert
|
|
93
|
+
assert _should_run_calculation_group([]) is True
|
|
54
94
|
|
|
55
95
|
|
|
56
96
|
@mark.parametrize("subfolder", SUBFOLDERS)
|
|
@@ -65,3 +105,9 @@ def test_run(_new_measurement_mock, get_source_mock, subfolder):
|
|
|
65
105
|
|
|
66
106
|
value = run(site)
|
|
67
107
|
assert value == expected
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
@patch(f"{class_path}.get_source", return_value={})
|
|
111
|
+
@patch(f"{class_path}._new_measurement", side_effect=fake_new_measurement)
|
|
112
|
+
def test_run_empty(_new_measurement_mock, get_source_mock):
|
|
113
|
+
assert run({}) == []
|
|
@@ -18,6 +18,7 @@ from hestia_earth.models.utils.blank_node import (
|
|
|
18
18
|
DatetimeRange,
|
|
19
19
|
get_node_value,
|
|
20
20
|
group_nodes_by_year,
|
|
21
|
+
group_nodes_by_year_and_month,
|
|
21
22
|
GroupNodesByYearMode
|
|
22
23
|
)
|
|
23
24
|
|
|
@@ -551,7 +552,7 @@ GROUP_NODES_BY_YEAR_SCENARIO_A_CYCLES = [
|
|
|
551
552
|
]
|
|
552
553
|
|
|
553
554
|
|
|
554
|
-
def
|
|
555
|
+
def test_group_nodes_by_year_scenario_a():
|
|
555
556
|
"""
|
|
556
557
|
Datestr in format `YYYY`. Some nodes missing `startDate` field. One multi-year cycle.
|
|
557
558
|
|
|
@@ -564,34 +565,34 @@ def test_group_nodes_scenario_a():
|
|
|
564
565
|
2002: [{
|
|
565
566
|
"@id": "cycle-1a",
|
|
566
567
|
"endDate": "2002",
|
|
567
|
-
"
|
|
568
|
+
"fraction_of_group_duration": 1.0,
|
|
568
569
|
"fraction_of_node_duration": 1.0
|
|
569
570
|
}],
|
|
570
571
|
2003: [{
|
|
571
572
|
"@id": "cycle-2a",
|
|
572
573
|
"endDate": "2003",
|
|
573
|
-
"
|
|
574
|
+
"fraction_of_group_duration": 1.0,
|
|
574
575
|
"fraction_of_node_duration": 1.0
|
|
575
576
|
}],
|
|
576
577
|
2004: [{
|
|
577
578
|
"@id": "cycle-3a",
|
|
578
579
|
"endDate": "2006",
|
|
579
580
|
"startDate": "2004",
|
|
580
|
-
"
|
|
581
|
+
"fraction_of_group_duration": 1.0,
|
|
581
582
|
"fraction_of_node_duration": 0.33394160583941607
|
|
582
583
|
}],
|
|
583
584
|
2005: [{
|
|
584
585
|
"@id": "cycle-3a",
|
|
585
586
|
"endDate": "2006",
|
|
586
587
|
"startDate": "2004",
|
|
587
|
-
"
|
|
588
|
+
"fraction_of_group_duration": 1.0,
|
|
588
589
|
"fraction_of_node_duration": 0.333029197080292
|
|
589
590
|
}],
|
|
590
591
|
2006: [{
|
|
591
592
|
"@id": "cycle-3a",
|
|
592
593
|
"endDate": "2006",
|
|
593
594
|
"startDate": "2004",
|
|
594
|
-
"
|
|
595
|
+
"fraction_of_group_duration": 1.0,
|
|
595
596
|
"fraction_of_node_duration": 0.333029197080292
|
|
596
597
|
}]
|
|
597
598
|
}
|
|
@@ -600,7 +601,7 @@ def test_group_nodes_scenario_a():
|
|
|
600
601
|
assert result == EXPECTED
|
|
601
602
|
|
|
602
603
|
|
|
603
|
-
def
|
|
604
|
+
def test_group_nodes_by_year_scenario_a_with_inner_key():
|
|
604
605
|
|
|
605
606
|
INNER_KEY = "inner_key"
|
|
606
607
|
EXPECTED = {
|
|
@@ -608,7 +609,7 @@ def test_group_nodes_scenario_a_with_inner_key():
|
|
|
608
609
|
INNER_KEY: [{
|
|
609
610
|
"@id": "cycle-1a",
|
|
610
611
|
"endDate": "2002",
|
|
611
|
-
"
|
|
612
|
+
"fraction_of_group_duration": 1.0,
|
|
612
613
|
"fraction_of_node_duration": 1.0
|
|
613
614
|
}]
|
|
614
615
|
},
|
|
@@ -616,7 +617,7 @@ def test_group_nodes_scenario_a_with_inner_key():
|
|
|
616
617
|
INNER_KEY: [{
|
|
617
618
|
"@id": "cycle-2a",
|
|
618
619
|
"endDate": "2003",
|
|
619
|
-
"
|
|
620
|
+
"fraction_of_group_duration": 1.0,
|
|
620
621
|
"fraction_of_node_duration": 1.0
|
|
621
622
|
}]
|
|
622
623
|
},
|
|
@@ -625,7 +626,7 @@ def test_group_nodes_scenario_a_with_inner_key():
|
|
|
625
626
|
"@id": "cycle-3a",
|
|
626
627
|
"endDate": "2006",
|
|
627
628
|
"startDate": "2004",
|
|
628
|
-
"
|
|
629
|
+
"fraction_of_group_duration": 1.0,
|
|
629
630
|
"fraction_of_node_duration": 0.33394160583941607
|
|
630
631
|
}]
|
|
631
632
|
},
|
|
@@ -634,7 +635,7 @@ def test_group_nodes_scenario_a_with_inner_key():
|
|
|
634
635
|
"@id": "cycle-3a",
|
|
635
636
|
"endDate": "2006",
|
|
636
637
|
"startDate": "2004",
|
|
637
|
-
"
|
|
638
|
+
"fraction_of_group_duration": 1.0,
|
|
638
639
|
"fraction_of_node_duration": 0.333029197080292
|
|
639
640
|
}]
|
|
640
641
|
},
|
|
@@ -643,7 +644,7 @@ def test_group_nodes_scenario_a_with_inner_key():
|
|
|
643
644
|
"@id": "cycle-3a",
|
|
644
645
|
"endDate": "2006",
|
|
645
646
|
"startDate": "2004",
|
|
646
|
-
"
|
|
647
|
+
"fraction_of_group_duration": 1.0,
|
|
647
648
|
"fraction_of_node_duration": 0.333029197080292
|
|
648
649
|
}]
|
|
649
650
|
}
|
|
@@ -653,7 +654,7 @@ def test_group_nodes_scenario_a_with_inner_key():
|
|
|
653
654
|
assert result == EXPECTED
|
|
654
655
|
|
|
655
656
|
|
|
656
|
-
def
|
|
657
|
+
def test_group_nodes_by_year_scenario_b():
|
|
657
658
|
"""
|
|
658
659
|
Datestr in format `YYYY-MM-DD`. Two concurrent cycles (`cycle-3b` & `cycle-4b`).
|
|
659
660
|
"""
|
|
@@ -671,7 +672,7 @@ def test_group_nodes_scenario_b():
|
|
|
671
672
|
"@id": "cycle-1b",
|
|
672
673
|
"endDate": "2000-12-31",
|
|
673
674
|
"startDate": "2000-01-01",
|
|
674
|
-
"
|
|
675
|
+
"fraction_of_group_duration": 1.0,
|
|
675
676
|
"fraction_of_node_duration": 1.0
|
|
676
677
|
}
|
|
677
678
|
],
|
|
@@ -680,7 +681,7 @@ def test_group_nodes_scenario_b():
|
|
|
680
681
|
"@id": "cycle-2b",
|
|
681
682
|
"endDate": "2001-12-31",
|
|
682
683
|
"startDate": "2001-01-01",
|
|
683
|
-
"
|
|
684
|
+
"fraction_of_group_duration": 1.0,
|
|
684
685
|
"fraction_of_node_duration": 1.0
|
|
685
686
|
}
|
|
686
687
|
],
|
|
@@ -689,14 +690,14 @@ def test_group_nodes_scenario_b():
|
|
|
689
690
|
"@id": "cycle-3b",
|
|
690
691
|
"endDate": "2002-12-31",
|
|
691
692
|
"startDate": "2002-01-01",
|
|
692
|
-
"
|
|
693
|
+
"fraction_of_group_duration": 1.0,
|
|
693
694
|
"fraction_of_node_duration": 1.0
|
|
694
695
|
},
|
|
695
696
|
{
|
|
696
697
|
"@id": "cycle-4b",
|
|
697
698
|
"endDate": "2002-12-31",
|
|
698
699
|
"startDate": "2002-01-01",
|
|
699
|
-
"
|
|
700
|
+
"fraction_of_group_duration": 1.0,
|
|
700
701
|
"fraction_of_node_duration": 1.0
|
|
701
702
|
}
|
|
702
703
|
]
|
|
@@ -706,7 +707,7 @@ def test_group_nodes_scenario_b():
|
|
|
706
707
|
assert result == EXPECTED
|
|
707
708
|
|
|
708
709
|
|
|
709
|
-
def
|
|
710
|
+
def test_group_nodes_by_year_scenario_c():
|
|
710
711
|
"""
|
|
711
712
|
Multiple overlapping 6 month and 12 month cycles.
|
|
712
713
|
"""
|
|
@@ -725,14 +726,14 @@ def test_group_nodes_scenario_c():
|
|
|
725
726
|
"@id": "cycle-1c",
|
|
726
727
|
"endDate": "2000-06",
|
|
727
728
|
"startDate": "2000-01",
|
|
728
|
-
"
|
|
729
|
+
"fraction_of_group_duration": 0.4972677595628415,
|
|
729
730
|
"fraction_of_node_duration": 1.0
|
|
730
731
|
},
|
|
731
732
|
{
|
|
732
733
|
"@id": "cycle-2c",
|
|
733
734
|
"endDate": "2001-12",
|
|
734
735
|
"startDate": "2000-07",
|
|
735
|
-
"
|
|
736
|
+
"fraction_of_group_duration": 0.5027322404371585,
|
|
736
737
|
"fraction_of_node_duration": 0.33515482695810567
|
|
737
738
|
}
|
|
738
739
|
],
|
|
@@ -741,21 +742,21 @@ def test_group_nodes_scenario_c():
|
|
|
741
742
|
"@id": "cycle-2c",
|
|
742
743
|
"endDate": "2001-12",
|
|
743
744
|
"startDate": "2000-07",
|
|
744
|
-
"
|
|
745
|
+
"fraction_of_group_duration": 1.0,
|
|
745
746
|
"fraction_of_node_duration": 0.6648451730418944
|
|
746
747
|
},
|
|
747
748
|
{
|
|
748
749
|
"@id": "cycle-3c",
|
|
749
750
|
"endDate": "2001-06",
|
|
750
751
|
"startDate": "2001-01",
|
|
751
|
-
"
|
|
752
|
+
"fraction_of_group_duration": 0.4958904109589041,
|
|
752
753
|
"fraction_of_node_duration": 1.0
|
|
753
754
|
},
|
|
754
755
|
{
|
|
755
756
|
"@id": "cycle-4c",
|
|
756
757
|
"endDate": "2002-06",
|
|
757
758
|
"startDate": "2001-07",
|
|
758
|
-
"
|
|
759
|
+
"fraction_of_group_duration": 0.5041095890410959,
|
|
759
760
|
"fraction_of_node_duration": 0.5041095890410959
|
|
760
761
|
}
|
|
761
762
|
],
|
|
@@ -764,14 +765,14 @@ def test_group_nodes_scenario_c():
|
|
|
764
765
|
"@id": "cycle-4c",
|
|
765
766
|
"endDate": "2002-06",
|
|
766
767
|
"startDate": "2001-07",
|
|
767
|
-
"
|
|
768
|
+
"fraction_of_group_duration": 0.4958904109589041,
|
|
768
769
|
"fraction_of_node_duration": 0.4958904109589041
|
|
769
770
|
},
|
|
770
771
|
{
|
|
771
772
|
"@id": "cycle-5c",
|
|
772
773
|
"endDate": "2002-12",
|
|
773
774
|
"startDate": "2002-01",
|
|
774
|
-
"
|
|
775
|
+
"fraction_of_group_duration": 1.0,
|
|
775
776
|
"fraction_of_node_duration": 1.0
|
|
776
777
|
}
|
|
777
778
|
]
|
|
@@ -781,7 +782,7 @@ def test_group_nodes_scenario_c():
|
|
|
781
782
|
assert result == EXPECTED
|
|
782
783
|
|
|
783
784
|
|
|
784
|
-
def
|
|
785
|
+
def test_group_nodes_by_year_scenario_d():
|
|
785
786
|
"""
|
|
786
787
|
Cases where nodes only overlap with year groups by a small amount.
|
|
787
788
|
Overlaps of less than 30% of a year should be not be included in a
|
|
@@ -833,7 +834,7 @@ def test_group_nodes_scenario_d():
|
|
|
833
834
|
"term.@id": "fullTillage",
|
|
834
835
|
"endDate": "2000-11",
|
|
835
836
|
"value": 100,
|
|
836
|
-
"
|
|
837
|
+
"fraction_of_group_duration": 0.9153005464480874,
|
|
837
838
|
"fraction_of_node_duration": 0.9153005464480874
|
|
838
839
|
},
|
|
839
840
|
{
|
|
@@ -841,7 +842,7 @@ def test_group_nodes_scenario_d():
|
|
|
841
842
|
"endDate": "2000-11",
|
|
842
843
|
"startDate": "2000-09",
|
|
843
844
|
"value": True,
|
|
844
|
-
"
|
|
845
|
+
"fraction_of_group_duration": 0.24863387978142076,
|
|
845
846
|
"fraction_of_node_duration": 1.0
|
|
846
847
|
}
|
|
847
848
|
],
|
|
@@ -851,7 +852,7 @@ def test_group_nodes_scenario_d():
|
|
|
851
852
|
"endDate": "2001-07",
|
|
852
853
|
"startDate": "2000-12",
|
|
853
854
|
"value": 50,
|
|
854
|
-
"
|
|
855
|
+
"fraction_of_group_duration": 0.5808219178082191,
|
|
855
856
|
"fraction_of_node_duration": 0.8724279835390947
|
|
856
857
|
},
|
|
857
858
|
{
|
|
@@ -859,7 +860,7 @@ def test_group_nodes_scenario_d():
|
|
|
859
860
|
"endDate": "2001-07",
|
|
860
861
|
"startDate": "2000-12",
|
|
861
862
|
"value": 50,
|
|
862
|
-
"
|
|
863
|
+
"fraction_of_group_duration": 0.5808219178082191,
|
|
863
864
|
"fraction_of_node_duration": 0.8724279835390947
|
|
864
865
|
},
|
|
865
866
|
{
|
|
@@ -867,7 +868,7 @@ def test_group_nodes_scenario_d():
|
|
|
867
868
|
"endDate": "2002-01",
|
|
868
869
|
"startDate": "2001-08",
|
|
869
870
|
"value": 100,
|
|
870
|
-
"
|
|
871
|
+
"fraction_of_group_duration": 0.4191780821917808,
|
|
871
872
|
"fraction_of_node_duration": 0.8315217391304348
|
|
872
873
|
},
|
|
873
874
|
{
|
|
@@ -875,7 +876,7 @@ def test_group_nodes_scenario_d():
|
|
|
875
876
|
"endDate": "2002-06",
|
|
876
877
|
"startDate": "2001-07",
|
|
877
878
|
"value": True,
|
|
878
|
-
"
|
|
879
|
+
"fraction_of_group_duration": 0.5041095890410959,
|
|
879
880
|
"fraction_of_node_duration": 0.5041095890410959
|
|
880
881
|
}
|
|
881
882
|
],
|
|
@@ -885,7 +886,7 @@ def test_group_nodes_scenario_d():
|
|
|
885
886
|
"endDate": "2002-06",
|
|
886
887
|
"startDate": "2001-07",
|
|
887
888
|
"value": True,
|
|
888
|
-
"
|
|
889
|
+
"fraction_of_group_duration": 0.4958904109589041,
|
|
889
890
|
"fraction_of_node_duration": 0.4958904109589041
|
|
890
891
|
}
|
|
891
892
|
]
|
|
@@ -895,7 +896,7 @@ def test_group_nodes_scenario_d():
|
|
|
895
896
|
assert result == EXPECTED
|
|
896
897
|
|
|
897
898
|
|
|
898
|
-
def
|
|
899
|
+
def test_group_nodes_by_year_scenario_e():
|
|
899
900
|
"""
|
|
900
901
|
Edge case where nodes with short durations are equally split between two
|
|
901
902
|
year groups. In this case, they should be categorised as the later of the
|
|
@@ -918,7 +919,7 @@ def test_group_nodes_scenario_e():
|
|
|
918
919
|
"endDate": "2001-01",
|
|
919
920
|
"startDate": "2000-12",
|
|
920
921
|
"value": 100,
|
|
921
|
-
"
|
|
922
|
+
"fraction_of_group_duration": 0.08493150684931507,
|
|
922
923
|
"fraction_of_node_duration": 0.50
|
|
923
924
|
}
|
|
924
925
|
]
|
|
@@ -943,19 +944,19 @@ def test_group_nodes_by_year_missing_dates():
|
|
|
943
944
|
2001: [{
|
|
944
945
|
"value": [3],
|
|
945
946
|
"dates": ["2001-12-31"],
|
|
946
|
-
"
|
|
947
|
+
"fraction_of_group_duration": 0.0027397260273972603,
|
|
947
948
|
"fraction_of_node_duration": 1.0
|
|
948
949
|
}],
|
|
949
950
|
2002: [{
|
|
950
951
|
"value": [4],
|
|
951
952
|
"dates": ["2002"],
|
|
952
|
-
"
|
|
953
|
+
"fraction_of_group_duration": 1.0,
|
|
953
954
|
"fraction_of_node_duration": 1.0
|
|
954
955
|
}],
|
|
955
956
|
2003: [{
|
|
956
957
|
"value": [5],
|
|
957
958
|
"dates": ["2003-06"],
|
|
958
|
-
"
|
|
959
|
+
"fraction_of_group_duration": 0.0821917808219178,
|
|
959
960
|
"fraction_of_node_duration": 1.0
|
|
960
961
|
}]
|
|
961
962
|
}
|
|
@@ -981,28 +982,87 @@ def test_group_nodes_by_year_multiple_values_and_dates():
|
|
|
981
982
|
2000: [{
|
|
982
983
|
"dates": ["2000-01", "2000-06"],
|
|
983
984
|
"fraction_of_node_duration": 0.32475598935226263,
|
|
984
|
-
"
|
|
985
|
+
"fraction_of_group_duration": 1.0,
|
|
985
986
|
"value": [1, 2]
|
|
986
987
|
}],
|
|
987
988
|
2001: [{
|
|
988
989
|
"dates": ["2001-02"],
|
|
989
990
|
"fraction_of_node_duration": 0.323868677905945,
|
|
990
|
-
"
|
|
991
|
+
"fraction_of_group_duration": 1.0,
|
|
991
992
|
"value": [3]
|
|
992
993
|
}],
|
|
993
994
|
2002: [{
|
|
994
995
|
"dates": ["2002-03"],
|
|
995
996
|
"fraction_of_node_duration": 0.323868677905945,
|
|
996
|
-
"
|
|
997
|
+
"fraction_of_group_duration": 1.0,
|
|
997
998
|
"value": [4]
|
|
998
999
|
}],
|
|
999
1000
|
2003: [{
|
|
1000
1001
|
"dates": ["2003-01"],
|
|
1001
1002
|
"fraction_of_node_duration": 0.027506654835847383,
|
|
1002
|
-
"
|
|
1003
|
+
"fraction_of_group_duration": 0.08493150684931507,
|
|
1003
1004
|
"value": [5]
|
|
1004
1005
|
}]
|
|
1005
1006
|
}
|
|
1006
1007
|
|
|
1007
1008
|
result = group_nodes_by_year(NODES, mode=GroupNodesByYearMode.DATES)
|
|
1008
1009
|
assert result == EXPECTED
|
|
1010
|
+
|
|
1011
|
+
|
|
1012
|
+
def test_group_nodes_by_year_and_month():
|
|
1013
|
+
MANAGEMENT = [
|
|
1014
|
+
{
|
|
1015
|
+
"term.@id": "fullTillage",
|
|
1016
|
+
"endDate": "2001-01",
|
|
1017
|
+
"startDate": "2000-12",
|
|
1018
|
+
"value": 100
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
"term.@id": "reducedTillage",
|
|
1022
|
+
"endDate": "2001-10",
|
|
1023
|
+
"startDate": "2001-09",
|
|
1024
|
+
"value": 100
|
|
1025
|
+
}
|
|
1026
|
+
]
|
|
1027
|
+
|
|
1028
|
+
EXPECTED = {
|
|
1029
|
+
2000: {
|
|
1030
|
+
12: [
|
|
1031
|
+
{
|
|
1032
|
+
"term.@id": "fullTillage",
|
|
1033
|
+
"endDate": "2001-01",
|
|
1034
|
+
"startDate": "2000-12",
|
|
1035
|
+
"value": 100,
|
|
1036
|
+
}
|
|
1037
|
+
]
|
|
1038
|
+
},
|
|
1039
|
+
2001: {
|
|
1040
|
+
1: [
|
|
1041
|
+
{
|
|
1042
|
+
"term.@id": "fullTillage",
|
|
1043
|
+
"endDate": "2001-01",
|
|
1044
|
+
"startDate": "2000-12",
|
|
1045
|
+
"value": 100,
|
|
1046
|
+
}
|
|
1047
|
+
],
|
|
1048
|
+
9: [
|
|
1049
|
+
{
|
|
1050
|
+
"term.@id": "reducedTillage",
|
|
1051
|
+
"endDate": "2001-10",
|
|
1052
|
+
"startDate": "2001-09",
|
|
1053
|
+
"value": 100,
|
|
1054
|
+
}
|
|
1055
|
+
],
|
|
1056
|
+
10: [
|
|
1057
|
+
{
|
|
1058
|
+
"term.@id": "reducedTillage",
|
|
1059
|
+
"endDate": "2001-10",
|
|
1060
|
+
"startDate": "2001-09",
|
|
1061
|
+
"value": 100,
|
|
1062
|
+
}
|
|
1063
|
+
],
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
result = group_nodes_by_year_and_month(MANAGEMENT)
|
|
1068
|
+
assert result == EXPECTED
|
tests/models/utils/test_term.py
CHANGED
|
@@ -4,7 +4,7 @@ from hestia_earth.models.utils.term import (
|
|
|
4
4
|
get_liquid_fuel_terms, get_irrigation_terms, get_urea_terms, get_excreta_N_terms, get_excreta_VS_terms,
|
|
5
5
|
get_generic_crop, get_rice_paddy_terms, get_tillage_terms, get_crop_residue_terms, get_cover_crop_property_terms,
|
|
6
6
|
get_crop_residue_incorporated_or_left_on_field_terms, get_irrigated_terms, get_residue_removed_or_burnt_terms,
|
|
7
|
-
|
|
7
|
+
get_upland_rice_land_cover_terms, get_upland_rice_crop_terms, get_long_fallow_land_cover_terms
|
|
8
8
|
)
|
|
9
9
|
|
|
10
10
|
class_path = 'hestia_earth.models.utils.term'
|
|
@@ -102,7 +102,21 @@ def test_get_residue_removed_or_burnt_terms(mock_find_node):
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
@patch(f"{class_path}.search")
|
|
105
|
-
def
|
|
105
|
+
def test_get_upland_rice_land_cover_terms(mock_find_node):
|
|
106
106
|
id = 'term-id'
|
|
107
107
|
mock_find_node.return_value = [{'@id': id}]
|
|
108
|
-
assert
|
|
108
|
+
assert get_upland_rice_land_cover_terms() == [id]
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
@patch(f"{class_path}.search")
|
|
112
|
+
def test_get_upland_rice_crop_terms(mock_find_node):
|
|
113
|
+
id = 'term-id'
|
|
114
|
+
mock_find_node.return_value = [{'@id': id}]
|
|
115
|
+
assert get_upland_rice_crop_terms() == [id]
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
@patch(f"{class_path}.search")
|
|
119
|
+
def test_get_long_fallow_land_cover_terms(mock_find_node):
|
|
120
|
+
id = 'term-id'
|
|
121
|
+
mock_find_node.return_value = [{'@id': id}]
|
|
122
|
+
assert get_long_fallow_land_cover_terms() == [id]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|