Efficient way to extract Subhalo Data using API

Ambica Govind
  • 2
  • 13 Apr

Hi , I'm trying to load some sub halo data using the API But the code runs really slow. Is there a more efficient way to do this?

baseUrl = 'http://www.tng-project.org/api/TNG50-1/snapshots/'
snaps=get(baseUrl)
snaprs=[(snaps[i]['number'],snaps[i]['redshift']) for i in range(len(snaps))]
snaprs[95:]
link=get(snaps[-1]['url'])

def get_data(link,z,n):

    ID=[]
    M=[]
    SFR=[]
    R=[]
    MG=[]
    MDM=[]
    MT=[]
    V=[]
    Rmax=[]    
    S=[]

    i=0
    h=0.6774

    while(i<=n):
        if i==0:
            data=get(link['subhalos'],{'limit':100})

        else:
            data=get(go)

        for gal in data['results']:

            d=get(gal['url'])

            if ((d['massinrad_stars']>8) and (d['massinrad_stars'] <11.5) and (d['sfrinrad']>0) and (d['subhaloflag']==1) and (d['halfmassrad_stars']>0):

                ID.append(d['id'])

                M.append(d['massinrad_stars']*1e10/h)
                SFR.append(d['sfrinrad'])
                R.append(d['halfmassrad_stars']/h)
                MG.append(d['massinrad_gas']*1e10/h)
                MDM.append(d['massinrad_dm']*1e10/h)
                MT.append(d['massinrad']*1e10/h)

                V.append(d['vmax'])
                Rmax.append(d['vmaxrad']/h)
                S.append(d['veldisp'])

        go=data['next']
        i+=1

    ID=np.array(ID)
    M=np.array(M)
    SFR=np.array(SFR)
    R=np.array(R)
    MG=np.array(MG)
    MDM=np.array(MDM)
    MT=np.array(MT)
    V=np.array(V)
    Rmax=np.array(Rmax)
    S=np.array(S)
    Z=z*np.ones(len(ID))

    return Z,ID,M,SFR,R,MG,MDM,MT,V,Rmax,S

Also the units of the physical quantities retrieved using the API seem to be different from that described in the documentation. Where can I find a description?

Dylan Nelson
  • 15 Apr

It seems like you are trying to search over some properties, including stellar mass.

You should send this search query, and then the resulting list of subhalos that you get are only those which satisfy the search.

You can find searching in the API documentation (see cookbook Task #2, for example).

Finally, if you want to go beyond this, you may want to just download the group catalog files, to work with them on your local machine.

  • Page 1 of 1