Commit 65a15b90 authored by langurmonkey's avatar langurmonkey

feat: jython to py4j works fully with all tests

Migration from Jython to Py4J is now complete. All tests and showcase scripts run. For more details, see the [scripting documentation](http://gaia.ari.uni-heidelberg.de/gaiasky/docs/html/latest/Scripting-with-python.html) or the [original gitlab issue](#286)

Fixes #286
parent f45aea56
Pipeline #51866795 passed with stage
in 2 minutes and 47 seconds
# Tour through the asteroids
from py4j.java_gateway import JavaGateway, GatewayParameters
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
# Camera params
gs.setCameraSpeed(1.0)
gs.setRotationCameraSpeed(1.0)
gs.setTurningCameraSpeed(1.0)
gs.setCinematicCamera(True)
gs.setFov(65.0)
# Visibility
gs.setVisibility("element.planets", True)
gs.setVisibility("element.atmospheres", True)
gs.setVisibility("element.stars", True)
gs.setVisibility("element.moons", True)
gs.setVisibility("element.satellites", True)
gs.setVisibility("element.galaxies", True)
gs.setVisibility("element.milkyway", True)
gs.setVisibility("element.asteroids", False)
gs.setVisibility("element.orbits", False)
gs.setVisibility("element.labels", False)
gs.setVisibility("element.constellations", False)
gs.setVisibility("element.boundaries", False)
gs.setVisibility("element.equatorial", False)
gs.setVisibility("element.ecliptic", False)
gs.setVisibility("element.galactic", False)
gs.setVisibility("element.clusters", False)
gs.setVisibility("element.meshes", False)
gs.setVisibility("element.titles", False)
gs.setCrosshairVisibility(False)
# Parallel view
gs.setStereoscopicProfile(3)
gs.setStereoscopicMode(True)
gs.configureFrameOutput(1920, 1080, 30, "/home/tsagrista/.gaiasky/frames/3d-asteroids_tour/", "gs")
stdwait = 5.0
stdwaitlong = 10.0
# Time
gs.stopSimulationTime()
gs.setSimulationTime(2018, 4, 25, 10, 0, 0, 0)
# Camera state
gs.setCameraPosition([-1294.3864339045447 * 1e6,156.30069319755347 * 1e6,-1150.2743059128413 * 1e6])
gs.setCameraDirection([0.739144930622408,-0.09348275378626529,0.6670275453680645])
gs.setCameraUp([-0.1374839626900124,0.9485312542098752,0.2852834025843425])
gs.setCameraFocus("Sol")
gs.sleep(stdwait)
# Uncomment next line to save still frames
#gs.setFrameOutput(True)
gs.sleep(stdwait)
# Enable orbits
gs.setVisibility("element.orbits", True)
gs.sleep(stdwait)
gs.setVisibility("element.asteroids", True)
gs.sleep(stdwait)
gs.goToObject("Sol", 0.05, 0.0)
gs.cameraRotate(0.5, 0.0)
gs.sleep(stdwaitlong)
gs.cameraStop()
gs.setVisibility("element.orbits", False)
gs.sleep(stdwait)
gs.startSimulationTime()
initime = 4000.0
endtime = 4000000.0
def frange(x, y, jump):
while x < y:
yield x
x += jump
# 10 seconds, in steps of 0.1 is 100 steps
step = (endtime - initime) / 200.0
gs.setSimulationPace(initime)
for t in frange(initime, endtime, step):
gs.setSimulationPace(t)
gs.sleep(0.05)
gs.cameraStop()
gs.sleep(stdwait)
gs.cameraRotate(0.0, 0.1)
gs.sleep(stdwaitlong)
gs.cameraRotate(0.0, -0.9)
gs.goToObject("Sol", 0.01, 0.0)
gs.stopSimulationTime()
gs.cameraStop()
gs.setFrameOutput(False)
gs.setStereoscopicMode(False)
gateway.close()
# Tour through the asteroids
from py4j.java_gateway import JavaGateway, GatewayParameters
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
# Camera params
gs.setCameraSpeed(1.0)
gs.setRotationCameraSpeed(1.0)
gs.setTurningCameraSpeed(1.0)
gs.setCinematicCamera(True)
gs.setFov(65.0)
# Visibility
gs.setVisibility("element.planets", True)
gs.setVisibility("element.atmospheres", True)
gs.setVisibility("element.stars", True)
gs.setVisibility("element.moons", True)
gs.setVisibility("element.satellites", True)
gs.setVisibility("element.galaxies", True)
gs.setVisibility("element.milkyway", True)
gs.setVisibility("element.asteroids", False)
gs.setVisibility("element.orbits", False)
gs.setVisibility("element.labels", False)
gs.setVisibility("element.constellations", False)
gs.setVisibility("element.boundaries", False)
gs.setVisibility("element.equatorial", False)
gs.setVisibility("element.ecliptic", False)
gs.setVisibility("element.galactic", False)
gs.setVisibility("element.clusters", False)
gs.setVisibility("element.meshes", False)
gs.setVisibility("element.titles", False)
gs.setCrosshairVisibility(False)
# Parallel view
gs.configureFrameOutput(1920, 1080, 30, "~/.local/share/gaiasky/frames/3d-asteroids_tour/", "gs")
stdwait = 5.0
stdwaitlong = 10.0
# Time
gs.stopSimulationTime()
gs.setSimulationTime(2018, 4, 25, 10, 0, 0, 0)
# Camera state
gs.setCameraPosition([-1294.3864339045447 * 1e6,156.30069319755347 * 1e6,-1150.2743059128413 * 1e6])
gs.setCameraDirection([0.739144930622408,-0.09348275378626529,0.6670275453680645])
gs.setCameraUp([-0.1374839626900124,0.9485312542098752,0.2852834025843425])
gs.setCameraFocus("Sol")
gs.sleep(stdwait)
# Uncomment next line to save still frames
#gs.setFrameOutput(True)
gs.sleep(stdwait)
# Enable orbits
gs.setVisibility("element.orbits", True)
gs.sleep(stdwait)
gs.setVisibility("element.asteroids", True)
gs.sleep(stdwait)
gs.goToObject("Sol", 0.05, 0.0)
gs.cameraRotate(0.5, 0.0)
gs.sleep(stdwaitlong)
gs.cameraStop()
gs.setVisibility("element.orbits", False)
gs.sleep(stdwait)
gs.startSimulationTime()
initime = 4000.0
endtime = 4000000.0
def frange(x, y, jump):
while x < y:
yield x
x += jump
# 10 seconds, in steps of 0.1 is 100 steps
step = (endtime - initime) / 200.0
gs.setSimulationPace(initime)
for t in frange(initime, endtime, step):
gs.setSimulationPace(t)
gs.sleep(0.05)
gs.cameraStop()
gs.sleep(stdwait)
gs.cameraRotate(0.0, 0.1)
gs.sleep(stdwaitlong)
gs.cameraRotate(0.0, -0.9)
gs.goToObject("Sol", 0.01, 0.0)
gs.stopSimulationTime()
gs.cameraStop()
gs.setFrameOutput(False)
gateway.close()
......@@ -3,9 +3,10 @@
## a zoom out of the galaxy
##
from py4j.java_gateway import JavaGateway
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = JavaGateway().entry_point
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
## PREPPING
......@@ -162,3 +163,6 @@ gs.setSaturationLevel(1.0)
gs.setVisibility('element.planets',True)
gs.setVisibility('element.moons',True)
# close gateway
gateway.close()
......@@ -7,60 +7,70 @@
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from java.lang import Runnable
from py4j.java_gateway import JavaGateway, GatewayParameters, CallbackServerParameters
class LineUpdaterRunnable(Runnable):
class LineUpdaterRunnable(object):
def __init__(self, polyline):
self.polyline = polyline
def run(self):
earthp = gs.getObjectPosition("Earth")
moonp = gs.getObjectPosition("Moon")
pl = self.polyline.getPolyline()
pl.x.set(0, earthp[0])
pl.y.set(0, earthp[1])
pl.z.set(0, earthp[2])
pl.x.set(1, moonp[0])
pl.y.set(1, moonp[1])
pl.z.set(1, moonp[2])
pl = self.polyline.getPointCloud()
pl.setX(0, earthp[0])
pl.setY(0, earthp[1])
pl.setZ(0, earthp[2])
pl.setX(1, moonp[0])
pl.setY(1, moonp[1])
pl.setZ(1, moonp[2])
self.polyline.markForUpdate()
gs = EventScriptingInterface.instance()
def toString():
return "line-update-runnable"
class Java:
implements = ["java.lang.Runnable"]
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True),
callback_server_parameters=CallbackServerParameters())
gs = gateway.entry_point
gs.cameraStop()
gs.stopSimulationTime()
gs.setVisibility("element.orbits", True)
gs.setCameraLock(True)
gs.setFov(49)
gs.goToObject("Earth", 91.38e-2)
gs.print("We will now add a line between the Earth and Moon")
gs.sleep(2)
print("We will now add a line between the Earth and Moon")
earthp = gs.getObjectPosition("Earth")
moonp = gs.getObjectPosition("Moon")
gs.addPolyline("line-em", earthp + moonp, [ 1., .2, .2, .8 ], 1 )
gs.addPolyline("line-em", [earthp[0], earthp[1], earthp[2], moonp[0], moonp[1], moonp[2]], [ 1., .2, .2, .8 ], 1 )
gs.sleep(1.0)
gs.sleep(0.5)
# create line
line_em = gs.getObject("line-em")
# park the line updater
gs.parkRunnable("line-updater", LineUpdaterRunnable(line_em))
gs.setSimulationPace(65536.0)
gs.setSimulationPace(1e5)
gs.startSimulationTime()
gs.sleep(30)
gs.sleep(20)
gs.stopSimulationTime()
gs.print("Cleaning up and ending")
# clean up and finish
print("Cleaning up and ending")
gs.unparkRunnable("line-updater")
gs.removeModelObject("line-em")
......@@ -68,3 +78,7 @@ gs.cameraStop()
gs.maximizeInterfaceWindow()
gs.enableInput()
# close connection
gateway.close()
# This script tests adding and removing polylines.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -37,3 +37,5 @@ gs.cameraStop()
gs.maximizeInterfaceWindow()
gs.enableInput()
gateway.close()
# This script tests the positioning of the camera with relation to two objects.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -32,3 +32,5 @@ gs.sleep(3)
gs.enableInput()
gateway.close()
# This script tests the synchronous camera file playing.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
import time
import time, os
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
# Prints to both Gaia Sky and Python logs
def printall(string):
# print to gaia sky log
gs.print(string)
# print to python log
print(string)
gs.disableInput()
gs.cameraStop()
gs.minimizeInterfaceWindow()
fname = "/home/tsagrista/.gaiasky/script/camera-path-test.gsc"
gs.print("(1/2) Starting synchronous camera file execution: %s" % fname)
fname = os.path.abspath("./camera-path-test.gsc")
printall("(1/2) Starting synchronous camera file execution: %s" % fname)
t0 = time.time()
gs.runCameraPath(fname, True)
t1 = time.time()
gs.print("Sync exec: script regained control after %.4f seconds" % (t1 - t0))
printall("Sync exec: script regained control after %.4f seconds" % (t1 - t0))
gs.print("(2/2) Starting asynchronous camera file execution: %s" % fname)
printall("(2/2) Starting asynchronous camera file execution: %s" % fname)
t0 = time.time()
gs.runCameraPath(fname)
t1 = time.time()
gs.print("Async exec: script regained control after %.4f seconds" % (t1 - t0))
printall("Async exec: script regained control after %.4f seconds" % (t1 - t0))
gs.maximizeInterfaceWindow()
gs.enableInput()
gs.print("Script finishes")
printall("Script finishes")
gateway.close()
# This script tests the displaying of custom messages and images.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
import os
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
# Minimize interface, disable input, stop camera
gs.disableInput()
......@@ -18,8 +19,13 @@ gs.displayMessageObject(1, "This is the first message", 0.2, 0.2, 0.3, 0.4, 0.6,
gs.sleep(1.5)
gs.displayMessageObject(2, "This is the second message", 0.3, 0.1, 0.0, 1.0, 0.0, 1.0, 11)
gs.sleep(1.5)
gs.preloadTextures("scripts/tests/profile.png")
gs.displayImageObject(10, "scripts/tests/profile.png", 0.1, 0.7)
# Image
profileimg = os.path.abspath("./profile.png")
gs.preloadTexture(profileimg)
gs.displayImageObject(10, profileimg, 0.1, 0.7)
# More messages
gs.displayMessageObject(3, "Monkey!", 0.7, 0.62, 0.9, 0.0, 1.0, 0.5, 18)
gs.sleep(1.5)
gs.displayMessageObject(4, "This is the fourth message", 0.4, 0.6, 1.0, 1.0, 0.0, 0.5, 17)
......@@ -44,3 +50,5 @@ gs.sleep(1.5)
# Maximize interface and enable input
gs.maximizeInterfaceWindow()
gs.enableInput()
gateway.close()
# Test script. Tests GUI expand and collapse.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -20,4 +20,6 @@ gs.sleep(1)
gs.collapseGuiComponent("VisibilityComponent")
gs.sleep(1)
gs.enableInput()
\ No newline at end of file
gs.enableInput()
gateway.close()
\ No newline at end of file
......@@ -2,10 +2,10 @@
# Created by Toni Sagrista
import math
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -27,15 +27,16 @@ absmag = body.getAbsmag()
appmag = body.getAppmag()
radec = body.getPosSph()
gs.print("Absmag: %f, appmag: %f, RA: %f, DEC: %f" % (absmag, appmag, radec.x, radec.y))
gs.print("Absmag: %f, appmag: %f, RA: %f, DEC: %f" % (absmag, appmag, radec.x(), radec.y()))
# Now stop at a certain distance of earth
dist = 15000 #Km
earthrad = gs.getObjectRadius("Earth")
anglerad = math.acos((earthrad*2)/dist)
anglerad = math.acos((earthrad * 2)/dist)
gs.goToObject("Earth", math.degrees(anglerad))
gs.enableInput()
gateway.close()
# This script tests the go-to and capture frame commands. To be run asynchronously.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -14,7 +14,7 @@ gs.setRotationCameraSpeed(40)
gs.setTurningCameraSpeed(30)
gs.setCameraSpeed(30)
gs.configureRenderOutput(1280, 720, 60, '/home/tsagrista/.gaiasky/frames', 'scripting-test')
gs.configureRenderOutput(1280, 720, 60, gs.getDefaultFramesDir(), 'scripting-test')
gs.setFrameOutput(True)
gs.goToObject("Sol", -1, 2.5)
......@@ -22,7 +22,7 @@ gs.goToObject("Sol", -1, 2.5)
gs.setHeadlineMessage("Sun")
gs.setSubheadMessage("This is the Sun, our star")
gs.sleepFrames(120)
gs.sleepFrames(40)
gs.clearAllMessages()
gs.goToObject("Earth", -1, 2.5)
......@@ -30,14 +30,15 @@ gs.goToObject("Earth", -1, 2.5)
gs.setHeadlineMessage("Earth")
gs.setSubheadMessage("This is the Earth, our home")
gs.sleepFrames(60)
gs.sleepFrames(40)
gs.clearAllMessages()
gs.setCameraFocus("Sol")
gs.gs.sleep(4)
gs.sleep(4)
gs.setFrameOutput(False)
gs.enableInput()
gs.maximizeInterfaceWindow()
\ No newline at end of file
gs.maximizeInterfaceWindow()
gateway.close()
\ No newline at end of file
# This script tests the go-to commands. To be run asynchronously.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -19,7 +19,7 @@ gs.goToObject("Sol", 20.0, 4.5)
gs.setHeadlineMessage("Sun")
gs.setSubheadMessage("This is the Sun, our star")
gs.gs.sleep(4)
gs.sleep(4)
gs.clearAllMessages()
gs.goToObject("Sol", 5.5)
......@@ -27,7 +27,7 @@ gs.goToObject("Sol", 5.5)
gs.setHeadlineMessage("Sun")
gs.setSubheadMessage("We are now zooming out a bit")
gs.gs.sleep(4)
gs.sleep(4)
gs.clearAllMessages()
gs.goToObject("Earth", 20.0, 6.5)
......@@ -35,7 +35,7 @@ gs.goToObject("Earth", 20.0, 6.5)
gs.setHeadlineMessage("Earth")
gs.setSubheadMessage("This is the Earth, our home")
gs.gs.sleep(4)
gs.sleep(4)
gs.clearAllMessages()
gs.goToObject("Earth", 2.5, 1.5)
......@@ -43,11 +43,13 @@ gs.goToObject("Earth", 2.5, 1.5)
gs.setHeadlineMessage("Earth")
gs.setSubheadMessage("Zooming out here...")
gs.gs.sleep(4)
gs.sleep(4)
gs.clearAllMessages()
gs.setCameraFocus("Sol")
gs.gs.sleep(4)
gs.sleep(4)
gs.enableInput()
gs.maximizeInterfaceWindow()
\ No newline at end of file
gs.maximizeInterfaceWindow()
gateway.close()
\ No newline at end of file
# Test script. Tests GUI position commands.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
gs.disableInput()
gs.cameraStop()
......@@ -22,4 +22,6 @@ gs.setGuiPosition(1, 1)
gs.sleep(1)
gs.setGuiPosition(0, 1)
gs.enableInput()
\ No newline at end of file
gs.enableInput()
gateway.close()
\ No newline at end of file
# Test script. Tests brightness and contrast commands.
# Created by Toni Sagrista
from gaia.cu9.ari.gaiaorbit.script import EventScriptingInterface
from py4j.java_gateway import JavaGateway, GatewayParameters
gs = EventScriptingInterface.instance()
gateway = JavaGateway(gateway_parameters=GatewayParameters(auto_convert=True))
gs = gateway.entry_point
<