hestia-earth-models 0.57.2__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.

Files changed (109) hide show
  1. hestia_earth/models/cycle/aboveGroundCropResidueTotal.py +17 -12
  2. hestia_earth/models/cycle/excretaKgMass.py +4 -5
  3. hestia_earth/models/cycle/excretaKgN.py +4 -5
  4. hestia_earth/models/cycle/excretaKgVs.py +4 -5
  5. hestia_earth/models/cycle/inorganicFertiliser.py +2 -2
  6. hestia_earth/models/cycle/{irrigated.py → irrigatedTypeUnspecified.py} +4 -4
  7. hestia_earth/models/cycle/liveAnimal.py +9 -11
  8. hestia_earth/models/cycle/milkYield.py +154 -0
  9. hestia_earth/models/cycle/residueIncorporated.py +1 -1
  10. hestia_earth/models/cycle/utils.py +6 -0
  11. hestia_earth/models/emepEea2019/nh3ToAirInorganicFertiliser.py +3 -3
  12. hestia_earth/models/faostat2018/seed.py +2 -3
  13. hestia_earth/models/geospatialDatabase/clayContent.py +17 -4
  14. hestia_earth/models/geospatialDatabase/sandContent.py +17 -4
  15. hestia_earth/models/geospatialDatabase/siltContent.py +2 -2
  16. hestia_earth/models/impact_assessment/irrigated.py +0 -3
  17. hestia_earth/models/ipcc2006/co2ToAirOrganicSoilCultivation.py +2 -2
  18. hestia_earth/models/ipcc2006/n2OToAirCropResidueDecompositionIndirect.py +2 -2
  19. hestia_earth/models/ipcc2006/n2OToAirExcretaDirect.py +1 -1
  20. hestia_earth/models/ipcc2006/n2OToAirExcretaIndirect.py +8 -4
  21. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserDirect.py +4 -1
  22. hestia_earth/models/ipcc2006/n2OToAirInorganicFertiliserIndirect.py +1 -1
  23. hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserDirect.py +1 -1
  24. hestia_earth/models/ipcc2006/n2OToAirOrganicFertiliserIndirect.py +1 -1
  25. hestia_earth/models/ipcc2006/utils.py +11 -8
  26. hestia_earth/models/ipcc2019/ch4ToAirEntericFermentation.py +4 -4
  27. hestia_earth/models/ipcc2019/ch4ToAirFloodedRice.py +16 -7
  28. hestia_earth/models/ipcc2019/co2ToAirSoilCarbonStockChangeManagementChange.py +759 -0
  29. hestia_earth/models/ipcc2019/croppingDuration.py +12 -6
  30. hestia_earth/models/ipcc2019/n2OToAirCropResidueDecompositionDirect.py +5 -52
  31. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserDirect.py +104 -0
  32. hestia_earth/models/ipcc2019/n2OToAirInorganicFertiliserIndirect.py +1 -1
  33. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserDirect.py +105 -0
  34. hestia_earth/models/ipcc2019/n2OToAirOrganicFertiliserIndirect.py +1 -1
  35. hestia_earth/models/ipcc2019/no3ToGroundwaterCropResidueDecomposition.py +1 -1
  36. hestia_earth/models/ipcc2019/no3ToGroundwaterExcreta.py +1 -1
  37. hestia_earth/models/ipcc2019/no3ToGroundwaterInorganicFertiliser.py +1 -1
  38. hestia_earth/models/ipcc2019/no3ToGroundwaterOrganicFertiliser.py +1 -1
  39. hestia_earth/models/ipcc2019/organicCarbonPerHa.py +1088 -1268
  40. hestia_earth/models/ipcc2019/pastureGrass.py +4 -4
  41. hestia_earth/models/ipcc2019/utils.py +102 -1
  42. hestia_earth/models/koble2014/aboveGroundCropResidue.py +15 -17
  43. hestia_earth/models/koble2014/cropResidueManagement.py +2 -2
  44. hestia_earth/models/koble2014/utils.py +19 -3
  45. hestia_earth/models/linkedImpactAssessment/__init__.py +4 -2
  46. hestia_earth/models/log.py +15 -3
  47. hestia_earth/models/mocking/search-results.json +184 -118
  48. hestia_earth/models/pooreNemecek2018/excretaKgN.py +6 -7
  49. hestia_earth/models/pooreNemecek2018/excretaKgVs.py +7 -6
  50. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterCropResidueDecomposition.py +3 -2
  51. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterExcreta.py +3 -2
  52. hestia_earth/models/pooreNemecek2018/no3ToGroundwaterInorganicFertiliser.py +3 -2
  53. hestia_earth/models/pooreNemecek2018/saplings.py +0 -1
  54. hestia_earth/models/site/management.py +168 -0
  55. hestia_earth/models/site/organicCarbonPerHa.py +251 -89
  56. hestia_earth/models/stehfestBouwman2006/n2OToAirCropResidueDecompositionDirect.py +3 -2
  57. hestia_earth/models/stehfestBouwman2006/n2OToAirExcretaDirect.py +3 -2
  58. hestia_earth/models/stehfestBouwman2006/n2OToAirInorganicFertiliserDirect.py +3 -2
  59. hestia_earth/models/stehfestBouwman2006/n2OToAirOrganicFertiliserDirect.py +3 -2
  60. hestia_earth/models/stehfestBouwman2006/noxToAirCropResidueDecomposition.py +3 -2
  61. hestia_earth/models/stehfestBouwman2006/noxToAirExcreta.py +3 -2
  62. hestia_earth/models/stehfestBouwman2006/noxToAirInorganicFertiliser.py +3 -2
  63. hestia_earth/models/stehfestBouwman2006/noxToAirOrganicFertiliser.py +3 -2
  64. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirCropResidueDecomposition.py +3 -2
  65. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirExcreta.py +3 -2
  66. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirInorganicFertiliser.py +3 -2
  67. hestia_earth/models/stehfestBouwman2006GisImplementation/noxToAirOrganicFertiliser.py +3 -2
  68. hestia_earth/models/utils/aggregated.py +1 -0
  69. hestia_earth/models/utils/blank_node.py +394 -72
  70. hestia_earth/models/utils/cropResidue.py +13 -0
  71. hestia_earth/models/utils/cycle.py +18 -9
  72. hestia_earth/models/utils/measurement.py +1 -1
  73. hestia_earth/models/utils/property.py +4 -4
  74. hestia_earth/models/utils/term.py +48 -3
  75. hestia_earth/models/version.py +1 -1
  76. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/METADATA +5 -9
  77. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/RECORD +109 -97
  78. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/WHEEL +1 -1
  79. tests/models/cycle/animal/input/test_hestiaAggregatedData.py +2 -14
  80. tests/models/cycle/input/test_hestiaAggregatedData.py +4 -16
  81. tests/models/cycle/test_coldCarcassWeightPerHead.py +1 -1
  82. tests/models/cycle/test_coldDressedCarcassWeightPerHead.py +1 -1
  83. tests/models/cycle/{test_irrigated.py → test_irrigatedTypeUnspecified.py} +1 -1
  84. tests/models/cycle/test_milkYield.py +58 -0
  85. tests/models/cycle/test_readyToCookWeightPerHead.py +1 -1
  86. tests/models/emepEea2019/test_nh3ToAirInorganicFertiliser.py +1 -1
  87. tests/models/geospatialDatabase/test_clayContent.py +9 -3
  88. tests/models/geospatialDatabase/test_sandContent.py +9 -3
  89. tests/models/ipcc2006/test_n2OToAirExcretaDirect.py +7 -2
  90. tests/models/ipcc2006/test_n2OToAirExcretaIndirect.py +1 -1
  91. tests/models/ipcc2006/test_n2OToAirInorganicFertiliserDirect.py +7 -2
  92. tests/models/ipcc2006/test_n2OToAirInorganicFertiliserIndirect.py +7 -2
  93. tests/models/ipcc2006/test_n2OToAirOrganicFertiliserDirect.py +7 -2
  94. tests/models/ipcc2006/test_n2OToAirOrganicFertiliserIndirect.py +7 -2
  95. tests/models/ipcc2019/test_ch4ToAirEntericFermentation.py +1 -1
  96. tests/models/ipcc2019/test_co2ToAirSoilCarbonStockChangeManagementChange.py +228 -0
  97. tests/models/ipcc2019/test_n2OToAirInorganicFertiliserDirect.py +74 -0
  98. tests/models/ipcc2019/test_n2OToAirOrganicFertiliserDirect.py +74 -0
  99. tests/models/ipcc2019/test_organicCarbonPerHa.py +303 -1044
  100. tests/models/koble2014/test_residueBurnt.py +1 -2
  101. tests/models/koble2014/test_residueLeftOnField.py +1 -2
  102. tests/models/koble2014/test_residueRemoved.py +1 -2
  103. tests/models/koble2014/test_utils.py +52 -0
  104. tests/models/site/test_management.py +117 -0
  105. tests/models/site/test_organicCarbonPerHa.py +51 -5
  106. tests/models/utils/test_blank_node.py +230 -34
  107. tests/models/utils/test_term.py +17 -3
  108. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/LICENSE +0 -0
  109. {hestia_earth_models-0.57.2.dist-info → hestia_earth_models-0.59.0.dist-info}/top_level.txt +0 -0
