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')
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
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).
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
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 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))
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:and
thank u
how can access to similar cods? are any in the site?
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.Hi Thank you why Illustris-1 ? Is any important limitation on Illustris-3 that we cant use it?
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).
import illustris_python as il
basePath = '/home/saeed/illustris-3'
GroupFirstSub = il.groupcat.loadHalos(basePath,135,fields=['GroupFirstSub'])
G = ''
for i in range(121209):
with open("lowmass.txt", "w") as text_file:
when I run this code, I have the error:
ValueError: Index (4294906691) out of range (0-60604)
how can i fix it?