Python bindings for Planetarium sub-pixel precision light spot rendering library for astronomy and video tracking applications.
```python from pyplanetarium import Canvas, SpotShape
c = Canvas.new(256, 256)
shape = SpotShape().scale(2.5)
spot1 = c.addspot((100.3, 130.8), shape, 0.5) spot2 = c.addspot((80.6, 200.2), shape.scale(0.5), 0.9)
spot3 = c.add_spot((256.1, 3.5), shape.scale(10.0), 1.1)
c.setbackground(int(0.05 * Canvas.PIXELMAX))
c.draw()
imagewidth, imageheight = c.dimensions() ```
Some of the light spot parameters like coordinates and peak intensity can be adjusted after the spot has been added to the canvas.
The spot position coordinates can be changed by adding an offset vector and the peak intensity can be adjusted by multiplying with a spot illumination factor.
It is possible to define a custom world coordinates to canvas coordinates transformation, which affects all light spots.
```python from pyplanetarium import Canvas, SpotShape, Transform
c = Canvas.new(256, 256)
shape1 = SpotShape().stretch(2.5, 1.5).rotate(45.0)
shape2 = SpotShape([[2.0, -0.5], [1.5, 3.0]])
spot1 = c.addspot((100.3, 130.8), shape1, 0.5) spot2 = c.addspot((80.6, 200.2), shape2, 0.9)
c.setspotoffset(spot1, (-34.2, 12.6)) c.setspotoffset(spot2, (114.2, -73.3))
c.setspotillumination(spot1, 1.2) c.setspotillumination(spot2, 0.7)
pos1 = c.spotposition(spot1) pos2 = c.spotposition(spot2)
int1 = c.spotintensity(spot1) int2 = c.spotintensity(spot2)
c.setviewtransform(Transform().translate((13.7, -20.3)))
pos1x = c.spotposition(spot1) pos2x = c.spotposition(spot2) ```
The Canvas
object supports image export to RAW and PNG file formats.
Both 8-bit and 16-bit PNG sample formats are supported.
Export to PNG formats requires the default png
feature to be enabled.
```python from pyplanetarium import Canvas, ImageFormat
c = Canvas.new(256, 256)
c.set_background(1000) c.clear()
raw8bppbytes = c.export_image(ImageFormat.RawGamma8Bpp)
raw10bppbytes = c.export_image(ImageFormat.RawLinear10BppLE)
raw12bppbytes = c.export_image(ImageFormat.RawLinear12BppLE)
png8bppbytes = c.export_image(ImageFormat.PngGamma8Bpp)
png16bppbytes = c.export_image(ImageFormat.PngLinear16Bpp) ```
The Canvas
object additionally supports windowed image export.
A single rectangular window represents a region of interest (ROI)
on the canvas image. Window rectangle coordinates are represented
by the public Window
structure.
```python from pyplanetarium import Canvas, ImageFormat, Window
c = Canvas.new(256, 256)
wnd = Window.new(64, 32).at(90, 120)
fmt = ImageFormat.RawGamma8Bpp
rawwindowbytes = c.exportwindowimage(wnd, fmt) ```
The Canvas
object additionally supports subsampled image export
with independent row and column subsampling factors.
Only whole canvas images can be exported with subsampling.
```python from pyplanetarium import Canvas, ImageFormat
c = Canvas.new(256, 256)
fmt = ImageFormat.RawLinear10BppLE
factors = (2, 2)
rawsubbytes = c.exportsubsampledimage(factors, fmt) ```