trescope

Trescope

class trescope. Trescope ( * args , ** kwargs ) [source]

Heterogeneous language client , used to connect backend for debugging , visualization ( display mode or file mode ) , fetching inputs from display , etc . Before using it , please ensure that a backend has been started by typing trescope in terminal with enter , after starting backend , you should invoke Trescope.initialize() first in your code before any other Trescope APIs called . It is a single instance , so you can use it globally in your code .

Usage :

  1. Open terminal , enter trescope :

1
$ trescope
  1. Open browser with the link info shown by terminal ( Available on ) .

  2. Run the code :

1
2
3
4
5
6
from trescope import Trescope
from trescope.config import Scatter3DConfig
from trescope.toolbox import simpleDisplayOutputs

Trescope().initialize(True, simpleDisplayOutputs(1, 4))
Trescope().selectOutput(0).plotScatter3D(x= [0, 1, 1, 0], y = [0, 0, 1, 1], z = [0, 0, 0, 0]).withConfig(Scatter3DConfig().color(0xffff0000))
  1. Check your browser , see the result .

breakPoint ( identifier : str ) → Dict [source]

Pause program execution and return input data from trescope.Input when resume .

Parameters

identifier – Any string identifies which breakpoint

Returns

Input data from control of display, see trescope.control

initialize ( open : bool , outputManager : Union [ trescope.core.OutputManager.FileOutputManager , trescope.core.OutputManager.DisplayOutputManager ] , identifier : str = 'main' ) → None [source]

Initialize heterogeneous language client : specify outputs ( file output for image rendering and display output for interaction , such as debugging algorithm process step by step … ) and identifier for backend connection .

Parameters
  • open – now always True

  • outputManager – The manager to arrange outputs , there are two types for OutputManager : trescope.DisplayOutputManager (plots data to display , ) and trescope.FileOutputManager .

  • identifier – Default “main” . Any string for identifying backend , only same identifier leads to successful connection of heterogeneous language client and backend launched in terminal , you can specify backend identifier by passing args like this trescope --identifier the-same-identifier or alias for trescope --id the-same-identifier .

selectOutput ( id : Union [ str , int ] ) → trescope.core.Output.Output [source]

Select an trescope.Output to plot data , add control , etc .

Parameters

id – Output id that added when call Trescope.initialize()

Returns

The output selected

OutputManager

In trescope , you can specify two outputs for visualization data : display ( trescope.DisplayOutputManager ) or file ( trescope.FileOutputManager ) , display for plotting data in display (browser) , file for plotting data to image file .

DisplayOutput

class trescope. DisplayOutputManager ( resolutionRow : int , resolutionColumn : int ) [source]

Specify output as display , check data in display ( browser ) with interaction , divide whole display to resolutionRow * resolutionColumn grids , then layout outputs by specifying which grid to start at and how many grids to span .

Parameters
  • resolutionRow – How many rows to divide

  • resolutionColumn – How many columns to divide

Example says all :

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
from trescope import Trescope, DisplayOutputManager, DisplayOutputDesc
from trescope.config import Scatter2DConfig

# Divide display to 4 * 10 grids
outputManager = DisplayOutputManager(4, 10)
# Output `startAt(0, 0).withSpan(1, 10)` occupies 1 * 10 grids and starts at grid(0 , 0)
outputManager.add(DisplayOutputDesc().id('startAt(0, 0).withSpan(1, 10)').startAt(0, 0).withSpan(1, 10))
outputManager.add(DisplayOutputDesc().id('startAt(1, 0).withSpan(5, 2)').startAt(1, 0).withSpan(3, 2))
outputManager.add(DisplayOutputDesc().id('startAt(1, 3).withSpan(3, 2)').startAt(1, 2).withSpan(3, 8))
Trescope().initialize(True, outputManager)
Trescope().selectOutput('startAt(0, 0).withSpan(1, 10)').plotScatter2D([0, 1, 2], [0, 1, 2]).withConfig(Scatter2DConfig())
Trescope().selectOutput('startAt(1, 0).withSpan(5, 2)').plotScatter2D([0, 1, 2], [0, 1, 2]).withConfig(Scatter2DConfig())
Trescope().selectOutput('startAt(1, 3).withSpan(3, 2)').plotScatter2D([0, 1, 2], [0, 1, 2]).withConfig(Scatter2DConfig())

