コード例 #1
0
def getHaloData(whichHalo, simulation='Illustris-1', snapshot=135):
    """
    Returns a dictionary with all catalog data corresponding to a halo or subhalo
    
    Docstring is identical for `getHaloData`and `getSubhaloData`
    
    These two commands are effectively identical. They have the same input and 
    output, except one deals with halos (roughly speaking 'groups/ clusters') 
    and the other with the subhalos in those halos (the 'galaxies' in those 
    'groups'). See Intro to the Data (or Naming Conventions) for more on the 
    data structure/ naming conventions used.

    Parameters
    ----------
    whichHalo : int
        halo/subhalo number of the galaxy you wish to get data for

    simulation : str
        Which simulation to pull data from

    snapshot : int
        Which snapshot (moment in time) to pull data from

        
    Returns
    -------
    data : dict
        A dictionary of data, with an entry for each field (with field names 
        from section 2. of this page
        http://www.illustris-project.org/data/docs/specifications/
        
    
    """

    units = changeUnits.makeHaloDict(simulation=simulation, snapshot=snapshot)
    url = 'http://www.illustris-project.org/api/' + simulation + '/snapshots/' + str(
        snapshot) + '/halos/' + str(whichHalo) + '/info.json'
    data = get(url)
    haloData = data['Group']
    haloKeys = list(haloData.keys())
    for i in range(len(haloKeys)):
        oldValue = np.array(haloData[haloKeys[i]])
        convFactor = units[haloKeys[i]]
        haloData[haloKeys[i]] = convFactor * oldValue
    return haloData
コード例 #2
0
def getHaloField(field,
                 simulation='Illustris-1',
                 snapshot=135,
                 fileName='tempCat',
                 rewriteFile=1):
    """
    Data from one field for all halos/subhalos in a given snapshot      
    
    These two commands are near identical, so I'm going to detail them both here. 
    They have the same input and output, except one deals with halos (roughly 
    speaking 'groups/ clusters') and the other with the subhalos in those halos 
    (the 'galaxies' in those 'groups'). See Intro to the Data (or Naming 
    Conventions) for more on the data structure/ naming conventions used.
    
    
    Parameters
    ----------
    field : str
        Name of the one field to be returned. The fields can be found in 
        section 2. of this page
        http://www.illustris-project.org/data/docs/specifications/

    simulation : str
        Which simulation to pull data from

    snapshot : int
        Which snapshot (moment in time) to pull data from

    The following two parameters are discussed in more detail here!

    fileName : str
        Default is 'tempGal.hdf5'. Filename for where to store or load the data 

    rewriteFile : int
        [0 or 1] If this is equal to 0 then the program will try and pull data 
        from the file specified by fileName rather than re-downloading. This can 
        save time, especially for galaxies which are large or you will work on 
        frequently, but you will only be able to access fields you originally 
        requested
        
        
    Returns
    -------
    data : array
        A numpy array containing the data for a specific field for all halos/subhalos

        
    Examples
    --------
    Let's pull out the velocity dispersion of stars in every subhalo and their 
    DM mass, and then restrict ourselves to only looking at the primary subhalo 
    in each halo (i.e. the most massive galaxy in each group).

    The velocity dispersion (N_sub values)
    
        >>> galaxyVelDisp=iApi.getSubhaloField('SubhaloVelDisp')

    The mass of each different particle type in a galaxy (N_sub x 6 values, 
    see getGalaxyData for more info on particle types)
    
        >>> galaxyMassType=iApi.getSubhaloField('SubhaloMassType') 

    The subhalo number of the primary subhalo in each halo (N_halo values)
        
        >>> primarySubhalos=iApi.getHaloField('GroupFirstSub') 

    Velocity dispersion of primary subhalos
    
        >>> velDisp=galaxyVelDisp[primarySubhalos]

    Total dark matter mass of primary subhalos 
    
        >>> mDM=galaxyMassType[primarySubhalos,1] 
    
    """

    if rewriteFile == 1:  # redownloads file from the internet
        url = 'http://www.illustris-project.org/api/' + simulation + '/files/groupcat-' + str(
            snapshot) + '/?Group=' + field
        dataFile = get(url, fName=fileName)
    if rewriteFile == 0:  # if we're not redownloading need to set path to the file
        dataFile = fileName + '.hdf5'

    with h5py.File(dataFile, 'r') as f:
        data = np.array(f['Group'][field])
    units = changeUnits.makeHaloDict(simulation=simulation, snapshot=snapshot)
    return data * units[field]