1

I have a line in x,y,z format. I would like to duplicate the line in parallel with increasing y values.

For example I have:

    x,y,z
    320300,6225380,-8.8
    320310,6225380,-8.8
    320320,6225380,-8.8

There are about 2000 entries.

I would like to create an array of points, such that this line is duplicated with x and z remaining the same but with increasing values of y so I could say, duplicate the line and increase y by 10, starting at 6225380 and ending at 6332640: then tag the x,y,z points onto the file and export as *.csv

example simplified result below:

    x,y,z
    320300,6225380,-8.8
    323310,6225380,-8.8
    320320,6225380,-8.8
    320300,6225400,-8.8
    323310,6225400,-8.8
    320320,6225400,-8.8
    320300,6225410,-8.8
    323310,6225410,-8.8
    320320,6225410,-8.8

I have tried the following:

import numpy as np
import pandas as pd

csv_path='PHid4_pts_6225380.csv'

df=pd.read_csv(csv_path)

sp=10
x1=df['x']
y1=np.arange(6225380,6232640,sp)
z1=df['z']

x_mesh, y_mesh =np.meshgrid(x1,y1)

coords = []
for a, b, c in  zip(x_mesh, y_mesh, z1):
    for a1, b1, c1 in zip(a, b, c):
      #  for a2, b2, c2 in zip(a1, b1, c1):
        coords.append((a1, b1, c1,))

It seems to be working ok until I get to the 'coords=[]' part where I am trying to re use an iterator i picked up elsewhere.

Any help would be much appreciated Thanks, Kaya

Kris
  • 8,680
  • 4
  • 39
  • 67
Kaya Wilson
  • 53
  • 1
  • 6

1 Answers1

1

The z1 is the problem creator here. The output of line

for a, b, c in  zip(x_mesh, y_mesh, z1)

will be an array of x, array of y and then value z1 which is -8.8 from your sample data. So in next line

 for a1, b1, c1 in zip(a, b, c):

The parameters a,b are lists, which can be zipped but not c because its just a value and not an array or iterable. So you need to make it a iterable. Eg.,

for a1, b1, c1 in zip(a, b, np.ones(len(b))*c):

I just made value -8.8 to repeat in the array for length of b.

Kris
  • 8,680
  • 4
  • 39
  • 67
  • This was great thanks but it makes the z1 value repeat along the horizontal and not the vertical as I need it to. I tried substituting the bracketed 'a' to 'b' but got the same result: for a1, b1, c1 in zip(a, b, np.ones(len(a))*c): I will have another go tomorrow but I think this is halfway there! – Kaya Wilson Mar 16 '20 at 08:55
  • I managed to get it working by substituting the above line to: for a1, b1, c1 in zip(a, b, df.loc[df['x']==a, 'z']): – Kaya Wilson Mar 16 '20 at 22:40
  • None better than you yourself to do it! :D – Kris Mar 17 '20 at 04:49