Created
July 25, 2016 18:50
-
-
Save auxiliary/bc8f07f5cca4822ed74268a539c6c151 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#for isabel | |
import itertools | |
def set_annotation_attributes(): | |
# Logging for SetAnnotationObjectOptions is not implemented yet. | |
AnnotationAtts = AnnotationAttributes() | |
AnnotationAtts.axes2D.visible = 0 | |
AnnotationAtts.axes2D.autoSetTicks = 1 | |
AnnotationAtts.axes2D.autoSetScaling = 1 | |
AnnotationAtts.axes2D.lineWidth = 0 | |
AnnotationAtts.axes2D.tickLocation = AnnotationAtts.axes2D.Outside # Inside, Outside, Both | |
AnnotationAtts.axes2D.tickAxes = AnnotationAtts.axes2D.BottomLeft # Off, Bottom, Left, BottomLeft, All | |
AnnotationAtts.axes2D.xAxis.title.visible = 1 | |
AnnotationAtts.axes2D.xAxis.title.font.font = AnnotationAtts.axes2D.xAxis.title.font.Courier # Arial, Courier, Times | |
AnnotationAtts.axes2D.xAxis.title.font.scale = 1 | |
AnnotationAtts.axes2D.xAxis.title.font.useForegroundColor = 1 | |
AnnotationAtts.axes2D.xAxis.title.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes2D.xAxis.title.font.bold = 1 | |
AnnotationAtts.axes2D.xAxis.title.font.italic = 1 | |
AnnotationAtts.axes2D.xAxis.title.userTitle = 0 | |
AnnotationAtts.axes2D.xAxis.title.userUnits = 0 | |
AnnotationAtts.axes2D.xAxis.title.title = "X-Axis" | |
AnnotationAtts.axes2D.xAxis.title.units = "" | |
AnnotationAtts.axes2D.xAxis.label.visible = 1 | |
AnnotationAtts.axes2D.xAxis.label.font.font = AnnotationAtts.axes2D.xAxis.label.font.Courier # Arial, Courier, Times | |
AnnotationAtts.axes2D.xAxis.label.font.scale = 1 | |
AnnotationAtts.axes2D.xAxis.label.font.useForegroundColor = 1 | |
AnnotationAtts.axes2D.xAxis.label.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes2D.xAxis.label.font.bold = 1 | |
AnnotationAtts.axes2D.xAxis.label.font.italic = 1 | |
AnnotationAtts.axes2D.xAxis.label.scaling = 0 | |
AnnotationAtts.axes2D.xAxis.tickMarks.visible = 1 | |
AnnotationAtts.axes2D.xAxis.tickMarks.majorMinimum = 0 | |
AnnotationAtts.axes2D.xAxis.tickMarks.majorMaximum = 1 | |
AnnotationAtts.axes2D.xAxis.tickMarks.minorSpacing = 0.02 | |
AnnotationAtts.axes2D.xAxis.tickMarks.majorSpacing = 0.2 | |
AnnotationAtts.axes2D.xAxis.grid = 0 | |
AnnotationAtts.axes2D.yAxis.title.visible = 1 | |
AnnotationAtts.axes2D.yAxis.title.font.font = AnnotationAtts.axes2D.yAxis.title.font.Courier # Arial, Courier, Times | |
AnnotationAtts.axes2D.yAxis.title.font.scale = 1 | |
AnnotationAtts.axes2D.yAxis.title.font.useForegroundColor = 1 | |
AnnotationAtts.axes2D.yAxis.title.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes2D.yAxis.title.font.bold = 1 | |
AnnotationAtts.axes2D.yAxis.title.font.italic = 1 | |
AnnotationAtts.axes2D.yAxis.title.userTitle = 0 | |
AnnotationAtts.axes2D.yAxis.title.userUnits = 0 | |
AnnotationAtts.axes2D.yAxis.title.title = "Y-Axis" | |
AnnotationAtts.axes2D.yAxis.title.units = "" | |
AnnotationAtts.axes2D.yAxis.label.visible = 1 | |
AnnotationAtts.axes2D.yAxis.label.font.font = AnnotationAtts.axes2D.yAxis.label.font.Courier # Arial, Courier, Times | |
AnnotationAtts.axes2D.yAxis.label.font.scale = 1 | |
AnnotationAtts.axes2D.yAxis.label.font.useForegroundColor = 1 | |
AnnotationAtts.axes2D.yAxis.label.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes2D.yAxis.label.font.bold = 1 | |
AnnotationAtts.axes2D.yAxis.label.font.italic = 1 | |
AnnotationAtts.axes2D.yAxis.label.scaling = 0 | |
AnnotationAtts.axes2D.yAxis.tickMarks.visible = 1 | |
AnnotationAtts.axes2D.yAxis.tickMarks.majorMinimum = 0 | |
AnnotationAtts.axes2D.yAxis.tickMarks.majorMaximum = 1 | |
AnnotationAtts.axes2D.yAxis.tickMarks.minorSpacing = 0.02 | |
AnnotationAtts.axes2D.yAxis.tickMarks.majorSpacing = 0.2 | |
AnnotationAtts.axes2D.yAxis.grid = 0 | |
AnnotationAtts.axes3D.visible = 0 | |
AnnotationAtts.axes3D.autoSetTicks = 1 | |
AnnotationAtts.axes3D.autoSetScaling = 1 | |
AnnotationAtts.axes3D.lineWidth = 0 | |
AnnotationAtts.axes3D.tickLocation = AnnotationAtts.axes3D.Inside # Inside, Outside, Both | |
AnnotationAtts.axes3D.axesType = AnnotationAtts.axes3D.ClosestTriad # ClosestTriad, FurthestTriad, OutsideEdges, StaticTriad, StaticEdges | |
AnnotationAtts.axes3D.triadFlag = 0 | |
AnnotationAtts.axes3D.bboxFlag = 0 | |
AnnotationAtts.axes3D.xAxis.title.visible = 1 | |
AnnotationAtts.axes3D.xAxis.title.font.font = AnnotationAtts.axes3D.xAxis.title.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axes3D.xAxis.title.font.scale = 1 | |
AnnotationAtts.axes3D.xAxis.title.font.useForegroundColor = 1 | |
AnnotationAtts.axes3D.xAxis.title.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes3D.xAxis.title.font.bold = 0 | |
AnnotationAtts.axes3D.xAxis.title.font.italic = 0 | |
AnnotationAtts.axes3D.xAxis.title.userTitle = 0 | |
AnnotationAtts.axes3D.xAxis.title.userUnits = 0 | |
AnnotationAtts.axes3D.xAxis.title.title = "X-Axis" | |
AnnotationAtts.axes3D.xAxis.title.units = "" | |
AnnotationAtts.axes3D.xAxis.label.visible = 1 | |
AnnotationAtts.axes3D.xAxis.label.font.font = AnnotationAtts.axes3D.xAxis.label.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axes3D.xAxis.label.font.scale = 1 | |
AnnotationAtts.axes3D.xAxis.label.font.useForegroundColor = 1 | |
AnnotationAtts.axes3D.xAxis.label.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes3D.xAxis.label.font.bold = 0 | |
AnnotationAtts.axes3D.xAxis.label.font.italic = 0 | |
AnnotationAtts.axes3D.xAxis.label.scaling = 0 | |
AnnotationAtts.axes3D.xAxis.tickMarks.visible = 1 | |
AnnotationAtts.axes3D.xAxis.tickMarks.majorMinimum = 0 | |
AnnotationAtts.axes3D.xAxis.tickMarks.majorMaximum = 1 | |
AnnotationAtts.axes3D.xAxis.tickMarks.minorSpacing = 0.02 | |
AnnotationAtts.axes3D.xAxis.tickMarks.majorSpacing = 0.2 | |
AnnotationAtts.axes3D.xAxis.grid = 0 | |
AnnotationAtts.axes3D.yAxis.title.visible = 1 | |
AnnotationAtts.axes3D.yAxis.title.font.font = AnnotationAtts.axes3D.yAxis.title.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axes3D.yAxis.title.font.scale = 1 | |
AnnotationAtts.axes3D.yAxis.title.font.useForegroundColor = 1 | |
AnnotationAtts.axes3D.yAxis.title.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes3D.yAxis.title.font.bold = 0 | |
AnnotationAtts.axes3D.yAxis.title.font.italic = 0 | |
AnnotationAtts.axes3D.yAxis.title.userTitle = 0 | |
AnnotationAtts.axes3D.yAxis.title.userUnits = 0 | |
AnnotationAtts.axes3D.yAxis.title.title = "Y-Axis" | |
AnnotationAtts.axes3D.yAxis.title.units = "" | |
AnnotationAtts.axes3D.yAxis.label.visible = 1 | |
AnnotationAtts.axes3D.yAxis.label.font.font = AnnotationAtts.axes3D.yAxis.label.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axes3D.yAxis.label.font.scale = 1 | |
AnnotationAtts.axes3D.yAxis.label.font.useForegroundColor = 1 | |
AnnotationAtts.axes3D.yAxis.label.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes3D.yAxis.label.font.bold = 0 | |
AnnotationAtts.axes3D.yAxis.label.font.italic = 0 | |
AnnotationAtts.axes3D.yAxis.label.scaling = 0 | |
AnnotationAtts.axes3D.yAxis.tickMarks.visible = 1 | |
AnnotationAtts.axes3D.yAxis.tickMarks.majorMinimum = 0 | |
AnnotationAtts.axes3D.yAxis.tickMarks.majorMaximum = 1 | |
AnnotationAtts.axes3D.yAxis.tickMarks.minorSpacing = 0.02 | |
AnnotationAtts.axes3D.yAxis.tickMarks.majorSpacing = 0.2 | |
AnnotationAtts.axes3D.yAxis.grid = 0 | |
AnnotationAtts.axes3D.zAxis.title.visible = 1 | |
AnnotationAtts.axes3D.zAxis.title.font.font = AnnotationAtts.axes3D.zAxis.title.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axes3D.zAxis.title.font.scale = 1 | |
AnnotationAtts.axes3D.zAxis.title.font.useForegroundColor = 1 | |
AnnotationAtts.axes3D.zAxis.title.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes3D.zAxis.title.font.bold = 0 | |
AnnotationAtts.axes3D.zAxis.title.font.italic = 0 | |
AnnotationAtts.axes3D.zAxis.title.userTitle = 0 | |
AnnotationAtts.axes3D.zAxis.title.userUnits = 0 | |
AnnotationAtts.axes3D.zAxis.title.title = "Z-Axis" | |
AnnotationAtts.axes3D.zAxis.title.units = "" | |
AnnotationAtts.axes3D.zAxis.label.visible = 1 | |
AnnotationAtts.axes3D.zAxis.label.font.font = AnnotationAtts.axes3D.zAxis.label.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axes3D.zAxis.label.font.scale = 1 | |
AnnotationAtts.axes3D.zAxis.label.font.useForegroundColor = 1 | |
AnnotationAtts.axes3D.zAxis.label.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axes3D.zAxis.label.font.bold = 0 | |
AnnotationAtts.axes3D.zAxis.label.font.italic = 0 | |
AnnotationAtts.axes3D.zAxis.label.scaling = 0 | |
AnnotationAtts.axes3D.zAxis.tickMarks.visible = 1 | |
AnnotationAtts.axes3D.zAxis.tickMarks.majorMinimum = 0 | |
AnnotationAtts.axes3D.zAxis.tickMarks.majorMaximum = 1 | |
AnnotationAtts.axes3D.zAxis.tickMarks.minorSpacing = 0.02 | |
AnnotationAtts.axes3D.zAxis.tickMarks.majorSpacing = 0.2 | |
AnnotationAtts.axes3D.zAxis.grid = 0 | |
AnnotationAtts.axes3D.setBBoxLocation = 0 | |
AnnotationAtts.axes3D.bboxLocation = (0, 1, 0, 1, 0, 1) | |
AnnotationAtts.userInfoFlag = 0 | |
AnnotationAtts.userInfoFont.font = AnnotationAtts.userInfoFont.Arial # Arial, Courier, Times | |
AnnotationAtts.userInfoFont.scale = 1 | |
AnnotationAtts.userInfoFont.useForegroundColor = 1 | |
AnnotationAtts.userInfoFont.color = (0, 0, 0, 255) | |
AnnotationAtts.userInfoFont.bold = 0 | |
AnnotationAtts.userInfoFont.italic = 0 | |
AnnotationAtts.databaseInfoFlag = 0 | |
AnnotationAtts.timeInfoFlag = 1 | |
AnnotationAtts.databaseInfoFont.font = AnnotationAtts.databaseInfoFont.Arial # Arial, Courier, Times | |
AnnotationAtts.databaseInfoFont.scale = 1 | |
AnnotationAtts.databaseInfoFont.useForegroundColor = 1 | |
AnnotationAtts.databaseInfoFont.color = (0, 0, 0, 255) | |
AnnotationAtts.databaseInfoFont.bold = 0 | |
AnnotationAtts.databaseInfoFont.italic = 0 | |
AnnotationAtts.databaseInfoExpansionMode = AnnotationAtts.File # File, Directory, Full, Smart, SmartDirectory | |
AnnotationAtts.databaseInfoTimeScale = 1 | |
AnnotationAtts.databaseInfoTimeOffset = 0 | |
AnnotationAtts.legendInfoFlag = 0 | |
AnnotationAtts.backgroundColor = (255, 255, 255, 255) | |
AnnotationAtts.foregroundColor = (0, 0, 0, 255) | |
AnnotationAtts.gradientBackgroundStyle = AnnotationAtts.Radial # TopToBottom, BottomToTop, LeftToRight, RightToLeft, Radial | |
AnnotationAtts.gradientColor1 = (0, 0, 255, 255) | |
AnnotationAtts.gradientColor2 = (0, 0, 0, 255) | |
AnnotationAtts.backgroundMode = AnnotationAtts.Solid # Solid, Gradient, Image, ImageSphere | |
AnnotationAtts.backgroundImage = "" | |
AnnotationAtts.imageRepeatX = 1 | |
AnnotationAtts.imageRepeatY = 1 | |
AnnotationAtts.axesArray.visible = 1 | |
AnnotationAtts.axesArray.ticksVisible = 1 | |
AnnotationAtts.axesArray.autoSetTicks = 1 | |
AnnotationAtts.axesArray.autoSetScaling = 1 | |
AnnotationAtts.axesArray.lineWidth = 0 | |
AnnotationAtts.axesArray.axes.title.visible = 1 | |
AnnotationAtts.axesArray.axes.title.font.font = AnnotationAtts.axesArray.axes.title.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axesArray.axes.title.font.scale = 1 | |
AnnotationAtts.axesArray.axes.title.font.useForegroundColor = 1 | |
AnnotationAtts.axesArray.axes.title.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axesArray.axes.title.font.bold = 0 | |
AnnotationAtts.axesArray.axes.title.font.italic = 0 | |
AnnotationAtts.axesArray.axes.title.userTitle = 0 | |
AnnotationAtts.axesArray.axes.title.userUnits = 0 | |
AnnotationAtts.axesArray.axes.title.title = "" | |
AnnotationAtts.axesArray.axes.title.units = "" | |
AnnotationAtts.axesArray.axes.label.visible = 1 | |
AnnotationAtts.axesArray.axes.label.font.font = AnnotationAtts.axesArray.axes.label.font.Arial # Arial, Courier, Times | |
AnnotationAtts.axesArray.axes.label.font.scale = 1 | |
AnnotationAtts.axesArray.axes.label.font.useForegroundColor = 1 | |
AnnotationAtts.axesArray.axes.label.font.color = (0, 0, 0, 255) | |
AnnotationAtts.axesArray.axes.label.font.bold = 0 | |
AnnotationAtts.axesArray.axes.label.font.italic = 0 | |
AnnotationAtts.axesArray.axes.label.scaling = 0 | |
AnnotationAtts.axesArray.axes.tickMarks.visible = 1 | |
AnnotationAtts.axesArray.axes.tickMarks.majorMinimum = 0 | |
AnnotationAtts.axesArray.axes.tickMarks.majorMaximum = 1 | |
AnnotationAtts.axesArray.axes.tickMarks.minorSpacing = 0.02 | |
AnnotationAtts.axesArray.axes.tickMarks.majorSpacing = 0.2 | |
AnnotationAtts.axesArray.axes.grid = 0 | |
SetAnnotationAttributes(AnnotationAtts) | |
def get_attributes(): | |
View3DAtts = View3DAttributes() | |
View3DAtts.viewNormal = (-0.997008, 0.0142551, -0.0457759) | |
View3DAtts.focus = (49.5, 249.5, 249.5) | |
View3DAtts.viewUp = (0.120107, 0.999883, 0.00252661) | |
View3DAtts.viewAngle = 30 | |
View3DAtts.parallelScale = 356.301 | |
View3DAtts.nearPlane = -712.603 | |
View3DAtts.farPlane = 712.603 | |
View3DAtts.imagePan = (0, 0) | |
View3DAtts.imageZoom = 1.77 | |
View3DAtts.perspective = 1 | |
View3DAtts.eyeAngle = 2 | |
View3DAtts.centerOfRotationSet = 0 | |
View3DAtts.centerOfRotation = (49.5, 249.5, 249.5) | |
View3DAtts.axis3DScaleFlag = 0 | |
View3DAtts.axis3DScales = (1, 1, 1) | |
View3DAtts.shear = (0, 0, 1) | |
View3DAtts.windowValid = 1 | |
return View3DAtts | |
def set_save_attributes(filename, size): | |
SaveWindowAtts = SaveWindowAttributes() | |
SaveWindowAtts.outputToCurrentDirectory = 1 | |
# SaveWindowAtts.outputDirectory = output_dir | |
SaveWindowAtts.fileName = filename | |
SaveWindowAtts.family = 0 | |
SaveWindowAtts.format = SaveWindowAtts.PNG # BMP, CURVE, JPEG, OBJ, PNG, POSTSCRIPT, POVRAY, PPM, RGB, STL, TIFF, ULTRA, VTK, PLY | |
SaveWindowAtts.width = size[0] | |
SaveWindowAtts.height = size[1] | |
SaveWindowAtts.screenCapture = 0 | |
SaveWindowAtts.saveTiled = 0 | |
SaveWindowAtts.quality = 80 | |
SaveWindowAtts.progressive = 0 | |
SaveWindowAtts.binary = 0 | |
SaveWindowAtts.stereo = 0 | |
SaveWindowAtts.compression = SaveWindowAtts.PackBits # None, PackBits, Jpeg, Deflate | |
SaveWindowAtts.forceMerge = 0 | |
SaveWindowAtts.resConstraint = SaveWindowAtts.EqualWidthHeight # NoConstraint, EqualWidthHeight, ScreenProportions | |
SaveWindowAtts.advancedMultiWindowSave = 0 | |
SetSaveWindowAttributes(SaveWindowAtts) | |
def init_visit(db_name, size=None): | |
OpenDatabase(db_name, 0) | |
draw_all(size) | |
volume_atts = None | |
def draw_all(size=None): | |
global volume_atts | |
if size == None: | |
size = DEFAULT_SIZE | |
AddPlot("Volume", "PRECIP", 1, 1) | |
View3DAtts = get_attributes() | |
SetView3D(View3DAtts) | |
#AddOperator("Threshold", 1) | |
set_annotation_attributes() | |
set_save_attributes('temp_img.png', size) | |
volume_atts = GetPlotOptions() | |
#threshold_atts = ThresholdAttributes() | |
#volume_atts.opacityMode = volume_atts.GaussianMode | |
volume_atts.resampleTarget = 5000000 | |
volume_atts.rendererType = volume_atts.Texture3D | |
volume_atts.num3DSlices = 400 | |
#volume_atts.lowGradientLightingReduction = volume_atts.High | |
#volume_atts.samplesPerRay = 150 | |
volume_atts.SetColorControlPoints(GetColorTable( 'xray' )) | |
InvertBackgroundColor() | |
DrawPlots() | |
def ApplyFreeformTransferFunction(opacities): | |
global volume_atts | |
opacities = tuple(opacities) | |
volume_atts.SetFreeformOpacity(opacities) | |
SetPlotOptions(volume_atts) | |
def render(settings): | |
# Making this backward compatible with other parts of the code | |
filename = 'temp_img.png' | |
if type(settings) is dict: | |
if 'colormap' in settings: | |
volume_atts.SetColorControlPoints(GetColorTable( settings[ 'colormap' ])) | |
if 'filename' in settings: | |
filename = settings['filename'] | |
opacity_settings = settings['opacity'] | |
else: | |
opacity_settings = settings | |
opacities = list(itertools.chain.from_iterable([ [i]*8 for i in opacity_settings ])) | |
#opacities = smoothCurve(opacities, 10) | |
ApplyFreeformTransferFunction(opacities) | |
#set_save_attributes(filename, DEFAULT_SIZE) | |
SaveWindow() | |
init_visit('16.nc', (512, 512)) | |
set_save_attributes("temp_img.png", (512, 512)) | |
SetView3D(get_attributes()) | |
a = [3, 229, 192, 224, 227, 32, 0, 64, 160, 65, 169, 96, 186, 128, 71, 78, 128, 88, 192, 160, 96, 172, 0, 32, 175, 96, 32, 194, 224, 160, 224, 0] # for 13.png | |
render(a) | |
SaveWindow() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment