This issue realy drives me crazy. I have got ascii file with ~1 000 000 rows in it. There are 3 columnsX - coordinate, Z- depths- V -speed. For instance:
X Z V 45000 -11657.8 5985.61 45000 -11578.22 5974.688 45000 -11259.92 5930.935 287800 -1034.451 2062.341 287800 -1014.557 2051.226 287800 -934.9814 2006.724I need interpolate Depth(Z)[-15 000 to 0] with Speed(V) by steps (For each 2000m or 100m etc)For example
45000 -11657.8 5985.61 45000 -11600 ?????? 45000 -11578.22 5974.688 45000 -11500 ????? 45000 -111034.451 2062.341 287800 -934.9814 2006.724 287800 -900 ???? 287800 -895.1937 1984.451What I did:
import numpy as npfrom scipy.interpolate import interp1dwith open('my data' ,'r') as f:header1 = f.readline() ###skip the first head line X_list=[] #### Create 3 empty listsZ_list=[]V_list=[]for line in f: line = line.strip() columns = line.split() X = (float(columns[0])) ### separete columns and add to list and convert Z = (float(columns[1])) ###to float V = (float(columns[2])) X_list.append(X) Z_list.append(Z) V_list.append(V)x = np.linspace(min(Z_list),max(Z_list),6) ## step 3000m = 6 partsprint (x)result:
[-15000. -12000. -9000. -6000. -3000. 0.]
Now I got:
X Z V45000 -15000 ??????45000 -12000 ??????45000 -9000 ??????45000 -6000 ??????45000 -3000 ??????So the question is. How could I interpolate this speed to interesting depths for each coordinates??Thank you for any advice
- Where are you actually applying
interp1dand what's going wrong, exactly?Praveen– Praveen2016-09-08 16:57:39 +00:00CommentedSep 8, 2016 at 16:57 - I didn't set 'x' I wrote np.interp(X_list,x,V_list)Protoss Reed– Protoss Reed2016-09-08 19:50:26 +00:00CommentedSep 8, 2016 at 19:50
1 Answer1
In order to interpolate, you need some example of inputs and outputs that will be the base of the interpolation. In your case,Z_list is the input andV_list, the output.
Next, you can use theinterp function fromnumpy, which expect an array to interpolatex, followed by the inputZ_list and outputV_list. Let's follow the example inits documentation.
import numpy as npprint np.interp(x, Z_list, V_list)1 Comment
Explore related questions
See similar questions with these tags.