@@ -17,7 +17,9 @@ from hestia_earth.models.utils.blank_node import (
17
17
  DatestrGapfillMode,
18
18
  DatetimeRange,
19
19
  get_node_value,
20
- group_nodes_by_year
20
+ group_nodes_by_year,
21
+ group_nodes_by_year_and_month,
22
+ GroupNodesByYearMode
21
23
  )
22
24
 
23
25
 
@@ -456,6 +458,11 @@ def test_get_date_month_day():
456
458
  assert _get_datestr_format(DATESTR_MONTH_DAY), DatestrFormat.MONTH_DAY
457
459
 
458
460
 
461
+ def test_get_datestr_format_no_zero_padding():
462
+ DATE_STR = "2000-1"
463
+ assert _get_datestr_format(DATE_STR) is None
464
+
465
+
459
466
  # --- test _gapfill_datestr ---
460
467
 
461
468
 
@@ -545,7 +552,7 @@ GROUP_NODES_BY_YEAR_SCENARIO_A_CYCLES = [
545
552
  ]
546
553
 
547
554
 
548
- def test_group_nodes_scenario_a():
555
+ def test_group_nodes_by_year_scenario_a():
549
556
  """
550
557
  Datestr in format `YYYY`. Some nodes missing `startDate` field. One multi-year cycle.
551
558
 
@@ -558,34 +565,34 @@ def test_group_nodes_scenario_a():
558
565
  2002: [{
559
566
  "@id": "cycle-1a",
560
567
  "endDate": "2002",
561
- "fraction_of_year": 1.0,
568
+ "fraction_of_group_duration": 1.0,
562
569
  "fraction_of_node_duration": 1.0
563
570
  }],
564
571
  2003: [{
565
572
  "@id": "cycle-2a",
566
573
  "endDate": "2003",
567
- "fraction_of_year": 1.0,
574
+ "fraction_of_group_duration": 1.0,
568
575
  "fraction_of_node_duration": 1.0
569
576
  }],
570
577
  2004: [{
571
578
  "@id": "cycle-3a",
572
579
  "endDate": "2006",
573
580
  "startDate": "2004",
574
- "fraction_of_year": 1.0,
581
+ "fraction_of_group_duration": 1.0,
575
582
  "fraction_of_node_duration": 0.33394160583941607
576
583
  }],
577
584
  2005: [{
578
585
  "@id": "cycle-3a",
579
586
  "endDate": "2006",
580
587
  "startDate": "2004",
581
- "fraction_of_year": 1.0,
588
+ "fraction_of_group_duration": 1.0,
582
589
  "fraction_of_node_duration": 0.333029197080292
583
590
  }],
584
591
  2006: [{
585
592
  "@id": "cycle-3a",
586
593
  "endDate": "2006",
587
594
  "startDate": "2004",
588
- "fraction_of_year": 1.0,
595
+ "fraction_of_group_duration": 1.0,
589
596
  "fraction_of_node_duration": 0.333029197080292
590
597
  }]
591
598
  }
@@ -594,7 +601,60 @@ def test_group_nodes_scenario_a():
594
601
  assert result == EXPECTED
595
602
 
596
603
 
597
- def test_group_nodes_scenario_b():
604
+ def test_group_nodes_by_year_scenario_a_with_inner_key():
605
+
606
+ INNER_KEY = "inner_key"
607
+ EXPECTED = {
608
+ 2002: {
609
+ INNER_KEY: [{
610
+ "@id": "cycle-1a",
611
+ "endDate": "2002",
612
+ "fraction_of_group_duration": 1.0,
613
+ "fraction_of_node_duration": 1.0
614
+ }]
615
+ },
616
+ 2003: {
617
+ INNER_KEY: [{
618
+ "@id": "cycle-2a",
619
+ "endDate": "2003",
620
+ "fraction_of_group_duration": 1.0,
621
+ "fraction_of_node_duration": 1.0
622
+ }]
623
+ },
624
+ 2004: {
625
+ INNER_KEY: [{
626
+ "@id": "cycle-3a",
627
+ "endDate": "2006",
628
+ "startDate": "2004",
629
+ "fraction_of_group_duration": 1.0,
630
+ "fraction_of_node_duration": 0.33394160583941607
631
+ }]
632
+ },
633
+ 2005: {
634
+ INNER_KEY: [{
635
+ "@id": "cycle-3a",
636
+ "endDate": "2006",
637
+ "startDate": "2004",
638
+ "fraction_of_group_duration": 1.0,
639
+ "fraction_of_node_duration": 0.333029197080292
640
+ }]
641
+ },
642
+ 2006: {
643
+ INNER_KEY: [{
644
+ "@id": "cycle-3a",
645
+ "endDate": "2006",
646
+ "startDate": "2004",
647
+ "fraction_of_group_duration": 1.0,
648
+ "fraction_of_node_duration": 0.333029197080292
649
+ }]
650
+ }
651
+ }
652
+
653
+ result = group_nodes_by_year(GROUP_NODES_BY_YEAR_SCENARIO_A_CYCLES, inner_key=INNER_KEY)
654
+ assert result == EXPECTED
655
+
656
+
657
+ def test_group_nodes_by_year_scenario_b():
598
658
  """
