Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paraview visualisation tool stand-alone #1499

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update finalanimation.py
New functions instead of comments
  • Loading branch information
olastrz authored Jan 10, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 53c032939f25239abed2949e9467fc9135bc0605
257 changes: 137 additions & 120 deletions examples/PySDM_examples/utils/finalanimation.py
Original file line number Diff line number Diff line change
@@ -19,7 +19,6 @@ def command_line_argument_parser_using_argparse(ap):
ap = argparse.ArgumentParser()
command_line_argument_parser_using_argparse(ap)


args = ap.parse_args()
sd_productspvd = OpenDataFile(args.product_path)
sd_attributespvd = OpenDataFile(args.attributes_path)
@@ -37,125 +36,143 @@ def command_line_argument_parser_using_argparse(ap):
sd_productspvdDisplay.SetRepresentationType('Surface With Edges')


# create a new 'Calculator'
calculator1 = Calculator(registrationName='Calculator1', Input=sd_attributespvd)
calculator1Display = Show(calculator1, renderView1, 'UnstructuredGridRepresentation')
calculator1Display.Representation = 'Surface'
calculator1.Function = '"relative fall velocity"*(-iHat)'
renderView1.Update()


# show and settings color bar legend
calculator1Display.SetScalarBarVisibility(renderView1, True)
scalarBar = GetScalarBar(effectiveradiusLUT, renderView1)
scalarBar.ComponentTitle = ""
scalarBar.Title = "effective radius [um]"


# create a new 'Glyph'
glyph1 = Glyph(registrationName='Glyph1', Input=calculator1,
GlyphType='Arrow')
glyph1Display = Show(glyph1, renderView1, 'GeometryRepresentation')
glyph1Display.Representation = 'Surface'
glyph1.ScaleArray = ['POINTS', 'relative fall velocity']
glyph1Display.SetScalarBarVisibility(renderView1, True)
glyph1.ScaleFactor = 100
renderView1.Update()


# create a new 'Calculator'
calculator2 = Calculator(registrationName='Calculator2', Input=sd_productspvd)
calculator2Display = Show(calculator2, renderView1, 'StructuredGridRepresentation')
calculator2.Function = 'cx*jHat+cy*iHat'
renderView1.Update()
ColorBy(calculator2Display, ('CELLS', 'Result', 'Magnitude'))
Hide(calculator2, renderView1)


# create a new 'Glyph'
glyph2 = Glyph(registrationName='Glyph2', Input=calculator2,
GlyphType='Arrow')
glyph2Display = Show(glyph2, renderView1, 'GeometryRepresentation')
glyph2Display.Representation = 'Surface'
glyph2.ScaleArray = ['CELLS', 'Result']
glyph2.ScaleFactor = 100
renderView1.Update()
ColorBy(glyph2Display, None)
HideScalarBarIfNotNeeded(effectiveradiusLUT, renderView1)


# apply presets, logscale, opacity, and update.
multiplicityLUT.ApplyPreset(args.multiplicity_preset, True)
if args.multiplicity_logscale:
multiplicityLUT.MapControlPointsToLogSpace()
multiplicityLUT.UseLogScale = 1
else:
multiplicityLUT.MapControlPointsToLinearSpace()
multiplicityLUT.UseLogScale = 0

effectiveradiusLUT.ApplyPreset(args.effectiveradius_preset, True)
if args.effectiveradius_logscale:
effectiveradiusLUT.MapControlPointsToLogSpace()
effectiveradiusLUT.UseLogScale = 1
else:
effectiveradiusLUT.MapControlPointsToLinearSpace()
effectiveradiusLUT.UseLogScale = 0

effectiveradiusLUT.NanColor = args.effectiveradius_nan_color

sd_productspvdDisplay.Opacity = args.sd_products_opacity
calculator1Display.Opacity = args.calculator1_opacity
sd_attributespvdDisplay.Opacity = args.sd_attributes_opacity

renderView1.Update()


# get layout
layout1 = GetLayout()
layout1.SetSize(1205, 739)


# set current camera placement
renderView1.InteractionMode = '2D'
renderView1.CameraPosition = [836.5045867211775, 677.8909274570431, -4098.0762113533165]
renderView1.CameraFocalPoint = [836.5045867211775, 677.8909274570431, 0.0]
renderView1.CameraViewUp = [1.0, 0.0, 0.0]
renderView1.CameraParallelScale = 1060.6601717798205


# axes settings
view = renderView1
view.ViewSize = [2000, 800]
view.Background = [1, 1, 1]
view.CenterAxesVisibility = True
view.OrientationAxesVisibility = True
axesGrid = view.AxesGrid
axesGrid.Visibility = True
axesGrid.XTitle = 'Z [m]'
axesGrid.YTitle = 'X [m]'

axesGrid.XAxisUseCustomLabels = True
axesGrid.XAxisLabels = [300, 600, 900, 1200]
axesGrid.YAxisUseCustomLabels = True
axesGrid.YAxisLabels = [300, 600, 900, 1200]

axesGrid.XTitleFontSize = 30
axesGrid.XLabelFontSize = 30
axesGrid.YTitleFontSize = 30
axesGrid.YLabelFontSize = 30

axesGrid.XTitleColor = [0, 0, 0]
axesGrid.XLabelColor = [0, 0, 0]
axesGrid.YTitleColor = [0, 0, 0]
axesGrid.YLabelColor = [0, 0, 0]
axesGrid.GridColor = [0.1, 0.1, 0.1]
renderView1.CenterAxesVisibility = False


