/
boxfill.py
executable file
·1118 lines (979 loc) · 40 KB
/
boxfill.py
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
"""
# Boxfill (Gfb) module
"""
###############################################################################
# Module: boxfill (Gfb) module #
# Copyright: 2000, Regents of the University of California #
# This software may not be distributed to others without #
# permission of the author. #
# Author: PCMDI Software Team #
# Lawrence Livermore NationalLaboratory: #
# support@pcmdi.llnl.gov #
# Description: Python command wrapper for VCS's boxfill graphics method. #
# Version: 5.0 #
###############################################################################
#
#
#
###############################################################################
# #
# Import: VCS C extension module. #
# #
###############################################################################
import vcs
import cdtime
import VCS_validation_functions
import xmldocs
import numpy
import warnings
def process_src(nm, code):
"""Takes VCS script code (string) as input and generates boxfill gm from it"""
try:
gm = Gfb(nm)
except:
gm = vcs.elements["boxfill"][nm]
# process attributes with = as assignement
for att in ["projection",
"xticlabels#1", "xticlabels#2",
"xmtics#1", "xmtics#2",
"yticlabels#1", "yticlabels#2",
"ymtics#1", "ymtics#2",
"xaxisconvert", "yaxisconvert",
"datawc_tunits",
"boxfill_type",
"level_1", "level_2",
"color_1", "color_2",
"fillareastyle", "fillareaindices",
"fillareacolors", "fillareaopacity",
"legend",
"ext_1", "ext_2",
"missing",
"datawc_tunits",
"datawc_calendar"]:
i = code.find(att)
if i == -1:
continue
j = code[i:].find(",") + i
if j - i == -1: # last one no comma
j = None
scode = code[i:j]
sp = scode.split("=")
nm = sp[0].strip()
nm = nm.replace("#", "")
if nm == "datawc_tunits":
nm = "datawc_timeunits"
if nm == "legend":
if sp[1] != "()":
gm.legend = sp[1][1:-1]
continue
try:
# int will be converted
setattr(gm, nm, int(sp[1]))
except:
try:
# int and floats will be converted
setattr(gm, nm, eval(sp[1]))
except:
# strings
try:
setattr(gm, nm, sp[1])
except:
pass # oh well we stick to default value
# Datawc
idwc = code.find("datawc(")
if idwc > -1:
jdwc = code[idwc:].find(")") + idwc
cd = code[idwc + 7:jdwc]
vals = cd.split(",")
gm.datawc_x1 = float(vals[0])
gm.datawc_y1 = float(vals[1])
gm.datawc_x2 = float(vals[2])
gm.datawc_y2 = float(vals[3])
# idatawc
idwc = code.find("idatawc(")
if idwc > -1:
jdwc = code[idwc:].find(")") + idwc
cd = code[idwc + 8:jdwc]
vals = cd.split(",")
if int(vals[0]) == 1:
gm.datawc_x1 = cdtime.reltime(
gm.datawc_x1,
gm.datawc_timeunits).tocomp(
gm.datawc_calendar)
if int(vals[1]) == 1:
gm.datawc_y1 = cdtime.reltime(
gm.datawc_x2,
gm.datawc_timeunits).tocomp(
gm.datawc_calendar)
if int(vals[2]) == 1:
gm.datawc_x2 = cdtime.reltime(
gm.datawc_y1,
gm.datawc_timeunits).tocomp(
gm.datawc_calendar)
if int(vals[3]) == 1:
gm.datawc_y2 = cdtime.reltime(
gm.datawc_y2,
gm.datawc_timeunits).tocomp(
gm.datawc_calendar)
vcs.utils.process_range_from_old_scr(code, gm)
#############################################################################
# #
# Boxfill (Gfb) graphics method Class. #
# #
#############################################################################
# class Gfb(graphics_method_core):
class Gfb(object):
"""
Options:::
%s
boxfill_type :: (str) ('linear') type of boxfill legend linear/log10
(i.e using color_1/2 and level_1/2 as limits) or
custom (similar to isofill method, using levels and colors to set intervals)
level_1 :: (float) (1.E20) used in conjunction with boxfill_type linear/log10,
sets the value of the legend's first level
level_2 :: (float) (1.E20) used in conjunction with boxfill_type linear/log10,
sets the value of the legend's end level
color_1 :: (float) (1.E20) used in conjunction with boxfill_type linear/log10,
sets the legend's color range first value
color_2 :: (float) (1.E20) used in conjunction with boxfill_type linear/log10,
sets the legend's color range lasst value
levels :: ([float,...]/[[float,float],...]) (([1.E20,1.E20],)) used in
conjunction for boxfill_type custom, sets the levels range to use, can be
either a list of contiguous levels, or list of tuples indicating, first
and last value of the range
fillareacolors :: (list) (None) used in conjunction for boxfill_type custom,
colors to use for each level
legend :: ({float:str}) (None) used in conjunction with boxfill_type
linear/log10, replaces the legend values in the dictionary keys with
their associated string
ext_1 :: (str) ('n') draws an extension arrow on right side
(values less than first range value)
ext_2 :: (str) ('n') draws an extension arrow on left side
(values greater than last range value)
missing :: (int) (241) color to use for missing value or values not in defined ranges
:::
Class: Gfb # Boxfill
Description of Gfb Class:
The boxfill graphics method (Gfb) displays a two-dimensional data array
by surrounding each data value by a colored grid box.
This class is used to define a boxfill table entry used in VCS, or it
can be used to change some or all of the attributes in an existing
boxfill table entry.
Other Useful Functions:
a=vcs.init() # Constructor
a.show('boxfill') # Show predefined boxfill graphics methods
a.setcolormap("AMIP") # Change the VCS color map
a.boxfill(s,b,'default') # Plot data 's' with boxfill 'b' and
'default' template
a.update() # Updates the VCS Canvas at user's request
a.mode=1, or 0 # If 1, then automatic update, else if
0, then use the update function to
update the VCS Canvas.
Example of Use:
a=vcs.init()
To Create a new instance of boxfill use:
box=a.createboxfill('new','quick') # Copies content of 'quick' to 'new'
box=a.createboxfill('new') # Copies content of 'default' to 'new'
To Modify an existing boxfill use:
box=a.getboxfill('AMIP_psl')
box.list() # Will list all the boxfill attribute values
box.projection='linear'
lon30={-180:'180W',-150:'150W',0:'Eq'}
box.xticlabels1=lon30
box.xticlabels2=lon30
box.xticlabels(lon30, lon30) # Will set them both
box.xmtics1=''
box.xmtics2=''
box.xmtics(lon30, lon30) # Will set them both
box.yticlabels1=lat10
box.yticlabels2=lat10
box.yticlabels(lat10, lat10) # Will set them both
box.ymtics1=''
box.ymtics2=''
box.ymtics(lat10, lat10) # Will set them both
box.datawc_y1=-90.0
box.datawc_y2=90.0
box.datawc_x1=-180.0
box.datawc_x2=180.0
box.datawc(-90, 90, -180, 180) # Will set them all
box.xaxisconvert='linear'
box.yaxisconvert='linear'
box.xyscale('linear', 'area_wt') # Will set them both
box.level_1=1e20
box.level_2=1e20
box.color_1=16
box.color_2=239
box.colors(16, 239 ) # Will set them both
box.boxfill_type='linear' # 'linear' - compute or specify legend
# 'log10' - plot using log10,
# 'custom' - use custom values to display legend evenly
box.legend=None # Hold the legend values
box.ext_1='n' # Show left overflow arrow
box.ext_2='y' # Show right overflow arrow
box.exts('n', 'y' ) # Will set them both
box.missing=241 # Color index value range 0 to 255
There are two possibilities for setting the boxfill levels:
A) Levels are all contiguous (Examples):
box.levels=([0,20,25,30,35,40],)
box.levels=([0,20,25,30,35,40,45,50])
box.levels=[0,20,25,30,35,40]
box.levels=(0.0,20.0,25.0,30.0,35.0,40.0,50.0)
B) Levels are not contiguous (Examples):
box.levels=([0,20],[30,40],[50,60])
box.levels=([0,20,25,30,35,40],[30,40],[50,60])
There are three possibilities for setting the fillarea color indices (Ex):
box.fillareacolors=([22,33,44,55,66,77])
box.fillareacolors=(16,19,33,44)
box.fillareacolors=None
There are three possibilities for setting the fillarea style (Ex):
box.fillareastyle = 'solid'
box.fillareastyle = 'hatch'
box.fillareastyle = 'pattern'
There are two ways to set the fillarea hatch or pattern indices (Ex):
box.fillareaindices=([1,3,5,6,9,20])
box.fillareaindices=(7,1,4,9,6,15)
See using fillarea objects below!
Using the fillarea secondary object (Ex):
f=createfillarea('fill1')
To Create a new instance of fillarea use:
fill=a.createfillarea('new','quick') # Copies 'quick' to 'new'
fill=a.createfillarea('new') # Copies 'default' to 'new'
To Modify an existing boxfill use:
fill=a.getboxfill('def37')
box.fillareaindices=(7,fill,4,9,fill,15) # Set index using fillarea
fill.list() # list fillarea attributes
fill.style='hatch' # change style
fill.color=241 # change color
fill.index=3 # change style index
""" % xmldocs.graphics_method_core # noqa
def rename(self, newname):
if newname == "default":
raise Exception(
"You cannot overwrite the default boxfill graphic method")
if newname in vcs.elements["boxfill"].keys():
raise Exception(
"Sorry %s boxfill graphic method already exists" %
newname)
vcs.elements["boxfill"][newname] = vcs.elements["boxfill"][self.name]
if self.name == "default":
warnings.warn(
"You were trying to rename the 'deafult' boxfill method, it was merely copied not renamed")
else:
del(vcs.elements["boxfill"][self.name])
self = vcs.elements["boxfill"][newname]
return
__slots__ = [
'colormap',
'_colormap',
'__doc__',
'name',
'g_name',
'xaxisconvert',
'yaxisconvert',
'levels',
'fillareacolors',
'fillareastyle',
'fillareaindices',
'fillareaopacity',
'ext_1',
'ext_2',
'missing',
'projection',
'xticlabels1',
'xticlabels2',
'yticlabels1',
'yticlabels2',
'xmtics1',
'xmtics2',
'ymtics1',
'ymtics2',
'datawc_x1',
'datawc_x2',
'datawc_y1',
'datawc_y2',
'boxfill_type',
'color_1',
'color_2',
'level_1',
'level_2',
'legend',
'boxfill_type',
'datawc_timeunits',
'datawc_calendar',
'_name',
'_xaxisconvert',
'_yaxisconvert',
'_levels',
'_fillareacolors',
'_fillareastyle',
'_fillareaindices',
'_fillareaopacity',
'_ext_1',
'_ext_2',
'_missing',
'_projection',
'_xticlabels1',
'_xticlabels2',
'_yticlabels1',
'_yticlabels2',
'_xmtics1',
'_xmtics2',
'_ymtics1',
'_ymtics2',
'_datawc_x1',
'_datawc_x2',
'_datawc_y1',
'_datawc_y2',
'_legend',
'_boxfill_type',
'_color_1',
'_color_2',
'_level_1',
'_level_2',
'_datawc_timeunits',
'_datawc_calendar',
'info',
]
colormap = VCS_validation_functions.colormap
# Removed from doc string
# box.levels(10, 90) # Will set them both
###########################################################################
# #
# Initialize the boxfill attributes. #
# #
###########################################################################
def __init__(self, Gfb_name=None, Gfb_name_src='default'):
# #
if isinstance(Gfb_name_src, Gfb):
Gfb_name_src = Gfb_name_src.name
if Gfb_name == "default" and Gfb_name_src != "default":
raise "You can not alter the 'default' boxfill method"
if Gfb_name in vcs.elements["boxfill"].keys():
raise Exception(
"Error boxfill method '%s' already exists" %
Gfb_name)
self._name = Gfb_name
self.g_name = 'Gfb'
if Gfb_name == "default":
self._projection = "linear"
self._xticlabels1 = "*"
self._xticlabels2 = "*"
self._xmtics1 = ""
self._xmtics2 = ""
self._yticlabels1 = "*"
self._yticlabels2 = "*"
self._ymtics1 = ""
self._ymtics2 = ""
self._datawc_y1 = 1.e20
self._datawc_y2 = 1.e20
self._datawc_x1 = 1.e20
self._datawc_x2 = 1.e20
# End Core Graphics Method attributes
self._xaxisconvert = "linear"
self._yaxisconvert = "linear"
self._ext_1 = False
self._ext_2 = False
self._missing = 1
self._fillareastyle = 'solid'
self._fillareaindices = [1, ]
self._fillareaopacity = []
self._fillareacolors = None
self._levels = ([1.e20, 1.e20])
self._level_1 = 1.e20
self._level_2 = 1.e20
self._color_1 = 16
self._color_2 = 239
self._boxfill_type = "linear"
self._datawc_timeunits = 'days since 2000'
self._datawc_calendar = cdtime.DefaultCalendar
self._legend = None
self._colormap = None
else:
src = vcs.elements["boxfill"][Gfb_name_src]
self._projection = src.projection
self._xticlabels1 = src.xticlabels1
self._xticlabels2 = src.xticlabels2
self._xmtics1 = src.xmtics1
self._xmtics2 = src.xmtics2
self._yticlabels1 = src.yticlabels1
self._yticlabels2 = src.yticlabels2
self._ymtics1 = src.ymtics1
self._ymtics2 = src.ymtics2
self._datawc_y1 = src.datawc_y1
self._datawc_y2 = src.datawc_y2
self._datawc_x1 = src.datawc_x1
self._datawc_x2 = src.datawc_x2
# End Core Graphics Method attributes
self._xaxisconvert = src.xaxisconvert
self._yaxisconvert = src.yaxisconvert
self._ext_1 = src.ext_1
self._ext_2 = src.ext_2
self._missing = src.missing
self._fillareastyle = src.fillareastyle
self._fillareaindices = src.fillareaindices
self._fillareacolors = src.fillareacolors
self._fillareaopacity = src.fillareaopacity
self._levels = src.levels
self._level_1 = src.level_1
self._level_2 = src.level_2
self._color_1 = src.color_1
self._color_2 = src.color_2
self._boxfill_type = src.boxfill_type
self._datawc_timeunits = src.datawc_timeunits
self._datawc_calendar = src.datawc_calendar
self._legend = src.legend
self._colormap = src.colormap
vcs.elements["boxfill"][Gfb_name] = self
###########################################################################
# #
# Set boxfill attributes. #
# #
###########################################################################
def _getcalendar(self):
return self._datawc_calendar
def _setcalendar(self, value):
value = VCS_validation_functions.checkCalendar(
self,
'datawc_calendar',
value)
self._datawc_calendar = value
datawc_calendar = property(_getcalendar, _setcalendar)
def _gettimeunits(self):
return self._datawc_timeunits
def _settimeunits(self, value):
value = VCS_validation_functions.checkTimeUnits(
self,
'datawc_timeunits',
value)
self._datawc_timeunits = value
datawc_timeunits = property(_gettimeunits, _settimeunits)
def _getboxfilltype(self):
return self._boxfill_type
def _setboxfilltype(self, value):
value = VCS_validation_functions.checkBoxfillType(
self,
'boxfill_type',
value)
self._boxfill_type = value
boxfill_type = property(_getboxfilltype, _setboxfilltype)
def _getlevel_1(self):
return self._level_1
def _setlevel_1(self, value):
value = VCS_validation_functions.checkIntFloat(self, 'level_1', value)
self._level_1 = value
level_1 = property(_getlevel_1, _setlevel_1)
def _getlevel_2(self):
return self._level_2
def _setlevel_2(self, value):
value = VCS_validation_functions.checkIntFloat(self, 'level_2', value)
self._level_2 = value
level_2 = property(_getlevel_2, _setlevel_2)
def _getcolor_1(self):
return self._color_1
def _setcolor_1(self, value):
value = VCS_validation_functions.checkColor(self, 'color_1', value)
self._color_1 = value
color_1 = property(_getcolor_1, _setcolor_1)
def _getcolor_2(self):
return self._color_2
def _setcolor_2(self, value):
value = VCS_validation_functions.checkColor(self, 'color_2', value)
self._color_2 = value
color_2 = property(_getcolor_2, _setcolor_2)
levels = VCS_validation_functions.levels
fillareacolors = VCS_validation_functions.fillareacolors
def _getfillareaindices(self):
return self._fillareaindices
def _setfillareaindices(self, value):
if value is not None:
value = VCS_validation_functions.checkIndicesList(
self,
'fillareaindices',
value)
self._fillareaindices = value
fillareaindices = property(_getfillareaindices, _setfillareaindices)
def _getfillareastyle(self):
return self._fillareastyle
def _setfillareastyle(self, value):
value = VCS_validation_functions.checkFillAreaStyle(
self,
'fillareastyle',
value)
self._fillareastyle = value
fillareastyle = property(_getfillareastyle, _setfillareastyle)
fillareaopacity = VCS_validation_functions.fillareaopacity
ext_1 = VCS_validation_functions.ext_1
ext_2 = VCS_validation_functions.ext_2
def _getmissing(self):
return self._missing
def _setmissing(self, value):
value = VCS_validation_functions.checkColor(self, 'missing', value)
self._missing = value
missing = property(_getmissing, _setmissing)
legend = VCS_validation_functions.legend
def _getname(self):
return self._name
def _setname(self, value):
value = VCS_validation_functions.checkname(self, 'name', value)
if value is not None:
self._name = value
name = property(_getname, _setname)
def _getxaxisconvert(self):
return self._xaxisconvert
def _setxaxisconvert(self, value):
value = VCS_validation_functions.checkAxisConvert(
self,
'xaxisconvert',
value)
self._xaxisconvert = value
xaxisconvert = property(_getxaxisconvert, _setxaxisconvert)
def _getyaxisconvert(self):
return self._yaxisconvert
def _setyaxisconvert(self, value):
value = VCS_validation_functions.checkAxisConvert(
self,
'yaxisconvert',
value)
self._yaxisconvert = value
yaxisconvert = property(_getyaxisconvert, _setyaxisconvert)
projection = VCS_validation_functions.projection
def _getxticlabels1(self):
return self._xticlabels1
def _setxticlabels1(self, value):
value = VCS_validation_functions.checkTicks(self, 'xticlabels1', value)
self._xticlabels1 = value
xticlabels1 = property(_getxticlabels1, _setxticlabels1)
def _getxticlabels2(self):
return self._xticlabels2
def _setxticlabels2(self, value):
value = VCS_validation_functions.checkTicks(self, 'xticlabels2', value)
self._xticlabels2 = value
xticlabels2 = property(_getxticlabels2, _setxticlabels2)
def _getyticlabels1(self):
return self._yticlabels1
def _setyticlabels1(self, value):
value = VCS_validation_functions.checkTicks(self, 'yticlabels1', value)
self._yticlabels1 = value
yticlabels1 = property(_getyticlabels1, _setyticlabels1)
def _getyticlabels2(self):
return self._yticlabels2
def _setyticlabels2(self, value):
value = VCS_validation_functions.checkTicks(self, 'yticlabels2', value)
self._yticlabels2 = value
yticlabels2 = property(_getyticlabels2, _setyticlabels2)
def _getxmtics1(self):
return self._xmtics1
def _setxmtics1(self, value):
value = VCS_validation_functions.checkTicks(self, 'xmtics1', value)
self._xmtics1 = value
xmtics1 = property(_getxmtics1, _setxmtics1)
def _getxmtics2(self):
return self._xmtics2
def _setxmtics2(self, value):
value = VCS_validation_functions.checkTicks(self, 'xmtics2', value)
self._xmtics2 = value
xmtics2 = property(_getxmtics2, _setxmtics2)
def _getymtics1(self):
return self._ymtics1
def _setymtics1(self, value):
value = VCS_validation_functions.checkTicks(self, 'ymtics1', value)
self._ymtics1 = value
ymtics1 = property(_getymtics1, _setymtics1)
def _getymtics2(self):
return self._ymtics2
def _setymtics2(self, value):
value = VCS_validation_functions.checkTicks(self, 'ymtics2', value)
self._ymtics2 = value
ymtics2 = property(_getymtics2, _setymtics2)
def _getdatawc_x1(self):
return self._datawc_x1
def _setdatawc_x1(self, value):
VCS_validation_functions.checkDatawc(self, 'datawc_x1', value)
self._datawc_x1 = value
datawc_x1 = property(_getdatawc_x1, _setdatawc_x1)
def _getdatawc_x2(self):
return self._datawc_x2
def _setdatawc_x2(self, value):
VCS_validation_functions.checkDatawc(self, 'datawc_x2', value)
self._datawc_x2 = value
datawc_x2 = property(_getdatawc_x2, _setdatawc_x2)
def _getdatawc_y1(self):
return self._datawc_y1
def _setdatawc_y1(self, value):
VCS_validation_functions.checkDatawc(self, 'datawc_y1', value)
self._datawc_y1 = value
datawc_y1 = property(_getdatawc_y1, _setdatawc_y1)
def _getdatawc_y2(self):
return self._datawc_y2
def _setdatawc_y2(self, value):
VCS_validation_functions.checkDatawc(self, 'datawc_y2', value)
self._datawc_y2 = value
datawc_y2 = property(_getdatawc_y2, _setdatawc_y2)
def colors(self, color1=16, color2=239):
"""
Sets the color_1 and color_2 properties of the object.
:param color1: Sets the color_1 value on the object
:type color1: int
:param color2: Sets the color_2 value on the object
:type color2: int
"""
self.color_1 = color1
self.color_2 = color2
#colors.__doc__ = xmldocs.colorsdoc
def exts(self, ext1='n', ext2='y'):
"""
Sets the ext_1 and ext_2 values on the object.
:param ext1: Sets the ext_1 value on the object. 'y' sets it to True, 'n' sets it to False.
:type ext1: str
:param ext2: Sets the ext_2 value on the object. 'y' sets it to True, 'n' sets it to False.
:type ext2: str
"""
self.ext_1 = ext1
self.ext_2 = ext2
#exts.__doc__ = xmldocs.extsdoc
#
# Doesn't make sense to inherit. This would mean more coding in C.
# I put this code back.
#
def xticlabels(self, xtl1='', xtl2=''):
"""
Sets xticlabels1 and xticlabels2 properties of the object.
:param xtl1: Sets the xticlabels1 property of the object.
:type xtl1: str
:param xtl2: Sets the xticlabels2 property of the object.
:type xtl2: str
"""
self.xticlabels1 = xtl1
self.xticlabels2 = xtl2
#xticlabels.__doc__ = xmldocs.xticlabelsdoc
def xmtics(self, xmt1='', xmt2=''):
"""
Sets xmtics1 and xmtics2 properties of the object.
:param xmt1: Sets the xmtics1 property of the object.
:type xmt1: str
:param xmt2: Sets the xmtics1 property of the object.
:type xmt2: str
"""
self.xmtics1 = xmt1
self.xmtics2 = xmt2
#xmtics.__doc__ = xmldocs.xmticsdoc
def yticlabels(self, ytl1='', ytl2=''):
"""
Sets yticlabels1 and yticlabels2 properties of the object.
:param ytl1: Sets yticlabels1 property of the object.
:type ytl1: str
:param ytl2: Sets yticlabels2 property of the object.
:type ytl2: str
"""
self.yticlabels1 = ytl1
self.yticlabels2 = ytl2
yticlabels.__doc__ = xmldocs.yticlabelsdoc
def ymtics(self, ymt1='', ymt2=''):
"""
Sets ymtics1 and ymtics2 properties of the object.
:param ymt1: Sets ymtics1 property of the object.
:type ymt1: str
:param ymt2: Sets ymtics2 property of the object.
:type ymt2: str
"""
self.ymtics1 = ymt1
self.ymtics2 = ymt2
#ymtics.__doc__ = xmldocs.ymticsdoc
def datawc(self, dsp1=1e20, dsp2=1e20, dsp3=1e20, dsp4=1e20):
"""
Sets datawc properties of the object.
:param dsp1: Sets the datawc_y1 property of the object.
:type dsp1: ???
:param dsp2: Sets the datawc_y2 property of the object.
:type dsp2: ???
:param dsp3: Sets the datawc_x1 property of the object.
:type dsp3: ???
:param dsp4: Sets the datawc_x2 property of the object.
:type dsp4: ???
"""
self.datawc_y1 = dsp1
self.datawc_y2 = dsp2
self.datawc_x1 = dsp3
self.datawc_x2 = dsp4
#datawc.__doc__ = xmldocs.datawcdoc
def xyscale(self, xat='linear', yat='linear'):
"""
Sets xaxisconvert and yaxisconvert properties of the object.
:param xat:
:type xat:
:param yat:
:type yat:
:returns:
:rtype:
"""
self.xaxisconvert = xat
self.yaxisconvert = yat
#xyscale.__doc__ = xmldocs.xyscaledoc
def getlevels(self, varmin, varmax):
if self.boxfill_type == "custom":
return self.levels
nlev = float(self.color_2 - self.color_1 + 1)
autolevels = False
if numpy.allclose(self.level_1, 1.e20) or numpy.allclose(self.level_2, 1.e20):
autolevels = True
low_end = varmin
high_end = varmax
else:
low_end = self.level_1
high_end = self.level_2
if self.boxfill_type == "log10":
low_end = numpy.ma.log10(low_end)
high_end = numpy.ma.log10(high_end)
if autolevels:
# Use nice values for the scale
scale = vcs.mkscale(low_end, high_end)
low_end = scale[0]
high_end = scale[-1]
dx = (high_end - low_end) / nlev
if dx == 0:
high_end += .00001
return [low_end, high_end]
float_epsilon = numpy.finfo(numpy.float32).eps
contourLevels = numpy.arange(low_end, high_end + float_epsilon, dx)
return contourLevels
def getlegendlabels(self, levels):
if self.legend:
return self.legend
if numpy.allclose(self.level_1, 1.e20) or numpy.allclose(self.level_2, 1.e20):
autolevels = True
else:
autolevels = False
if len(levels) > 12:
scale = vcs.mkscale(levels[0], levels[-1])
if autolevels:
return vcs.mklabels(scale)
else:
# Create our own scale
dx = (self.level_2 - self.level_1) / float(len(scale) - 1)
real_values = [self.level_1, self.level_2]
float_epsilon = numpy.finfo(numpy.float32).eps
levels = numpy.arange(levels[0], levels[-1] + float_epsilon, dx)
else:
real_values = levels
# Need to line up the levels and the labels, so we'll massage the label positions
max_round = 0
for l in real_values:
round_pos = 0
while numpy.round(l, round_pos) != l:
round_pos += 1
max_round = max(max_round, round_pos)
round_values = [numpy.round(l, round_pos) for l in levels]
round_labels = vcs.mklabels(round_values, "list")
return {lev: label for lev, label in zip(levels, round_labels)}
###########################################################################
# #
# List out boxfill graphics method members (attributes). #
# #
###########################################################################
def list(self):
""" Lists object values """
if (self.name == '__removed_from_VCS__'):
raise ValueError('This instance has been removed from VCS.')
print "", "----------Boxfill (Gfb) member (attribute) listings ----------"
print "graphics method =", self.g_name
print "name =", self.name
print "projection =", self.projection
print "xticlabels1 =", self.xticlabels1
print "xticlabels2 =", self.xticlabels2
print "xmtics1 =", self.xmtics1
print "xmtics2 =", self.xmtics2
print "yticlabels1 =", self.yticlabels1
print "yticlabels2 =", self.yticlabels2
print "ymtics1 = ", self.ymtics1
print "ymtics2 = ", self.ymtics2
print "datawc_x1 =", self.datawc_x1
print "datawc_y1 = ", self.datawc_y1
print "datawc_x2 = ", self.datawc_x2
print "datawc_y2 = ", self.datawc_y2
print "datawc_timeunits = ", self.datawc_timeunits
print "datawc_calendar = ", self.datawc_calendar
print "xaxisconvert = ", self.xaxisconvert
print "yaxisconvert = ", self.yaxisconvert
print "boxfill_type = ", self.boxfill_type
print "level_1 = ", self.level_1
print "level_2 = ", self.level_2
print "levels = ", self.levels
print "color_1 = ", self.color_1
print "color_2 = ", self.color_2
print "fillareacolors = ", self.fillareacolors
print "fillareastyle = ", self.fillareastyle
print "fillareaindices = ", self.fillareaindices
print "fillareaopacity = ", self.fillareaopacity
print "legend = ", self.legend
print "ext_1 = ", self.ext_1
print "ext_2 = ", self.ext_2
print "missing = ", self.missing
list.__doc__ = xmldocs.listdoc
###########################################################################
# #
# Script out primary boxfill graphics method in VCS to a file. #
# #
###########################################################################
def script(self, script_filename, mode='a'):
"""
%s
Saves out a boxfill graphics method in Python or VCS script form to a
designated file.
Note: If the the filename has a ".py" at the end, it will produce a
Python script. If the filename has a ".scr" at the end, it will
produce a VCS script. If neither extensions are give, then by
default a Python script will be produced.
:Example:
::
a=vcs.init()
box=a.createboxfill('temp')
# Append to a Python script named "filename.py"
box.script('filename.py')
# Append to a VCS script named "filename.scr"
box.script('filename.scr')
box.script('filename','w')
:param script_filename: Output name of the script file. If no extension is specified, a .json object is created.
:type script_filename: str
:param mode: Either 'w' for replace, or 'a' for append. Defaults to 'a', if not specified.
:type mode: str
:returns:
:rtype:
"""
if (script_filename is None):
raise ValueError(
'Error - Must provide an output script file name.')
if (mode is None):
mode = 'a'
elif (mode not in ('w', 'a')):
raise ValueError(
'Error - Mode can only be "w" for replace or "a" for append.')
# By default, save file in json
scr_type = script_filename.split(".")
if len(scr_type) == 1 or len(scr_type[-1]) > 5:
scr_type = "json"
if script_filename != "initial.attributes":
script_filename += ".json"
else:
scr_type = scr_type[-1]
if scr_type == '.scr':
raise DeprecationWarning("scr script are no longer generated")
elif scr_type == "py":
mode = mode + '+'
py_type = script_filename[
len(script_filename) -