Skip to content
This repository was archived by the owner on Dec 16, 2024. It is now read-only.

poliastro/czml3

Folders and files

NameName
Last commit message
Last commit date

Latest commit

author
Daniel Stoops
Dec 9, 2024
755d2ee · Dec 9, 2024
Nov 27, 2024
Dec 9, 2024
Dec 9, 2024
Jun 28, 2024
Jun 28, 2024
Jun 24, 2024
Dec 11, 2020
Dec 11, 2020
Jun 10, 2019
Dec 4, 2024
Nov 27, 2024
Oct 25, 2019

Repository files navigation

czml3

pypi conda Python codecov pypi-downloads conda-downloads workflow-status license

czml3 aims to make the process of writing CZML files in Python easy by:

  • Type checking properties
  • Conversion of properties to their expected format

From the official CZML Guide:

CZML is a JSON format for describing a time-dynamic graphical scene, primarily for display in a web browser running Cesium. It describes lines, points, billboards, models, and other graphical primitives, and specifies how they change with time.

Insallation

You can install czml3 using pip:

pip install czml3

or conda:

conda install czml3 --channel conda-forge

Examples

A CZML document is a list of packets, which have several properties. Recreating the blue box from Cesium sandcastle's CZML Box:

from czml3 import Document, Packet, Preamble
from czml3.properties import (
    Box,
    BoxDimensions,
    Cartesian3Value,
    Color,
    Material,
    Position,
    SolidColorMaterial,
)
packet_box = Packet(
    position=Position(cartographicDegrees=[-114.0, 40.0, 300000.0]),
    box=Box(
        dimensions=BoxDimensions(
            cartesian=Cartesian3Value(values=[400000.0, 300000.0, 500000.0])
        ),
        material=Material(
            solidColor=SolidColorMaterial(color=Color(rgba=[0, 0, 255, 255]))
        ),
    ),
)
doc = Document(packets=[Preamble(name="box"), packet_box])
print(doc)
[
    {
        "id": "document",
        "version": "1.0",
        "name": "box"
    },
    {
        "id": "b9f211b1-6e9d-45b2-b484-516d127ffa22",
        "position": {
            "cartographicDegrees": [
                -114.0,
                40.0,
                300000.0
            ]
        },
        "box": {
            "dimensions": {
                "cartesian": [
                    400000.0,
                    300000.0,
                    500000.0
                ]
            },
            "material": {
                "solidColor": {
                    "color": {
                        "rgba": [
                            0.0,
                            0.0,
                            255.0,
                            255.0
                        ]
                    }
                }
            }
        }
    }
]

czml3 uses pydantic for all classes. As such czml3 automatically converts some properties to their appropriate type. For example, the following creates a Position property of doubles using a numpy array of interger type:

import numpy as np
from czml3.properties import Position
print(Position(cartographicDegrees=np.array([-114, 40, 300000], dtype=int)))
{
    "cartographicDegrees": [
        -114.0,
        40.0,
        300000.0
    ]
}

Jupyter Widget

You can easily display your CZML document using our interactive widget:

from czml3.examples import simple
from czml3.widget import CZMLWidget
CZMLWidget(simple)

Widget

Contributing

You want to contribute? Awesome! There are lots of CZML properties that we still did not implement. Also, it would be great to have better validation, a Cesium widget in Jupyter notebook and JupyterLab... Ideas welcome!

Before you send us a pull request, remember to reformat all the code: tox -e reformat. This will apply ruff and lots of love ❤️