You will see something below in browser :

../_images/display-output-manager.png
add ( outputDesc : trescope.core.OutputManager.DisplayOutputDesc ) [source]

Add output description .

Parameters

outputDesc – Display output description to specify output id , where starts , how many spans

Returns

self , for chain call

class trescope. DisplayOutputDesc [source]

Display output description , specify id , start and span of output .

id ( id : Union [ str , int ] ) [source]

Specify id of display output .

Parameters

id – ID of display output

Returns

self , for chain call

startAt ( rowStart : int , columnStart : int ) [source]

Specify start of display output .

Parameters
  • rowStart – Start row

  • columnStart – Start column

Returns

self , for chain call

withSpan ( rowSpan : int , columnSpan : int ) [source]

Specify span of display output .

Parameters
  • rowSpan – Rows to span

  • columnSpan – Columns to span

Returns

self , for chain call

FileOutput

class trescope. FileOutputManager ( directory : Union [ str , pathlib.Path ] , widthPixel : int = 640 , heightPixel : int = 480 ) [source]

Specify output as file , plot data to image file .

Parameters
  • directory – Directory where image file generated

  • widthPixel – image width

  • heightPixel – image height

add ( outputDesc : trescope.core.OutputManager.FileOutputDesc ) [source]

Add output description .

Parameters

outputDesc – File output description to specify output id (file names)

Returns

self , for chain call

class trescope. FileOutputDesc [source]

Display output description , specify id (name of image file) of output .

id ( id : Union [ str , int ] ) [source]

Specify id of file output .

Parameters

id – ID of file output

Returns

self , for chain call

Output and Input

In trescope , we use trescope.Output for data plotting and trescope.Input for user input .

Output

class trescope. Output ( id : str , trescope ) [source]

Output for plotting data .

asInput ( ) → trescope.core.Input.Input [source]

Change to input for add control .

Returns

Input

clear ( ) [source]

Clear output .

flush ( ) [source]

Flush data to file , no influence for display output .

plotAxisHelper3D ( ) [source]

Plot 3d axis helper .

Returns

Content

plotFRONT3D ( houseLayoutFile : Union [ str , pathlib.Path ] ) → trescope.core.Content.Content [source]

Plot FRONT3D scene .

Parameters

houseLayoutFile – Scene file

Returns

Content

