Skip to content

Commit

Permalink
Fix stratified and kriging analysis INPFC bugs (OSOceanAcoustics#312)
Browse files Browse the repository at this point in the history
* Create test file script

* Tweaks to `kriging_analysis` to correctly use `stratum_inpfc` as a valid column name for internal dataframes

* Fix to transect coordinate storage and removing duplication of `stratum_inpfc`

* Remove test file script

* Pre-commit changes
  • Loading branch information
brandynlucca authored Dec 5, 2024
1 parent 1492a53 commit 3067a55
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
13 changes: 12 additions & 1 deletion echopop/spatial/transect.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,16 @@ def save_transect_coordinates(transect_data: pd.DataFrame, settings_dict: dict):
# Get the correct haul and stratum names
age_group_cols = settings_dict["age_group_columns"]

# Get stratum definition
stratum_def = settings_dict["stratum"]

# Get stratum column name
stratum_col = settings_dict["stratum_name"]
# ---- Set up the column renaming scheme
if stratum_def == "inpfc":
stratum_rename = "stratum_num"
else:
stratum_rename = stratum_col

# Extract transect numbers, coordinates, and strata
transect_data_extract = transect_data.filter(
Expand All @@ -88,7 +96,10 @@ def save_transect_coordinates(transect_data: pd.DataFrame, settings_dict: dict):

# Rename the group-specific columns and return the output
return transect_data_extract.rename(
columns={age_group_cols["haul_id"]: "haul_num", age_group_cols["stratum_id"]: stratum_col}
columns={
age_group_cols["haul_id"]: "haul_num",
age_group_cols["stratum_id"]: stratum_rename,
}
)


Expand Down
6 changes: 1 addition & 5 deletions echopop/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -887,17 +887,13 @@ def kriging_analysis(
# ---- From `self.transect_analysis` settings
"exclude_age1": self.analysis["settings"]["transect"]["exclude_age1"],
"stratum": self.analysis["settings"]["transect"]["stratum"],
"stratum_name": self.analysis["settings"]["transect"]["stratum_name"],
},
)

# Calculate additional keys for the settings
self.analysis["settings"]["kriging"].update(
{
"stratum_name": (
"stratum_num"
if self.analysis["settings"]["kriging"]["stratum"] == "ks"
else "inpfc"
),
"variogram_parameters": (
{
**self.input["statistics"]["variogram"]["model_config"],
Expand Down

0 comments on commit 3067a55

Please sign in to comment.