scitex 2.4.3__py3-none-any.whl → 2.5.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. scitex/__version__.py +1 -1
  2. scitex/io/_load.py +5 -0
  3. scitex/io/_load_modules/_canvas.py +171 -0
  4. scitex/io/_save.py +8 -0
  5. scitex/io/_save_modules/_canvas.py +356 -0
  6. scitex/plt/_subplots/_export_as_csv_formatters/_format_plot.py +77 -22
  7. scitex/plt/docs/FIGURE_ARCHITECTURE.md +257 -0
  8. scitex/plt/utils/__init__.py +10 -0
  9. scitex/plt/utils/_collect_figure_metadata.py +14 -12
  10. scitex/plt/utils/_csv_column_naming.py +237 -0
  11. scitex/session/_decorator.py +13 -1
  12. scitex/vis/README.md +246 -615
  13. scitex/vis/__init__.py +138 -78
  14. scitex/vis/canvas.py +423 -0
  15. scitex/vis/docs/CANVAS_ARCHITECTURE.md +307 -0
  16. scitex/vis/editor/__init__.py +1 -1
  17. scitex/vis/editor/_dearpygui_editor.py +1830 -0
  18. scitex/vis/editor/_defaults.py +40 -1
  19. scitex/vis/editor/_edit.py +54 -18
  20. scitex/vis/editor/_flask_editor.py +37 -0
  21. scitex/vis/editor/_qt_editor.py +865 -0
  22. scitex/vis/editor/flask_editor/__init__.py +21 -0
  23. scitex/vis/editor/flask_editor/bbox.py +216 -0
  24. scitex/vis/editor/flask_editor/core.py +152 -0
  25. scitex/vis/editor/flask_editor/plotter.py +130 -0
  26. scitex/vis/editor/flask_editor/renderer.py +184 -0
  27. scitex/vis/editor/flask_editor/templates/__init__.py +33 -0
  28. scitex/vis/editor/flask_editor/templates/html.py +295 -0
  29. scitex/vis/editor/flask_editor/templates/scripts.py +614 -0
  30. scitex/vis/editor/flask_editor/templates/styles.py +549 -0
  31. scitex/vis/editor/flask_editor/utils.py +81 -0
  32. scitex/vis/io/__init__.py +84 -21
  33. scitex/vis/io/canvas.py +226 -0
  34. scitex/vis/io/data.py +204 -0
  35. scitex/vis/io/directory.py +202 -0
  36. scitex/vis/io/export.py +460 -0
  37. scitex/vis/io/panel.py +424 -0
  38. {scitex-2.4.3.dist-info → scitex-2.5.0.dist-info}/METADATA +9 -2
  39. {scitex-2.4.3.dist-info → scitex-2.5.0.dist-info}/RECORD +42 -21
  40. scitex/vis/DJANGO_INTEGRATION.md +0 -677
  41. scitex/vis/editor/_web_editor.py +0 -1440
  42. scitex/vis/tmp.txt +0 -239
  43. {scitex-2.4.3.dist-info → scitex-2.5.0.dist-info}/WHEEL +0 -0
  44. {scitex-2.4.3.dist-info → scitex-2.5.0.dist-info}/entry_points.txt +0 -0
  45. {scitex-2.4.3.dist-info → scitex-2.5.0.dist-info}/licenses/LICENSE +0 -0