plotGraph ( vertex : Union [ List , numpy.ndarray ] , link : Union [ List , numpy.ndarray ] , edge : Union [ List , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot graph .

Parameters
  • vertex – vertex

  • link – link

  • edge – edge

Returns

Content

plotHeatMap ( intensity2DArray : Union [ List [ float ] , numpy.ndarray ] ) [source]

Plot heatmap .

Parameters

intensity2DArray – intensity

Returns

Content

plotHistogram ( x : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot histogram .

Parameters

x – x

Returns

Content

plotImage ( remoteOrLocalPath : Union [ str , pathlib.Path ] ) → trescope.core.Content.Content [source]

Plot image .

Parameters

remoteOrLocalPath – Image local path or url

Returns

Content

plotLineSegment ( x : Union [ List [ float ] , numpy.ndarray ] , y : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot line segment .

Parameters
  • x – x

  • y – y

Returns

Content

plotLollipop3D ( u : Union [ List [ float ] , numpy.ndarray ] , v : Union [ List [ float ] , numpy.ndarray ] , w : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot lollipop .

Parameters
  • u – u

  • v – v

  • w – w

Returns

Content

plotMesh3D ( x : Union [ List [ float ] , numpy.ndarray ] , y : Union [ List [ float ] , numpy.ndarray ] , z : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot mesh .

Parameters
  • x – x

  • y – y

  • z – z

Returns

Content

plotPie ( label : Union [ List , numpy.ndarray ] , value : Union [ List , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot pie .

Parameters
  • label – label

  • value – value

Returns

Content

plotScatter2D ( x : Union [ List [ float ] , numpy.ndarray ] , y : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot 2D scatter .

Parameters
  • x – x

  • y – y

Returns

Content

plotScatter3D ( x : Union [ List [ float ] , numpy.ndarray ] , y : Union [ List [ float ] , numpy.ndarray ] , z : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot 3D scatter .

Parameters
  • x – x

  • y – y

  • z – z

Returns

Content

plotSurface3D ( intensity2DArray : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot surface .

Parameters

intensity2DArray – intensity

Returns

Content

plotVectorField3D ( u : Union [ List [ float ] , numpy.ndarray ] , v : Union [ List [ float ] , numpy.ndarray ] , w : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot 3D vector field .

Parameters
  • u – u

  • v – v

  • w – w

Returns

Content

plotViolin ( x : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot violin , probability density .

Parameters

x – x

Returns

Content

plotVolume3D ( x : Union [ List [ float ] , numpy.ndarray ] , y : Union [ List [ float ] , numpy.ndarray ] , z : Union [ List [ float ] , numpy.ndarray ] , value : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot volume .

Parameters
  • x – x

  • y – y

  • z – z

  • value – value

Returns

Content

plotWireframe3D ( x : Union [ List [ float ] , numpy.ndarray ] , y : Union [ List [ float ] , numpy.ndarray ] , z : Union [ List [ float ] , numpy.ndarray ] ) → trescope.core.Content.Content [source]

Plot wireframe .

Parameters
  • x – x

  • y – y

  • z – z

Returns

Content

updateLayout ( layout : trescope.core.Layout.Layout ) [source]

Update layout .

Parameters

layout – layout

Input

class trescope. Input ( host ) [source]

Input for adding control , only works for display output . By adding control , you can input user information to control program execution to complete some jobs , such as labelling . Input data will return by Trescope.breakPoint()

addControl ( controlNode : trescope.controller.ControllerNode.ControllerNode ) [source]

Add control .

Parameters

controlNode – control

Returns

self , for chain call

Content

class trescope. Content ( output , ** kwargs ) [source]

Contains all information to plot data , basic data and config of data .

withConfig ( config : trescope.config.Config.Config ) → None [source]

Specify config and commit all data to plot .

Parameters

config – config , see trescope.config

Layout

class trescope. Layout [source]

Specify output layout , such as title , axis , camera (if 3d data) and so on .

axisUniformScale ( axisUniformScale : bool ) [source]

Specify axis uniform scale or not .

Parameters

axisUniformScale – True or False , default True

Returns

self , for chain call

axisXTicks ( tickValues : Union [ List [ float ] , numpy.ndarray ] , tickTexts : List [ str ] ) [source]

Specify x axis ticks .

Parameters
  • tickValues – values of ticks

  • tickTexts – text of ticks

Returns

self , for chain call

camera ( camera : trescope.config.Camera ) [source]

Specify camera , only works for 3d data .

Parameters

camera – camera

Returns

self , for chain call

hoverLabelStyle ( textColor : int , backgroundColor : int ) [source]

Specify hover label style .

Parameters
  • textColor – text color

  • backgroundColor – background color

Returns

self , for chain call

legendOrientation ( orientation : str ) [source]

Specify legend orientation .

Parameters

orientation vertical or horizontal , default vertical

Returns

self , for chain call

showLegend ( show : bool ) [source]

Show legend or not .

Parameters

show – True or False , default True

Returns

self , for chain call

title ( title : str ) [source]

Specify output title .

Parameters

title – title

Returns

self , for chain call