Commit 92bc2db8 authored by cyrush's avatar cyrush
Browse files

merge visit_utils.ult changes from 2.7RC

git-svn-id: http://visit.ilight.com/svn/visit/trunk/src@23190 18c085ea-50e0-402c-830e-de6fd14e8384
parent 33829aca
......@@ -76,16 +76,45 @@ Utils for processing ultra curves.
#
# Cyrus Harrison, Wed Mar 7 13:21:23 PST 2012
# Change numpy import style.
#
# Cyrus Harrison, Thu Apr 17 16:04:18 PDT 2014
# Add numpy guards and helper that plots all the curves in a database.
#
#*****************************************************************************
import sys
import math
using_numpy = False
try:
import visit
except:
pass
try:
import numpy as npy
using_numpy = True
except:
pass
from common import VisItException, require_visit
@require_visit
def plot(dbfile=None):
if not dbfile is None:
visit.OpenDatabase(dbfile)
else:
wi = visit.GetWindowInformation()
dbfile = wi.activeSource
md = visit.GetMetaData(dbfile)
ncrvs = md.GetNumCurves()
cnames = [md.GetCurves(i).name for i in xrange(ncrvs)]
cnames.sort()
for cname in cnames:
visit.AddPlot("Curve",cname)
visit.DrawPlots()
class Sample:
"""
Holds a single sample.
......@@ -159,7 +188,7 @@ class Curve(object):
else:
# Check if samples is an ndarray, if so
# convert to a list of Samples.
if isinstance(samples,npy.ndarray):
if using_numpy and isinstance(samples,npy.ndarray):
lshape = len(samples.shape)
if lshape == 1:
r = samples.shape
......@@ -169,7 +198,8 @@ class Curve(object):
samples = [ Sample(samples[i,0],samples[i,1]) for i in xrange(r)]
else:
# error
pass
msg = "Cannot convert ndarry w/ shape %s to Curve " % str(lshape)
raise VisItException(msg)
self.samples = samples
self.__xmap = None
def first(self):
......@@ -216,6 +246,10 @@ class Curve(object):
x_max = max([s.x for s in self.samples])
y_max = max([s.y for s in self.samples])
return [x_min,x_max,y_min,y_max]
def add_sample(self,x,y):
# this invalidates the xmap
self.__xmap = None
return self.samples.append(Sample(x,y))
def get_sample(self,index):
if index <0 or index >= len(self.samples):
return None
......@@ -230,7 +264,9 @@ class Curve(object):
return None
def ndarray(self):
#assumes successful numpy import ...
return npy.array([[s.x,s.y] for s in self.samples])
if using_numpy:
return npy.array([[s.x,s.y] for s in self.samples])
return None
def __get_y(self,x):
"""
Helper to get a y value given x.
......@@ -328,9 +364,12 @@ class Curve(object):
if isinstance(data,Curve):
for v in data.values():
fobj.write("%s %s\n" % (str(v[0]),str(v[1])))
elif isinstance(data,npy.ndarray):
elif using_numpy and isinstance(data,npy.ndarray):
for i in range(data.shape[0]):
fobj.write("%s %s\n" % (str(data[i,0]),str(data[i,1])))
else: # error unknown data type
msg = "Cannot save curve w/ data object of type: %s" % repr(type(data))
raise VisItException(msg)
@classmethod
def load(cls,fname):
"""
......@@ -358,7 +397,8 @@ class Curve(object):
if curr.first() > curr.last():
curr.reverse_samples()
curves.append(curr)
return curves
return curves
......
......@@ -84,7 +84,10 @@ class WindowManager(object):
@classmethod
def registered_windows(cls):
return cls.__windows.values()
@classmethod
def cleanup_windows(cls):
for win in cls.registered_windows():
win.remove()
class Window(object):
@require_visit
......
# random_crv_000
0 0.0
1 0.0
2 0.0
3 0.0
4 0.0
5 0.0
6 0.0
7 0.0
8 0.0
9 0.0
10 0.0
11 0.0
12 0.0
13 0.0
14 0.0
15 0.0
16 0.0
17 0.0
18 0.0
19 0.0
20 0.0
21 0.0
22 0.0
23 0.0
24 0.0
25 0.0
26 0.0
27 0.0
28 0.0
29 0.0
30 0.0
31 0.0
32 0.0
33 0.0
34 0.0
35 0.0
36 0.0
37 0.0
38 0.0
39 0.0
40 0.0
41 0.0
42 0.0
43 0.0
44 0.0
45 0.0
46 0.0
47 0.0
48 0.0
49 0.0
50 0.0
51 0.0
52 0.0
53 0.0
54 0.0
55 0.0
56 0.0
57 0.0
58 0.0
59 0.0
60 0.0
61 0.0
62 0.0
63 0.0
64 0.0
65 0.0
66 0.0
67 0.0
68 0.0
69 0.0
70 0.0
71 0.0
72 0.0
73 0.0
74 0.0
75 0.0
76 0.0
77 0.0
78 0.0
79 0.0
80 0.0
81 0.0
82 0.0
83 0.0
84 0.0
85 0.0
86 0.0
87 0.0
88 0.0
89 0.0
90 0.0
91 0.0
92 0.0
93 0.0
94 0.0
95 0.0
96 0.0
97 0.0
98 0.0
99 0.0
# random_crv_001
0 0.29872318414
1 0.739046317357
2 0.96765642995
3 0.395814928725
4 0.563587342151
5 0.399283438396
6 0.176114082639
7 0.807447627503
8 0.469813428817
9 0.138001646242
10 0.626767895172
11 0.665438503187
12 0.565783581192
13 0.469888494442
14 0.60549092159
15 0.74677093422
16 0.0792222550185
17 0.864307439487
18 0.757171389332
19 0.534864260264
20 0.852004803451
21 0.598453348871
22 0.536818373982
23 0.084395308476
24 0.448999420401
25 0.487607140785
26 0.835709641856
27 0.711818755896
28 0.0248344312879
29 0.391643835597
30 0.853759954752
31 0.0803912036619
32 0.234185619995
33 0.84072728279
34 0.45357202154
35 0.193325741534
36 0.9726478664
37 0.878925671692
38 0.548387771952
39 0.759911618593
40 0.0592978767469
41 0.809765834818
42 0.145081809869
43 0.767596299746
44 0.256699904878
45 0.820817519515
46 0.340800733019
47 0.968682219036
48 0.315857635047
49 0.0545966212662
50 0.987881987485
51 0.578912578225
52 0.186927611737
53 0.938566228805
54 0.440870790426
55 0.0362286382317
56 0.502790345145
57 0.994025152684
58 0.294827079702
59 0.661782132626
60 0.586597296776
61 0.112144413893
62 0.260955708873
63 0.274975206211
64 0.21953664293
65 0.416741673899
66 0.84835882186
67 0.416030152456
68 0.951579641418
69 0.15342641145
70 0.770148884147
71 0.0693597565514
72 0.245429011783
73 0.862503776149
74 0.176895841555
75 0.0172598488318
76 0.188905893896
77 0.392829573114
78 0.476646726299
79 0.426313563054
80 0.81535121739
81 0.204605230521
82 0.817976318559
83 0.387078241325
84 0.513570948088
85 0.985218810785
86 0.845528739574
87 0.679631257966
88 0.141263594319
89 0.595942495105
90 0.867020593517
91 0.613911894112
92 0.824312995761
93 0.4262522249
94 0.989862720392
95 0.0834576043526
96 0.375962832973
97 0.0792166170267
98 0.380032726985
99 0.6055790123
# random_crv_002
0 0.924072013167
1 1.53660178903
2 1.16037324653
3 0.634289109847
4 0.509779794533
5 1.21252124238
6 0.44207359909
7 1.82813748872
8 1.8372876264
9 0.213935976039
10 1.96030601457
11 0.0713049042273
12 1.64526245414
13 1.28577201315
14 1.04735705163
15 1.78679834222
16 1.94812993759
17 0.0933553486325
18 1.23285483255
19 1.27783222268
20 0.0712240323586
21 1.47186278605
22 1.51550386891
23 1.12277384978
24 0.938738360823
25 1.73589366529
26 1.39305440792
27 1.39855414889
28 1.06708438516
29 0.97759321411
30 1.45120308585
31 0.802726470947
32 1.05791712916
33 1.79246524761
34 1.62060699177
35 1.62639985265
36 1.47624112723
37 1.97565952165
38 0.423370708135
39 0.411285975831
40 1.01818200529
41 1.9006594829
42 0.818507157868
43 0.29717255022
44 0.399934606802
45 1.99471122618
46 1.70162008851
47 1.21067387751
48 1.7237372663
49 1.7571967951
50 1.23898337298
51 1.09903269676
52 0.350633193493
53 0.494322316514
54 0.658974818559
55 0.131236467051
56 0.587709943194
57 0.227733506165
58 1.16317720047
59 0.37872487733
60 1.80115012608
61 1.45977434471
62 1.54949439826
63 1.71543117859
64 1.59091453818
65 0.313448829354
66 1.36990865038
67 1.76129285116
68 0.116306548935
69 1.10297121675
70 0.238200229778
71 1.73128952771
72 0.716794890525
73 0.387474144223
74 0.055679816894
75 1.86807671087
76 1.81692484346
77 0.929002101617
78 0.557179479635
79 0.319632236875
80 0.0605699758406
81 1.12506844776
82 0.71127750646
83 0.580810011825
84 1.8316876838
85 0.7116668086
86 0.880185208469
87 1.37524192027
88 1.6819079746
89 0.163944982662
90 1.64189272568
91 1.7040595792
92 0.67371005703
93 1.95623560481
94 1.06192013493
95 0.810755747308
96 1.84692315812
97 1.94356966797
98 0.127397557259
99 0.073646149655
# random_crv_003
0 1.05905779508
1 1.80905063013
2 1.44080328192
3 0.329806234098
4 2.01630622328
5 2.81098763571
6 2.87460308369
7 1.78683608489
8 0.279289087142
9 0.0615272726105
10 1.01964580563
11 0.949431570674
12 1.58963965069
13 2.8930494147
14 2.82527477852
15 0.585666388606
16 1.41103284321
17 1.09675991727
18 2.98966365116
19 1.8165014854
20 2.01579832301
21 2.27419415059
22 0.495144727753
23 2.9579220362
24 2.36856747069
25 2.06507012483
26 0.520395759368
27 0.672774976425
28 0.0222828059432
29 1.95256480007
30 1.89928032386
31 2.56217082954
32 0.603553054905
33 0.569441326101
34 2.23264422798
35 0.324351494104
36 2.20817461247
37 1.86587268863
38 1.56405036044
39 2.23023505649
40 1.1052601499
41 1.00465845684
42 2.1890544911
43 0.355013865723
44 0.370342090133
45 1.4956444654
46 0.0980373618716
47 2.921485258
48 1.8629269858
49 1.31573919748
50 1.50471769699
51 1.55394238992
52 2.49419478503
53 2.19507319626
54 1.92017524405
55 0.655061063366
56 0.815662737349
57 2.7206530041
58 1.33299639757
59 2.59608030444
60 1.67245893264
61 0.111864756258
62 0.549976678614
63 1.65897167528
64 0.656900472514
65 2.76537326361
66 0.340763664913
67 0.397848484624
68 0.83306017542
69 1.12792104416
70 2.76682549261
71 2.26864186593
72 1.36383281489
73 2.18375219393
74 0.958296439815
75 0.46900426515
76 2.5052744446
77 1.37111044233
78 2.83976616438
79 1.8094196498
80 1.58342460914
81 1.25352301867
82 2.51363475569
83 0.0168851472476
84 1.95058942068
85 1.71720515309
86 2.80384895058
87 2.74039590057
88 2.39038856564
89 2.27381550178
90 0.150233391548
91 1.80006858197
92 2.04790266042
93 0.805253540364
94 2.94497178791
95 0.28076978385
96 0.795381084179
97 1.63917980965
98 2.67496581023
99 1.65215033309
# random_crv_004
0 0.975084286926
1 2.58125010747
2 2.79449583785
3 1.83459929206
4 1.47569174058
5 0.51640903759
6 1.82194742686
7 2.84987443514
8 0.450801640172
9 0.0487346682688
10 0.0338876015341
11 1.0438891669
12 3.97240328609
13 1.09051403081
14 1.4254106815
15 1.87973510246
16 2.80787258468
17 3.89157426301
18 2.95405540622
19 3.95147432408
20 3.38267950481
21 1.87001560588
22 2.4759655116
23 0.951700557138
24 2.73605177234
25 2.98860928486
26 2.69252130906
27 1.71280165167
28 0.326054503675
29 1.05188122652
30 2.08135717244
31 0.307486079483
32 3.56527778492
33 1.75623099193
34 1.33880763352
35 1.97222306393
36 1.20718169689
37 3.6971295269
38 1.20656792533
39 2.69775198702
40 3.38828866768
41 3.88404981539
42 2.46414515709
43 3.07191711303
44 1.71723132501
45 3.3748584392
46 0.666648787524
47 1.40182764312
48 1.45763999969
49 2.574898383
50 0.773227089576
51 2.94267946089
52 2.4841843654
53 1.85134684344
54 3.32153394636
55 1.40898184254
56 0.0110502678735
57 1.67140206516
58 1.68332372666
59 0.958506033886
60 3.08993376552
61 3.27500384764
62 3.4388665326
63 0.278145447258
64 2.41355593407
65 0.196326906456
66 2.42072799751
67 2.51828532644
68 0.719341596073
69 0.0291670921248
70 0.656274361368
71 2.32285119672
72 3.10195562059
73 0.432221941622
74 3.37139212078
75 0.141681961773
76 3.98960755659
77 3.7541294265
78 1.83051725024
79 2.72211717533
80 1.47718220882
81 1.3860510244
82 2.56972248763
83 1.1389492001
84 3.81218903779
85 2.89787988129
86 2.92144791083
87 1.15878887658
88 1.96243146245
89 1.00146627113
90 3.15833742519
91 2.89907160593
92 1.91415047082
93 1.91186845146
94 0.401432079349
95 3.76844428102
96 3.67481309523
97 2.69532452075
98 3.4899162705
99 1.81708742079
# random_crv_005
0 2.09831200184
1 0.566344602327
2 1.65506078979
3 0.11221616171
4 2.4635991413
5 1.24978281557
6 3.59355434219
7 1.85872836129
8 0.261679770442
9 0.913098329262
10 2.31387532825
11 0.586101660344
12 1.33707486375
13 2.5812928591
14 2.59097468247
15 1.33953206359
16 0.477475855537
17 4.31740898315