day-night.py 22.4 KB
Newer Older
1
2
3
4
# state file generated using paraview version 5.8.1-2374-gdd080cd

#### import the simple module from the paraview
from paraview.simple import *
5
import sys
6
7
8
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

9
10
11
12
13
14
print (sys.argv)


from argparse import ArgumentParser
import glob

15
def sphere_proj (lat, lon) :
Florian Ziemen's avatar
Florian Ziemen committed
16
    r = 1264.
17
18
19
20
21
22
23
    theta = (90 - lat) * pi / 180.
    phi = lon * pi / 180.
    z = r * cos (theta)
    x = r * sin(theta) * cos (phi)
    y = r * sin(theta) * sin (phi)
    return (x, y, z)

24
25
26
27
28
29
30
options = {}
def parse_args():
    '''Parses the command line arguments'''
    global options
    parser = ArgumentParser()
    parser.description = "Plot icon files"
    parser.add_argument("--clouds")
31
32
    parser.add_argument("--cloud_expr")
    parser.add_argument("--cloud_vars")
33
34
    parser.add_argument("--psl",)
    parser.add_argument("--light")
35
    parser.add_argument("--lonlat", nargs = 2, type=float)
Florian Ziemen's avatar
Florian Ziemen committed
36
    parser.add_argument("--output", "-o")
37
38
39
    op = parser.parse_args()
    options = vars(op)
    print (options)
40
41
42
    if not options.get("cloud_vars", False) :
        options["cloud_vars"] = "cloud"
    options["cloud_vars"] = options["cloud_vars"].split(",")
Florian Ziemen's avatar
Florian Ziemen committed
43
44
45
46

    if not options.get("output", False) :
        options["output"] = options["clouds"][:-3]

47
    print (options)
48
49
50
51
    return options

options=parse_args()

52
53
54



55
56
57
58
59
60
# ----------------------------------------------------------------
# setup views used in the visualization
# ----------------------------------------------------------------

# Create a new 'Light'
light1 = CreateLight()
61
light1.Intensity = 1.0
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
light1.Position = [50.0, -87.0, -28.6]

# Create a new 'Light'
light2 = CreateLight()
light2.Coords = 'Ambient'
light2.Intensity = 0.25
light2.Position = [0.0, -100.0, 0.0]
light2.DiffuseColor = [0.7529411764705882, 0.8196078431372549, 1.0]

# Create a new 'Light'
light3 = CreateLight()
light3.Enable = 0
light3.Position = [562.3115794309297, -528.4831081310286, 194.20829319495272]
light3.FocalPoint = [562.3058234478694, -528.4776977247036, 194.2062917442533]

# get the material library
materialLibrary1 = GetMaterialLibrary()

# create light
# create light
# create light
# Create a new 'Render View'
renderView1 = CreateView('RenderView')
85
renderView1.ViewSize = [1594, 1233]
86
87
88
89
90
renderView1.AxesGrid = 'GridAxes3DActor'
renderView1.OrientationAxesVisibility = 0
renderView1.KeyLightIntensity = 0.0
renderView1.StereoType = 'Crystal Eyes'
renderView1.CameraPosition = [1144.0024360966738, -682.5869061407763, 142.4868048724324]
Florian Ziemen's avatar
Florian Ziemen committed
91
renderView1.CameraViewUp = [0, 0., 1]
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
renderView1.CameraViewAngle = 20.0
renderView1.CameraFocalDisk = 1.0
renderView1.CameraParallelScale = 564.2333216713644
renderView1.EyeAngle = 1.0
renderView1.Background = [1.0, 1.0, 1.0]
renderView1.BackEnd = 'OSPRay raycaster'
renderView1.EnvironmentNorth = [0.0, 0.0, 0.0]
renderView1.AdditionalLights = [light1, light2, light3]
renderView1.OSPRayMaterialLibrary = materialLibrary1

SetActiveView(None)

# ----------------------------------------------------------------
# setup view layouts
# ----------------------------------------------------------------

# create new layout object 'Layout #1'
layout1 = CreateLayout(name='Layout #1')
layout1.AssignView(0, renderView1)
111
layout1.SetSize(1594, 1233)
112
113
114
115
116
117
118
119
120

# ----------------------------------------------------------------
# restore active view
SetActiveView(renderView1)
# ----------------------------------------------------------------

