-
Notifications
You must be signed in to change notification settings - Fork 1
/
valid_epatrol.pro
627 lines (530 loc) · 19.1 KB
/
valid_epatrol.pro
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
;+
;Name:
;
; valid_epatrol
;
;Purpose:
;
; Track events at in a given time range
;
;Calling Sequence:
;
; valid_epatrol, [ minvalue, maxvalue ]
;
;Optional Inputs:
;
; minvalue = The cluster to begin at
; maxvalue = The cluster to stop at
;
;Outputs:
;
; Will output values into a csv under the default title of: fe_times_sources.txt
;
;Some notes:
; The program will read in values from compile_eventlist_visual_search_clusters_test.txt by default
; The default cadence is 1 frame every 12 minutes
; The first cluster is cluster #0
;
; The longitude/latitude obtained by pushing 'e' within the program is in heliographic degrees
; The output longitude/latitude is in arcseconds
; Output filetime format is in ecs
;
;Author:
;
; George Lee
; Intern At LMASAL
; Email: [email protected]
;
;Version of IDL used to test this program: 8.3
;Warning: Some routines or variables will fail to work for older versions of IDL
;
;
;Running this program:
; Type in valid_epatrol
;To pick up where you left off,
; Type in valid_epatrol, cluster
;
;This program will also work when working on clusters in a specified range
; valid_epatrol, min, max
;-
pro run_epatrol, whichevent, infile, logfilein, cadencein, difmap,snap,evplot, verb=verb
;Default Output
thisline={available:'',cluster:'', flare:'', surge:'', region:'',tinit:'', xsource:0.0D, ysource:0.0D, xloc1:0.0D, yloc1:0.0D, xloc2:0.0D, yloc2:0.0D}
;thisline={available:'',cluster:'', flare:'', region:'',tinit:'',source:[0,0],loc:[[0,0],[0,0]]}
;Sets up read/write variables
logfile=logfilein
file = infile[whichevent]
evdir = 'epatrol_data/'
;Set up identification variables
clust = file.CLUSTID
thisline.cluster = clust
;set parameters for movie
cadence=cadencein ;x2 = 12 minutes between images
stmovie=3. ; = 3 hours before Eruption Patrol event start time
;Read in eruption patrol events using HEK API
;Set up time variables
d1 = file.DATEST
d2 = file.DATEEN
t1=anytim(d1)-stmovie*3600.
t2=anytim(d2)
;Directory where program will fetch the images
dir = '/archive/sdo/AIA/synoptic'
;Finds http:// directories for the given files
ff=getjsoc_synoptic_read(t1,t2,wave = 304,/nodat, $ ; cadence=20*60., $
info=info,file=files,remfile=remfiles,outind=inds)
;; Checks to see if there is data for the given date
IF (ff[0] ne '') THEN BEGIN
;Sets up variables about number of images to be read in
nimg=n_elements(ff)
imgnums=findgen(nimg)
ff=ff[where(imgnums mod cadence eq 0)]
nimg=n_elements(ff)
set_plot, 'x'
;example return link : http://jsoc.stanford.edu/data/aia/synoptic//2011/01/02/H1700/AIA20110102_1716_0304.fits
;;goal: extract /2011/01/02/H1700/AIA20110102_1716_0304.fits
;done by doing: test = 'http://jsoc.stanford.edu/data/aia/synoptic//2011/01/02/H1700/AIA20110102_1716_0304.fits'
;c = strmid(teststr, 43)
;;Converts http:// directories to a /yyyy/mm/dd/Hxxxx/ format
ffloc = ''
FOR i=0, nimg-1 DO BEGIN
IF (i eq 0) THEN BEGIN
ffloc = [dir+ strmid(ff[i], 43)]
ENDIF ELSE BEGIN
ffloc = [ffloc, dir+ strmid(ff[i], 43)]
ENDELSE
ENDFOR
;read in the images
read_sdo,ffloc,indarr,datarr,/noshell
;Sets color table to one that is more natural looking for the sun
loadct,3
;display initial image, and have user pick out the source
keyin = ''
counter = 0
; snap = 0
; evplot = 0
; difmap = 0
evlist = ['','']
print, 'Ready!'
h1 = 'Press h to view this message again'
h2 = 'q - quit, s - skip current cluster, d - back, f - forward, e- list events, m - play movie, g - input data, c - set new cadence'
h3 = 'i - toggle automatic event snapshots, o - toggle event location plotting, u - toggle difference ratio maps'
print, h1
print, h2
print, h3
window,0,xsize=1024,ysize=1024
WHILE (keyin ne 'q') DO BEGIN
;Sets up array for scrolling through the images
if(difmap eq 0) then begin
index2map,indarr[counter],datarr[*,*,counter],imap
plot_map,imap,/log,grid = 10, drange = [0, 2000]
time = indarr[counter].date_obs
thisline.tinit = anytim(time,/ecs)
endif else begin
if(difmap eq 1) then begin
if (counter eq 0) then begin
index2map,indarr[counter],datarr[*,*,counter],map1
index2map,indarr[counter+1],datarr[*,*,counter+1],map2
diff = map1
diff.data = (map1.data-map2.data)/map1.data
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endif else begin
index2map,indarr[counter-1],datarr[*,*,counter-1],map1
index2map,indarr[counter],datarr[*,*,counter],map2
diff = map2
diff.data = (map2.data-map1.data)/map2.data
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endelse
endif else begin
print, 'Something went wrong!'
print, 'Resetting.'
difmap = 0
endelse
endelse
; if(difmap eq 0) then begin
; plot_map,imap,/log,grid = 10, drange = [0, 2000]
; endif else begin
; if(difmap eq 1) then begin
; plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
; endif
; endelse
;Plots points in event list
IF (evplot eq 1) and (evlist[0,0] ne 0) and (evlist[1,0] ne 0) THEN BEGIN
plotsym,0,2
for i=0,n_elements(evlist)/2-1 do begin
plots,evlist[0,i],evlist[1,i],ps = 8,color = 16711680 ;blue
endfor
; print, 'Plotted!'
ENDIF
keyin = get_kbrd()
if keyword_set(verb) THEN BEGIN
print, keyin
endif
;Print help message
IF (keyin eq 'h') THEN BEGIN
print, h1
print, h2
print, h3
ENDIF
IF (keyin eq '~') THEN STOP
;Toggles Difference Ratio Maps
IF (keyin eq 'u') THEN BEGIN
IF (difmap eq 0) THEN BEGIN
difmap = 1
print,'Now plotting with difference ratio maps!'
ENDIF ELSE BEGIN
difmap = 0
print, 'Now plotting from telescope data!'
ENDELSE
ENDIF
;Toggles automatic event snapshots, more in input data section
IF (keyin eq 'i') THEN BEGIN
IF (snap eq 0) THEN BEGIN
snap = 1
print,'Automatic event snapshots are now enabled!'
ENDIF ELSE BEGIN
snap = 0
print, 'Automatic event snapshots are now disabled!'
ENDELSE
ENDIF
;Toggles event location plotting for current cluster
IF (keyin eq 'o') THEN BEGIN
IF (evplot eq 0) THEN BEGIN
evplot = 1
print,'Event plotting is now enabled!'
ENDIF ELSE BEGIN
evplot = 0
print, 'Event plotting is now disabled'
ENDELSE
ENDIF
;Plays images in a semi-fast sequence to give the appearance of a movie
IF (keyin eq 'm') THEN BEGIN
IF(difmap eq 0) THEN BEGIN
for i=0, nimg-1,1 do begin
index2map,indarr[i],datarr[*,*,i],imap
plot_map,imap,/log, grid = 10, /noerase, drange = [0, 2000]
wait,0.1
endfor
ENDIF ELSE BEGIN
for i=0, nimg-2,1 do begin
index2map,indarr[i],datarr[*,*,i],map1
index2map,indarr[i+1],datarr[*,*,i+1],map2
diff = map2
diff.data = (map2.data-map1.data)/map2.data
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75],/noerase
endfor
ENDELSE
ENDIF
;Prints event date, latitude, longitude for all events in cluster
IF (keyin eq 'e') THEN BEGIN
evdatearr = strsplit(file.evdates,',',/extract)
evlatarr = strsplit(file.evlats,',',/extract)
evlonarr = strsplit(file.evlons,',',/extract)
for i=0, file.nevents-1 do begin
; amin = hel2arcmin(evlatarr[i],evlonarr[i])
; asec = [amin[0]*60.,amin[1]*60.]
print, 'Event #' + strtrim(i+1,2) + ' Event date: ' + evdatearr[i] + ' Longitude: ' + evlonarr[i] + ' Latitude: ' + evlatarr[i]
endfor
ENDIF
;Takes in Event Related Statistics
IF (keyin eq 'g') THEN BEGIN
set_plot,'x'
print,'Click on the source location of the eruption, Right click to confirm your selection'
xsource = 0
ysource = 0
mousenum = 0
; ;Picks Location of Event
print, 'Plot 1'
WHILE (mousenum ne 4) DO BEGIN
cursor,xinit,yinit
mousenum = !mouse.button
IF(mousenum eq 1) THEN BEGIN
xsource = xinit & ysource = yinit
ERASE
if(difmap eq 0) then begin
plot_map,imap,/log,grid = 10, drange = [0, 2000]
endif else begin
if(difmap eq 1) then begin
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endif
endelse
vline,xsource & hline,ysource
ENDIF
IF(mousenum eq 4) THEN BEGIN
xinit = xsource & yinit = ysource
mousenum = 0
mousenum2 = 0
BREAK
ENDIF
wait,0.05
ENDWHILE
vline,xsource & hline,ysource
print,xsource,ysource
wait, 1.0
thisline.xsource = xsource
thisline.ysource = ysource
IF (evlist[0,0] ne 0) and (evlist[1,0] ne 0) THEN BEGIN
evlist = [[evlist],[xsource,ysource]]
; thisline.source = [xinit,yinit]
;Creates bounding box of the event
ENDIF ELSE BEGIN
evlist = [xsource,ysource]
ENDELSE
ERASE
if(difmap eq 0) then begin
plot_map,imap,/log,grid = 10, drange = [0, 2000]
endif else begin
if(difmap eq 1) then begin
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endif
endelse
print, 'Click two times to select a bounding box for the event, Right click to confirm your selection'
print, 'Plot 2'
mousenum2 = 0
xstore1 = 0
ystore1 = 0
xstore2 = 0
ystore2 = 0
counter1 = 0
counter2 = 0
;Finds bounding box
WHILE(mousenum2 ne 4) DO BEGIN
;crosshair 1
;find point for 1
cursor, xstore1, ystore1
mousenum2 = !mouse.button
IF (mousenum2 eq 1) THEN BEGIN
IF(counter1 eq 0) THEN BEGIN
vline,xstore1 & hline,ystore1
print, '1 done'
print, xstore1 & print, ystore1
wait,0.5
counter1 += 1
ENDIF ELSE BEGIN
;Replots points
ERASE
if(difmap eq 0) then begin
plot_map,imap,/log,grid = 10, drange = [0, 2000]
endif else begin
if(difmap eq 1) then begin
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endif
endelse
vline,xstore1 & hline,ystore1
vline,xstore2 & hline,ystore2
print, '1 done'
print, xstore1 & print, ystore1
wait,0.5
ENDELSE
ENDIF
;crosshair 2
;find point for 2
cursor, xstore2, ystore2
mousenum2 = !mouse.button
;crosshair 2
IF (mousenum2 eq 1) THEN BEGIN
IF(counter2 eq 0) THEN BEGIN
vline,xstore2 & hline,ystore2
print, '2 done'
print, xstore2 & print, ystore2
wait,0.5
counter2 +=1
ENDIF ELSE BEGIN
;Replots points
ERASE
if(difmap eq 0) then begin
plot_map,imap,/log,grid = 10, drange = [0, 2000]
endif else begin
if(difmap eq 1) then begin
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endif
endelse
vline,xstore1 & hline,ystore1
vline,xstore2 & hline,ystore2
print, '2 done'
print, xstore2 & print, ystore2
wait,0.5
ENDELSE
ENDIF
ENDWHILE
thisline.xloc1 = xstore1 & thisline.yloc1 = ystore1
thisline.xloc2 = xstore2 & thisline.yloc2 = ystore2
; store1 = [xstore1,ystore1]
; store2 = [xstore2,ystore2]
; thisline.loc = [store1,store2]
ERASE
if(difmap eq 0) then begin
plot_map,imap,/log,grid = 10, drange = [0, 2000]
endif else begin
if(difmap eq 1) then begin
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
endif
endelse
while (0 ne 1) DO BEGIN
print, 'Flare? (y/n)'
type = get_kbrd()
IF (type eq 'y') or (type eq 'n')THEN BEGIN
thisline.flare = type
BREAK
ENDIF ELSE BEGIN
print, 'Input Is Not Valid'
ENDELSE
endwhile
while (0 ne 1) DO BEGIN
print, 'Surge? (y/n)'
type = get_kbrd()
IF (type eq 'y') or (type eq 'n')THEN BEGIN
thisline.surge = type
BREAK
ENDIF ELSE BEGIN
print, 'Input Is Not Valid'
ENDELSE
endwhile
while (0 ne 1) DO BEGIN
print, 'Event from an active region or quiet sun or unknown? (a/q/u)'
type = get_kbrd()
IF (type eq 'a') or (type eq 'q') or (type eq 'u')THEN BEGIN
thisline.region = type
BREAK
ENDIF ELSE BEGIN
print, 'Input Is Not Valid'
ENDELSE
endwhile
;Writes into data file
thisline.available = 'y'
thisline.tinit = anytim(imap.time, /ecs)
write_data_file,thisline,filecsv=evdir+logfile,/append
print, 'Written!'
;Create event snapshot if boolean snap is equal to true (1)
IF (snap eq 1) THEN BEGIN
setplot, 'z'
device, set_resolution = [1024,1024], decomp=0, set_pixel_depth=24
loadct,3
plotsym,0,2,thick = 2
if(difmap eq 0) then begin
index2map,indarr[counter],datarr[*,*,counter],imap
plot_map,imap,/log,grid = 10, drange = [0, 2000]
time = indarr[counter].date_obs
thisline.tinit = anytim(time,/ecs)
plots, xsource, ysource, ps = 8, color = 0 ;Plot symbol to source location
endif else begin
if(difmap eq 1) then begin
if (counter eq 0) then begin
index2map,indarr[counter],datarr[*,*,counter],map1
index2map,indarr[counter+1],datarr[*,*,counter+1],map2
diff = map1
diff.data = (map1.data-map2.data)/map1.data
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
plots, xsource, ysource, ps = 8, color = 14772545;Plot symbol to source location
endif else begin
index2map,indarr[counter-1],datarr[*,*,counter-1],map1
index2map,indarr[counter],datarr[*,*,counter],map2
diff = map2
diff.data = (map2.data-map1.data)/map2.data
plot_map,diff,/log,grid = 10, drange = [0.02, 1.75]
plots, xsource, ysource, ps = 8, color = 14772545;Plot symbol to source location
endelse
endif else begin
print, 'Something went wrong!'
print, 'Resetting.'
difmap = 0
endelse
endelse
xyouts,-800,1400,'Cluster ID:' +string(thisline.cluster) +' Evtime: '+ string(thisline.tinit)+ ' Region: '+string(thisline.region)+ ' Flare: ' + string(thisline.flare) + ' Surge: ' + string(thisline.surge),font = 42
; oplot, [xstore1,xstore2,xstore2,xstore1,xstore1],[ystore1,ystore1,ystore2,ystore2,ystore1] ;Bounding Box /does not seem to work
zb_plot = tvrd(true=1)
pic = 0
outfile = ''
while (0 ne 1) do begin
outfile = evdir+'evdat_' +string(file.clustid)+'_'+string(pic,format = '(I02)') + '.png'
if(~file_test(outfile)) then begin
break
endif else begin
pic += 1
endelse
endwhile
write_png,outfile,zb_plot
set_plot,'x'
print, 'Snapshot taken!'
ENDIF
ENDIF
IF (keyin eq 'f') THEN BEGIN
IF (difmap eq 0) THEN BEGIN
IF (counter NE nimg-1) THEN counter +=1
ENDIF ELSE BEGIN
IF (counter NE nimg-2) THEN counter +=1
ENDELSE
ENDIF
IF (keyin eq 'd') THEN BEGIN
IF (counter GT 0) THEN counter -=1
ENDIF
;Skips current cluster
IF (keyin eq 's') THEN BEGIN
thisline.available = 's'
thisline.tinit = anytim(d1, /ecs)
write_data_file,thisline,filecsv=evdir+logfile,/append
print, 'Written!'
print, 'Cluster #' + STRTRIM(whichevent, 2) + ' Skipped!'
BREAK
ENDIF
IF (keyin eq 'c') THEN BEGIN
WHILE (0 ne 1) DO BEGIN
newint = 0
read, newint, prompt ='Type in a new cadence (default = 6): '
if(valid_num(newint, /integer)) THEN BEGIN
run_epatrol, whichevent, infile, logfilein, newint
break
endif else begin
print, 'Invalid Input'
endelse
ENDWHILE
; break
ENDIF
ENDWHILE
;;Prints out log file for dates with no data
ENDIF ELSE BEGIN
print, 'There is no data for the date specified.'
thisline.available = 'n'
thisline.tinit = anytim(d1, /ecs)
write_data_file,thisline,filecsv=evdir+logfile,/append
print, 'Written!'
ENDELSE
print, 'Finished!'
end
pro valid_epatrol, minvalue, maxvalue
;Set in/out file names
logfile='fe_times_sources.txt'
infile= 'compile_eventlist_visual_search_clusters.txt'
evdir = 'epatrol_data/'
spawn, 'mkdir '+evdir,/sh
file = read_data_file(infile)
;Settings for run_epatrol
mapenv = 0
snapenv = 0
plotenv = 0
;Will automatically create a blank logfile in the current IDL directory if there is no existing one
if(~file_test(evdir+logfile)) then begin
thisline={available:'',cluster:'', flare:'', surge:'', region:'',tinit:'', xsource:0.0D, ysource:0.0D, xloc1:0.0D, yloc1:0.0D, xloc2:0.0D, yloc2:0.0D}
; thisline={available:'',cluster:'', flare:'', region:'',tinit:'',source:[0,0],loc:[[0,0],[0,0]]}
head = '#Event Patrol Data'
write_data_file,thisline,filecsv=evdir+logfile,/nodata, header = head
CD, Current=theDirectory
print, 'New File Written To ' + theDirectory
endif
;Automatically sets minimum value to 0 if not specified
if (n_elements(minvalue) eq 0) then begin
minval = 0
endif else begin
minval = minvalue
endelse
;Automatically sets the maximum value to the last value in the file read in
if (n_elements(maxvalue) eq 0) then begin
maxval = n_elements(file)
endif else begin
maxval = maxvalue
endelse
for i= minval,maxval,1 do begin
run_epatrol, i, file,logfile, 6, mapenv,snapenv,plotenv
clustnum = STRTRIM(i, 2)
print,'Cluster #'+ clustnum +' is complete'
endfor
end