-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaste-script.py
277 lines (251 loc) · 9.41 KB
/
paste-script.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
#To edit with Vim, use this
#:set tabstop=8 expandtab shiftwidth=4 softtabstop=4
##macOS paths on local machine
import os
import sys
import re
import numpy as np
import datetime
import calendar
#Which layers
which_layers = [1]
# Set the run name to label the images
mifiles = ["date_0717201512.nc"]
sfiles = ["date_07172015.txt"]
#The directory where the nc and txt files are located. The slash at the end of the directory name is required.
EPA_directory = "/Users/lllowe/visit-for-fvcom/"
Station_directory = "/Users/lllowe/visit-for-fvcom/"
Shapefile_directory = "Users/lllowe/visit-for-fvcom/"
#This is cut/paste from the original loop using 'i'
i = 0
EPA_database = EPA_directory + mifiles[i]
#IMGS_NAME = file_prefix_epa + "_Layer=" + str(LAYER)
STATIONS_NAME = Station_directory + sfiles[i]
CSMI_NAME = Station_directory + "csmi_" + sfiles[i]
LAYER = 1
url = mifiles[i]
#string reformatting thing
url = re.sub('\.nc','',url)
IMGS_NAME = url + "_Layer=" + str(LAYER)
#print(LAYER)
print(IMGS_NAME)
#Open file
OpenDatabase(EPA_database,0)
#Creates date/time stamp based on .nc file metadata
t_start = calendar.timegm(datetime.datetime(1858, 11, 17, 0, 0, 0).timetuple())
text2D_timestamp = CreateAnnotationObject("Text2D")
text2D_timestamp.position = (0.78,0.9)
text2D_timestamp.height = 0.020
m = GetMetaData(EPA_database)
istate = 0
tcur = m.times[istate]*86400. + t_start
ts = datetime.datetime.utcfromtimestamp(tcur).strftime('%m-%d-%Y %H:%M')
timestamp = ts
text2D_timestamp.text = timestamp
#Get metadata for database
m = GetMetaData(EPA_database)
#Annotations on 2D plot
AnnotationAtts = AnnotationAttributes()
AnnotationAtts.userInfoFlag = 0
AnnotationAtts.databaseInfoFlag = 0
AnnotationAtts.axes3D.triadFlag = 0
AnnotationAtts.legendInfoFlag = 1
AnnotationAtts.axes3D.visible = 0
#Black background
AnnotationAtts.backgroundColor = (0, 0, 0, 255)
#White foreground
AnnotationAtts.foregroundColor = (255, 255, 255, 255)
AnnotationAtts.backgroundMode = AnnotationAtts.Solid # Solid, Gradient, Image, ImageSphere
SetAnnotationAttributes(AnnotationAtts)
#Finished setting annotation
#Add pseudocolor plot and set attributes
PLOT_VAR = "TP"
AddPlot("Pseudocolor", PLOT_VAR, 1, 1)
SetActivePlots(0)
#Atts
PseudocolorAtts = PseudocolorAttributes()
PseudocolorAtts.minFlag = 1
PseudocolorAtts.maxFlag = 1
#If you change the colormap, change it in Scatter to be the same
PseudocolorAtts.skewFactor = 0.1
PseudocolorAtts.min = 0.002
PseudocolorAtts.max = 0.035
PseudocolorAtts.colorTableName = "turbo"
PseudocolorAtts.scaling = PseudocolorAtts.Skew # Linear, Log, Skew
PseudocolorAtts.legendFlag = 1
SetPlotOptions(PseudocolorAtts)
#SetAtts
DrawPlots()
#Format the legend
plotName = GetPlotList().GetPlots(0).plotName
legend = GetAnnotationObject(plotName)
legend.managePosition = 0
legend.position = (0.7,0.65)
legend.drawTitle=0
legend.drawMinMax = 0
legend.numberFormat = "%1.3f"
#Just one layer
TurnMaterialsOff()
layer_string = "Layer " + str(LAYER)
TurnMaterialsOn(layer_string)
DrawPlots()
#
# Begin spontaneous state
View3DAtts = View3DAttributes()
View3DAtts.viewNormal = (0, 0, 1)
View3DAtts.focus = (546981, 4.8567e+06, -135.085)
View3DAtts.viewUp = (0, 1, 0)
View3DAtts.viewAngle = 30
View3DAtts.parallelScale = 279685
View3DAtts.nearPlane = -559370
View3DAtts.farPlane = 559370
View3DAtts.imagePan = (-0.00968456, 0.142186)
View3DAtts.imageZoom = 11.3436
View3DAtts.perspective = 1
View3DAtts.eyeAngle = 2
View3DAtts.centerOfRotationSet = 0
View3DAtts.centerOfRotation = (546981, 4.8567e+06, -135.085)
View3DAtts.axis3DScaleFlag = 0
View3DAtts.axis3DScales = (1, 1, 1)
View3DAtts.shear = (0, 0, 1)
View3DAtts.windowValid = 1
SetView3D(View3DAtts)
# End spontaneous state
#Add 'shoreline', which is just model border
AddPlot("Subset", "Bathymetry_Mesh", 1, 1)
SetActivePlots(1)
SubsetAtts = SubsetAttributes()
SubsetAtts.colorType = SubsetAtts.ColorBySingleColor # ColorBySingleColor, ColorByMultipleColors, ColorByColorTable
SubsetAtts.legendFlag = 0
SubsetAtts.lineWidth = 2
SubsetAtts.singleColor = (0, 0, 0, 255)
SubsetAtts.subsetNames = ("Whole mesh (Bathymetry_Mesh)")
SubsetAtts.opacity = 1
SubsetAtts.wireframe = 1
SubsetAtts.pointType = SubsetAtts.Point # Box, Axis, Icosahedron, Octahedron, Tetrahedron, SphereGeometry, Point, Sphere
SubsetAtts.pointSizePixels = 2
SetPlotOptions(SubsetAtts)
DrawPlots()
#Add 'bathymetry', which is model depth contours
AddPlot("Contour", "h", 1, 1)
SetActivePlots(2)
ContourAtts = ContourAttributes()
ContourAtts.colorType = ContourAtts.ColorBySingleColor # ColorBySingleColor, ColorByMultipleColors, ColorByColorTable
ContourAtts.legendFlag = 0
ContourAtts.lineWidth = 1
ContourAtts.singleColor = (0, 0, 0, 255)
ContourAtts.contourValue = (10, 20, 30, 50)
ContourAtts.contourMethod = ContourAtts.Value # Level, Value, Percent
ContourAtts.scaling = ContourAtts.Linear # Linear, Log
ContourAtts.wireframe = 1
SetPlotOptions(ContourAtts)
DrawPlots()
##Add measured data points
#set file open defaults
plainTextOpenOptions = GetDefaultFileOpenOptions("PlainText")
plainTextOpenOptions['First row has variable names'] = 1
plainTextOpenOptions['Lines to skip at beginning of file'] = 0
plainTextOpenOptions['Column for X coordinate (or -1 for none)'] = 0
plainTextOpenOptions['Column for Y coordinate (or -1 for none)'] = 1
plainTextOpenOptions['Column for Z coordinate (or -1 for none)'] = 2
SetDefaultFileOpenOptions("PlainText", plainTextOpenOptions)
#River shapefile from Tom H.
OpenDatabase(Shapefile_directory + "Shapefiles/NHD_Sel_MI_Rivers_UTM16.shp", 0)
AddPlot("Mesh", "polylineZ", 1, 1)
DrawPlots()
#Make the lines thicker (lineWidth=5) and blue mesh color
MeshAtts = MeshAttributes()
MeshAtts.legendFlag = 0
MeshAtts.lineWidth = 5
MeshAtts.meshColor = (0, 0, 255, 255)
MeshAtts.meshColorSource = MeshAtts.MeshCustom # Foreground, MeshCustom, MeshRandom
MeshAtts.opaqueColorSource = MeshAtts.Background # Background, OpaqueCustom, OpaqueRandom
MeshAtts.opaqueMode = MeshAtts.Auto # Auto, On, Off
MeshAtts.pointSize = 0.05
MeshAtts.opaqueColor = (255, 255, 255, 255)
MeshAtts.smoothingLevel = MeshAtts.NONE # NONE, Fast, High
MeshAtts.pointSizeVarEnabled = 0
MeshAtts.pointSizeVar = "default"
MeshAtts.pointType = MeshAtts.Point # Box, Axis, Icosahedron, Octahedron, Tetrahedron, SphereGeometry, Point, Sphere
MeshAtts.showInternal = 0
MeshAtts.pointSizePixels = 2
MeshAtts.opacity = 1
SetPlotOptions(MeshAtts)
#It resets the view after the shape file thing, so recenter
# Begin spontaneous state
View3DAtts = View3DAttributes()
View3DAtts.viewNormal = (0, 0, 1)
View3DAtts.focus = (546981, 4.8567e+06, -135.085)
View3DAtts.viewUp = (0, 1, 0)
View3DAtts.viewAngle = 30
View3DAtts.parallelScale = 279685
View3DAtts.nearPlane = -559370
View3DAtts.farPlane = 559370
View3DAtts.imagePan = (-0.00968456, 0.142186)
View3DAtts.imageZoom = 11.3436
View3DAtts.perspective = 1
View3DAtts.eyeAngle = 2
View3DAtts.centerOfRotationSet = 0
View3DAtts.centerOfRotation = (546981, 4.8567e+06, -135.085)
View3DAtts.axis3DScaleFlag = 0
View3DAtts.axis3DScales = (1, 1, 1)
View3DAtts.shear = (0, 0, 1)
View3DAtts.windowValid = 1
SetView3D(View3DAtts)
# End spontaneous state
#open file, add plot
OpenDatabase(CSMI_NAME, 0)
AddPlot("Scatter", "TP", 1, 1)
ScatterAtts = ScatterAttributes()
ScatterAtts.var1 = "X"
ScatterAtts.var1Role = ScatterAtts.Coordinate0 # Coordinate0, Coordinate1, Coordinate2, Color, NONE
ScatterAtts.var1Scaling = ScatterAtts.Linear # Linear, Log, Skew
ScatterAtts.var2Role = ScatterAtts.Coordinate1 # Coordinate0, Coordinate1, Coordinate2, Color, NONE
ScatterAtts.var2 = "Y"
ScatterAtts.var2Scaling = ScatterAtts.Linear # Linear, Log, Skew
ScatterAtts.var3Role = ScatterAtts.Coordinate2 # Coordinate0, Coordinate1, Coordinate2, Color, NONE
ScatterAtts.var3 = "Z"
ScatterAtts.var4Role = ScatterAtts.Color # Coordinate0, Coordinate1, Coordinate2, Color, NONE
ScatterAtts.var4 = "TP"
ScatterAtts.var4MinFlag = 1
ScatterAtts.var4MaxFlag = 1
#If you change the colormap, change it in Pseudo to be the same
ScatterAtts.var4Min = 0.002
ScatterAtts.var4Max = 0.035
ScatterAtts.var4Scaling = ScatterAtts.Skew # Linear, Log, Skew
ScatterAtts.var4SkewFactor = 0.1
#Change size of marker here
ScatterAtts.pointSize = 600
ScatterAtts.pointSizePixels = 1
#Change type of marker here
ScatterAtts.pointType = ScatterAtts.Sphere # Box, Axis, Icosahedron, Octahedron, Tetrahedron, SphereGeometry, Point, Sphere
ScatterAtts.scaleCube = 0
ScatterAtts.colorType = ScatterAtts.ColorByColorTable # ColorByForegroundColor, ColorBySingleColor, ColorByColorTable
ScatterAtts.colorTableName = "turbo"
ScatterAtts.invertColorTable = 0
ScatterAtts.legendFlag = 0
SetPlotOptions(ScatterAtts)
DrawPlots()
#Save
SaveWindowAtts = SaveWindowAttributes()
SaveWindowAtts.outputToCurrentDirectory = 0
SaveWindowAtts.outputDirectory = IMGS_DIR
SaveWindowAtts.fileName = IMGS_NAME
SaveWindowAtts.family = 0
SaveWindowAtts.format = SaveWindowAtts.PNG # BMP, CURVE, JPEG, OBJ, PNG, POSTSCRIPT, POVRAY, PPM, RGB, STL, TIFF, ULTRA, VTK, PLY, EXR
SaveWindowAtts.width = 1024
SaveWindowAtts.height = 1024
SaveWindowAtts.screenCapture = 0
SaveWindowAtts.saveTiled = 0
SaveWindowAtts.quality = 80
SaveWindowAtts.progressive = 0
SaveWindowAtts.binary = 0
SaveWindowAtts.stereo = 0
SaveWindowAtts.compression = SaveWindowAtts.NONE # NONE, PackBits, Jpeg, Deflate, LZW
SaveWindowAtts.forceMerge = 0
SaveWindowAtts.resConstraint = SaveWindowAtts.NoConstraint # NoConstraint, EqualWidthHeight, ScreenProportions
SaveWindowAtts.pixelData = 1
SaveWindowAtts.opts.types = ()
SaveWindowAtts.opts.help = ""
SetSaveWindowAttributes(SaveWindowAtts)
SaveWindow()