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

Updates and bug fixes #163

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
84d8a8c
Packet.position can be Position, PositionList, PositionListOfLists
Dec 2, 2024
197815e
Material.polylineOutline can be PolylineMaterial or PolylineOutline
Dec 2, 2024
6390203
Add types.Cartesian3VelocityValue
Dec 2, 2024
9c990de
Update types in Position and add checks to ensure correct sizes
Dec 2, 2024
2db0b39
Implement check_num_points() in all relevant types
Dec 2, 2024
8c4947e
All properties can be a Sequence
Dec 2, 2024
9ca4b4c
Fix tests
Dec 2, 2024
bedc18c
Add validators to PositionList
Dec 2, 2024
0273806
FIX: list values can't vary with time + values can vary with time + c…
Dec 2, 2024
62d42c2
Better checking of Value types and ListValue types, drop support of h…
Dec 2, 2024
7b00b21
Material.solidColor cannot be a Color class
Dec 3, 2024
7b00b27
Field validator method names start with validate
Dec 3, 2024
e5a8580
test_ellipsoid_parameters() implements SolidColorMaterial correctly
Dec 3, 2024
044806b
All classes in types.py cannot be initialised to None
Dec 3, 2024
a019b33
Add types: CartographicDegreesListOfListsValue, CartographicRadiansLi…
Dec 3, 2024
f9ef3ee
Remove None defaults in all types
Dec 3, 2024
944de79
Correct typing of PositionList and PositionListOfLists
Dec 3, 2024
28d6f7c
Ensure references in PositionList and PositionListOfLists is of the c…
Dec 3, 2024
84049a9
Fix validator of ReferenceListOfListsValue()
Dec 3, 2024
5c6ad69
Update simple.py
Dec 3, 2024
a5ee7fe
Mypy fixes
Dec 3, 2024
eb6c41b
custom_serializer of types returns values (instead of list of values)
Dec 3, 2024
eb0fe7b
Update readme
Dec 4, 2024
62e339b
All classes that have cartesian inputs converts list[float] inputs to…
Dec 4, 2024
4710726
Sequence -> TimeIntervalCollection
Dec 9, 2024
755d2ee
Update tests
Dec 9, 2024
4bc605b
Bump to 2.1.0
Dec 9, 2024
ad9493d
Fix mypy issues
Dec 9, 2024
3061a7b
Move all RgbafValue() and RgbaValue() to get_color() + get_color() su…
Dec 9, 2024
6d1398c
Expand testing
Dec 9, 2024
406ca83
ReferenceValue.string -> ReferenceValue.value
Dec 9, 2024
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
126 changes: 126 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
# czml3
![pypi](https://img.shields.io/pypi/v/czml3)
![conda](https://img.shields.io/conda/vn/conda-forge/czml3?label=conda)
![Python](https://img.shields.io/pypi/pyversions/czml3)
![codecov](https://img.shields.io/codecov/c/github/poliastro/czml3.svg?style=flat-square)
![pypi-downloads](https://img.shields.io/pepy/dt/czml3?label=pypi%20downloads)
![conda-downloads](https://img.shields.io/conda/dn/conda-forge/czml3?label=conda%20downloads)
![workflow-status](https://img.shields.io/github/actions/workflow/status/poliastro/czml3/workflow.yml?branch=main)
![license](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)

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](https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/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](https://sandcastle.cesium.com/?src=CZML%20Box.html&label=CZML):

```
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](https://docs.pydantic.dev/latest/) 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](https://raw.githubusercontent.com/poliastro/czml3/master/widget-screenshot.png)

## Contributing
You want to contribute? Awesome! There are lots of [CZML properties](https://github.com/AnalyticalGraphicsInc/czml-writer/wiki/Packet) 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 ❤️
154 changes: 0 additions & 154 deletions README.rst

This file was deleted.

2 changes: 1 addition & 1 deletion src/czml3/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .core import CZML_VERSION, Document, Packet, Preamble

__version__ = "2.0.1"
__version__ = "2.1.0"

__all__ = ["Document", "Preamble", "Packet", "CZML_VERSION"]
9 changes: 7 additions & 2 deletions src/czml3/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@
class BaseCZMLObject(BaseModel):
@model_validator(mode="before")
@classmethod
def check_model_before(cls, data: dict[str, Any]) -> Any:
if data is not None and "delete" in data and data["delete"]:
def validate_model_before(cls, data: dict[str, Any]) -> Any:
if (
data is not None
and isinstance(data, dict)
and "delete" in data
and data["delete"]
):
return {
"delete": True,
"id": data.get("id"),
Expand Down
10 changes: 6 additions & 4 deletions src/czml3/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from pydantic import BaseModel, field_validator

from .enums import InterpolationAlgorithms
from .types import format_datetime_like
from .types import TimeIntervalCollection, format_datetime_like


class Deletable(BaseModel):
Expand All @@ -18,9 +18,11 @@ class Interpolatable(BaseModel):
The interpolation happens over provided time-tagged samples.
"""

epoch: None | str | dt.datetime = None
interpolationAlgorithm: None | InterpolationAlgorithms = None
interpolationDegree: None | int = None
epoch: None | str | dt.datetime | TimeIntervalCollection = None
interpolationAlgorithm: None | InterpolationAlgorithms | TimeIntervalCollection = (
None
)
interpolationDegree: None | int | TimeIntervalCollection = None

@field_validator("epoch")
@classmethod
Expand Down
Loading
Loading