599
659
  Datestr in format `YYYY-MM-DD`. Two concurrent cycles (`cycle-3b` & `cycle-4b`).
600
660
  """
@@ -612,7 +672,7 @@ def test_group_nodes_scenario_b():
612
672
  "@id": "cycle-1b",
613
673
  "endDate": "2000-12-31",
614
674
  "startDate": "2000-01-01",
615
- "fraction_of_year": 1.0,
675
+ "fraction_of_group_duration": 1.0,
616
676
  "fraction_of_node_duration": 1.0
617
677
  }
618
678
  ],
@@ -621,7 +681,7 @@ def test_group_nodes_scenario_b():
621
681
  "@id": "cycle-2b",
622
682
  "endDate": "2001-12-31",
623
683
  "startDate": "2001-01-01",
624
- "fraction_of_year": 1.0,
684
+ "fraction_of_group_duration": 1.0,
625
685
  "fraction_of_node_duration": 1.0
626
686
  }
627
687
  ],
@@ -630,14 +690,14 @@ def test_group_nodes_scenario_b():
630
690
  "@id": "cycle-3b",
631
691
  "endDate": "2002-12-31",
632
692
  "startDate": "2002-01-01",
633
- "fraction_of_year": 1.0,
693
+ "fraction_of_group_duration": 1.0,
634
694
  "fraction_of_node_duration": 1.0
635
695
  },
636
696
  {
637
697
  "@id": "cycle-4b",
638
698
  "endDate": "2002-12-31",
639
699
  "startDate": "2002-01-01",
640
- "fraction_of_year": 1.0,
700
+ "fraction_of_group_duration": 1.0,
641
701
  "fraction_of_node_duration": 1.0
642
702
  }
643
703
  ]
@@ -647,7 +707,7 @@ def test_group_nodes_scenario_b():
647
707
  assert result == EXPECTED
648
708
 
649
709
 
650
- def test_group_nodes_scenario_c():
710
+ def test_group_nodes_by_year_scenario_c():
651
711
  """
