0

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.724

I 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.451

What 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

askedSep 8, 2016 at 16:02
Protoss Reed's user avatar
2
  • Where are you actually applyinginterp1d and what's going wrong, exactly?CommentedSep 8, 2016 at 16:57
  • I didn't set 'x' I wrote np.interp(X_list,x,V_list)CommentedSep 8, 2016 at 19:50

1 Answer1

2

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)
answeredSep 8, 2016 at 17:04
Matheus Portela's user avatar
Sign up to request clarification or add additional context in comments.

1 Comment

That realy wokrs! Thank you! I tried it before, but instead ''x'' I put X_list - becouse I thought the first parametr need to be a coordinate

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.