Jan-Hendrik Müller
commited on
Commit
•
9eddefb
1
Parent(s):
5060601
add content
Browse files- a_df.csv +0 -0
- b_reference_frame.csv +0 -0
- housing_data_igor.blend +0 -0
- marimo_california.py +123 -0
a_df.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
b_reference_frame.csv
ADDED
The diff for this file is too large to render.
See raw diff
|
|
housing_data_igor.blend
ADDED
Binary file (842 kB). View file
|
|
marimo_california.py
ADDED
@@ -0,0 +1,123 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import marimo
|
2 |
+
|
3 |
+
__generated_with = "0.9.20"
|
4 |
+
app = marimo.App()
|
5 |
+
|
6 |
+
|
7 |
+
@app.cell
|
8 |
+
def __(mo):
|
9 |
+
mo.md("""# Marimo + Blender""")
|
10 |
+
return
|
11 |
+
|
12 |
+
|
13 |
+
@app.cell
|
14 |
+
def __():
|
15 |
+
#run with
|
16 |
+
#cd california_housing
|
17 |
+
#uv run marimo edit marimo_california.py
|
18 |
+
import marimo as mo
|
19 |
+
import numpy as np
|
20 |
+
import polars as pl
|
21 |
+
import quak
|
22 |
+
import bpy
|
23 |
+
|
24 |
+
blend_file_path = "housing_data_igor.blend"
|
25 |
+
bpy.ops.wm.open_mainfile(filepath=blend_file_path)
|
26 |
+
|
27 |
+
bpy.context.scene.render.engine = "BLENDER_EEVEE_NEXT"
|
28 |
+
bpy.context.scene.render.resolution_x = 800
|
29 |
+
bpy.context.scene.render.resolution_y = 500
|
30 |
+
|
31 |
+
df = pl.read_csv("a_df.csv")
|
32 |
+
reference_frame = pl.read_csv("b_reference_frame.csv")
|
33 |
+
|
34 |
+
vertices = [(row["longitude_normalized"], row["latitude_normalized"], 0) for row in reference_frame.iter_rows(named=True)]
|
35 |
+
|
36 |
+
mesh = bpy.data.meshes.new("NormalizedMesh")
|
37 |
+
obj = bpy.data.objects.new("CaliforninaNormalizedObject", mesh)
|
38 |
+
bpy.context.collection.objects.link(obj)
|
39 |
+
|
40 |
+
mesh.from_pydata(vertices, [], [])
|
41 |
+
mesh.update()
|
42 |
+
obj.modifiers.new(name="GeometryNodes", type='NODES').node_group = bpy.data.node_groups["geo_house"]
|
43 |
+
bpy.context.view_layer.objects.active = obj
|
44 |
+
obj.select_set(True)
|
45 |
+
reference_frame.head()
|
46 |
+
|
47 |
+
def render_result():
|
48 |
+
|
49 |
+
bpy.ops.render.render()
|
50 |
+
bpy.data.images['Render Result'].save_render(filepath="img.png")
|
51 |
+
return mo.image(src="img.png")
|
52 |
+
return (
|
53 |
+
blend_file_path,
|
54 |
+
bpy,
|
55 |
+
df,
|
56 |
+
mesh,
|
57 |
+
mo,
|
58 |
+
np,
|
59 |
+
obj,
|
60 |
+
pl,
|
61 |
+
quak,
|
62 |
+
reference_frame,
|
63 |
+
render_result,
|
64 |
+
vertices,
|
65 |
+
)
|
66 |
+
|
67 |
+
|
68 |
+
@app.cell
|
69 |
+
def __(df, mo, quak):
|
70 |
+
widget = mo.ui.anywidget(quak.Widget(df))
|
71 |
+
widget
|
72 |
+
return (widget,)
|
73 |
+
|
74 |
+
|
75 |
+
@app.cell
|
76 |
+
def __(np, obj, pl, reference_frame, render_result, widget):
|
77 |
+
widget_df = widget.data().pl()
|
78 |
+
|
79 |
+
plotting_frame = reference_frame.with_columns(
|
80 |
+
pl.lit(0).alias("custom_plotting")
|
81 |
+
).join(
|
82 |
+
widget_df.select(["short_id", "median_house_value"]),
|
83 |
+
on="short_id",
|
84 |
+
how="left"
|
85 |
+
).with_columns(
|
86 |
+
pl.when(pl.col("median_house_value").is_not_null())
|
87 |
+
.then(pl.col("median_house_value"))
|
88 |
+
.otherwise(pl.col("custom_plotting"))
|
89 |
+
.alias("custom_plotting")
|
90 |
+
).select(["short_id", "custom_plotting"])
|
91 |
+
|
92 |
+
custom_plotting_list = plotting_frame["custom_plotting"].to_list()
|
93 |
+
normalized_values = list(np.interp(custom_plotting_list,
|
94 |
+
(min(custom_plotting_list), max(custom_plotting_list)),
|
95 |
+
(0.1, 3)))
|
96 |
+
|
97 |
+
attr_name = 'median_house_value'
|
98 |
+
attr = obj.data.attributes.get(attr_name) or obj.data.attributes.new(
|
99 |
+
name=attr_name,
|
100 |
+
type='FLOAT',
|
101 |
+
domain='POINT'
|
102 |
+
)
|
103 |
+
attr.data.foreach_set('value', normalized_values)
|
104 |
+
obj.data.update()
|
105 |
+
|
106 |
+
render_result()
|
107 |
+
return (
|
108 |
+
attr,
|
109 |
+
attr_name,
|
110 |
+
custom_plotting_list,
|
111 |
+
normalized_values,
|
112 |
+
plotting_frame,
|
113 |
+
widget_df,
|
114 |
+
)
|
115 |
+
|
116 |
+
|
117 |
+
@app.cell
|
118 |
+
def __():
|
119 |
+
return
|
120 |
+
|
121 |
+
|
122 |
+
if __name__ == "__main__":
|
123 |
+
app.run()
|