# ----------------------------------------------------------------
# setup the data processing pipelines
# ----------------------------------------------------------------
Florian Ziemen's avatar
Florian Ziemen committed
121
fn = options["clouds"]
122

123
124
125
if "UM" in options["clouds"] or "SAM" in options["clouds"] :
    if ":" in fn:
        files = fn.split(":")
Florian Ziemen's avatar
Florian Ziemen committed
126
127
128
129
        readers = [ NetCDFReader(registrationName='cloud_psl_%d'%n, FileName=[x]) for n, x in enumerate( files ) ]
        for x in readers:
            x.Dimensions = '(latitude, longitude)' 
            x.VerticalScale = 200.0
130
131
132
133
134
        cloud_psl = AppendAttributes(registrationName='cloud_psl', Input=readers )
    else:
        cloud_psl = NetCDFReader(registrationName='cloud_psl', FileName=[options["clouds"]])
        cloud_psl.Dimensions = '(latitude, longitude)'
        cloud_psl.VerticalScale = 200.0
135
else:
Florian Ziemen's avatar
Florian Ziemen committed
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
    if ":" in fn:
        files = fn.split(":")
        readers = [ CDIReader(registrationName='cloud_psl_%d'%n, FileNames=[x]) for n, x in enumerate( files ) ]
        for n, x in enumerate(readers):
            x.Dimensions = '(clon, clat, sfc)' 
            x.CellArrayStatus = [options['cloud_vars'][n]]
            x.SetProjection = 'Spherical Projection' 
            x.LayerThickness = 50 
        cloud_psl = AppendAttributes(registrationName='cloud_psl', Input=readers )

    else:
        # create a new 'CDIReader'
        cloud_psl = CDIReader(registrationName='cloud_psl', FileNames=[options["clouds"]])
        cloud_psl.Dimensions = '(clon, clat, sfc)'
        cloud_psl.CellArrayStatus = options['cloud_vars']
        cloud_psl.SetProjection = 'Spherical Projection'
        cloud_psl.LayerThickness = 50
153
154

if options.get("psl", False):
155
    print ("Getting psl", file=sys.stderr)
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
    psl = CDIReader(registrationName='psl', FileNames=[options["psl"]])
    psl.Dimensions = '(clon, clat, sfc)'
    psl.CellArrayStatus = ['psl']
    psl.SetProjection = 'Spherical Projection'
    psl.LayerThickness = 50
    psl.MaskingValueVar = 'psl'
    # create a new 'Cell Data to Point Data'
    psl_to_point = CellDatatoPointData(registrationName='psl_to_point', Input=psl)
    psl_to_point.ProcessAllArrays = 0
    psl_to_point.CellDataArraytoprocess = ['psl']

    # create a new 'Contour'
    psl_contour = Contour(registrationName='psl_contour', Input=psl_to_point)
    psl_contour.ContourBy = ['POINTS', 'psl']
    psl_contour.Isosurfaces = [99000.0, 100500.0, 102000.0, 103500.0]
    psl_contour.PointMergeMethod = 'Uniform Binning'
172
    print ("Done getting psl", file=sys.stderr)
173
174

# create a new 'NetCDF Time Annotation'
175
netCDFTimeAnnotation1 = NetCDFTimeAnnotation(registrationName='NetCDFTimeAnnotation1', Input=cloud_psl)
Florian Ziemen's avatar
Florian Ziemen committed
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
netCDFTimeAnnotation1.Expression = '"%02i-%02i-%02i %02i:%02i" % (Date[0], Date[1], Date[2], Date[3], Date[4])'

# show data in view
netCDFTimeAnnotation1Display = Show(netCDFTimeAnnotation1, renderView1, 'TextSourceRepresentation')


# Properties modified on netCDFTimeAnnotation1Display
netCDFTimeAnnotation1Display.FontSize = 96


# Properties modified on netCDFTimeAnnotation1

# Properties modified on netCDFTimeAnnotation1Display
netCDFTimeAnnotation1Display.FontFamily = 'Courier'



193

194
195
196
197
# create a new 'Calculator'
alpha = Calculator(registrationName='alpha', Input=cloud_psl)
alpha.AttributeType = 'Cell Data'
alpha.ResultArrayName = 'alpha'
198
199
200
201
cloud_expr = options.get("cloud_expr", False)
if not cloud_expr:
    cloud_expr = " ( 5* clivi + clwvi ) "
