Problem with API example scripts

Neda Stojkovic
  • 1
  • 23 Aug '19

Hello Dylan,

I'm trying to use your API getting started guide to get snapshot cutouts of several subhaloes. But I have always the same problem with loading data. Both with lines of code:

mpb1 = get( sub['trees']['sublink_mpb'] ) # file saved, mpb1 contains the filename

f = h5py.File(mpb1,'r')

and:

cutout = get(sub_prog_url+"cutout.hdf5", cutout_request)
with h5py.File(cutout,'r') as f:
x = f['PartType0']['Coordinates'][:,0] - sub_prog['pos_x']
y = f['PartType0']['Coordinates'][:,1] - sub_prog['pos_y']
dens = np.log10(f['PartType0']['Masses'][:])

I have the same error:

Traceback (most recent call last):
File "api_tng.py", line 62, in
with h5py.File(cutout,'r') as f:
File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/files.py", line 266, in init
name = filename_encode(name)
File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/compat.py", line 111, in filename_encode
filename = fspath(filename)
File "/usr/local/lib/python2.7/dist-packages/h5py/_hl/compat.py", line 42, in fspath + path_type.name)
TypeError: expected str, bytes or os.PathLike object, not Response

I didn't change your code, just tested it as it is, just for TNG100-1 simulation and subhalo with subfind id 10 for z=0.
Do you have any idea why is this happening?

Dylan Nelson
  • 25 Aug '19

Hi Neda,

There are two versions of get(), the one at the top of the tutorial, and the one half way down (also available at the top of the Cookbook). It's this second "full" version you need, which directly saves responses which are files, to a file on the hard drive.

Neda Stojkovic
  • 25 Aug '19

Thank you for your quick response. I am using second version of the get(). But there are no difference when I turn on and off that second part. Also there is no new file on the hard drive when I run second version.

Dylan Nelson
  • 25 Aug '19

Hi Neda,

You should check what mpb1 and cutout actually are, then. They should be filenames, and the paths should point to actual files.

If this isn't working, perhaps try a manual wget or download in the web browser of e.g. sub['trees']['sublink_mpb'] and see that you can get the expected HDF5 file.

Neda Stojkovic
  • 26 Aug '19

Thank you, Dylan, I succeeded downloading cutouts I need using manual wget, and I will try it on merger trees also.
Thank you very much for your help.

  • Page 1 of 1