dendrograms / astrodendro

Generate a dendrogram from a dataset
https://dendrograms.readthedocs.io/
Other
37 stars 36 forks source link

How can I delete leave structures that don't meet a criteria iteratively? #172

Open seb-lopez opened 3 years ago

seb-lopez commented 3 years ago

Hello so the issue I am having is that based off the information from the catalog from ppv_catalog I am setting criteria for the structures I want and the reasoning behind that is that once I run astrodendro and then with SCIMES I still get weather strips identified as structures and the show up in the final cube I want to use as a mask on ppv cubes for my data.

I have tried the following:

ar_ind = []

for i in range(len(AxRs)): if (abs(PAs[i])>170) and (abs(PAs[i])<181): ar_ind.append(i)

cat.remove_rows(ar_ind)

for j in range(len(d.leaves)): for k in ar_ind: if d.leaves[j].idx == k: d.leaves.remove(d.leaves[j])

So in this case the criteria is based off position angle and the indices in the catalog are being matched with those in the leaves list and I try to remove the ones I don't want.

However it seems after I print out the result there is no change whatsoever and the structures I tried to remove via list.remove are still there.

Can I get any advice on fixing this? I don't recall seeing any remove function in astrodendro.structure.Structure so I opted to use the method above.

e-koch commented 3 years ago

Hi @seb-lopez -- You should be able to use the Dendrogram.prune function here: https://github.com/dendrograms/astrodendro/blob/master/astrodendro/dendrogram.py#L513.

There is no built-in method to remove by position angle, so you will need to define your own criteria function and pass it to the is_independent keyword of prune. A couple of examples of criteria functions are here: https://github.com/dendrograms/astrodendro/blob/master/astrodendro/pruning.py#L108. There are a couple more here, too: https://github.com/dendrograms/astrodendro/pull/167/files#diff-d662f9d97218a42233417b75e9455f294cfce4506ea5c063d9bca056f00ff7d9R136.

seb-lopez commented 2 years ago

Hi @e-koch, thanks for the reply and sorry for my late reply. I just picked this project back up after months of other things I needed to work on.

For pruning by PA I tried the following code:

` def param(ind):

     def result(structure, index=None, value=None):
        return structure.idx == ind
     return result  

d = Dendrogram.prune(d,is_independent=param(ar_ind)) `

Where ind is the list of indices that I want to filter out. I've tried this out before and my code just gets a 'Killed' output. Would I have to specify what part of the structure I am trying to prune such as structure.leaves or something like that?