Skip to content

Commit 366d8ea

Browse files
Better pydantic API for model creation (#31)
* initial prototype * Update tests/test_model_api.py --------- Co-authored-by: alisterburt <alisterburt@gmail.com>
1 parent 17551fb commit 366d8ea

5 files changed

Lines changed: 405 additions & 74 deletions

File tree

README.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,60 @@ array([0., 0., 35.22094345, ...])
6060

6161
That's it!
6262

63+
### Create and save model files
64+
65+
```python
66+
model = ImodModel(
67+
objects=[
68+
Object(
69+
color=(0.0,1.0,0.0),
70+
header = ObjectHeader(
71+
flags=ObjectFlags(
72+
scattered=True
73+
)
74+
),
75+
contours = [
76+
Contour(
77+
points=np.array([
78+
[4.5,8.0,0.0],
79+
[9.0,8.0,0.0]
80+
])
81+
82+
)
83+
]
84+
),
85+
Object(
86+
color=(0.0,0.0,1.0),
87+
header=ObjectHeader(
88+
pdrawsize=0
89+
),
90+
contours=[
91+
Contour(
92+
points = np.column_stack((6.75 + 6.75 * np.cos(np.linspace(0, 2 * np.pi, 200, endpoint=False)), 6.75 + 6.75 * np.sin(np.linspace(0, 2 * np.pi, 200, endpoint=False)), np.zeros(200)))
93+
)
94+
]
95+
),
96+
Object(
97+
color=(1.0,0.0,0.0),
98+
header=ObjectHeader(
99+
pdrawsize=0,
100+
flags=ObjectFlags(
101+
open=True
102+
)
103+
),
104+
105+
contours=[
106+
Contour(
107+
points = np.column_stack((6.75 + 4.75 * np.cos(np.linspace(1 * np.pi, 2 * np.pi, 100, endpoint=False)), 6.75 + 4.75 * np.sin(np.linspace( 1 * np.pi, 2 * np.pi, 100, endpoint=False)), np.zeros(100)))
108+
)
109+
]
110+
)
111+
]
112+
)
113+
114+
model.to_file("smiley.mod")
115+
```
116+
63117
## Installation
64118
`imodmodel` can be installed from the [Python Package Index](https://pypi.org/) (PyPI)
65119

0 commit comments

Comments
 (0)