Skip to content

Commit

Permalink
Merge branch 'find_features_fix' of https://github.com/chkim-usgs/ISIS3
Browse files Browse the repository at this point in the history
… into chkim-usgs-find_features_fix
  • Loading branch information
Kelvinrr committed Aug 5, 2024
2 parents 1238d34 + 698afc6 commit fa78c06
Showing 1 changed file with 37 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ def segment(img_path : Path, nlines : int = MAX_LEN):

def generate_cnet(params, images):

match_segment_n = images["match"]["Segment"]
if isinstance(images["match"], list):
images_match_n = images["match"][0]
else:

images_match_n = images["match"]
match_segment_n = images_match_n["Segment"]
from_segment_n = images["from"][0]["Segment"]

new_params = deepcopy(params)
Expand All @@ -145,7 +150,7 @@ def generate_cnet(params, images):
# make sure none of these keys are still in the params
new_params.pop("FROMLIST", None)
new_params.pop("FROM", None)
new_params["MATCH"] = images["match"]["Path"]
new_params["MATCH"] = images_match_n["Path"]

og_onet = Path(params["ONET"])
og_tolist = Path(params["TOLIST"])
Expand Down Expand Up @@ -175,7 +180,7 @@ def generate_cnet(params, images):

# check for overlaps
is_overlapping = []
for image in from_images:
for image in from_images:
with tempfile.TemporaryDirectory() as tmpdir:
tmpdir = Path(tmpdir)
overlapfromlist = tmpdir / "fromlist.lis"
Expand Down Expand Up @@ -230,12 +235,11 @@ def generate_cnet(params, images):
log.debug(' '.join(err.cmd))
log.debug(err.stdout)
log.debug(err.stderr)
return "ERROR"

segmented_net = cnet.from_isis(new_params["ONET"])

# starting sample in inclusive, so subtract 1
segmented_net.loc[segmented_net.serialnumber == images["match"]["SN"], "line"] += images["match"]["StartingLine"]-1
segmented_net.loc[segmented_net.serialnumber == images_match_n["SN"], "line"] += images_match_n["StartingLine"]-1

# offset the images
for k, image in enumerate(images["from"]):
Expand Down Expand Up @@ -318,12 +322,20 @@ def findFeaturesSegment(ui):
pool.close()
pool.join()
output = output.get()

match_segments = segment(ui.GetCubeName("match"), ui.GetInteger("NL"))
from_segments = reduce(lambda d1,d2: {k: merge(d1, d2, k) for k in set(d1)|set(d2)}, output)

if len(img_list) > 1:
from_segments = reduce(lambda d1,d2: {k: merge(d1, d2, k) for k in set(d1)|set(d2)}, output)
else:
# img_list = 1
from_segments = output[0]
for seg, value in from_segments.items():
og_value = value
from_segments[seg] = [og_value]

segment_paths = [s["Path"] for sublist in list(from_segments.values()) for s in sublist]
segment_paths = segment_paths + [s["Path"] for s in list(match_segments.values())]

# re-generate footprints
pool = ThreadPool(ceil(nthreads/len(segment_paths)))
output = pool.map_async(footprintinit, segment_paths)
Expand All @@ -332,21 +344,33 @@ def findFeaturesSegment(ui):
output = output.get()
log.debug(f"{output}")

image_sets = list(itertools.product(match_segments.values(), from_segments.values()))

# Remove redundant overlapping pairs
x = match_segments.values()
y = from_segments.values()
x,y = (x,y) if len(x) > len(y) else (y,x)
image_cartesian = list(itertools.product(x, y))
image_sets = []
for i in image_cartesian:
if i[0][0]["Segment"] >= i[1]["Segment"]:
image_sets.append(i)

# restructure things to be easier to manage
job_dicts = []
for im in image_sets:
match = im[0]
from_images = im[1]
if not isinstance(from_images, list):
# from_images must be list type
from_images_list = []
from_images_list.append(from_images)
from_images = from_images_list
job_dicts.append({
"match" : match,
"from" : from_images
})
})

# get params as a dictionary
params = ui.GetParams()

pool = ThreadPool(ceil(nthreads/len(job_dicts)))
starmap_args = list(zip([params]*len(job_dicts), job_dicts))
output = pool.starmap_async(generate_cnet, starmap_args)
Expand Down

0 comments on commit fa78c06

Please sign in to comment.