mass of all ids in z=0

Mohammad Hossein Najafi
  • 8 May '17

i need mass of all ids in z=0, but when i run the code, it print mass of first 100 ids.

can u help me?

Mohammad Hossein

Dylan Nelson
  • 10 May '17

Hi Mohammad,

You sent me some code, the main fix is you need to add a ?limit=N to the URL.

Also, much better to make just 1 request, instead of 1 for every subhalo.

import requests
import h5py
import numpy as np
import matplotlib.pyplot as plt

def get(path, params=None):
        headers = {"api-key":"KEY_HERE"}
        r = requests.get(path, params=params, headers=headers)
        r.raise_for_status()
        if r.headers['content-type'] == 'application/json':
                return r.json()
        if 'content-disposition' in r.headers:
                filename = r.headers['content-disposition'].split("filename=")[1]
                with open(filename, 'wb') as f:
                        f.write(r.content)
                return filename
        return r

mass_log_msun = []

# make only one API request
url = "http://www.illustris-project.org/api/Illustris-3/snapshots/135/subhalos/?limit=10000000"
subhalos = get(url)

# loop over all returned subhalos
for subhalo in subhalos['results']:
        mass_log_msun.append(subhalo['mass_log_msun'])

# write
with open("mass_histogram.txt", "w") as text_file:
        for mass in mass_log_msun:
                text_file.write(str(mass) + '\n')
Mohammad Hossein Najafi
  • 1
  • 14 May '17
  • list itemthank u I fixed it. How can i access to "GroupNsubs " that are more than 300? when i run my code , after sum times i have not any results .

import requests

import h5py

import matplotlib.pyplot as plt

def get(path, params=None): headers = {"api-key":"55b3f0a3e018d38bc4c3d0a10871a076"} r = requests.get(path, params=params, headers=headers) r.raise_for_status() if r.headers['content-type'] == 'application/json': return r.json() if 'content-disposition' in r.headers: filename = r.headers['content-disposition'].split("filename=")[1] with open(filename, 'wb') as f: f.write(r.content) return filename return r

url = "http://www.illustris-project.org/api/Illustris-3/snapshots/z=0/subhalos/" subhalos = get(url) ids=[] j=0 s= ""

while(len(ids)<200):

while j< 121208: url = "http://www.illustris-project.org/api/Illustris-3/snapshots/z=0/subhalos/" + str(subhalos['results'][j]['id']) sub = get(url) N_url = sub['related']['parent_halo'] + "info.json" parent_fof = get(N_url) if(parent_fof['Group']['GroupNsubs'] > 600): ids.append((subhalos['results'][j]['id'])) s = s + "\n " + str(ids[j])+" , "+str(parent_fof['Group']['GroupNsubs']) j+=1

with open("GroupNsubs.txt", "w") as text_file: text_file.write(str(s))

Dylan Nelson
  • 14 May '17

Hi,

Are you sure you do not want to download the group catalog (4.5GB)? If you do this once, you can then do all these searches and exploration faster.

For example, for Illustris-1 at z=0 there are 232 groups with >300 GroupNsubs and 112 groups with >600 GroupNsubs. Their IDs are:

[  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
         13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,
         26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,
         39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,
         52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
         65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,
         78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  89,  90,
         91,  92,  93,  94,  95,  96,  97,  98,  99, 100, 101, 102, 103,
        104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116,
        117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
        130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142,
        143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155,
        156, 157, 158, 159, 161, 162, 163, 164, 165, 166, 167, 169, 170,
        171, 172, 173, 175, 176, 177, 178, 179, 180, 181, 182, 184, 185,
        186, 188, 192, 193, 194, 195, 196, 197, 198, 199, 201, 203, 205,
        206, 207, 208, 209, 210, 211, 212, 214, 217, 218, 219, 224, 225,
        227, 230, 231, 233, 237, 238, 239, 241, 250, 251, 254, 255, 263,
        267, 279, 282, 289, 298, 307, 308, 309, 318, 375, 377]

and

[  0,   1,   2,   3,   4,   5,   6,   7,   8,   9,  10,  11,  12,
         13,  14,  15,  16,  17,  18,  19,  20,  21,  22,  23,  24,  25,
         26,  27,  28,  29,  30,  31,  32,  33,  34,  35,  36,  37,  38,
         39,  40,  41,  42,  43,  44,  45,  46,  47,  48,  49,  50,  51,
         52,  53,  54,  55,  56,  57,  58,  59,  60,  61,  62,  63,  64,
         65,  66,  67,  68,  69,  70,  71,  72,  73,  74,  75,  76,  77,
         78,  79,  80,  81,  82,  83,  84,  85,  86,  87,  88,  90,  91,
         92,  93,  94,  95,  96,  97,  98, 101, 102, 103, 106, 110, 111,
        114, 115, 118, 122, 126, 129, 139, 141]
Mohammad Hossein Najafi
  • 1
  • 15 May '17

thank u

how can access to similar cods? are any in the site?

Dylan Nelson
  • 16 May '17

Hi,

I suggest you follow the first section "Group Catalogs" of this page:

http://www.illustris-project.org/data/docs/scripts/

Next, change Illustris-3 to Illustris-1 and download the Illustris-1 group catalog. After, you should be able to search on GroupNsubs in a similar method as the documentation.

Mohammad Hossein Najafi
  • 20 May '17

Hi Thank you why Illustris-1 ? Is any important limitation on Illustris-3 that we cant use it?

Dylan Nelson
  • 20 May '17

Illustris-3 is just low resolution. Usually, we start on Illustris-3 and write a code/analysis, then apply it to Illustris-2 and then Illustris-1 to see what the 'best' result is at the highest resolution (Illustris-1).

Mohammad Hossein Najafi
  • 3
  • 26 May '17

import illustris_python as il

basePath = '/home/saeed/illustris-3'

GroupFirstSub = il.groupcat.loadHalos(basePath,135,fields=['GroupFirstSub'])

G = ''

for i in range(121209):

all_fields = il.groupcat.loadSingle(basePath,135,subhaloID=GroupFirstSub[i])

SubhaloMass = all_fields['SubhaloMass']

if (10**11.5 / 1e10 * 0.704) < SubhaloMass < (10**12 / 1e10 * 0.704):

    G = G + '\n' + str(GroupFirstSub[i])

with open("lowmass.txt", "w") as text_file:

text_file.write(str(G))

when I run this code, I have the error:

ValueError: Index (4294906691) out of range (0-60604)

how can i fix it?

  • Page 1 of 1