Skip to content

Commit b2ff977

Browse files
jjmaynardgarobrik
authored andcommitted
fix/OSD data aggregation
- Fixed array length inconsistencies in OSD infilling by using stored horizon depths from hzb_lyrs instead of muhorzdata_pd_group - Applied fix to sand/clay/texture aggregation (lines 919-942) - Applied fix to LAB/Munsell aggregation (lines 775-806)
1 parent cc5733b commit b2ff977

1 file changed

Lines changed: 26 additions & 8 deletions

File tree

soil_id/us_soil.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -766,20 +766,29 @@ def list_soils(lon, lat):
766766
lab_lyrs.append(["", "", ""])
767767
munsell_lyrs.append("")
768768
else:
769+
# Use the horizon bottom depths that match the stored horizon structure
770+
# Convert string values to float, filtering out empty strings
771+
horizon_bottom_depths = [
772+
float(v) if v != "" else np.nan
773+
for v in hzb_lyrs[index].values()
774+
]
775+
# Filter out NaN values
776+
horizon_bottom_depths = [d for d in horizon_bottom_depths if not np.isnan(d)]
777+
769778
# Aggregate data for each color dimension
770779
l_d = aggregate_data(
771780
data=lab_intpl["l"],
772-
bottom_depths=muhorzdata_pd_group["hzdepb_r"].tolist(),
781+
bottom_depths=horizon_bottom_depths,
773782
sd=2,
774783
).fillna("")
775784
a_d = aggregate_data(
776785
data=lab_intpl["a"],
777-
bottom_depths=muhorzdata_pd_group["hzdepb_r"].tolist(),
786+
bottom_depths=horizon_bottom_depths,
778787
sd=2,
779788
).fillna("")
780789
b_d = aggregate_data(
781790
data=lab_intpl["b"],
782-
bottom_depths=muhorzdata_pd_group["hzdepb_r"].tolist(),
791+
bottom_depths=horizon_bottom_depths,
783792
sd=2,
784793
).fillna("")
785794

@@ -909,16 +918,25 @@ def list_soils(lon, lat):
909918

910919
getProfile_cokey[index] = getProfile_mod
911920

921+
# Use the horizon bottom depths that match the stored horizon structure
922+
# Convert string values to float, filtering out empty strings
923+
horizon_bottom_depths = [
924+
float(v) if v != "" else np.nan
925+
for v in hzb_lyrs[index].values()
926+
]
927+
# Filter out NaN values
928+
horizon_bottom_depths = [d for d in horizon_bottom_depths if not np.isnan(d)]
929+
912930
# Aggregate sand data
913931
snd_d_osd = aggregate_data(
914932
data=OSD_sand_intpl.iloc[:, 0],
915-
bottom_depths=muhorzdata_pd_group["hzdepb_r"].tolist(),
933+
bottom_depths=horizon_bottom_depths,
916934
)
917935

918936
# Aggregate clay data
919937
cly_d_osd = aggregate_data(
920938
data=OSD_clay_intpl.iloc[:, 1],
921-
bottom_depths=muhorzdata_pd_group["hzdepb_r"].tolist(),
939+
bottom_depths=horizon_bottom_depths,
922940
)
923941

924942
# Calculate texture data based on sand and clay data
@@ -931,7 +949,7 @@ def list_soils(lon, lat):
931949
# Aggregate rock fragment data
932950
rf_d_osd = aggregate_data(
933951
data=OSD_rfv_intpl.c_cfpct_intpl,
934-
bottom_depths=muhorzdata_pd_group["hzdepb_r"].tolist(),
952+
bottom_depths=horizon_bottom_depths,
935953
)
936954

937955
# Fill NaN values
@@ -952,9 +970,9 @@ def list_soils(lon, lat):
952970
# Update cec, ph, and ec layers if they contain only a single
953971
# empty string
954972
for lyr in [cec_lyrs, ph_lyrs, ec_lyrs]:
955-
if len(lyr[index]) == 1 and lyr[index][0] == "":
973+
if len(lyr[index]) == 1 and list(lyr[index].values())[0] == "":
956974
empty_values = [""] * len(hzb_lyrs[index])
957-
lyr[index] = dict(zip(hzb_lyrs[index], empty_values))
975+
lyr[index] = dict(zip(hzb_lyrs[index].keys(), empty_values))
958976

959977
else:
960978
OSDhorzdata_group_cokey[index] = group_sorted

0 commit comments

Comments
 (0)