Skip to content

Commit cbc6eec

Browse files
author
Travis-Simmons
committed
setfinder bugfix for expansion
1 parent 7cf4efa commit cbc6eec

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

run_setfinder.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ def get_args():
7575
parser.add_argument("-r",
7676
"--reachsubset",
7777
type=str,
78-
help="Name of reach subset file",
79-
default="reaches_of_interest.json")
78+
help="Name of reach subset file")
8079

8180
return parser.parse_args()
8281

@@ -98,7 +97,7 @@ def get_reach_list(indir:str, continent_prefix:str, continent_id_list:list, expa
9897

9998
# read in data depending on if it is the first or second run of the setfinder and return a list of reaches to consider
10099

101-
if expanded:
100+
if expanded or reach_subset_file:
102101
with open(os.path.join(indir, reach_subset_file)) as jsonfile:
103102
reaches_of_interest = json.load(jsonfile)
104103

@@ -179,20 +178,28 @@ def main():
179178
else:
180179
reach_list = get_reach_list(indir=indir, continent_prefix=continent_prefix, continent_id_list=continent_id_list,
181180
expanded=expanded, reach_subset_file=reach_subset_file)
182-
print(f"Number of reaches to process: {len(reach_list)}")
181+
print(f"Number of reaches to process: {len(list(set(reach_list)))}")
183182

184183
if reach_list:
185184

186185
sword_file = os.path.basename(sword_filepath)
187186
reach_dict_list = parse_reach_list_for_output(reach_list=list(set(reach_list)), continent_prefix=continent_prefix,
188187
sword_version=sword_version, sword_file=sword_file)
189188

189+
print('here is how many before generation of sets', len(list(set(reach_list))))
190+
190191
# Generate sets for FLPEs
191192
reach_list = generate_sets(reaches = reach_dict_list, continent=continent_prefix,
192193
output_dir = outdir, algorithms = algorithms,
193194
sword_dataset = sword, sword_filepath = sword_filepath,
194195
expanded = expanded)
195196

197+
print('here is how many after generation of sets', len(list(set(reach_list))))
198+
print(reach_list[:5])
199+
200+
reach_dict_list = parse_reach_list_for_output(reach_list=list(set(reach_list)), continent_prefix=continent_prefix,
201+
sword_version=sword_version, sword_file=sword_file)
202+
196203
save_reach_list(outdir=outdir, reachesjson_dict=reach_dict_list, continent_prefix=continent_prefix, expanded=expanded)
197204

198205
else:

sets/getAllSets.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def generate_sets(reaches:list, continent:str, output_dir:str, algorithms:list,
8787
all_reaches = []
8888
for Algorithm in algorithms:
8989
print('Getting set for',Algorithm)
90-
params = SetParameters(Algorithm, continent)
90+
params = SetParameters(Algorithm, continent, expanded)
9191
# print(params)
9292
for key, value in params.items():
9393
print(" {} : {}.".format(key.capitalize(), value))
@@ -105,7 +105,7 @@ def generate_sets(reaches:list, continent:str, output_dir:str, algorithms:list,
105105
all_reaches.sort()
106106
return all_reaches
107107

108-
def SetParameters(algo, cont):
108+
def SetParameters(algo, cont, expanded):
109109
"""Seting parameters for setfinder
110110
111111
Parameters
@@ -126,7 +126,7 @@ def SetParameters(algo, cont):
126126
"""
127127
LargeNumber=1000
128128

129-
RequireAllReachesInFile=True #usual operation, set this to true, False makes it expand
129+
RequireAllReachesInFile=not expanded #usual operation, set this to true, False makes it expand
130130
# RequireAllReachesInFile=False #in dev set "step 1" set this to false, so we can scrape a list of all reaches in sets
131131

132132

0 commit comments

Comments
 (0)