lmoss commited on
Commit
2eea8e7
·
1 Parent(s): b39fc9a

added slice

Browse files
Files changed (1) hide show
  1. app.py +24 -25
app.py CHANGED
@@ -4,6 +4,8 @@ from dcgan import DCGAN3D_G
4
  import torch
5
  import requests
6
  import time
 
 
7
 
8
  url = "https://github.com/LukasMosser/PorousMediaGan/blob/master/checkpoints/berea/berea_generator_epoch_24.pth?raw=true"
9
 
@@ -14,7 +16,6 @@ with open('berea_generator_epoch_24.pth', 'wb') as f:
14
  f.write(resp.content)
15
  time.sleep(5)
16
 
17
- print(resp.status_code)
18
  st.text(resp.status_code)
19
 
20
  pv.set_plot_theme("document")
@@ -23,30 +24,32 @@ pl = pv.Plotter(shape=(1, 1),
23
 
24
  netG = DCGAN3D_G(64, 512, 1, 32, 1)
25
  netG.load_state_dict(torch.load("berea_generator_epoch_24.pth", map_location=torch.device('cpu')))
26
- z = torch.randn(1, 512, 3, 3, 3)
27
  with torch.no_grad():
28
  X = netG(z)
29
 
30
  st.image((X[0, 0, 32].numpy()+1)/2, output_format="png")
31
- """
32
- data = examples.load_channels()
33
- channels = data.threshold([0.9, 1.1])
34
- print(channels)
35
- bodies = channels.split_bodies()
36
- # Now remove all bodies with a small volume
37
- for key in bodies.keys():
38
- b = bodies[key]
39
- vol = b.volume
40
- if vol < 1000.0:
41
- del bodies[key]
42
- continue
43
- # Now lets add a volume array to all blocks
44
- b.cell_data["TOTAL VOLUME"] = np.full(b.n_cells, vol)
45
-
46
- for i, body in enumerate(bodies):
47
- print(f"Body {i:02d} volume: {body.volume:.3f}")
48
-
49
- pl.add_mesh(bodies)
 
 
50
  pl.export_html('pyvista.html')
51
 
52
  st.header("test html import")
@@ -56,7 +59,3 @@ HtmlFile = open("pyvista.html", 'r', encoding='utf-8')
56
  source_code = HtmlFile.read()
57
 
58
  components.html(source_code, width=view_width, height=view_height)
59
-
60
- #snippet = embed.embed_snippet(views=view(reader.GetOutput()))
61
- #html = embed.html_template.format(title="", snippet=snippet)
62
- #components.html(html, width=view_width, height=view_height)"""
 
4
  import torch
5
  import requests
6
  import time
7
+ import numpy as np
8
+ import streamlit.components.v1 as components
9
 
10
  url = "https://github.com/LukasMosser/PorousMediaGan/blob/master/checkpoints/berea/berea_generator_epoch_24.pth?raw=true"
11
 
 
16
  f.write(resp.content)
17
  time.sleep(5)
18
 
 
19
  st.text(resp.status_code)
20
 
21
  pv.set_plot_theme("document")
 
24
 
25
  netG = DCGAN3D_G(64, 512, 1, 32, 1)
26
  netG.load_state_dict(torch.load("berea_generator_epoch_24.pth", map_location=torch.device('cpu')))
27
+ z = torch.randn(1, 512, 1, 1, 1)
28
  with torch.no_grad():
29
  X = netG(z)
30
 
31
  st.image((X[0, 0, 32].numpy()+1)/2, output_format="png")
32
+
33
+ img = (X[0, 0].numpy()+1)/2
34
+
35
+ a = 0.9
36
+
37
+ # create a uniform grid to sample the function with
38
+ x_min, y_min, z_min = 0, 0, 0
39
+ grid = pv.UniformGrid(
40
+ dims=img.shape,
41
+ spacing=(1, 1, 1),
42
+ origin=(x_min, y_min, z_min),
43
+ )
44
+ x, y, z = grid.points.T
45
+
46
+ # sample and plot
47
+ values = img.flatten()
48
+ grid.point_data['my_array'] = values
49
+ slices = grid.slice_orthogonal()
50
+
51
+ pl.add_mesh(slices, cmap="gray")
52
+
53
  pl.export_html('pyvista.html')
54
 
55
  st.header("test html import")
 
59
  source_code = HtmlFile.read()
60
 
61
  components.html(source_code, width=view_width, height=view_height)