alpha.Function = ' (3/2 * {cloud_expr} *100)/ (3/2 * {cloud_expr} *100+7)'.format(cloud_expr=cloud_expr)
202

203
204

# create a new 'CDIReader'
Florian Ziemen's avatar
Florian Ziemen committed
205
print ("Getting light", file=sys.stderr)
206
207
208
209
210
211
212
rsdt_file = options["light"]
rsdt = CDIReader(registrationName='rsdt', FileNames=[rsdt_file])
rsdt.Dimensions = '(clon, clat, sfc)'
rsdt.CellArrayStatus = ['rsdt']
rsdt.SetProjection = 'Spherical Projection'
rsdt.LayerThickness = 50
rsdt.MaskingValueVar = 'rsdt'
Florian Ziemen's avatar
Florian Ziemen committed
213
214
print ("Done getting light", file=sys.stderr)
print ("Adjusting light", file=sys.stderr)
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
lightadjust = ProgrammableFilter(registrationName='light-adjust', Input=rsdt)
lightadjust.OutputDataSetType = 'vtkTable'
lightadjust.Script = """
import sys
sys.path.append ("/usr/local/Caskroom/miniconda/base/lib/python3.7/site-packages/")
from paraview.simple import GetActiveViewOrCreate, GetLight, AddLight

try:
    import cftime as ct
except:
    try:
        import netcdftime as ct
    except:
        print("Need the python cftime (or the older netcdftime) module for the NetCDFTimeAnnotation plugin!", file=sys.stderr)

import datetime as dt
import numpy as np

inp = self.GetInputDataObject(0,0)
currentTime = inp.GetInformation().Get(vtk.vtkDataObject.DATA_TIME_STEP())
sdate=vtk.vtkStringArray()
timeUnitsArray= inp.GetFieldData().GetAbstractArray("time_units")
if timeUnitsArray:
    timeUnits = timeUnitsArray.GetValue(0)
cdftime = ct.utime(timeUnits)
t = cdftime.num2date(currentTime)
first = ct.JulianDayFromDate(dt.datetime(t.year,1,1,0,0,0))
jd =  (ct.JulianDayFromDate(t) - first + 1)

angle = 23.45 *np.pi/180 * np.sin(2 * np.pi * (284 + jd ) /365.25)

time = jd-np.floor(jd)
x = - np.cos(time * 2 * np.pi)
y = np.sin(time * 2 * np.pi)
z = np.tan(angle)

print (jd, time, x, y , z)


renderView1 = GetActiveViewOrCreate(\'RenderView\')
# Create a new \'Light\'
light = GetLight(0, view=renderView1)
if light is None:
    light = AddLight(view=renderView1)
dist = 1e6
light.Position = [x*dist, y*dist, z*dist]
light.DiffuseColor = [1.0, 1.0, 1.0]"""
lightadjust.RequestInformationScript = ''
lightadjust.RequestUpdateExtentScript = ''
lightadjust.PythonPath = ''

# create a new 'Programmable Annotation'
dummylabel = ProgrammableAnnotation(registrationName='dummy-label', Input=lightadjust)
dummylabel.Script = """to = self.GetTableOutput()
arr = vtk.vtkStringArray()
arr.SetName("Text")
arr.SetNumberOfComponents(1)
arr.InsertNextValue("")
to.AddColumn(arr)"""
dummylabel.PythonPath = ''
dummylabelDisplay = Show(dummylabel, renderView1, 'TextSourceRepresentation')

Florian Ziemen's avatar
Florian Ziemen committed
277
print ("Done adjusting light", file=sys.stderr)
278

Florian Ziemen's avatar
Florian Ziemen committed
279
print ("Setting up textures", file=sys.stderr)
280
281
282
# create a new 'Texture Map to Sphere'
night = TextureMaptoSphere(registrationName='night', Input=rsdt)
night.PreventSeam = 0
283
284

# create a new 'Texture Map to Sphere'
285
286
day = TextureMaptoSphere(registrationName='day', Input=rsdt)
day.PreventSeam = 0
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

# ----------------------------------------------------------------
# setup the visualization in view 'renderView1'
# ----------------------------------------------------------------

# show data from day
dayDisplay = Show(day, renderView1, 'UnstructuredGridRepresentation')