652
712
  Multiple overlapping 6 month and 12 month cycles.
653
713
  """
@@ -666,14 +726,14 @@ def test_group_nodes_scenario_c():
666
726
  "@id": "cycle-1c",
667
727
  "endDate": "2000-06",
668
728
  "startDate": "2000-01",
669
- "fraction_of_year": 0.4972677595628415,
729
+ "fraction_of_group_duration": 0.4972677595628415,
670
730
  "fraction_of_node_duration": 1.0
671
731
  },
672
732
  {
673
733
  "@id": "cycle-2c",
674
734
  "endDate": "2001-12",
675
735
  "startDate": "2000-07",
676
- "fraction_of_year": 0.5027322404371585,
736
+ "fraction_of_group_duration": 0.5027322404371585,
677
737
  "fraction_of_node_duration": 0.33515482695810567
678
738
  }
679
739
  ],
@@ -682,21 +742,21 @@ def test_group_nodes_scenario_c():
682
742
  "@id": "cycle-2c",
683
743
  "endDate": "2001-12",
684
744
  "startDate": "2000-07",
685
- "fraction_of_year": 1.0,
745
+ "fraction_of_group_duration": 1.0,
686
746
  "fraction_of_node_duration": 0.6648451730418944
687
747
  },
688
748
  {
689
749
  "@id": "cycle-3c",
690
750
  "endDate": "2001-06",
691
751
  "startDate": "2001-01",
692
- "fraction_of_year": 0.4958904109589041,
752
+ "fraction_of_group_duration": 0.4958904109589041,
693
753
  "fraction_of_node_duration": 1.0
694
754
  },
695
755
  {
696
756
  "@id": "cycle-4c",
697
757
  "endDate": "2002-06",
698
758
  "startDate": "2001-07",
699
- "fraction_of_year": 0.5041095890410959,
759
+ "fraction_of_group_duration": 0.5041095890410959,
700
760
  "fraction_of_node_duration": 0.5041095890410959
701
761
  }
702
762
  ],
@@ -705,14 +765,14 @@ def test_group_nodes_scenario_c():
705
765
  "@id": "cycle-4c",
706
766
  "endDate": "2002-06",
707
767
  "startDate": "2001-07",
708
- "fraction_of_year": 0.4958904109589041,
768
+ "fraction_of_group_duration": 0.4958904109589041,
709
769
  "fraction_of_node_duration": 0.4958904109589041
710
770
  },
711
771
  {
712
772
  "@id": "cycle-5c",
713
773
  "endDate": "2002-12",
714
774
  "startDate": "2002-01",
715
- "fraction_of_year": 1.0,
775
+ "fraction_of_group_duration": 1.0,
716
776
  "fraction_of_node_duration": 1.0
717
777
  }
718
778
  ]
@@ -722,7 +782,7 @@ def test_group_nodes_scenario_c():
722
782
  assert result == EXPECTED
723
783
 
724
784
 
725
- def test_group_nodes_scenario_d():
785
+ def test_group_nodes_by_year_scenario_d():
726
786
  """
