|
1 |
| -# # #################################################################################################### |
2 |
| -# # # TEST BACKWARDS COMPATIBILITY WITH OTHER SURVEY YEARS |
3 |
| -# # # LINKED ISSUE: https://github.com/OSOceanAcoustics/echopop/issues/307 |
4 |
| -# # #################################################################################################### |
5 |
| -# # # SUCCESSFUL TESTS |
6 |
| -# # # 2015, 2017, 2019, 2021, 2023 |
7 |
| -# # #################################################################################################### |
8 |
| -# # # FAILURE NOTES |
9 |
| -# # # 2012: Transect-region mapping |
10 |
| -# # # Initialize year-specific survey parameters |
11 |
| -# # #################################################################################################### |
12 |
| -# # # Import libraries |
13 |
| -# from echopop.survey import Survey |
14 |
| -# from echopop.extensions import generate_reports |
15 |
| -# import pandas as pd |
16 |
| -# from pathlib import Path |
17 |
| -# import glob |
18 |
| -# import json |
19 |
| -# import os |
| 1 | +#################################################################################################### |
| 2 | +# TEST BACKWARDS COMPATIBILITY WITH OTHER SURVEY YEARS |
| 3 | +# LINKED ISSUE: https://github.com/OSOceanAcoustics/echopop/issues/307 |
| 4 | +#################################################################################################### |
| 5 | +# SUCCESSFUL TESTS |
| 6 | +# 2015, 2017, 2019, 2021, 2023 |
| 7 | +#################################################################################################### |
| 8 | +# FAILURE NOTES |
| 9 | +# 2012: Transect-region mapping |
| 10 | +# Initialize year-specific survey parameters |
| 11 | +#################################################################################################### |
| 12 | +# Import libraries |
| 13 | +from echopop.survey import Survey |
| 14 | +from echopop.extensions import generate_reports |
| 15 | +import pandas as pd |
| 16 | +from pathlib import Path |
| 17 | +import glob |
| 18 | +import json |
| 19 | +import os |
20 | 20 |
|
21 |
| -# # #################################################################################################### |
22 |
| -# # # CURRENT SURVEY YEAR BEING TESTED: 2019 |
23 |
| -# # #################################################################################################### |
24 |
| -# # # Define current survey year |
25 |
| -# SURVEY_YEAR = 2019 |
| 21 | +#################################################################################################### |
| 22 | +# CURRENT SURVEY YEAR BEING TESTED: 2019 |
| 23 | +#################################################################################################### |
| 24 | +# Define current survey year |
| 25 | +SURVEY_YEAR = 2011 |
26 | 26 |
|
27 |
| -# # Initialization configuration |
28 |
| -# init_config_path = f"C:/Users/Brandyn/Documents/GitHub/echopop/config_files/initialization_\ |
29 |
| -# config_{SURVEY_YEAR}.yml" |
| 27 | +# Initialization configuration |
| 28 | +init_config_path = f"C:/Users/Brandyn/Documents/GitHub/echopop/config_files/initialization_\ |
| 29 | +config_{SURVEY_YEAR}.yml" |
30 | 30 |
|
31 |
| -# # Filepath/dataset configuration |
32 |
| -# survey_year_config_path = f"C:/Users/Brandyn/Documents/GitHub/echopop/config_files\ |
33 |
| -# /survey_year_{SURVEY_YEAR}_config.yml" |
| 31 | +# Filepath/dataset configuration |
| 32 | +survey_year_config_path = f"C:/Users/Brandyn/Documents/GitHub/echopop/config_files\ |
| 33 | +/survey_year_{SURVEY_YEAR}_config.yml" |
34 | 34 |
|
35 |
| -# # Load json settings |
36 |
| -# # ---- File open |
37 |
| -# with open(Path(os.getcwd() + "\\echopop\\compatibility_parameters_test.json").as_posix()) as f: |
38 |
| -# json_dict = json.load(f) |
39 |
| -# # ---- Load |
40 |
| -# parameters = json_dict[f"{SURVEY_YEAR}"] |
| 35 | +# Load json settings |
| 36 | +# ---- File open |
| 37 | +with open(Path(os.getcwd() + "\\echopop\\compatibility_parameters_test.json").as_posix()) as f: |
| 38 | + json_dict = json.load(f) |
| 39 | +# ---- Load |
| 40 | +parameters = json_dict[f"{SURVEY_YEAR}"] |
41 | 41 |
|
42 |
| -# #################################################################################################### |
43 |
| -# # Run |
44 |
| -# # ---- Create object |
45 |
| -# survey = Survey(init_config_path, survey_year_config_path) |
46 |
| -# # ---- Load acoustic data (Echoview export ingestion) |
47 |
| -# survey.load_acoustic_data(ingest_exports="echoview", |
48 |
| -# read_transect_region_file=parameters["read_transect_region_file"], |
49 |
| -# write_transect_region_file=parameters["write_transect_region_file"]) |
50 |
| -# # ---- Load acoustic data (Already-defined file) |
51 |
| -# if parameters["default_acoustics"]: |
52 |
| -# survey = Survey(init_config_path, survey_year_config_path) |
53 |
| -# survey.load_acoustic_data() |
54 |
| -# else: |
55 |
| -# Survey(init_config_path, survey_year_config_path).load_acoustic_data() |
56 |
| -# # ---- Load survey data |
57 |
| -# survey.load_survey_data() |
58 |
| -# # ---- Initial transect analysis test |
59 |
| -# survey.transect_analysis() |
60 |
| -# # ---- Counter |
61 |
| -# counter = 1 |
62 |
| -# # ---- Iterate across multiple strata types |
63 |
| -# for stratum in parameters["strata_types"]: |
64 |
| -# # ---- Iterate across different age-1 exclusion definitions |
65 |
| -# for excl in parameters["exclude_age1"]: |
66 |
| -# # ---- Transect analysis |
67 |
| -# survey.transect_analysis(exclude_age1=excl, stratum=stratum, verbose=False) |
68 |
| -# print( |
69 |
| -# f"{SURVEY_YEAR} transect analysis [{counter}/8] success!" |
70 |
| -# ) |
71 |
| -# # ---- Stratified analysis (transect analysis) |
72 |
| -# survey.stratified_analysis(bootstrap_ci_method=parameters["bootstrap_ci_method"], |
73 |
| -# transect_replicates=parameters["transect_replicates"], |
74 |
| -# verbose=False) |
75 |
| -# print( |
76 |
| -# f"{SURVEY_YEAR} stratified analysis (transect) [{counter}/8] success!" |
77 |
| -# ) |
78 |
| -# # ---- Fit variogram |
79 |
| -# survey.fit_variogram(verbose=False) |
80 |
| -# print( |
81 |
| -# f"{SURVEY_YEAR} variogram fitting [{counter}/8] success!" |
82 |
| -# ) |
83 |
| -# # ---- Iterate across different extrapolation schema |
84 |
| -# for extrap in parameters["extrapolate"]: |
85 |
| -# # ---- Kriging analysis (no variogram fitting) |
86 |
| -# survey.kriging_analysis(extrapolate=extrap, verbose=False) |
87 |
| -# print( |
88 |
| -# f"{SURVEY_YEAR} kriging analysis (default variogram) [{counter}/8] success!" |
89 |
| -# ) |
90 |
| -# # ---- Apply best-fit variogram |
91 |
| -# survey.kriging_analysis(best_fit_variogram=True, extrapolate=extrap, verbose=False) |
92 |
| -# print( |
93 |
| -# f"{SURVEY_YEAR} kriging analysis (best-fit variogram) [{counter}/8] success!" |
94 |
| -# ) |
95 |
| -# # ---- Stratified analysis (kriging analysis) |
96 |
| -# survey.stratified_analysis(dataset="kriging", |
97 |
| -# bootstrap_ci_method=parameters["bootstrap_ci_method"], |
98 |
| -# transect_replicates=parameters["transect_replicates"], |
99 |
| -# verbose=False) |
100 |
| -# print( |
101 |
| -# f"{SURVEY_YEAR} stratified analysis (kriging) [{counter}/8] success!" |
102 |
| -# ) |
103 |
| -# # ---- Test reports |
104 |
| -# survey.generate_reports(reports=["aged_length_haul_counts", |
105 |
| -# "kriging_input", |
106 |
| -# "kriged_length_age_abundance", |
107 |
| -# "kriged_length_age_biomass", |
108 |
| -# "kriged_mesh_results", |
109 |
| -# "total_length_haul_counts", |
110 |
| -# "transect_length_age_abundance", |
111 |
| -# "transect_length_age_biomass", |
112 |
| -# "transect_population_results"]) |
113 |
| -# # ---- Print out success |
114 |
| -# print( |
115 |
| -# f""" |
116 |
| -# Year: {SURVEY_YEAR} success [{counter}/8 configurations]! |
117 |
| -# Stratum: {stratum} |
118 |
| -# Age-1 fish excluded: {excl} |
119 |
| -# Extrapolated: {extrap} |
120 |
| -# """ |
121 |
| -# ) |
122 |
| -# # ---- Advance counter |
123 |
| -# counter += 1 |
| 42 | +#################################################################################################### |
| 43 | +# Run |
| 44 | +# ---- Create object |
| 45 | +survey = Survey(init_config_path, survey_year_config_path) |
| 46 | +# ---- Load acoustic data (Echoview export ingestion) |
| 47 | +survey.load_acoustic_data(ingest_exports="echoview", |
| 48 | + transect_pattern=parameters["transect_pattern"].replace(r"\\", "\\"), |
| 49 | + read_transect_region_file=parameters["read_transect_region_file"], |
| 50 | + write_transect_region_file=parameters["write_transect_region_file"]) |
| 51 | +# ---- Load acoustic data (Already-defined file) |
| 52 | +if parameters["default_acoustics"]: |
| 53 | + survey = Survey(init_config_path, survey_year_config_path) |
| 54 | + survey.load_acoustic_data() |
| 55 | +else: |
| 56 | + Survey(init_config_path, survey_year_config_path).load_acoustic_data() |
| 57 | +# ---- Load survey data |
| 58 | +survey.load_survey_data() |
| 59 | +# ---- Initial transect analysis test |
| 60 | +survey.transect_analysis() |
| 61 | +# ---- Counter |
| 62 | +counter = 1 |
| 63 | +# ---- Iterate across multiple strata types |
| 64 | +for stratum in parameters["strata_types"]: |
| 65 | + # ---- Iterate across different age-1 exclusion definitions |
| 66 | + for excl in parameters["exclude_age1"]: |
| 67 | + # ---- Transect analysis |
| 68 | + survey.transect_analysis(exclude_age1=excl, stratum=stratum, verbose=False) |
| 69 | + print( |
| 70 | + f"{SURVEY_YEAR} transect analysis [{counter}/8] success!" |
| 71 | + ) |
| 72 | + # ---- Stratified analysis (transect analysis) |
| 73 | + survey.stratified_analysis(bootstrap_ci_method=parameters["bootstrap_ci_method"], |
| 74 | + transect_replicates=parameters["transect_replicates"], |
| 75 | + verbose=False) |
| 76 | + print( |
| 77 | + f"{SURVEY_YEAR} stratified analysis (transect) [{counter}/8] success!" |
| 78 | + ) |
| 79 | + # ---- Fit variogram |
| 80 | + survey.fit_variogram(verbose=False) |
| 81 | + print( |
| 82 | + f"{SURVEY_YEAR} variogram fitting [{counter}/8] success!" |
| 83 | + ) |
| 84 | + # ---- Iterate across different extrapolation schema |
| 85 | + for extrap in parameters["extrapolate"]: |
| 86 | + # ---- Kriging analysis (no variogram fitting) |
| 87 | + survey.kriging_analysis(extrapolate=extrap, verbose=False) |
| 88 | + print( |
| 89 | + f"{SURVEY_YEAR} kriging analysis (default variogram) [{counter}/8] success!" |
| 90 | + ) |
| 91 | + # ---- Apply best-fit variogram |
| 92 | + survey.kriging_analysis(best_fit_variogram=True, extrapolate=extrap, verbose=False) |
| 93 | + print( |
| 94 | + f"{SURVEY_YEAR} kriging analysis (best-fit variogram) [{counter}/8] success!" |
| 95 | + ) |
| 96 | + # ---- Stratified analysis (kriging analysis) |
| 97 | + survey.stratified_analysis(dataset="kriging", |
| 98 | + bootstrap_ci_method=parameters["bootstrap_ci_method"], |
| 99 | + transect_replicates=parameters["transect_replicates"], |
| 100 | + verbose=False) |
| 101 | + print( |
| 102 | + f"{SURVEY_YEAR} stratified analysis (kriging) [{counter}/8] success!" |
| 103 | + ) |
| 104 | + # ---- Test reports |
| 105 | + survey.generate_reports(reports=["aged_length_haul_counts", |
| 106 | + "kriging_input", |
| 107 | + "kriged_length_age_abundance", |
| 108 | + "kriged_length_age_biomass", |
| 109 | + "kriged_mesh_results", |
| 110 | + "total_length_haul_counts", |
| 111 | + "transect_length_age_abundance", |
| 112 | + "transect_length_age_biomass", |
| 113 | + "transect_population_results"]) |
| 114 | + # ---- Print out success |
| 115 | + print( |
| 116 | + f""" |
| 117 | + Year: {SURVEY_YEAR} success [{counter}/8 configurations]! |
| 118 | + Stratum: {stratum} |
| 119 | + Age-1 fish excluded: {excl} |
| 120 | + Extrapolated: {extrap} |
| 121 | + """ |
| 122 | + ) |
| 123 | + # ---- Advance counter |
| 124 | + counter += 1 |
124 | 125 |
|
125 |
| -# #################################################################################################### |
126 |
| -# # Get report outputs |
127 |
| -# # ---- Define directory |
128 |
| -# output_dir = f"C:/Users/Brandyn/Documents/GitHub/EchoPro_data/echopo_backtest_years/Outputs/\ |
129 |
| -# Historical Outputs (KS Stratification with aged data)/without extrapolation/{SURVEY_YEAR}" |
130 |
| -# # ---- Get files |
131 |
| -# files = glob.glob(output_dir + "/EchoPro_un-kriged_output*") |
132 |
| -# # ---- Filter files |
133 |
| -# filtered_files = [f for f in files if f.endswith("_1.xlsx")] |
134 |
| -# # ---- Read |
135 |
| -# echopro_data = pd.read_excel(filtered_files[0]) |
136 |
| -# #################################################################################################### |
137 |
| -# # Compare |
138 |
| -# echopop_data = survey.analysis["transect"]["acoustics"]["adult_transect_df"].copy() |
139 |
| -# # ---- Calculate: NASC |
140 |
| -# echopro_data["NASC"].sum() - echopop_data["nasc"].sum() |
141 |
| -# # ---- Calculate: biomass |
142 |
| -# (echopro_data["wgt_total"].sum() - echopop_data["biomass"].sum()) * 1e-6 |
| 126 | +#################################################################################################### |
| 127 | +# Get report outputs |
| 128 | +# ---- Define directory |
| 129 | +output_dir = f"C:/Users/Brandyn/Documents/GitHub/EchoPro_data/echopo_backtest_years/Outputs/\ |
| 130 | +Historical Outputs (KS Stratification with aged data)/without extrapolation/{SURVEY_YEAR}" |
| 131 | +# ---- Get files |
| 132 | +files = glob.glob(output_dir + "/EchoPro_un-kriged_output*") |
| 133 | +# ---- Filter files |
| 134 | +filtered_files = [f for f in files if f.endswith("_1.xlsx")] |
| 135 | +# ---- Read |
| 136 | +echopro_data = pd.read_excel(filtered_files[0]) |
| 137 | +#################################################################################################### |
| 138 | +# Compare |
| 139 | +echopop_data = survey.analysis["transect"]["acoustics"]["adult_transect_df"].copy() |
| 140 | +# ---- Calculate: NASC |
| 141 | +echopro_data["NASC"].sum() - echopop_data["nasc"].sum() |
| 142 | +# ---- Calculate: biomass |
| 143 | +(echopro_data["wgt_total"].sum() - echopop_data["biomass"].sum()) * 1e-6 |
0 commit comments