d-chambers / Detex

A Python package for subspace detection and waveform similarity clustering
Other
32 stars 6 forks source link

exclude temporally coincident detections from unassociated templates? #36

Open quapity opened 8 years ago

quapity commented 8 years ago

doesn't seem robust to report a new event from temporally correlated detections on 2 stations with uncorrelated templates. So if you have templates A-C and you look at which templates are linked in a detection requiring 2 stations, they should like like [A,A],[B,B] or [C,C]. If A and C made a subspace they could look like [[A,C],C] or [[A,C],A] etc...

worth adding a new filter in results?

If helpful, I'm using the following code verify template continuity. It's hack, so check it if you follow this route.

screen shot 2016-09-21 at 3 29 17 pm

%%

sgdb = loadSQLite('SubSpace.db','sg_info') ssdb = loadSQLite('SubSpace.db','ss_info')

"""I think Kris makes this with res = detex.results.detResults(blah,blah) res.Dets.to_pickle('detections_2RS.pkl')"""

with open('detections_2RS.pkl','rb') as f: detections = pickle.load(f)

templates = readKey('TemplateKey.csv')

%%

yams = [] for i in range(len(detections.Dets)): tempyam = [] for j in range(len(detections.Dets[i])): each = detections.Dets[i].reset_index(drop=True) try: tempyam.append([templates[templates['NAME'] == sgdb[(sgdb['Name'] == each.Name[j]) & (sgdb['Sta'] == each.Sta[j])].Events.iloc[0]].index[0]]) except: junkyam = list(np.empty(len(ssdb[(ssdb['Name'] == each.Name[j]) & (ssdb['Sta'] == each.Sta[j])].Events.iloc[0].split(',')))) for k in range(len(ssdb[(ssdb['Name'] == each.Name[j]) & (ssdb['Sta'] == each.Sta[j])].Events.iloc[0].split(','))): junkyam[k]=templates[templates['NAME'] == ssdb[(ssdb['Name'] == each.Name[j]) & (ssdb['Sta'] == each.Sta[j])].Events.iloc[0].split(',')[k]].index[0] tempyam.append(junkyam) yams.append(tempyam)

idx=[min(len(set(x).intersection(set(yams[i][0]))) for x in yams[i]) for i in range(len(yams))]

where idx == 0 is not a valid detection

d-chambers commented 8 years ago

Yes this is a good idea, and something I meant to implement originally but ran into problems (and just wanted to graduate).

I looked at your code for a few minutes and I am afraid I don't really understand what it is doing but I do agree with your description.

The other complexity with subspace that could be considered is how many shared training events (what % maybe?) should be common in order for them to link together, rather than just require one common training event.

I am in the field this week. I will work on this next week when I get back.

quapity commented 8 years ago

Graduating... right. Anyhoo.

This does something like the following:

Say I have templates 1-15 in the template key I require 3 stations to link for each detection

yams gives me the templates (or subspace) that contribute to each detection, for example [2,6,8] [8,[8,13],13] [5,5,5] [2,9,9]

idx filters for intersection. If I require 3 stations, they all have to intersect. that snippet uses the first element to test intersection. It makes more sense to use the largest subspace per detection to test for intersection though.

idx=[min(len(set(x).intersection(set(yams[i][0]))) for x in yams[i]) for i in range(len(yams))]

where 0 would instead be the element with the largest subspace- or the first element if only singles.

I'm sure there is a better way to accomplish this. Ping when you get back if I can be helpful.

On Fri, Sep 23, 2016 at 5:59 AM, Derrick notifications@github.com wrote:

Yes this is a good idea, and something I meant to implement originally but ran into problems (and just wanted to graduate).

I looked at your code for a few minutes and I am afraid I don't really understand what it is doing but I do agree with your description.

The other complexity with subspace that could be considered is how many shared training events (what % maybe?) should be common in order for them to link together, rather than just require one common training event.

I am in the field this week. I will work on this next week when I get back.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/d-chambers/Detex/issues/36#issuecomment-249173409, or mute the thread https://github.com/notifications/unsubscribe-auth/AMmHblbLm3SmR7Kb6WTSJ6XpWqGuauylks5qs78KgaJpZM4KDT2f .

d-chambers commented 8 years ago

Turns out this is already implemented. In the detResults function there is a parameter called associateReq that is set to 0 by default. If you change this to 1 it should produce the behavior you describe. Give it a try and let me know if it returns what you expect.

quapity commented 8 years ago

Noted. Will try it. Thanks.

On Thu, Sep 29, 2016 at 8:12 PM, Derrick notifications@github.com wrote:

Turns out this is already implemented. In the detResults function there is a parameter called associateReq that is set to 0 by default. If you change this to 1 it should produce the behavior you describe. Give it a try and let me know if it returns what you expect.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/d-chambers/Detex/issues/36#issuecomment-250641880, or mute the thread https://github.com/notifications/unsubscribe-auth/AMmHbsyN3dcsM7JuKZhwJADGb50kOZr9ks5qvHAngaJpZM4KDT2f .

kpankow commented 8 years ago

Was this recently implemented? I am running version 1.0.8e

res = detex.results.detResults(requiredNumStations=2,templateKey='TemplateKey_box7.csv',stationKey='StationKey_box7.csv',fetch='../ContinuousWaveForms/',associateReq=1) Traceback (most recent call last):

File "", line 1, in res = detex.results.detResults(requiredNumStations=2,templateKey='TemplateKey_box7.csv',stationKey='StationKey_box7.csv',fetch='../ContinuousWaveForms/',associateReq=1)

File "/home/pankow/anaconda/lib/python2.7/site-packages/detex/results.py", line 116, in detResults raise detex.log(name, msg, level='error')

File "/home/pankow/anaconda/lib/python2.7/site-packages/detex/init.py", line 136, in log raise e(msg)

Exception: associateReq values other than 0 not yet supported