727
787
  Cases where nodes only overlap with year groups by a small amount.
728
788
  Overlaps of less than 30% of a year should be not be included in a
@@ -774,7 +834,7 @@ def test_group_nodes_scenario_d():
774
834
  "term.@id": "fullTillage",
775
835
  "endDate": "2000-11",
776
836
  "value": 100,
777
- "fraction_of_year": 0.9153005464480874,
837
+ "fraction_of_group_duration": 0.9153005464480874,
778
838
  "fraction_of_node_duration": 0.9153005464480874
779
839
  },
780
840
  {
@@ -782,7 +842,7 @@ def test_group_nodes_scenario_d():
782
842
  "endDate": "2000-11",
783
843
  "startDate": "2000-09",
784
844
  "value": True,
785
- "fraction_of_year": 0.24863387978142076,
845
+ "fraction_of_group_duration": 0.24863387978142076,
786
846
  "fraction_of_node_duration": 1.0
787
847
  }
788
848
  ],
@@ -792,7 +852,7 @@ def test_group_nodes_scenario_d():
792
852
  "endDate": "2001-07",
793
853
  "startDate": "2000-12",
794
854
  "value": 50,
795
- "fraction_of_year": 0.5808219178082191,
855
+ "fraction_of_group_duration": 0.5808219178082191,
796
856
  "fraction_of_node_duration": 0.8724279835390947
