Commit 13ca0ceb authored by Cedrick Copol's avatar Cedrick Copol

shape et dimension sont inversés

parent d68b008f
......@@ -10,8 +10,7 @@ def make_image(data, outputname, size=(2400, 1220)):
fig = plt.figure()
# Size is in pixel "dimension"
dpi = fig.get_dpi()
fig.set_size_inches(size[0]/float(dpi), size[1]/float(dpi))
fig.set_size_inches(size[0]/dpi, size[1]/dpi)
# Remove axis and fill the space
ax = plt.Axes(fig, [0., 0., 1., 1.])
ax.set_axis_off()
......@@ -43,29 +42,29 @@ def asc2fmt(filename, outputname, fmt="png", cellsize=None, widthIRL=400):
#xmin, xmaxii, ymin, ymax = limits
with open(filename, "r") as txt:
data = [line.strip().split() for line in txt.readlines()]
data = [line.strip().split() for line in txt.readlines() if line.strip() != ""]
dim = data[:6]
# Number of points
npy, npx = [int(d[1]) for d in data[:2]]
ncols, nrows = [int(d[1]) for d in data[:2]]
# Origin coordinates (Actually these can be ignored in our case)
Ox, Oy = [float(d[1]) for d in data[2:4]]
if cellsize is None:
cellsize = float(data[4][1])
# Topography
data = np.array(data[6:], dtype="float64", order="F")
data = np.array(data[6:], dtype="float64")
if fmt == "vts":
#To export data stored in a rectilinear grid (AKA irregular Cartesian grid):
from evtk.hl import gridToVTK
#X = [Ox + i*cellsize for i in range(npx)]
#Y = [Oy + j*cellsize for j in range(npy)]
X = np.linspace(Ox, Ox + npx*cellsize, npx, dtype="float64")
Y = np.linspace(Oy, Oy + npy*cellsize, npy, dtype="float64")
X = [Ox + i*cellsize for i in range(ncols)]
Y = [Oy + j*cellsize for j in range(nrows)]
# X = np.linspace(Ox, Ox + (ncols-1)*cellsize, ncols, dtype="float64")
# Y = np.linspace(Oy, Oy + (nrows-1)*cellsize, nrows, dtype="float64")
x = np.zeros((npx,npy,1))
y = np.zeros((npx,npy,1))
z = data.flatten().reshape(npx, npy, 1)
x = np.zeros((ncols,nrows,1))
y = np.zeros((ncols,nrows,1))
z = data.flatten().reshape(ncols, nrows, 1)
for i, Xi in enumerate(X):
x[i,:,0] = Xi
......@@ -75,17 +74,21 @@ def asc2fmt(filename, outputname, fmt="png", cellsize=None, widthIRL=400):
print(gridToVTK(outputname, x, y, z, pointData = {"elevation" : z.flatten(order="F")}))
elif fmt == "png":
xsize = (npx-1)*cellsize
ysize = (npy-1)*cellsize
xsize = (ncols-1) * cellsize
ysize = (nrows-1) * cellsize
hsize = data.max() - data.min()
print("dim:", xsize, ysize, hsize)
# Image dimension (pixel)
pixel_width = 1200.
pixel_scale = pixel_width/xsize
print("scale 1 pix = {} m".format(pixel_scale))
pixel_depth = pixel_scale * ysize
make_image(data, outputname+".png", size=(pixel_width, pixel_depth))
# pixel_height = 1200.
# pixel_scale = pixel_height/ncols
# print("scale 1 pix = {} m".format(pixel_scale))
# print(pixel_scale)
# pixel_depth = pixel_scale * ysize
# make_image(data, outputname+"_001.png", size=(pixel_width, pixel_depth))
# print(data.shape, (ncols,nrows) )
# WARNING data shape and pixel size are reversed
make_image(data, outputname+".png", size=data.shape[::-1])
# make_image(data, outputname+".png", size=(ncols*cellsize, nrows*cellsize))
# dimension cura en mm
scale = widthIRL/xsize
......@@ -98,7 +101,7 @@ def asc2fmt(filename, outputname, fmt="png", cellsize=None, widthIRL=400):
print("height (mm) {:.2f}".format(height))
print("Base (mm) 1.0")
print("Width (mm) {:.2f}".format(width))
print("Depth (mm) {:.2f}".format(depth))
# print("Depth (mm) {:.2f}".format(depth))
print(" Lighter is higher")
elif fmt == "stl":
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment