From 0eabef938011a4eadeda2582db21e7168b38555b Mon Sep 17 00:00:00 2001 From: e-koch Date: Sun, 22 Dec 2019 12:53:05 -0700 Subject: [PATCH 1/3] Add Dario's new pruning functions --- astrodendro/pruning.py | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/astrodendro/pruning.py b/astrodendro/pruning.py index 1263e22..b54743e 100644 --- a/astrodendro/pruning.py +++ b/astrodendro/pruning.py @@ -133,6 +133,58 @@ def result(structure, index=None, value=None): return result +def min_area(area): + """ + Minimum area criteria + + Parameters + ---------- + area : int + The minimum area in pixels of a leaf + """ + def result(structure, index=None, value=None): + # EWK: I _think_ this is more memory efficient than converting to a set + return np.unique(np.array(structure.indices()[:2]), axis=-1).shape[1] > = area + # return len(set(zip(*tuple(structure.indices()[i] for i in [1,2])))) >= area + return result + + +def min_spectral(chan): + """ + Minimum velocity channels criteria + + Parameters + ---------- + chan : int + The minimum velocity channels of a leaf + """ + def result(structure, index=None, value=None): + v = structure.indices()[0] + v0, v1 = min(v), max(v) + return (v1 - v0) >= chan + return result + + +def min_ppv_connected(delta, area, chan): + ''' + Minimum delta, spatial area, and spectral pixels combined. This function + forces regions to be kept only when they are spatially and spectrally + contiguous. + + Parameters + ---------- + delta : float + The minimum height of a leaf above its merger level + area : int + The minimum area in pixels of a leaf + + ''' + + return all_true((min_delta(min_delta), + min_area(area), + min_spectral(chan))) + + def contains_seeds(seeds): """ Critieria that leaves contain at least one of a list of seed positions From ada23fa5b89aed48e5fe893873aa08db450a47f9 Mon Sep 17 00:00:00 2001 From: e-koch Date: Sun, 22 Dec 2019 12:54:01 -0700 Subject: [PATCH 2/3] Typo --- astrodendro/pruning.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/astrodendro/pruning.py b/astrodendro/pruning.py index b54743e..7e9aace 100644 --- a/astrodendro/pruning.py +++ b/astrodendro/pruning.py @@ -144,7 +144,7 @@ def min_area(area): """ def result(structure, index=None, value=None): # EWK: I _think_ this is more memory efficient than converting to a set - return np.unique(np.array(structure.indices()[:2]), axis=-1).shape[1] > = area + return np.unique(np.array(structure.indices()[:2]), axis=-1).shape[1] >= area # return len(set(zip(*tuple(structure.indices()[i] for i in [1,2])))) >= area return result From 9ebeac2384addb643eb70b87eaaf07062dbff016 Mon Sep 17 00:00:00 2001 From: e-koch Date: Sun, 22 Dec 2019 13:14:47 -0700 Subject: [PATCH 3/3] Fixing a few more typos and local testing --- astrodendro/pruning.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/astrodendro/pruning.py b/astrodendro/pruning.py index 7e9aace..9d48b25 100644 --- a/astrodendro/pruning.py +++ b/astrodendro/pruning.py @@ -177,12 +177,13 @@ def min_ppv_connected(delta, area, chan): The minimum height of a leaf above its merger level area : int The minimum area in pixels of a leaf - + chan : int + The minimum velocity channels of a leaf ''' - return all_true((min_delta(min_delta), + return all_true([min_delta(delta), min_area(area), - min_spectral(chan))) + min_spectral(chan)]) def contains_seeds(seeds):