Problem building velocity model with build_taup_model

Hi everyone,

I am trying to use the function build_taup_model to create a velocity model using the following .tvel-file:

ak135 - P
ak135 - S
0.0000 5.8000 3.4600 2.7200
10.0000 5.8000 3.4600 2.7201
10.0000 5.8001 3.4602 2.7202
20.0000 5.8000 3.4601 2.7201
20.0000 5.8001 3.4602 2.7202
30.0000 6.5000 3.8501 2.9201
30.0000 6.5001 3.8502 2.9202
35.000 6.5000 3.8500 2.9200
35.000 8.0400 4.4800 3.3198
40.0000 8.0406 4.4812 3.3228

The code in which I call the function is as follows:

CWD = str(os.getcwd())
CWD = CWD[:CWD.index("V")]
CWD = CWD.replace("\\", "/")
CWD = CWD.replace(':/','://') + "Veegeo_ Dropbox/"
file_name = 'test.tvel'
build_taup_model(CWD + "Projecten/Seismisch Monitoring/Data - Tijn/Velocity model/.tvel_files/" + file_name, output_folder = CWD + "Projecten/Seismisch Monitoring/Data - Tijn/Velocity model/taup_models/", verbose = True) 

I get the following chain of errors:

runfile('C:/Users/veege/Veegeo_ Dropbox/Projecten/Seismisch monitoring/Python scripts - Tijn/Main program/', wdir='C:/Users/veege/Veegeo_ Dropbox/Projecten/Seismisch monitoring/Python scripts - Tijn/Main program')
Building obspy.taup model for 'C://Users/veege/Veegeo_ Dropbox/Projecten/Seismisch Monitoring/Data - Tijn/Velocity model/.tvel_files/test.tvel' ...
Traceback (most recent call last):

  File ~\Veegeo_ Dropbox\Projecten\Seismisch monitoring\Python scripts - Tijn\Main program\ in <module>
    build_taup_model(CWD + "Projecten/Seismisch Monitoring/Data - Tijn/Velocity model/.tvel_files/test.tvel")

  File ~\miniconda3\lib\site-packages\obspy\taup\ in build_taup_model

  File ~\miniconda3\lib\site-packages\obspy\taup\ in load_velocity_model
    self.v_mod = VelocityModel.read_velocity_file(filename)

  File ~\miniconda3\lib\site-packages\obspy\taup\ in read_velocity_file
    v_mod = cls.read_tvel_file(filename)

  File ~\miniconda3\lib\site-packages\obspy\taup\ in read_tvel_file
    data = np.genfromtxt(filename, skip_header=2, comments='#')

  File ~\miniconda3\lib\site-packages\numpy\lib\ in genfromtxt
    fid =, 'rt', encoding=encoding)

  File ~\miniconda3\lib\site-packages\numpy\lib\ in open
    return, mode, encoding=encoding, newline=newline)

  File ~\miniconda3\lib\site-packages\numpy\lib\ in open
    found = self._findfile(path)

  File ~\miniconda3\lib\site-packages\numpy\lib\ in _findfile
    name = self._cache(name)

  File ~\miniconda3\lib\site-packages\numpy\lib\ in _cache
    with urlopen(path) as openedurl:

  File ~\miniconda3\lib\urllib\ in urlopen
    return, data, timeout)

  File ~\miniconda3\lib\urllib\ in open
    response = self._open(req, data)

  File ~\miniconda3\lib\urllib\ in _open
    return self._call_chain(self.handle_open, 'unknown',

  File ~\miniconda3\lib\urllib\ in _call_chain
    result = func(*args)

  File ~\miniconda3\lib\urllib\ in unknown_open
    raise URLError('unknown url type: %s' % type)

URLError: <urlopen error unknown url type: c>

The error seems to arise in the urllib before the file has been properly read. Does anyone have an idea how to fix this?

Looks like numpy has trouble finding your file and thinks whatever you feed in as the location is an URL. Ideally you should use pathlib.Path for building your filepath, it seems quite messy how you build up your path.
Aside from that you might want to look into these slash/backslash escape problems on Windows, I can’t comment on those.

In any case when you finalize your path, something like this should work (I expect this will fail on what you input as first argument to build_taup_model):

path = ...
print(open(path, "rt").readline())
# should print that first line of your file

P.S.: Please take a second to look up how to do proper markup for codeblocks/command line output, so it’s easier to read (I just added that markup in your post)

Hi Megies,

You were correct about the pathname. Thanks for your help!