# time annotation
time = AnnotateTimeFilter(guiName = "AnnotateTimeFilter1", Format = 'Time:{time:f}s')
repr = Show(time, view)
renderView1.Update()
def create_new_calculator(registrationame, input, index, representation, function, color_by1, color_by2, color_by3, scalar_coloring = False, hide = False):
calculator = Calculator(registrationName=registrationame, Input=input)
variable_name = f"calculator{index}Display"
display = globals()[variable_name] = Show(calculator, renderView1, representation)
calculator.Function = function
renderView1.Update()
if scalar_coloring == True:
ColorBy(display, (color_by1, color_by2, color_by3))
else:
None
if hide == True:
Hide(calculator, renderView1)
else:
None

calculator1 = create_new_calculator('Calculator1', sd_attributespvd, 1, 'UnstructuredGridRepresentation', '"relative fall velocity"*(-iHat)', 'None', 'None', 'None')


def color_bar_legend():
calculator1Display.SetScalarBarVisibility(renderView1, True)
scalarBar = GetScalarBar(effectiveradiusLUT, renderView1)
scalarBar.ComponentTitle = ""
scalarBar.Title = "effective radius [um]"
renderView1.Update()

color_bar_legend()


def create_glyph(registration_name, input, scale_array1, scale_array2, scalarbar = True, color_by = False):
glyph = Glyph(registrationName=registration_name, Input=input,
GlyphType='Arrow')
glyphDisplay = Show(glyph, renderView1, 'GeometryRepresentation')
glyphDisplay.Representation = 'Surface'
glyph.ScaleArray = [scale_array1, scale_array2]
glyph.ScaleFactor = 100
if scalarbar == True:
glyphDisplay.SetScalarBarVisibility(renderView1, True)
else:
glyphDisplay.SetScalarBarVisibility(renderView1, False)
if color_by == True:
ColorBy(glyphDisplay, None)
else:
None
renderView1.Update()

glyph1 = create_glyph('Glyph1', calculator1, 'POINTS', 'relative fall velocity')

calculator2 = create_new_calculator('Calculator2', sd_productspvd, 2, 'StructuredGridRepresentation', 'cx*jHat+cy*iHat', 'CELLS', 'Result', 'Magnitude', True, True)

glyph2 = create_glyph('Glyph2', calculator2, 'CELLS', 'Result', False, True)


def apply_presets_logscale_opacity_and_update():
multiplicityLUT.ApplyPreset(args.multiplicity_preset, True)
if args.multiplicity_logscale:
multiplicityLUT.MapControlPointsToLogSpace()
multiplicityLUT.UseLogScale = 1
else:
multiplicityLUT.MapControlPointsToLinearSpace()
multiplicityLUT.UseLogScale = 0

effectiveradiusLUT.ApplyPreset(args.effectiveradius_preset, True)
if args.effectiveradius_logscale:
effectiveradiusLUT.MapControlPointsToLogSpace()
effectiveradiusLUT.UseLogScale = 1
else:
effectiveradiusLUT.MapControlPointsToLinearSpace()
effectiveradiusLUT.UseLogScale = 0

effectiveradiusLUT.NanColor = args.effectiveradius_nan_color

sd_productspvdDisplay.Opacity = args.sd_products_opacity
calculator1Display.Opacity = args.calculator1_opacity
sd_attributespvdDisplay.Opacity = args.sd_attributes_opacity

renderView1.Update()

apply_presets_logscale_opacity_and_update()


def get_layout():
layout1 = GetLayout()
layout1.SetSize(1205, 739)
renderView1.Update()

get_layout()


def set_current_camera_placement():
renderView1.InteractionMode = '2D'
renderView1.CameraPosition = [836.5045867211775, 677.8909274570431, -4098.0762113533165]
renderView1.CameraFocalPoint = [836.5045867211775, 677.8909274570431, 0.0]
renderView1.CameraViewUp = [1.0, 0.0, 0.0]
renderView1.CameraParallelScale = 1060.6601717798205
renderView1.Update()

set_current_camera_placement()


def axes_settings():
view = renderView1
view.ViewSize = [2000, 800]
view.Background = [1, 1, 1]
view.CenterAxesVisibility = True
view.OrientationAxesVisibility = True
axesGrid = view.AxesGrid
axesGrid.Visibility = True
axesGrid.XTitle = 'Z [m]'
axesGrid.YTitle = 'X [m]'

axesGrid.XAxisUseCustomLabels = True
axesGrid.XAxisLabels = [300, 600, 900, 1200]
axesGrid.YAxisUseCustomLabels = True
axesGrid.YAxisLabels = [300, 600, 900, 1200]

axesGrid.XTitleFontSize = 30
axesGrid.XLabelFontSize = 30
axesGrid.YTitleFontSize = 30
axesGrid.YLabelFontSize = 30

axesGrid.XTitleColor = [0, 0, 0]
axesGrid.XLabelColor = [0, 0, 0]
axesGrid.YTitleColor = [0, 0, 0]
axesGrid.YLabelColor = [0, 0, 0]
axesGrid.GridColor = [0.1, 0.1, 0.1]
renderView1.CenterAxesVisibility = False
renderView1.Update()

axes_settings()


def time_annotation():
time = AnnotateTimeFilter(guiName = "AnnotateTimeFilter1", Format = 'Time:{time:f}s')
repr = Show(time, view)
renderView1.Update()

time_annotation()


# save animation to an Ogg Vorbis file