797
857
  },
798
858
  {
@@ -800,7 +860,7 @@ def test_group_nodes_scenario_d():
800
860
  "endDate": "2001-07",
801
861
  "startDate": "2000-12",
802
862
  "value": 50,
803
- "fraction_of_year": 0.5808219178082191,
863
+ "fraction_of_group_duration": 0.5808219178082191,
804
864
  "fraction_of_node_duration": 0.8724279835390947
805
865
  },
806
866
  {
@@ -808,7 +868,7 @@ def test_group_nodes_scenario_d():
808
868
  "endDate": "2002-01",
809
869
  "startDate": "2001-08",
810
870
  "value": 100,
811
- "fraction_of_year": 0.4191780821917808,
871
+ "fraction_of_group_duration": 0.4191780821917808,
812
872
  "fraction_of_node_duration": 0.8315217391304348
813
873
  },
814
874
  {
@@ -816,7 +876,7 @@ def test_group_nodes_scenario_d():
816
876
  "endDate": "2002-06",
817
877
  "startDate": "2001-07",
818
878
  "value": True,
819
- "fraction_of_year": 0.5041095890410959,
879
+ "fraction_of_group_duration": 0.5041095890410959,
820
880
  "fraction_of_node_duration": 0.5041095890410959
821
881
  }
822
882
  ],
@@ -826,7 +886,7 @@ def test_group_nodes_scenario_d():
826
886
  "endDate": "2002-06",
827
887
  "startDate": "2001-07",
828
888
  "value": True,
829
- "fraction_of_year": 0.4958904109589041,
889
+ "fraction_of_group_duration": 0.4958904109589041,
830
890
  "fraction_of_node_duration": 0.4958904109589041
831
891
  }
832
892
  ]
@@ -836,7 +896,7 @@ def test_group_nodes_scenario_d():
836
896
  assert result == EXPECTED
837
897
 
838
898
 