scitex/vis/tmp.txt DELETED
@@ -1,239 +0,0 @@
1
- ざっと構造レベルで見た限り、かなりきれいにまとまってます。
2
- 「JSON ⇔ dataclass モデル ⇔ matplotlib (scitex.plt)」の三層がちゃんと分離されていて、将来の拡張もしやすそうです。
3
-
4
- 20251121_105809-vis
5
-
6
- 1. 全体の構成について
7
-
8
- scitex.vis パッケージ構造
9
-
10
- model/(Figure/Axes/Plot/Guide/Annotation + Style)
11
-
12
- backend/(parser, render, export)
13
-
14
- io/(project ディレクトリ構造との橋渡し)
15
-
16
- utils/(validate + journal テンプレート)
17
-
18
- __init__.py で
19
-
20
- FigureModel, AxesModel, PlotModel, GuideModel, AnnotationModel
21
-
22
- build_figure_from_json, export_figure 系
23
-
24
- get_template, list_templates, NATURE_SINGLE_COLUMN_MM など
25
- が top-level に綺麗にエクスポートされていて、
26
- import scitex as stx; stx.vis.xxx で使える API としては十分わかりやすいです。
27
-
28
- 設計としては「論文図用の JSON DSL」として、もう “モジュールとして完成” しているレベルだと思います。
29
-
30
- 2. backend 周りの確認ポイント
31
- 2-1. validate_figure_json
32
- from ..utils import validate_json_structure, validate_axes_layout
33
-
34
- validate_json_structure(fig_json)
35
- fig_model = parse_figure_json(fig_json)
36
- fig_model.validate()
37
- validate_axes_layout(...)
38
-
39
-
40
- 粗い JSON チェック → dataclass 化 → モデルの validate → レイアウト整合性
41
- というパイプラインになっていて、エントリポイントとしてとても良いです。
42
-
43
- io.load_figure_json(validate=True) からもこれを呼び出していて、
44
- 「ファイル読み込み=即 validation」になっているのも、SciTeX 全体の哲学と合っていると思います。
45
-
46
- 2-2. render_figure / mm 制御
47
-
48
- width_mm, height_mm をインチに変換して stx.plt.subplots(...) に渡し、
49
-
50
- その上で nrows, ncols, dpi などを統一的に指定。
51
-
52
- ここはすでに「mm ベースの figure サイズ」は担保済みなので、
53
- 後から left_mm などを stx.plt.subplots() の引数にマップするだけで、
54
- “完全 mm 制御” にアップグレードできます(TODO コメントも書いてあって良いです)。
55
-
56
- 3. Axes / Plot / Guide / Annotation + Style
57
-
58
- backend.render から見える前提は:
59
-
60
- AxesModel に style: AxesStyle
61
-
62
- PlotModel に style: PlotStyle
63
-
64
- GuideModel に style: GuideStyle
65
-
66
- AnnotationModel に style: TextStyle
67
-
68
- があり、style.to_dict() で matplotlib に渡す kwargs を生成、という設計になっています。
69
-
70
- style = axes_model.style
71
- ...
72
- if style.grid:
73
- ax.grid(alpha=style.grid_alpha, ...)
74
- ...
75
- if style.legend:
76
- ax.legend(loc=style.legend_loc, ...)
77
-
78
- style_dict = plot_model.style.to_dict()
79
- ...
80
- kwargs = {k: v for k, v in style_dict.items() if k in relevant_keys}
81
-
82
- kwargs = guide_model.style.to_dict()
83
- ...
84
- kwargs = annotation_model.style.to_dict()
85
-
86
- 3-1. モデル側で確認したいこと
87
-
88
- コード全体が長く、該当ファイルが途中でトランケートされているので推測も入りますが、
89
- 最低限、次が守られているかだけ一度ローカルで確認しておくと安心です:
90
-
91
- 各 Model に style フィールドが定義されていること
92
-
93
- AxesModel(style: AxesStyle = AxesStyle()) のような形
94
-
95
- PlotModel, GuideModel, AnnotationModel も同様
96
-
97
- .from_dict() が style を正しく復元していること
98
-
99
- 例:
100
-
101
- @classmethod
102
- def from_dict(cls, data: Dict[str, Any]) -> "PlotModel":
103
- style_data = data.pop("style", {})
104
- obj = cls(**data)
105
- obj.style = PlotStyle.from_dict(style_data) # など
106
- return obj
107
-
108
-
109
- こうしておかないと、JSON → Model の round-trip で style がただの dict のままになってしまいます。
110
-
111
- validate() が style に依存するフィールドにアクセスしていないこと
112
-
113
- たとえば旧実装では Annotation で self.ha, self.va を直接見ていましたが、
114
- これを style.ha, style.va に移しているなら、validate() も必ず style 経由に統一する必要があります。
115
-
116
- 4. plot_type の網羅性(小さめの仕様ギャップ)
117
-
118
- PlotModel.validate() 側では、かなり多くの plot_type を許容しているはずです(line, scatter, bar, barh, hist, errorbar, fill_between, heatmap, imshow, contour, contourf, box, violin, step, stem など)。
119
- 一方で render_plot() の本体は、現状だと line / scatter / errorbar / bar / barh / hist / fill_between / heatmap / imshow / contour / contourf までしか実装されていません。
120
-
121
- 20251121_105809-vis
122
-
123
- 結果として:
124
-
125
- plot_type="box" や "violin" を JSON では許容しているのに、
126
-
127
- 実際に render_plot すると Unsupported plot type になります。
128
-
129
- 提案
130
-
131
- どちらかに寄せる:
132
-
133
- (A) 先に実装する plot_type だけ validate() で許可する
134
-
135
- MVP の段階では line / scatter / bar / barh / hist / errorbar / heatmap / imshow / contour / contourf / fill_between に限定
136
-
137
- (B) box, violin, step, stem も最低限の実装を書く
138
-
139
- 例えば:
140
-
141
- box: ax.boxplot(...)
142
-
143
- violin: ax.violinplot(...)
144
-
145
- step: ax.step(...)
146
-
147
- stem: ax.stem(...)
148
-
149
- MVP を急ぐなら (A) で一旦締めてしまって、
150
- Sigma UI 側のメニューからも「未実装タイプ」は隠すのが UX 的にも安全だと思います。
151
-
152
- 5. I/O & プロジェクト構造
153
-
154
- io.load_figure_json_from_project / save_figure_json_to_project は
155
-
156
- project_dir/scitex/vis/figs/{figure_id}.json
157
-
158
-
159
- という構造で統一されていて、以前話していた project-dir/scitex/vis/figs にきちんと揃っています。
160
-
161
- 20251121_105809-vis
162
-
163
- これは /vis/sigma/ フロントエンドとかなり綺麗につながる形になっていて、
164
-
165
- UI 側:Figure ツリーの編集 → JSON
166
-
167
- Django API:JSON を scitex.vis.io.save_figure_json_to_project(...) で保存
168
-
169
- 解析/論文側:scitex.vis.backend.export_figure(...) or build_figure_from_json(...) で再利用
170
-
171
- というフローが素直に組めます。
172
-
173
- 6. テストとしてやっておくといいこと
174
-
175
- ローカルで、次の 2〜3 個だけ回しておけば、かなり安心できると思います:
176
-
177
- 最小構成 + line plot
178
-
179
- import scitex as stx
180
- import numpy as np
181
-
182
- fig_json = stx.vis.utils.get_template("nature_single", height_mm=100)
183
- fig_json["axes"] = [{
184
- "row": 0,
185
- "col": 0,
186
- "xlabel": "X",
187
- "ylabel": "Y",
188
- "title": "Demo",
189
- "plots": [{
190
- "plot_type": "line",
191
- "data": {
192
- "x": list(range(10)),
193
- "y": [i*i for i in range(10)],
194
- },
195
- # style はデフォルトに任せる or 最小限指定
196
- }],
197
- "annotations": [],
198
- "guides": [],
199
- # style は AxesStyle のデフォルト
200
- }]
201
-
202
- stx.vis.backend.validate_figure_json(fig_json)
203
- fig, axes = stx.vis.backend.build_figure_from_json(fig_json)
204
- stx.io.save(fig, "test.png", dpi=300)
205
-
206
-
207
- project round-trip
208
-
209
- stx.vis.io.save_figure_json_to_project("/tmp/proj", "fig-001", fig_json)
210
- loaded = stx.vis.io.load_figure_json_from_project("/tmp/proj", "fig-001")
211
- stx.vis.backend.validate_figure_json(loaded)
212
-
213
-
214
- 存在しない plot_type でちゃんとエラーになるか
215
-
216
- plot_type="unknown" にして render_plot 実行 → ValueError になるか確認
217
-
218
- 7. 結論
219
-
220
- モジュール構造・API 形状・mm ベース設計・project 連携まで含めて、
221
- 「論文図用のバックエンド」としてかなり完成度が高いです。
222
-
223
- いま見えている主なタスクは:
224
-
225
- style dataclass と Model の整合性(style フィールドの from_dict/to_dict/validate)
226
-
227
- plot_type の実装範囲と validate() の整合性
228
-
229
- mm-based spacing を stx.plt.subplots にどう渡すか(これは TODO でも問題なし)
230
-
231
- ここまで出来ていれば、/vis/sigma/ からは
232
-
233
- JSON を組み立てて
234
-
235
- save_figure_json_to_project で保存し
236
-
237
- 裏で export_figure を叩いて PNG を生成
238
-
239
- という「世界一まともな論文図パイプライン」の中核は、もう出来ていると言って良いと思います。
File without changes