|
1 | 1 | gms = {} |
2 | 2 | import histograms |
| 3 | +import polar |
3 | 4 | import EzTemplate |
4 | 5 | import yxvsxfill |
5 | 6 | import continents |
| 7 | +import vcs |
| 8 | + |
6 | 9 |
|
7 | 10 | def createyxvsxfill(name=None,source='default',x=None,template=None): |
8 | 11 | return yxvsxfill.Gyf(name,source=source,x=x,template=template) |
| 12 | + |
| 13 | + |
9 | 14 | def createhistogram(name=None,source='default',x=None,template=None): |
10 | 15 | return histograms.Ghg(name,source=source,x=x,template=template) |
| 16 | + |
| 17 | + |
11 | 18 | def createusercontinents(name=None,source="default",x=None,template=None): |
12 | 19 | return continents.Guc(name,source=source,x=x,template=template) |
| 20 | + |
| 21 | + |
| 22 | +def createpolar(name=None, source="default", x=None, template=None): |
| 23 | + if "polar_oned" not in gms: |
| 24 | + init_polar() |
| 25 | + return polar.Gpo(name, source=source, x=x, template=template) |
| 26 | + |
| 27 | + |
| 28 | +def getpolar(name=None): |
| 29 | + if "polar_oned" not in gms: |
| 30 | + init_polar() |
| 31 | + if name in gms["polar_oned"]: |
| 32 | + return gms["polar_oned"][name] |
| 33 | + raise KeyError("No Polar GM exists with name '%s'" % name) |
| 34 | + |
| 35 | + |
| 36 | +def init_polar(): |
| 37 | + # Create nice polar template |
| 38 | + try: |
| 39 | + t = vcs.createtemplate("polar_oned") |
| 40 | + t.data.x1 = .2 |
| 41 | + t.data.x2 = .8 |
| 42 | + t.data.y1 = .2 |
| 43 | + t.data.y2 = .8 |
| 44 | + |
| 45 | + t.legend.x1 = .85 |
| 46 | + t.legend.x2 = 1 |
| 47 | + t.legend.y1 = .15 |
| 48 | + t.legend.y2 = .85 |
| 49 | + |
| 50 | + dash = vcs.createline() |
| 51 | + dash.type = "dash" |
| 52 | + dot = vcs.createline() |
| 53 | + dot.type = "dot" |
| 54 | + t.xtic1.line = dash |
| 55 | + t.ytic1.line = dot |
| 56 | + |
| 57 | + left_aligned = vcs.createtextorientation() |
| 58 | + left_aligned.halign = "left" |
| 59 | + left_aligned.valign = "half" |
| 60 | + t.legend.textorientation = left_aligned |
| 61 | + except vcs.vcsError: |
| 62 | + # Template already exists |
| 63 | + pass |
| 64 | + # Create some nice default polar GMs |
| 65 | + degree_polar = polar.Gpo("degrees", template="polar_oned") |
| 66 | + degree_polar.datawc_x1 = 0 |
| 67 | + degree_polar.datawc_x2 = 360 |
| 68 | + degree_polar.xticlabels1 = { |
| 69 | + i: str(i) for i in range(0, 360, 45) |
| 70 | + } |
| 71 | + |
| 72 | + clock_24 = polar.Gpo("diurnal", template="polar_oned") |
| 73 | + clock_24.datawc_x1 = 0 |
| 74 | + clock_24.datawc_x2 = 24 |
| 75 | + clock_24.clockwise = True |
| 76 | + # 6 AM on the right |
| 77 | + clock_24.theta_offset = -6 |
| 78 | + clock_24.xticlabels1 = { |
| 79 | + i: str(i) for i in range(0, 24, 3) |
| 80 | + } |
| 81 | + |
| 82 | + clock_24_meridiem = polar.Gpo("diurnal_12_hour", source="diurnal", template="polar_oned") |
| 83 | + clock_24_meridiem.xticlabels1 = { |
| 84 | + 0: "12 AM", |
| 85 | + 3: "3 AM", |
| 86 | + 6: "6 AM", |
| 87 | + 9: "9 AM", |
| 88 | + 12: "12 PM", |
| 89 | + 15: "3 PM", |
| 90 | + 18: "6 PM", |
| 91 | + 21: "9 PM" |
| 92 | + } |
| 93 | + |
| 94 | + clock_12 = polar.Gpo("semidiurnal", source="diurnal", template="polar_oned") |
| 95 | + clock_12.datawc_x2 = 12 |
| 96 | + clock_12.xticlabels1 = { |
| 97 | + i: str(i) for i in range(3, 13, 3) |
| 98 | + } |
| 99 | + # 3 on the right |
| 100 | + clock_12.theta_offset = -3 |
| 101 | + |
| 102 | + annual_cycle = polar.Gpo("annual_cycle", template="polar_oned") |
| 103 | + annual_cycle.datawc_x1 = 1 |
| 104 | + annual_cycle.datawc_x2 = 13 |
| 105 | + annual_cycle.clockwise = True |
| 106 | + annual_cycle.xticlabels1 = { |
| 107 | + 1: "Jan", |
| 108 | + 2: "Feb", |
| 109 | + 3: "Mar", |
| 110 | + 4: "Apr", |
| 111 | + 5: "May", |
| 112 | + 6: "Jun", |
| 113 | + 7: "Jul", |
| 114 | + 8: "Aug", |
| 115 | + 9: "Sep", |
| 116 | + 10: "Oct", |
| 117 | + 11: "Nov", |
| 118 | + 12: "Dec" |
| 119 | + } |
| 120 | + # Put December on the top |
| 121 | + annual_cycle.theta_offset = -2 |
| 122 | + |
| 123 | + seasonal = polar.Gpo("seasonal", template="polar_oned") |
| 124 | + seasonal.datawc_x1 = 0 |
| 125 | + seasonal.datawc_x2 = 4 |
| 126 | + seasonal.xticlabels1 = {0: "DJF", 1: "MAM", 2: "JJA", 3: "SON"} |
| 127 | + seasonal.clockwise = True |
| 128 | + # DJF on top |
| 129 | + seasonal.theta_offset = -1 |
0 commit comments