839
- def test_group_nodes_scenario_e():
899
+ def test_group_nodes_by_year_scenario_e():
840
900
  """
841
901
  Edge case where nodes with short durations are equally split between two
842
902
  year groups. In this case, they should be categorised as the later of the
@@ -859,14 +919,150 @@ def test_group_nodes_scenario_e():
859
919
  "endDate": "2001-01",
860
920
  "startDate": "2000-12",
861
921
  "value": 100,
862
- "fraction_of_year": 0.08493150684931507,
922
+ "fraction_of_group_duration": 0.08493150684931507,
863
923
  "fraction_of_node_duration": 0.50
864
924
  }
865
925
  ]
866
926
  }
867
927
 
868
- result = group_nodes_by_year(
869
- MANAGEMENT,
870
- # gapfill_incomplete_datestrs=False
871
- )
928
+ result = group_nodes_by_year(MANAGEMENT)
929
+ assert result == EXPECTED
930
+
931
+
932
+ def test_group_nodes_by_year_missing_dates():
933
+
934
+ NODES = [
935
+ {"value": [0], "endDate": "2000-12-31", "startDate": "2000-01-01"},
936
+ {"value": [1], "endDate": "2000-12-31", "startDate": "2000-01-01"},
937
+ {"value": [2], "endDate": "2001-12-31", "startDate": "2001-01-01"},
938
+ {"value": [3], "dates": ["2001-12-31"]},
939
+ {"value": [4], "dates": ["2002"]},
940
+ {"value": [5], "dates": ["2003-06"]}
941
+ ]
942
+
943
+ EXPECTED = {
944
+ 2001: [{
945
+ "value": [3],
946
+ "dates": ["2001-12-31"],
947
+ "fraction_of_group_duration": 0.0027397260273972603,
948
+ "fraction_of_node_duration": 1.0
949
+ }],
950
+ 2002: [{
951
+ "value": [4],
952
+ "dates": ["2002"],
953
+ "fraction_of_group_duration": 1.0,
954
+ "fraction_of_node_duration": 1.0
955
+ }],
956
+ 2003: [{
957
+ "value": [5],
958
+ "dates": ["2003-06"],
959
+ "fraction_of_group_duration": 0.0821917808219178,
960
+ "fraction_of_node_duration": 1.0
961
+ }]
962
+ }
963
+
964
+ result = group_nodes_by_year(NODES, mode=GroupNodesByYearMode.DATES)
965
+ assert result == EXPECTED
966
+
967
+
968
+ def test_group_nodes_by_year_multiple_values_and_dates():
969
+
970
+ NODES = [{
971
+ "value": [1, 2, 3, 4, 5],
972
+ "dates": [
973
+ "2000-01",
974
+ "2000-06",
975
+ "2001-02",
976
+ "2002-03",
977
+ "2003-01"
978
+ ]
979
+ }]
980
+
981
+ EXPECTED = {
982
+ 2000: [{
983
+ "dates": ["2000-01", "2000-06"],
984
+ "fraction_of_node_duration": 0.32475598935226263,
985
+ "fraction_of_group_duration": 1.0,
986
+ "value": [1, 2]
987
+ }],
988
+ 2001: [{
989
+ "dates": ["2001-02"],
990
+ "fraction_of_node_duration": 0.323868677905945,
991
+ "fraction_of_group_duration": 1.0,
992
+ "value": [3]
993
+ }],
994
+ 2002: [{
995
+ "dates": ["2002-03"],
996
+ "fraction_of_node_duration": 0.323868677905945,
997
+ "fraction_of_group_duration": 1.0,
998
+ "value": [4]
999
+ }],
1000
+ 2003: [{
1001
+ "dates": ["2003-01"],
1002
+ "fraction_of_node_duration": 0.027506654835847383,
1003
+ "fraction_of_group_duration": 0.08493150684931507,
1004
+ "value": [5]
1005
+ }]
1006
+ }
1007
+
1008
+ result = group_nodes_by_year(NODES, mode=GroupNodesByYearMode.DATES)
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)
872
1068
  assert result == EXPECTED
@@ -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
- get_rice_plant_upland_terms
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 test_get_rice_plant_upland_terms(mock_find_node):
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 get_rice_plant_upland_terms() == [id]
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]