# get separate color transfer function/color map for 'rsdt'
separate_dayDisplay_rsdtLUT = GetColorTransferFunction('rsdt', dayDisplay, separate=True)
separate_dayDisplay_rsdtLUT.AutomaticRescaleRangeMode = 'Never'
separate_dayDisplay_rsdtLUT.EnableOpacityMapping = 1
separate_dayDisplay_rsdtLUT.RGBPoints = [0.0, 1.0, 1.0, 1.0, 10.0, 1.0, 1.0, 1.0]
separate_dayDisplay_rsdtLUT.ScalarRangeInitialized = 1.0

# a texture
world2 = CreateTexture('/home/k/k202134/world.200408.3x5400x2700_for_pv.jpg')

# get separate opacity transfer function/opacity map for 'rsdt'
separate_dayDisplay_rsdtPWF = GetOpacityTransferFunction('rsdt', dayDisplay, separate=True)
separate_dayDisplay_rsdtPWF.Points = [0.0, 0.0, 0.5, 0.0, 10.0, 1.0, 0.5, 0.0]
separate_dayDisplay_rsdtPWF.ScalarRangeInitialized = 1

# trace defaults for the display properties.
dayDisplay.Representation = 'Surface'
dayDisplay.ColorArrayName = ['CELLS', 'rsdt']
dayDisplay.LookupTable = separate_dayDisplay_rsdtLUT
dayDisplay.SelectTCoordArray = 'Texture Coordinates'
dayDisplay.SelectNormalArray = 'None'
dayDisplay.SelectTangentArray = 'None'
dayDisplay.Texture = world2
dayDisplay.OSPRayScaleArray = 'Texture Coordinates'
dayDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
dayDisplay.SelectOrientationVectors = 'None'
dayDisplay.ScaleFactor = 40.0
dayDisplay.SelectScaleArray = 'None'
dayDisplay.GlyphType = 'Arrow'
dayDisplay.GlyphTableIndexArray = 'None'
dayDisplay.GaussianRadius = 2.0
dayDisplay.SetScaleArray = ['POINTS', 'Texture Coordinates']
dayDisplay.ScaleTransferFunction = 'PiecewiseFunction'
dayDisplay.OpacityArray = ['POINTS', 'Texture Coordinates']
dayDisplay.OpacityTransferFunction = 'PiecewiseFunction'
dayDisplay.DataAxesGrid = 'GridAxesRepresentation'
dayDisplay.PolarAxes = 'PolarAxesRepresentation'
dayDisplay.ScalarOpacityFunction = separate_dayDisplay_rsdtPWF
dayDisplay.ScalarOpacityUnitDistance = 2.329517136805135
dayDisplay.OpacityArrayName = ['POINTS', 'Texture Coordinates']
dayDisplay.BumpMapInputDataArray = [None, '']
dayDisplay.ExtrusionInputDataArray = ['POINTS', 'Texture Coordinates']
dayDisplay.SelectInputVectors = ['POINTS', 'Texture Coordinates']
dayDisplay.WriteLog = ''

# init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
dayDisplay.ScaleTransferFunction.Points = [4.875790182268247e-05, 0.0, 0.5, 0.0, 0.9999512434005737, 1.0, 0.5, 0.0]

# init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
dayDisplay.OpacityTransferFunction.Points = [4.875790182268247e-05, 0.0, 0.5, 0.0, 0.9999512434005737, 1.0, 0.5, 0.0]

# set separate color map
dayDisplay.UseSeparateColorMap = True

Florian Ziemen's avatar
Florian Ziemen committed
349
350
351
352
353

print ("Done setting up textures", file=sys.stderr)

print ("Activating clouds", file=sys.stderr)

354
355
# show data from alpha
alphaDisplay = Show(alpha, renderView1, 'UnstructuredGridRepresentation')
Florian Ziemen's avatar
Florian Ziemen committed
356
print ("Done activating clouds", file=sys.stderr)
357

