-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcubeview.i
2974 lines (2665 loc) · 99.6 KB
/
cubeview.i
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
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
CUBEVIEW.I
Routines to visualize 3D data, particularly spectroimaging data.
Copyright (C) 2003-2013 Thibaut Paumard <[email protected]>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
extern cv_ui;
/* DOCUMENT cv_ui = "gtk"
or cv_ui = "tws"
or cv_ui = "text"
Which ui should cubeview use? This is the initial default, the last
one used is remembered for the duration of the session.
*/
if (is_void(cv_ui)) cv_ui="gtk"; // or tws, or text
// Standard include files
#include "style.i"
#include "spline.i"
#include "fits.i"
#include "ieee.i"
#include "gauss.i"
#include "pathfun.i"
#include "pnm.i"
// from yutils: is_numerical
#include "plot.i"
#include "utils.i"
#include "doppler.i"
#include "tws.i"
#include "graphk.i"
// bundled with cubeview
#include "bear.i"
// string.i needs to be included _after_ utils.i to get he right strchr
#include "string.i"
// A few other files may be required for certain tasks:
// Standard: fits.i, string.i, pnm.i
// Non standard: gy_gtk.i, coords.i
CUBEVIEW_VERSION="2.2";
func cv_toolbox_state(wgd, evt, udata)
{
extern cv_nodraw;
if (_cvgy.realized) return 0;
_cvgy, realize=1;
cv_nodraw=0;
// gywindow, cv_interns.sp_wid,width=0,height=0,style="work.gs",
// on_realize=cv_spdraw;
//gywindow, cv_interns.slice_wid,width=0,height=0,style="work.gs",
// on_realize=cv_sldraw_first;
return 0;
}
func cv_sldraw_first(void)
{
cv_sldraw;
cv_sllims;
cv_vpaspect,cv_interns.xyaspect;
}
func cv_gtk(void)
{
require, "gy_gtk.i";
extern _cvgy, cv_interns, gy_gtk_on_main_quit;
if (is_void(_cvgy)) _cvgy=save();
if (is_void(cv_interns))
cv_interns=CV_Interns(slice_wid=cv_defaults.slice_wid,
sp_wid=cv_defaults.sp_wid, cmd_wid=cv_defaults.cmd_wid,
depth=cv_defaults.depth, origin=cv_defaults.origin,
scale=cv_defaults.scale, overs=cv_defaults.overs,
slboxcol=cv_defaults.slboxcol,zwlwise=cv_defaults.zwlwise,
sltype=cv_defaults.sltype, slpalette=cv_defaults.slpalette,
slinterp=cv_defaults.slinterp,refwl=cv_defaults.refwl,
zaxistype=cv_defaults.zaxistype,vlsr=cv_defaults.vlsr,
pixel=cv_defaults.pixel,hook=cv_defaults.hook,
spkeywords=cv_defaults.spkeywords,
aperture_type=cv_defaults.aperture_type,
blank=cv_defaults.blank,xyaspect=cv_defaults.xyaspect);
save, _cvgy, builder = gy_gtk_builder("cubeview.glade");
// Set widget initial values from cv_interns
sldepth = pr1(cv_interns.depth)+"bit";
noop, _cvgy.builder.get_object(cv_interns.zaxistype).set_active(1);
noop, _cvgy.builder.get_object(cv_interns.aperture_type).set_active(1);
noop, _cvgy.builder.get_object("refwl").set_value(cv_interns.refwl);
noop, _cvgy.builder.get_object("spsmooth").set_value(cv_interns.spsmooth);
noop, _cvgy.builder.get_object(sldepth).set_active(1);
noop, _cvgy.builder.get_object(cv_interns.sltype).set_active(1);
noop, _cvgy.builder.get_object("slsmooth").set_value(cv_interns.slsmooth);
noop, _cvgy.builder.get_object("sloversampling").set_value(cv_interns.overs);
gy_signal_connect, _cvgy.builder;
gy_gtk_ycmd_connect, _cvgy.builder.get_object("ycmd");
mhbox = _cvgy.builder.get_object("ywindows");
yid = [];
if (!is_void(cv_cube)) on_realize=cv_spdraw; else on_realize=[];
win = gy_gtk_ywindow(yid, style="work.gs", width=450, height=450,
on_realize=on_realize, grab=1);
noop, mhbox.pack1(win, 1, 1);
cv_interns.sp_wid = yid;
yid = [];
if (!is_void(cv_cube)) on_realize=cv_sldraw_first; else on_realize=[];
win = gy_gtk_ywindow(yid, style="work.gs", width=450, height=450,
on_realize=on_realize, grab=1);
noop, mhbox.pack2(win, 1, 1);
noop, mhbox.set_size_request(900,0);
cv_interns.slice_wid = yid;
save, _cvgy, toolbox=_cvgy.builder.get_object("toolbox"), realized=0;
iconf = find_in_path("cubeview-big.png", takefirst=1, path=Y_DATA);
if (iconf) {
icon = GdkPixbuf.Pixbuf.new_from_file(iconf);
noop, _cvgy.toolbox.set_icon(icon);
_cvgy, icon=icon;
}
noop, _cvgy.builder.get_object("slsel").set_active(1);
noop, _cvgy.builder.get_object("spsel").set_active(1);
if (is_func(gy_gtk_main)) gy_gtk_main, _cvgy.toolbox;
else noop, _cvgy.toolbox.show_all();
}
func cv_quit(void)
{
winkill, cv_interns.slice_wid;
winkill, cv_interns.sp_wid;
quit;
error, "Error triggered to exit Cubeview in batch mode. Should not happen.";
}
func cv_open(wdg, udata) {
chooser = Gtk.FileChooserDialog();
noop, chooser.add_button(Gtk.STOCK_OPEN, Gtk.ResponseType.ok);
noop, chooser.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.cancel);
fcfc = Gtk.FileChooser(chooser);
noop, fcfc.set_action(Gtk.FileChooserAction.open);
noop, fcfc.set_do_overwrite_confirmation(1);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[fF][iI][tT][sS]");
noop, filter.add_pattern("*.[fF][iI][tT]");
noop, filter.add_pattern("*.[fF][iI][tT][sS].gz");
noop, filter.add_pattern("*.[fF][iI][tT].gz");
noop, filter.set_name("FITS files");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*");
noop, filter.set_name("All files");
noop, fcfc.add_filter(filter);
noop, chooser.show_all();
answer = chooser.run();
noop,chooser.hide();
if (answer==Gtk.ResponseType.ok) {
file=Gtk.FileChooser(chooser).get_filename();
cv_init, file, slice_wid=cv_interns.slice_wid, sp_wid=cv_interns.sp_wid;
cv_spdraw;
cv_sldraw_first;
}
noop, chooser.destroy();
}
func cv_save(wdg, udata) {
chooser = Gtk.FileChooserDialog();
noop, chooser.add_button(Gtk.STOCK_SAVE, Gtk.ResponseType.ok);
noop, chooser.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.cancel);
fcfc = Gtk.FileChooser(chooser);
noop, fcfc.set_action(Gtk.FileChooserAction.save);
noop, fcfc.set_do_overwrite_confirmation(1);
noop, fcfc.set_create_folders(1);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[fF][iI][tT][sS]");
noop, filter.add_pattern("*.[fF][iI][tT]");
noop, filter.add_pattern("*.[fF][iI][tT][sS].gz");
noop, filter.add_pattern("*.[fF][iI][tT].gz");
noop, filter.set_name("FITS files");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*");
noop, filter.set_name("All files");
noop, fcfc.add_filter(filter);
noop, chooser.show_all();
answer = chooser.run();
noop,chooser.hide();
if (answer==Gtk.ResponseType.ok) {
file=Gtk.FileChooser(chooser).get_filename();
cv_save_sel, file;
}
noop, chooser.destroy();
}
func cv_export(wdg, udata) {
chooser = Gtk.FileChooserDialog();
noop, chooser.add_button(Gtk.STOCK_SAVE, Gtk.ResponseType.ok);
noop, chooser.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.cancel);
grid = Gtk.Grid();
noop, grid.set_column_homogeneous(1);
noop, chooser.get_content_area().pack_start(grid, 0,0,0);
slice = Gtk.RadioButton.new_with_label(,"Slice");
spectrum = Gtk.RadioButton.new_with_label(slice.get_group(),"Spectrum");
noop, grid.attach(slice, 1, 1, 1, 1);
noop, grid.attach(spectrum, 1, 2, 1, 1);
data = Gtk.RadioButton.new_with_label(,"Data");
plot = Gtk.RadioButton.new_with_label(data.get_group(),"Plot");
noop, grid.attach(data, 2, 1, 1, 1);
noop, grid.attach(plot, 2, 2, 1, 1);
sel = Gtk.CheckButton.new_with_label("Selection only");
noop, grid.attach(sel, 3, 1, 1, 1);
fcfc = Gtk.FileChooser(chooser);
noop, fcfc.set_action(Gtk.FileChooserAction.save);
noop, fcfc.set_do_overwrite_confirmation(1);
noop, fcfc.set_create_folders(1);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[fF][iI][tT][sS]");
noop, filter.add_pattern("*.[fF][iI][tT]");
noop, filter.add_pattern("*.[tT][xX][tT]");
noop, filter.add_pattern("*.[cC][sS][vV]");
noop, filter.add_pattern("*.[dD][aA][tT]");
noop, filter.add_pattern("*.[pP][dD][fF]");
noop, filter.add_pattern("*.[eE][pP][sS]");
noop, filter.add_pattern("*.[jJ][pP][eE][gG]");
noop, filter.add_pattern("*.[jJ][pP][gG]");
noop, filter.add_pattern("*.[jJ][fF][iI][fF]");
noop, filter.add_pattern("*.[pP][nN][gG]");
noop, filter.add_pattern("*.[pP][nN][mM]");
noop, filter.add_pattern("*.[pP][pP][mM]");
noop, filter.set_name("All supported files");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[fF][iI][tT][sS]");
noop, filter.add_pattern("*.[fF][iI][tT]");
noop, filter.set_name("FITS files");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[tT][xX][tT]");
noop, filter.add_pattern("*.[cC][sS][vV]");
noop, filter.add_pattern("*.[dD][aA][tT]");
noop, filter.set_name("Text files");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[pP][dD][fF]");
noop, filter.set_name("PDF documents");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[eE][pP][sS]");
noop, filter.set_name("EPS documents");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[jJ][pP][eE][gG]");
noop, filter.add_pattern("*.[jJ][pP][gG]");
noop, filter.add_pattern("*.[jJ][fF][iI][fF]");
noop, filter.set_name("JPEG images");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[pP][nN][gG]");
noop, filter.set_name("PNG images");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*.[pP][nN][mM]");
noop, filter.add_pattern("*.[pP][pP][mM]");
noop, filter.set_name("PNM images");
noop, fcfc.add_filter(filter);
filter = Gtk.FileFilter();
noop, filter.add_pattern("*");
noop, filter.set_name("All files");
noop, fcfc.add_filter(filter);
noop, chooser.show_all();
answer = chooser.run();
noop,chooser.hide();
if (answer==Gtk.ResponseType.ok) {
file=Gtk.FileChooser(chooser).get_filename();
savedata = data.get_active();
if (slice.get_active()) what="slice";
selection=sel.get_active();
cv_export_misc, file, [], what, savedata, selection;
}
noop, chooser.destroy();
}
func cv_about(wdg, udata)
{
dialog = Gtk.AboutDialog();
noop, dialog.set_program_name("Cubeview");
noop, dialog.set_version(CUBEVIEW_VERSION);
noop, dialog.set_logo(icon);
noop, dialog.set_copyright("Copyright © 2003-2013 Thibaut Paumard");
noop, dialog.set_license_type(Gtk.License.gpl_2_0);
noop, dialog.run();
noop, dialog.destroy();
}
func cv_wakeup {resume;}
func cv_valids(x,y,z){
if (cv_interns.isbig) {
//did not cache.
blank=cv_interns.blank;
if (is_real(cv_cube))
valids=ieee_test(cv_cube(x,y,z))==0; else
valids=array(char(1),dimsof(cv_cube(x,y,z)));
// We no the cube is big, don't make several copies of valids
if (is_scalar(z)) {
if (ieee_test(blank)==0) valids &= cv_cube(x,y,z)!=blank;
return valids;
}
if (is_void(z)) {
z_ind=indgen(dimsof(cv_cube)(4));
} else if (is_range(z)) {
z_ind=indgen(z);
} else {
// else we assume z is an array of indices.
z_ind=z;
}
nz=numberof(z_ind);
if (ieee_test(blank)==0) {
for (k=1;k<=nz;k++)
valids(..,z_ind(k)) &= (*cv_interns)(x,y,z_ind(k))!=blank;
}
return valids;
}
return cv_valids(x,y,z);
}
func cv_freeylimits(wdg, udata) {
/* DOCUMENT cv_freeylimits
Frees Y limits, hence the name... Indeed, calls LIMITS to uset every
limits, then sets back X limits. Very useful if you've set limits using the
mouse and want to explore data only within the selected range.
Normally called through cubeview's "Spectrum Y limits" button.
*/
extern cv_nodraw;
if (cv_nodraw) return;
cv_spwin;
oldlimits=limits();
limits;
limits,oldlimits(1),oldlimits(2);
}
struct CV_Interns {
/* DOCUMENT CV_Interns: structure type use internally by cubeview.
{
pointer slice; // pointer to the current slice, either indexed color or RGB,
// so either NxM or 3xNxM.
pointer spectrum; // pointer to the current spectrum, of size P.
pointer zaxis; // spectral axis, in pixels
pointer waxis; // wavelength spectral axis, in microns
pointer faxis; // frequency spectral axis, in cm-1
pointer vaxis; // velocity spectral axis, in km/s
pointer root; // pointer to cubeview's TWS_Root widget. See tws.i and
// tws_root.i
long slice_wid,sp_wid,cmd_wid; // Cubeview windows identifiers
long sllims(2); // indices of the first and last z-planes of the current slice
long depth; // depth of the slice image in 3 color mode: 8 or 24
long big_size; // if cubes has more voxels than that, sopme treatements will
// be memory-optimized.
double spbox(4); // integer pixel coordinates of the spectrum aperture if rectangular
or square, center x, center y, radius and nothing if circular
double cmin,cmax; // lower and upper cut for displaying the slice
double origin(3); // 3D position of the data cell (1,1,1) in you prefered
// coordinate system
double scale(3); // scales of the data in the three
// dimensions
double slpos(4); // "real world" coordinates of the 4 corners of the field
double overs; // oversampling factor to display the slice
double refwl; // reference wavelength in microns for conversion into velocity
double vlsr; // true "systemic" velocity in the local standard of rest if its observed velocity is 0.
double spsmooth ; // smoothing box for the displayed spectrum
double slsmooth ; // smoothing box for the displayed slice
char slboxcol; // color index to draw the box inicating the slice bandpass
// when in normal mode
char zwlwise; // 0 zaxis is frequency-wise, 1 if it is wavelength-wise
string sltype; // String containing the type of slice, either "Normal" or "3
// color". Used by most cv_ routines that access the slice.
string slpalette; // palette to use for the slice when in normal mode
string zaxistype; // type of Z-axis to use: "PIX", "WAVE", "FREQ" or "VELOCITY"
string slinterp; // use interp or spline to interpolate? spline is much better
// and... slower. Should not be a problem, except if you
// work on really big data.
string aperture_type; // rectangular, square, circular
string hook; // name of a function to call from time to times (basically each
// time a window is updated). Format not well defined yet. One
// (or several?) general interest hook is provided. See cv_*_hook.
GraphK spkeywords; // graphic keywords to plot the spectra. See graphk.i.
double xyaspect; // aspect ratio X/Y of the viewport in the slice window.
// by default, depends on the dimensions of the data.
// Set to 0 for this behavior, or to a scalar.
}
SEE ALSO: cv_interns, cubeview, cv_library
*/
pointer slice,spectrum,zaxis,waxis,faxis,vaxis,root,popup,header;
long slice_wid,sp_wid,cmd_wid,sllims(2),depth,big_size;
double cmin,cmax,origin(3),scale(3),slpos(4),overs,refwl,vlsr,spsmooth,slsmooth,spbox(4),blank,xyaspect;
char slboxcol,zwlwise,pixel,isbig,mouselock;
string sltype,slpalette,slinterp,zaxistype,hook,aperture_type;
GraphK spkeywords; // see graphk.i
}
extern cv_interns, cv_cube, cv_valids, cv_fh;
/* DOCUMENT extern cv_cube, cv_interns
cv_cube is an external variable holding the data cube being viewed
in Cubeview.
cv_interns is a structure of type CV_Interns, containing all other
variables shared by Cubeview routines.
cv_valids is a mask indicating which cells in cv_cube are valid
data. It is used to speed up various treatments, unless the cube
"isbig".
The most usefull items for the user are .slice and .spectrum,
pointers to eponym arrays. .spbox is a 4 elements array containing
the coordinates of the corners of the region defining the spectrum
aperture, and likewise .sllims contains the limits of the spectral
region defining the slice. .slice is either a NxM indexed color
array, or a 3xNxM RGB array.
SEE ALSO: CV_Interns, cubeview, cv_library
*/
struct CV_Defaults
/* DOCUMENT CV_Defaults
Structure to handle defaults for cubeview. The members are the ones of
CV_Interns for which setting a default makes sense. The external variable
cv_defaults is normally the only variable of type CV_Defaults. You may set
defaults by accessing this variable, that is erased when you #include
cubeview.
{
long slice_wid,sp_wid,cmd_wid,depth;
double origin(3),scale(3),overs,vlsr,spsmooth,slsmooth,blank,xyaspect;
char slboxcol,zwlwise,pixel;
string sltype,slpalette,slinterp,hook,aperture_type;
GraphK spkeywords;
}
SEE ALSO: cv_defaults, cv_library
*/
{
long slice_wid,sp_wid,cmd_wid,depth,big_size;
double origin(3),scale(3),overs,refwl,vlsr,spsmooth,slsmooth,blank,xyaspect;
char slboxcol,zwlwise,pixel;
string sltype,slpalette,slinterp,zaxistype,hook,aperture_type;
GraphK spkeywords;
}
// Here I define the defaults
extern cv_defaults;
/* DOCUMENT cv_defaults
Instance of CV_Defaults defining defaults for Cubeview.
cv_defaults=CV_Defaults(slice_wid=0,
sp_wid=1,
cmd_wid=2,
depth=24,
origin=[1,1,1],
scale=[1,1,1],
overs=1,
slboxcol=248,
zwlwise=0,
sltype="Normal",
slpalette="stern.gp",
slinterp="spline",
zaxistype="PIX",
refwl=2.166120,
pixel=1);
SEE ALSO: CV_Defaults, cubeview, cv_library
*/
if (is_void(defaults)) {
junk=[0.];
ieee_set,junk,2;
cv_defaults=CV_Defaults(slice_wid=0,sp_wid=1,cmd_wid=2,depth=24,
origin=[1,1,2],scale=[1,1,1e-3],overs=1,
slboxcol=248,zwlwise=0,sltype="Normal",
slpalette="stern.gp",slinterp="spline",
zaxistype="WAVE",refwl=2.166120,pixel=1,
aperture_type="circular",big_size=1e8,
blank=junk(1),spkeywords=GraphK(marks=&long(0)));
}
func cv_init(data,slice_wid=,sp_wid=,cmd_wid=,origin=,scale=,depth=,overs=,
slboxcol=,sltype=,slpalette=,slinterp=,zwlwise=,refwl=,
waxis=,faxis=,vaxis=,zaxistype=,vlsr=,pixel=,hook=,spkeywords=,
postinit=,big_size=,isbig=,blank=,xyaspect=)
/* DOCUMENT cv_init,"file.fits" or cv_init,3D_array
It's probably better not to call directly CV_INIT and let the almost
graphical tool CUBEVIEW do it. Initiates Cubeview. If called with a fits
file name, includes "fits.i" and reads the file. Feeds all items of the
external variable CV_INTERNS, and displays a first slice and a first
spectrum. After, you could use cv_spsel and cv_slsel.
Cubeview has a kind of graphical user interface that can be launched with
"cubeview,data", or "cv_resume" once CV_INIT has been called.
cv_init takes as keyword any member of CV_Defaults, override the defaults.
In addition to this, cv_init will include any .i file specified as
POSTINIT keyword.
SEE ALSO: cubeview, cv_library, cv_defaults
*/
{
local slice_wid,sp_wid,cmd_wid,origin,scale,depth,overs,slbox,sltype,slpalette;
extern cv_interns,cv_defaults,cv_cube,cv_valids, __cv_palette;
cv_interns=CV_Interns(slice_wid=cv_defaults.slice_wid,
sp_wid=cv_defaults.sp_wid, cmd_wid=cv_defaults.cmd_wid,
depth=cv_defaults.depth, origin=cv_defaults.origin,
scale=cv_defaults.scale, overs=cv_defaults.overs,
slboxcol=cv_defaults.slboxcol,zwlwise=cv_defaults.zwlwise,
sltype=cv_defaults.sltype, slpalette=cv_defaults.slpalette,
slinterp=cv_defaults.slinterp,refwl=cv_defaults.refwl,
zaxistype=cv_defaults.zaxistype,vlsr=cv_defaults.vlsr,
pixel=cv_defaults.pixel,hook=cv_defaults.hook,
spkeywords=cv_defaults.spkeywords,
aperture_type=cv_defaults.aperture_type,
blank=cv_defaults.blank,xyaspect=cv_defaults.xyaspect);
// Read data and coordinate system if available
if (is_void(data)) {
require,"ytk.i";
ftypes="{{{FITS Files} {.fits .fit .FIT .fts .FITS .FTS}} {{All files} {*}}}";
data=get_openfn(filetypes=ftypes);
}
// Keywords overwritting defaults
if (!is_void(pixel)) cv_interns.pixel=pixel;
else pixel=cv_interns.pixel;
if (typeof(data)=="string") {
pos=strchr(data,'.',last=1);
if (pos>0) {
suffix=strpart(data,pos:);
if (suffix==".gz") {
system,"gzip -d < "+data+" > cubeview.tmp.fits";
cv_cube=double(fits_read("cubeview.tmp.fits",cv_fh, hdu=cv_hdu));
system,"rm -f cubeview.tmp.fits";
} else {
cv_cube=double(fits_read(data,cv_fh, hdu=cv_hdu));
}
} else {
cv_cube=double(fits_read(data,cv_fh, hdu=cv_hdu));
}
BLANK = fits_get(cv_fh,"BLANK");
if (is_numerical(BLANK)) cv_interns.blank=BLANK;
if (cv_is_osiris(cv_fh)) {
cv_cube=transpose(cv_cube, 0);
if (!pixel){
CRPIX1 = fits_get(cv_fh,"CRPIX2");
CRVAL1 = fits_get(cv_fh,"CRVAL2");
CDELT1 = fits_get(cv_fh,"CDELT2");
CRPIX2 = fits_get(cv_fh,"CRPIX3");
CRVAL2 = fits_get(cv_fh,"CRVAL3");
CDELT2 = fits_get(cv_fh,"CDELT3");
}
CRPIX3 = fits_get(cv_fh,"CRPIX1");
CRVAL3 = fits_get(cv_fh,"CRVAL1");
CDELT3 = fits_get(cv_fh,"CDELT1");
CUNIT3 = fits_get(cv_fh,"CUNIT1");
CTYPE3 = "WAVE";
if ( CUNIT3 == "nm" ) {
CRVAL3 *= 0.001;
CDELT3 *= 0.001;
}
} else {
if (!pixel){
CRPIX1 = fits_get(cv_fh,"CRPIX1");
CRVAL1 = fits_get(cv_fh,"CRVAL1");
CDELT1 = fits_get(cv_fh,"CDELT1");
CRPIX2 = fits_get(cv_fh,"CRPIX2");
CRVAL2 = fits_get(cv_fh,"CRVAL2");
CDELT2 = fits_get(cv_fh,"CDELT2");
}
CRPIX3 = fits_get(cv_fh,"CRPIX3");
CRVAL3 = fits_get(cv_fh,"CRVAL3");
CDELT3 = fits_get(cv_fh,"CDELT3");
CTYPE3 = fits_get(cv_fh,"CTYPE3");
}
if (is_numerical(CDELT1) && is_numerical(CRVAL1) && is_numerical(CRPIX1)) {
cv_interns.scale(1)=CDELT1;
cv_interns.origin(1)=CRVAL1-(CRPIX1-1)*CDELT1;
}
if (is_numerical(CDELT2) && is_numerical(CRVAL2) && is_numerical(CRPIX2)) {
cv_interns.scale(2)=CDELT2;
cv_interns.origin(2)=CRVAL2-(CRPIX2-1)*CDELT2;
}
if (is_numerical(CDELT3) && is_numerical(CRVAL3) && is_numerical(CRPIX3)) {
cv_interns.scale(3)=CDELT3;
cv_interns.origin(3)=CRVAL3-(CRPIX3-1)*CDELT3;
} else if (is_bear(cv_fh)) {
faxis=bear_faxis(cv_fh);
cv_interns.zwlwise=0;
}
if ( CTYPE3 == "WAVE") cv_interns.zwlwise=1;
else cv_interns.zwlwise=0;
} else {
cv_cube=double(data);
cv_fh=[];
}
// Keywords overwritting defaults
if (!is_void(blank)) cv_interns.blank=blank;
if (!is_void(slice_wid)) cv_interns.slice_wid=slice_wid;
if (!is_void(sp_wid)) cv_interns.sp_wid =sp_wid ;
if (!is_void(cmd_wid)) cv_interns.cmd_wid =cmd_wid ;
if (!is_void(depth)) cv_interns.depth =depth ;
if (!is_void(origin)) cv_interns.origin =origin ;
if (!is_void(scale)) cv_interns.scale =scale ;
if (!is_void(overs)) cv_interns.overs =overs ;
if (!is_void(slboxcol)) cv_interns.slboxcol =slboxcol ;
if (!is_void(sltype)) cv_interns.sltype =sltype ;
if (!is_void(slpalette)) cv_interns.slpalette=slpalette ;
__cv_palette=closure(palette, cv_interns.slpalette);
if (!is_void(slinterp)) cv_interns.slinterp =slinterp ;
if (!is_void(zaxistype)) cv_interns.zaxistype=zaxistype;
if (!is_void(refwl)) cv_interns.refwl =refwl;
if (!is_void(vlsr)) cv_interns.vlsr =vlsr;
if (!is_void(hook)) cv_interns.hook =hook;
if (!is_void(spkeywords)) cv_interns.spkeywords =spkeywords;
if (!is_void(zwlwise)) cv_interns.zwlwise =zwlwise;
//cv_interns.=override(cv_interns.,);
// Try so set up the spectral axes
data_dims=dimsof(cv_cube);
if (data_dims(1) < 3) "This is no cube";
cv_interns.zaxis=&indgen(data_dims(4));
if (is_void(faxis) && is_void(waxis) && is_void(vaxis)){
if (cv_interns.zwlwise) waxis=(*cv_interns.zaxis-1)*cv_interns.scale(3)+cv_interns.origin(3);
else faxis=(*cv_interns.zaxis-1)*cv_interns.scale(3)+cv_interns.origin(3);
}
if (!is_void(faxis)) {
cv_interns.faxis=&faxis ; // cm-1
cv_interns.waxis=&(10000./faxis) ; // microns
cv_interns.vaxis=&(voflambda(*cv_interns.waxis,cv_interns.refwl)/1000.); // km/s
} else if (!is_void(waxis)) {
cv_interns.waxis=&waxis ; // microns
cv_interns.faxis=&(10000./waxis) ; // cm-1
cv_interns.vaxis=&(voflambda(*cv_interns.waxis,cv_interns.refwl)/1000.); // km/s
} else if (!is_void(vaxis)) {
cv_interns.vaxis=&vaxis; // km/s
cv_interns.waxis=&(lambdaofv(*cv_interns.vaxis*1000.,cv_interns.refwl)) ; // microns
cv_interns.faxis=&(10000./(*cv_interns.waxis)) ; // cm-1
}
*cv_interns.vaxis=*cv_interns.vaxis+cv_interns.vlsr;
if ((*cv_interns.waxis)(0)>(*cv_interns.waxis)(1)) cv_interns.zwlwise=1; else cv_interns.zwlwise=0;
if (!is_void(zwlwise)) cv_interns.zwlwise =zwlwise ;
cv_interns.sllims=[1,data_dims(4)];
cv_interns.slpos=[cv_xpix2data(0.5),cv_ypix2data(0.5),cv_xpix2data(data_dims(2)+0.5),cv_ypix2data(data_dims(3)+0.5)];
if (cv_interns.xyaspect==0.) cv_interns.xyaspect=double(data_dims(2))/data_dims(3);
if (!is_void(isbig)) {
cv_interns.isbig=isbig;
} else {
if (data_dims(2)*data_dims(3)*data_dims(4)>cv_defaults.big_size) {
cv_interns.isbig=1;
isbig=1;
} else isbig=0;
}
if (!isbig){
cv_valids=long(ieee_test(cv_cube)==0);
if (ieee_test(cv_interns.blank)==0)
cv_valids &= long(cv_cube != cv_interns.blank);
indices=where(!cv_valids);
if (numberof(indices)) cv_cube(indices)=0.;
}
if (!isbig) cv_slextract,1,data_dims(4);
else cv_slextract,data_dims(4)/2,data_dims(4)/2;
slice=*cv_interns.slice;
cv_interns.cmin=min(slice);
cv_interns.cmax=max(slice);
if (!isbig) {
if (cv_interns.aperture_type=="circular")
cv_spextract,[data_dims(2),data_dims(3),data_dims(min:2:3)]/2;
else cv_spextract,[1,1,data_dims(2),data_dims(3)];
} else {
if (cv_interns.aperture_type=="circular")
cv_spextract,[data_dims(2)/2,data_dims(3)/2,1];
else cv_spextract,[data_dims(2),data_dims(3),data_dims(2),data_dims(3)]/2;
}
if (!is_void(postinit)) include,postinit,1;
}
extern cv_xypix2data,cv_xydata2pix,cv_xpix2data,cv_xdata2pix,cv_ypix2data,cv_ydata2pix,cv_zpix2data,cv_zdata2pix;
/*DOCUMENT
cv_xypix2data,cv_xydata2pix,cv_xpix2data,cv_xdata2pix,cv_ypix2data,cv_ydata2pix,cv_zpix2data,cv_zdata2pix
Simple functions to go between data pixels and the coordinate system used to
plot. Currently useless since this system is pixels (!), but these should
ease implementation of world coordinates in the futures. Some (but not all)
of cubeview's routines are world coordinates-ready.
*/
func cv_xypix2data(xypix)
{
extern cv_interns;
resultat=cv_interns.origin(1:2)+(xypix-1)*cv_interns.scale(1:2);
return resultat;
}
func cv_xydata2pix(xydata)
{
extern cv_interns;
return ([1.,1.]+(xydata-cv_interns.origin(1:2)/cv_interns.scale(1:2)));
}
func cv_xpix2data(xpix)
{
extern cv_interns;
return cv_interns.origin(1)+(xpix-1)*cv_interns.scale(1);
}
func cv_xdata2pix(xdata)
{
extern cv_interns;
return 1+(xdata-cv_interns.origin(1))/cv_interns.scale(1);
}
func cv_ypix2data(ypix)
{
extern cv_interns;
return cv_interns.origin(2)+(ypix-1)*cv_interns.scale(2);
}
func cv_ydata2pix(ydata)
{
extern cv_interns;
return 1+(ydata-cv_interns.origin(2))/cv_interns.scale(2);
}
func cv_current_zaxis(dummy)
/* DOCUMENT cv_current_zaxis()
Returns as a vector the spectral axis currently used by Cubeview,
considering the current state of cv_interns.zaxistype.
*/
{
zaxistype=cv_interns.zaxistype;
if (zaxistype=="PIX") return cv_interns.zaxis;
else if (zaxistype=="FREQ") return cv_interns.faxis;
else if (zaxistype=="WAVE") return cv_interns.waxis;
else return cv_interns.vaxis;
}
func cv_zpix2data(zpix)
{
extern cv_interns;
// return cv_interns.origin(3)+(zpix-1)*cv_interns.scale(3);
//pix=cv_lround(zpix);
axis=*cv_current_zaxis();
if (zpix<1) val=axis(1)-0.5*(axis(2)-axis(1));
else if (zpix>dimsof(cv_cube)(4)) val=axis(0)+0.5*(axis(0)-axis(-1));
else val=interp(axis,*cv_interns.zaxis,zpix)(1);
return val;
// return (*cv_current_zaxis())(min(max(cv_lround(zpix),0),cv_interns.data_dims(4)));
}
func cv_zdata2pix(zdata)
{
extern cv_interns;
// return 1+(zdata-cv_interns.origin(3))/cv_interns.scale(3);
return (abs(*cv_current_zaxis()-zdata))(mnx);
}
func cv_sldraw(depth=)
/* DOCUMENT cv_sldraw
Displays current Cubeview slice (CV_SLICE) in the right window (pointed at
by CV_SLICE_WID). Displays a box around the spectrum region.
*/
{
extern cv_nodraw;
if (cv_nodraw) return;
extern cv_interns;
cv_slwin;
fma;
slice=*cv_interns.slice;
slpos=cv_interns.slpos;
if (cv_interns.sltype=="3 color") {
if (is_void(depth)) depth=cv_interns.depth;
im24=bytscl(cv_oversamp(slice),cmin=cv_interns.cmin,cmax=cv_interns.cmax);
if (depth==8) {
im=cv_rgb2indexed(im24,red,green,blue);
palette,red,green,blue;
pli,im,slpos(1),slpos(2),slpos(3),slpos(4);
} else {
im=im24;
cv_plfi,im,slpos(1),slpos(2),slpos(3),slpos(4);
// eps output of RGB images traced using pli doesn't work. cv_plfi is a workaround.
}
} else if (cv_interns.sltype=="Normal") {
pli,cv_oversamp(slice),slpos(1),slpos(2),slpos(3),slpos(4),
cmin=cv_interns.cmin,cmax=cv_interns.cmax;
}
cv_putspbox;
cv_callhook,"cv_sldraw";
}
func cv_slpnm(filename)
/* DOCUMENT cv_slpnm
Write current slice, affected by current cuts and palette (for a "Normal
slice"), to an RGB PNM file (PPM), using PNM_WRITE. The box is saved in
"axes_"+filename+".epsi", so that you can get the original image with axes
using xfig for instance, so LaTeX programming would probably be
better. For this kind of purpose, I recommend using any tool to convert
the slice to JPEG, then jpeg2ps. That allows to keep JPEG compression for
the bitmap part.
*/
{
extern cv_interns;
require,"pnm.i";
cv_slwin;
if (cv_interns.sltype=="3 color") im=bytscl(*cv_interns.slice,cmin=cv_interns.cmin,cmax=cv_interns.cmax);
else if (cv_interns.sltype=="Normal") im=pnm_colorize(*cv_interns.slice,cmin=cv_interns.cmin,cmax=cv_interns.cmax);
pnm_write,im,filename;
fma;
plg,0,0;
cv_sllims;
eps,"axes_"+filename;
}
func cv_3colslice
/* DOCUMENT cv_3colslice & Cubeview's "3 color slice" radio button
If you click on this button or call this routine, all slices from then on
will be of type "3 color".
See cv_normalslice & Cubeview's "Normal slice" radio button.
*/
{
extern cv_interns;
cv_interns.sltype="3 color";
cv_slextract;
cv_cutregonce,1,1,0,0;
cv_spdraw;
}
func cv_normalslice
/* DOCUMENT cv_normal slice & Cubeview's "Normal slice" radio button
If you click on this button or call this routine, all slices from then on
will be of type "Normal", that is standard Yorick indexed color image.
See cv_3colslice & Cubeview's "3 color slice" radio button.
*/
{
extern cv_interns;
cv_interns.sltype="Normal";
cv_slextract;
cv_slwin;
__cv_palette;
//palette,cv_interns.slpalette;
cv_cutregonce,1,1,0,0;
cv_spwin;
//palette,cv_interns.slpalette;
cv_spdraw;
if (cv_ui=="gtk") noop, _cvgy.builder.get_object("Normal").set_active(1);
}
func cv_slextract_set_handler(wdg, evt, udata)
{
gy_gtk_ywindow_mouse_handler,cv_interns.sp_wid, cv_slextract_handler;
}
func cv_slextract_handler(yid, x0, y0, x1, y1, button, flags)
{
cv_slextract,cv_lround(cv_zdata2pix(x0)),cv_lround(cv_zdata2pix(x1));
cv_sldraw;
cv_spdraw;
}
func cv_spextract_handler(yid, x0, y0, x1, y1, button, flags)
{
slice_wid=cv_interns.slice_wid;
aperture_type=cv_interns.aperture_type;
if (aperture_type=="rectangular") ty=1; else ty=2;
window,slice_wid;
if (aperture_type=="circular") {
pp=[cv_xdata2pix(x0),cv_ydata2pix(y0),cv_xdata2pix(x1),cv_ydata2pix(y1)];
if (button >=2 ) radius=max(sqrt(double(pp(3)-pp(1))^2+double(pp(4)-pp(2))^2),0.7);
else radius=cv_interns.spbox(3);
center=cv_lround(2*pp(1:2))/2.;
cv_spextract,[center(1),center(2),radius];
} else {
pp=cv_lround([cv_xdata2pix(x0),cv_ydata2pix(y0),cv_xdata2pix(x1),cv_ydata2pix(y1)]);
if (aperture_type=="rectangular") cv_spextract,[cv_xdata2pix(x0),cv_ydata2pix(y0),cv_xdata2pix(x1),cv_ydata2pix(y1)];
else if (aperture_type=="square") {
center=pp(1:2);
if (button >=2 ) radius=max(abs([pp(3)-pp(1),pp(4)-pp(2)]));
else radius=cv_interns.spbox(3);
cv_spextract,[center(1),center(2),radius];
}
}
cv_spdraw;
cv_sldraw;
}
func cv_slcontrast_handler(yid, x0, y0, x1, y1, button, flags)
{
extern cv_interns,__cv_cutbox;
x0=cv_lround(cv_xdata2pix(x0));
y0=cv_lround(cv_ydata2pix(y0));
x1=cv_lround(cv_xdata2pix(x1));
y1=cv_lround(cv_ydata2pix(y1));
if (button==1) {
cv_cutregonce, x0, y0, x1, y1;
} else {
if (cv_interns.sltype=="Normal") {
cv_interns.cmin=(*cv_interns.slice)(x0,y0);
cv_interns.cmax=(*cv_interns.slice)(x1,y1);
} else if (cv_interns.sltype=="3 color") {
cv_interns.cmin=sum((*cv_interns.slice)(,x0,y0));
cv_interns.cmax=sum((*cv_interns.slice)(,x1,y1));
}
__cv_cutbox=[x0,y0,x1,y1];
cv_callhook,"cv_cutsel";
cv_sldraw;
}
}
func cv_spwin_handler(wdg, udata)
{
if (wdg.get_active()) gy_gtk_ywindow_mouse_handler,cv_interns.sp_wid, [];
else gy_gtk_ywindow_mouse_handler, cv_interns.sp_wid, cv_slextract_handler;
}
func cv_sltype_handler(wdg, udata)
{
if (wdg.get_active()) cv_normalslice;
else cv_3colslice;
}
func cv_slwin_handler(wdg, udata)
{
if (!wdg.get_active()) return;
id = Gtk.Buildable(wdg).get_name();
if (id == "slzoom") handler = [];
else if (id == "spsel") handler = cv_spextract_handler;
else if (id == "slcontrast") handler = cv_slcontrast_handler;
gy_gtk_ywindow_mouse_handler, cv_interns.slice_wid, handler;
}
func cv_slextract(begin,end)
/* DOCUMENT cv_slextract,begin,end
Extracts new Cubview slice (*CV_INTERNS.SLICE) by summing up
CV_CUBE planes from range BEGIN to range END. If called as a
subroutine, updates a few items in CV_INTERNS. As a function,
returns the slice.
If cv_interns.sltype=="3 color", the slice is a 3xNxM array, all
3 planes being sums of CV_CUBE planes from BEGIN to END with
different ponderations. This keeps some velocity information in
the image displayed... (blueshifted regions can appear in blue
and so...)
*/
{
data_dims=dimsof(cv_cube);
if (is_void(begin)) begin=cv_interns.sllims(1);
if (is_void(end)) end=cv_interns.sllims(2);