Florian Ziemen's avatar
Florian Ziemen committed
358
print ("Setting up clouds", file=sys.stderr)
359
360
361
362
363
364
365
366
367
368
369
370
371
# get color transfer function/color map for 'alpha'
alphaLUT = GetColorTransferFunction('alpha')
alphaLUT.AutomaticRescaleRangeMode = 'Never'
alphaLUT.EnableOpacityMapping = 1
alphaLUT.RGBPoints = [0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
alphaLUT.ColorSpace = 'RGB'
alphaLUT.ScalarRangeInitialized = 1.0

# get opacity transfer function/opacity map for 'alpha'
alphaPWF = GetOpacityTransferFunction('alpha')
alphaPWF.ScalarRangeInitialized = 1

# trace defaults for the display properties.
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
alphaDisplay.Representation = 'Surface'
alphaDisplay.ColorArrayName = ['CELLS', 'alpha']
alphaDisplay.LookupTable = alphaLUT
alphaDisplay.SelectTCoordArray = 'None'
alphaDisplay.SelectNormalArray = 'None'
alphaDisplay.SelectTangentArray = 'None'
alphaDisplay.Scale = [1.001, 1.001, 1.001]
alphaDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
alphaDisplay.SelectOrientationVectors = 'None'
alphaDisplay.ScaleFactor = 40.0
alphaDisplay.SelectScaleArray = 'alpha'
alphaDisplay.GlyphType = 'Arrow'
alphaDisplay.GlyphTableIndexArray = 'alpha'
alphaDisplay.GaussianRadius = 2.0
alphaDisplay.SetScaleArray = [None, '']
alphaDisplay.ScaleTransferFunction = 'PiecewiseFunction'
alphaDisplay.OpacityArray = [None, '']
alphaDisplay.OpacityTransferFunction = 'PiecewiseFunction'
alphaDisplay.DataAxesGrid = 'GridAxesRepresentation'
alphaDisplay.PolarAxes = 'PolarAxesRepresentation'
alphaDisplay.ScalarOpacityFunction = alphaPWF
alphaDisplay.ScalarOpacityUnitDistance = 2.5123335565563587
alphaDisplay.OpacityArrayName = ['CELLS', 'alpha']
alphaDisplay.BumpMapInputDataArray = [None, '']
alphaDisplay.ExtrusionInputDataArray = ['CELLS', 'alpha']
alphaDisplay.SelectInputVectors = ['CELLS', 'alpha']
alphaDisplay.WriteLog = ''
399
400

# init the 'PolarAxesRepresentation' selected for 'PolarAxes'
401
alphaDisplay.PolarAxes.Scale = [1.001, 1.001, 1.001]
402

Florian Ziemen's avatar
Florian Ziemen committed
403
404
405
406
print ("Done setting up clouds", file=sys.stderr)

print ("Activating textures", file=sys.stderr)

407
408
409
410
411
412
413
414
415
416
417
# show data from night
nightDisplay = Show(night, renderView1, 'UnstructuredGridRepresentation')

# get color transfer function/color map for 'rsdt'
rsdtLUT = GetColorTransferFunction('rsdt')
rsdtLUT.AutomaticRescaleRangeMode = 'Never'
rsdtLUT.EnableOpacityMapping = 1
rsdtLUT.RGBPoints = [0.0, 1.0, 1.0, 1.0, 10.0, 1.0, 1.0, 1.0]
rsdtLUT.ScalarRangeInitialized = 1.0

# a texture
418
blackMarble_2016_3km_for_pv = CreateTexture('/home/k/k202134/Paraview/BlackMarble_2016_3km_for_pv-dark.png')
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

# get opacity transfer function/opacity map for 'rsdt'
rsdtPWF = GetOpacityTransferFunction('rsdt')
rsdtPWF.Points = [0.0, 1.0, 0.5, 0.0, 10.0, 0.0, 0.5, 0.0]
rsdtPWF.ScalarRangeInitialized = 1

# trace defaults for the display properties.
nightDisplay.Representation = 'Surface'
nightDisplay.ColorArrayName = ['CELLS', 'rsdt']
nightDisplay.LookupTable = rsdtLUT
nightDisplay.Specular = 0.99
nightDisplay.SpecularPower = 10.0
nightDisplay.Ambient = 0.33
nightDisplay.SelectTCoordArray = 'Texture Coordinates'
nightDisplay.SelectNormalArray = 'None'
nightDisplay.SelectTangentArray = 'None'
nightDisplay.Texture = blackMarble_2016_3km_for_pv
nightDisplay.OSPRayScaleArray = 'Texture Coordinates'
nightDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
nightDisplay.SelectOrientationVectors = 'None'
nightDisplay.ScaleFactor = 40.0
nightDisplay.SelectScaleArray = 'alpha'
nightDisplay.GlyphType = 'Arrow'
nightDisplay.GlyphTableIndexArray = 'alpha'
nightDisplay.GaussianRadius = 2.0
nightDisplay.SetScaleArray = ['POINTS', 'Texture Coordinates']
nightDisplay.ScaleTransferFunction = 'PiecewiseFunction'
nightDisplay.OpacityArray = ['POINTS', 'Texture Coordinates']
nightDisplay.OpacityTransferFunction = 'PiecewiseFunction'
nightDisplay.DataAxesGrid = 'GridAxesRepresentation'
nightDisplay.PolarAxes = 'PolarAxesRepresentation'
nightDisplay.ScalarOpacityFunction = rsdtPWF
nightDisplay.ScalarOpacityUnitDistance = 10.049316464272104
nightDisplay.OpacityArrayName = ['CELLS', 'alpha']
nightDisplay.BumpMapInputDataArray = [None, '']
nightDisplay.ExtrusionInputDataArray = ['CELLS', 'alpha']
nightDisplay.SelectInputVectors = ['POINTS', 'Texture Coordinates']
nightDisplay.WriteLog = ''

Florian Ziemen's avatar
Florian Ziemen committed
458
459
460
print ("Done activating textures", file=sys.stderr)


461
if options.get("psl", False):
462
    print ("Displaying psl", file=sys.stderr)
463
464
    # show data from psl_contour
    psl_contourDisplay = Show(psl_contour, renderView1, 'GeometryRepresentation')
465
    print ("... initialized ... ", file=sys.stderr)
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

    # get color transfer function/color map for 'psl'
    pslLUT = GetColorTransferFunction('psl')
    pslLUT.AutomaticRescaleRangeMode = 'Never'
    pslLUT.RGBPoints = [100000.0, 0.23137254902, 0.298039215686, 0.752941176471, 101250.0, 0.865, 0.865, 0.865, 102500.0, 0.705882352941, 0.0156862745098, 0.149019607843]
    pslLUT.ScalarRangeInitialized = 1.0

    # trace defaults for the display properties.
    psl_contourDisplay.Representation = 'Surface'
    psl_contourDisplay.ColorArrayName = ['POINTS', 'psl']
    psl_contourDisplay.LookupTable = pslLUT
    psl_contourDisplay.LineWidth = 4.0
    psl_contourDisplay.SelectTCoordArray = 'None'
    psl_contourDisplay.SelectNormalArray = 'None'
    psl_contourDisplay.SelectTangentArray = 'None'
    psl_contourDisplay.Scale = [1.001, 1.001, 1.001]
    psl_contourDisplay.OSPRayScaleArray = 'psl'
    psl_contourDisplay.OSPRayScaleFunction = 'PiecewiseFunction'
    psl_contourDisplay.SelectOrientationVectors = 'None'
    psl_contourDisplay.ScaleFactor = 39.99499206542969
    psl_contourDisplay.SelectScaleArray = 'psl'
    psl_contourDisplay.GlyphType = 'Arrow'
    psl_contourDisplay.GlyphTableIndexArray = 'psl'
    psl_contourDisplay.GaussianRadius = 1.9997496032714843
    psl_contourDisplay.SetScaleArray = ['POINTS', 'psl']
    psl_contourDisplay.ScaleTransferFunction = 'PiecewiseFunction'
    psl_contourDisplay.OpacityArray = ['POINTS', 'psl']
    psl_contourDisplay.OpacityTransferFunction = 'PiecewiseFunction'
    psl_contourDisplay.DataAxesGrid = 'GridAxesRepresentation'
    psl_contourDisplay.PolarAxes = 'PolarAxesRepresentation'
    psl_contourDisplay.BumpMapInputDataArray = ['POINTS', 'psl']
    psl_contourDisplay.ExtrusionInputDataArray = ['POINTS', 'psl']
    psl_contourDisplay.SelectInputVectors = ['POINTS', 'psl']
    psl_contourDisplay.WriteLog = ''

    # init the 'PiecewiseFunction' selected for 'ScaleTransferFunction'
    psl_contourDisplay.ScaleTransferFunction.Points = [99000.0, 0.0, 0.5, 0.0, 103500.0, 1.0, 0.5, 0.0]

    # init the 'PiecewiseFunction' selected for 'OpacityTransferFunction'
    psl_contourDisplay.OpacityTransferFunction.Points = [99000.0, 0.0, 0.5, 0.0, 103500.0, 1.0, 0.5, 0.0]

    # init the 'PolarAxesRepresentation' selected for 'PolarAxes'
    psl_contourDisplay.PolarAxes.Scale = [1.001, 1.001, 1.001]

    # ----------------------------------------------------------------
    # setup color maps and opacity mapes used in the visualization
    # note: the Get..() functions create a new object, if needed
    # ----------------------------------------------------------------

    # get opacity transfer function/opacity map for 'psl'
    pslPWF = GetOpacityTransferFunction('psl')
    pslPWF.Points = [100000.0, 0.0, 0.5, 0.0, 102500.0, 1.0, 0.5, 0.0]
    pslPWF.ScalarRangeInitialized = 1
519
    print ("Done displaying psl", file=sys.stderr)
520
521
522

# ----------------------------------------------------------------
# restore active source
Florian Ziemen's avatar
Florian Ziemen committed
523
SetActiveSource(rsdt)
524
525
526
# ----------------------------------------------------------------


527
528
529
530
if "SHiELD" in options["clouds"] :
    psl_contour.Isosurfaces = [ x / 100. for x in psl_contour.Isosurfaces ]
    pslLUT.RGBPoints = [1000.0, 0.23137254902, 0.298039215686, 0.752941176471, 1012.500, 0.865, 0.865, 0.865, 1025.0, 0.705882352941, 0.0156862745098, 0.149019607843]

Florian Ziemen's avatar
Florian Ziemen committed
531
    
532
if __name__ == '__main__':
533
534
    view = GetActiveView()

Florian Ziemen's avatar
Florian Ziemen committed
535
536
    oldpos = view.CameraPosition
    
537
538
539
540
541
542
543
544
545
546
547
548
    print ('in main', file=sys.stderr)
    reader=GetActiveSource()
    tsteps=reader.TimestepValues
    print ("Timesteps: ", ", ".join((str (x) for x in tsteps)))
    def genname(fn, n, atts):
        attstr = "_".join((x for x in atts if x))
        return "{fn}_{atts}_{n:03d}.png".format(fn=fn, n=n, atts=attstr)
    for n,t in enumerate (tsteps):
        print ("rendering for time %f"%t)
        view.ViewTime = t

        # generate extracts
Florian Ziemen's avatar
Florian Ziemen committed
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
        # renderView1.Background = [1.0, 1.0, 1.0]
        # SaveScreenshot(genname (options["output"], n, [ll_string, "white", "HD"]), renderView1, ImageResolution=[1920, 1080])
        # SaveScreenshot(genname (options["output"], n, [ll_string, "white", "4k"]), renderView1, ImageResolution=[3840, 2160])  # TransparentBackground=1
        # renderView1.Background = [0., 0., 0.]
        # SaveScreenshot(genname (options["output"], n, [ll_string, "black", "HD"]), renderView1, ImageResolution=[1920, 1080])
        # SaveScreenshot(genname (options["output"], n, [ll_string, "black", "4k"]), renderView1, ImageResolution=[3840, 2160])  # TransparentBackground=1
        # #
        # SaveScreenshot(genname (options["output"], n, [ll_string, "transparent", "HD"]), renderView1, ImageResolution=[1920, 1080], TransparentBackground=1)
        ll_string=""
        lonlat = [-30, 0]
        view.CameraPosition = sphere_proj(lon=lonlat[0], lat=lonlat[1])
        ll_string="%.0fN_%.0fE"%(lonlat[1],lonlat[0])
        view.CameraParallelScale = 120
        SaveScreenshot(genname (options["output"], n, [ll_string, "transparent", "4k"]), renderView1, ImageResolution=[3840, 2160], TransparentBackground=1)
        view.CameraPosition = oldpos
        ll_string=""            


        if options.get("lonlat", False ):
            lonlat = options["lonlat"]
            view.CameraPosition = sphere_proj(lon=lonlat[0], lat=lonlat[1])
            ll_string="%.0fN_%.0fE"%(lonlat[1],lonlat[0])
            view.CameraParallelScale = 120
            SaveScreenshot(genname (options["output"], n, [ll_string, "transparent", "4k"]), renderView1, ImageResolution=[3840, 2160], TransparentBackground=1)
            view.CameraPosition = oldpos
            ll_string=""            

576