The py-galaxies API
Driver routines
Parameters
- class parameters.C_parameters(param_file)
Read in yml parameters and store them.
Simple class to read in and store parameters from the yml file. Simple methods included to print out the parameters etc. All global parameters are stored here.
- b_*
Flag for each of the model parameters
- Type:
boolean
- c_*
Various dimensionless physical constants for use in astrophysics routines
- Type:
float
- D_param
Dictionary containing contents of yml file.
- Type:
dictionary
- units_*
The units used for input, output and internally within the code, and conversion factors between them.
- Type:
float
- F_create_header_file()
Writes out all the attributes of parameters to code/parameters.h.
- F_update_parameters(graph_file)
Reads in attributes of the graph and the snapshot table
- Parameters:
graph_file (obj : HDF5 File) – Open HDF5 file containing the merger graphs.
- Return type:
None
- __init__(param_file)
Reads in and generates global parameters.
- Parameters:
param_file (str) – Filepath to the yml file containing the model parameters.
- __str__()
Simple method to print out parameters.
Main driver routine
- push_snap.F_push_snap(halos_last_snap, halos_this_snap, subs_last_snap, subs_this_snap, gals_last_snap, graph, parameters, variables)
Propagate properties from progenitor halos to descendants. To convert this to C one would first have to extract all the required graph properties into numpy arrays, then pass those into this routine as arguments. This would not be too hard to do, but only worth it if this routine is CPU time-limiting.
Done as a push rather than a pull because sharing determined by progenitor. First loop to push halo / subhalo properties; then structured gal array needs to be generated; then second push of gal properties.
- Parameters:
halos_last (obj : D_halo[n_halo_last_snap]) – The halos from the last (ie previous) snapshot
halos_this (obj : D_halo[n_halo_last_snap]) – The halos from the current snapshot
subs_last (obj : D_sub[n_sub_last_snap]) – The subhalos from the last (ie previous) snapshot
subs_this (obj : D_sub[n_sub_last_snap]) – The subhalos from the current snapshot
gals_last (obj : D_gal[n_gal_last_snap]) – The galaxies from the last (ie previous) snapshot
graph (obj : C_graph) – Instance of class containing the current graph
parameters (obj : C_parameters) – Instance of class containing the run-time parameters
variables (obj : C_variables) – Instance of class containing global variables structure
- Returns:
n_gal_this_snap – The number of galaxies in this snapshot
- Return type:
int
Data structures
Graphs
Class file for reading and storage of graph properties
- class graphs.C_graph(graph_ID, open_graph_file, parameters)
A container for all data contained within a single graph.
Note that all attributes are in internal units. In the following attributes the sizes of the arrays are specified in terms of the total number of snapshots, halos, subhalos, progenitors and descendants within the graph.
- # Graph and snapshot properties
- graph_ID
The unique identifier of the graph within the file.
- Type:
int
- n_gal
Running total of the number of galaxies created by py-galaxies when processing the graph
- Type:
int
- snap_n_halo
The number of halos in each snapshot.
- Type:
int[n_snap]
- snap_first_halo_gid
The first halo in each snapshot, relative to the graph.
- Type:
int[n_snap]
- snap_n_sub
The number of subhalos in each snapshot.
- Type:
int[n_snap]
- snap_first_sub_gid
The first subhalo in each snapshot, relative to the graph.
- Type:
int[n_snap]
- # Halo properties
- halo_desc_contribution
The particle contributions to descendant halos.
- Type:
float[halo_n_desc]
- halo_desc_IDs_gid
The locations in the graph of all descendant halos of each halo.
- Type:
int[halo_n_desc]
- halo_first_desc_gid
The locations in the graph of the first descendant halo of each halo.
- Type:
int[n_halo]
- halo_first_sub_gid
The locations in the graph of first subhalo in each halo.
- Type:
float[n_halo]
- half_mass_radius
The radii containing half of the halo particles.
- Type:
float[n_halo]
- halo_mass
The mass of each halo.
- Type:
float[n_halo]
- halo_mean_pos
The position of each halo.
- Type:
float[n_halo,3]
- halo_mean_vel
The velocity of each halo.
- Type:
float[n_halo,3]
- halo_n_desc
The number of descendants of each halo.
- Type:
float[n_halo]
- halo_n_sub
The number of subhalos of each halo
- Type:
float[n_halo]
- halo_rms_radius
The rms radii of halo particles
- Type:
float[n_halo]
- halo_rms_speed
The rms speeds of halo particles
- Type:
float[n_halo]
- # Subhalo properties
- sub_desc_contribution
The particle contributions to descendant subhalos.
- Type:
float[n_desc_sub]
- sub_desc_IDs_gid
The locations in the graph of all descendant subhalos.
- Type:
int[n_desc_sub]
- sub_first_desc_gid
The locations in the graph of the first descendant subhalo of each subhalo.
- Type:
int[n_sub]
- sub_half_mass_radius
The radii containing half of the subhalo particles.
- Type:
float[n_sub]
- sub_host_gid
The host halo of each subhalo.
- Type:
int[n_sub]
- sub_mass
The mass of each subhalo.
- Type:
float[n_sub]
- sub_n_desc
The number of descendants of each subhalo.
- Type:
float[n_sub]
- sub_pos
The position of each subhalo.
- Type:
float[n_sub,3]
- sub_rms_speed
The rms speed of subhalo particles within each subhalo.
- Type:
float[n_sub]
- sub_vel
The velocity of each subhalo.
- Type:
float[n_sub,3]
- __init__(graph_ID, open_graph_file, parameters)
Opening HDF datasets for a graph and saving them to the class.
- Parameters:
graph_ID (int) – The ID within the file of the graph to be opened.
open_graph_file (obj : 'File') – Open HDF5 file that is to be read from.
parameters (obj : 'C_parameters class') – Contains parameters describing the simulation.
Halos
Halo numpy structured array dtype definition and template for initialisation, and python class for output.
All physical quantities are in internal code units.
Methods now moved to halos.c
- halos.graph_ID
The graph_ID (from HDF5 group).
- Type:
int
- halos.snap_ID
The snapshot ID currently being processed.
- Type:
int
- halos.halo_gid
The halo location within the graph of the halo currently being processed.
- Type:
int
- halos.halo_sid
The halo location within the snapshot of the halo currently being processed.
- Type:
int
- halos.b_done
Whether or not the halo has been fully processed.
- Type:
bool
- halos.desc_end_gid
The index at which this halo’s descendents end (+1 as is usual for python).
- Type:
int
- halos.desc_main_sid
The main descendant location in this snapshot (ie in halos_this_snap).
- Type:
int
- halos.desc_start_gid
The index at which this halo’s descendents start.
- Type:
int
- halos.half_mass_radius
The radius containing half the total mass of the halo in the DM-only sim.
- Type:
float
- halos.half_mass_virial_speed
The circular speed at the half-mass radius.
- Type:
float
- halos.mass
The DM-only mass of this halo.
- Type:
float
- halos.mass_baryon
Mass of baryons within the halo, inclusive of subhalos and galaxies.
- Type:
float
- halos.mass_baryon_from_progenitors
Total mass of all the baryons contained within the progenitor halos.
- Type:
float
- halos.mass_baryon_delta_dthalo
The accretion needed per halo timestep to bring the baryon content up to the universal mean.
- Type:
float
- halos.mass_from_progenitors
Total DM-only mass of all the progenitor halos.
- Type:
float
- halos.mass_gas_eject
The mass of ejected gas
- Type:
float
- halos.mass_gas_hot
The mass of hot gas in the halo, exclusive of subhalos.
- Type:
float
- halos.mass_stars
The mass of stars in the halo, exclusive of subhalos.
- Type:
float
- halos.mass_metals_gas_eject
The mass of metals in ejected gas.
- Type:
float
- halos.mass_metals_gas_hot
The mass of metals in hot gas in the halo, exclusive of subhalos.
- Type:
float
- halos.mass_metals_stars
The mass of metals in stars in the halo, exclusive of subhalos.
- Type:
float
- halos.n_desc
The number of direct descendants of this halo
- Type:
int
- halos.n_dt
Number of times that this halo has been processed this snapshot
- Type:
int
- halos.n_gal
The number of galaxies in the halo, inclusive of subhalos
- Type:
int
- halos.n_orphan
The number of orphan galaxies (i.e. galaxies not contained in subhalos)
- Type:
int
- halos.n_sub
The number of subhalos.
- Type:
int
- halos.orphan_start_sid
The location of the first orphan galaxy within the current snapshot galaxy array
- Type:
int
- halos.orphan_next_sid
To track the processing of orphan galaxies during the halo_update phase.
- Type:
int
- halos.pos
The position of the halo.
- Type:
float[3]
- halos.rms_radius
The rms radius of the halo particles in the DM-only sim.
- Type:
float
- halos.rms_speed
The rms speed of the halo particles in the DM-only sim.
- Type:
float
- halos.sub_central_sid
The location in the snapshot of the subhalo at the centre of the halo (if any)
- Type:
int
- halos.sub_end_gid
The location in the graph of the last subhalo (+1 because of python indexing)
- Type:
int
- halos.sub_end_sid
The location in the snapshot of the last subhalo (+1 because of python indexing)
- Type:
int
- halos.sub_mass
The DM-only masses of the subhalos
- Type:
float[n_sub]
- halos.sub_rel_pos
The positions of the subhalos relative to that of the halo
- Type:
float[n_sub,3]
- halos.sub_rel_vel
The velocities of the subhalos relative to that of the halo
- Type:
float[n_sub,3]
- halos.sub_start_gid
The location in the graph of the first subhalo
- Type:
int
- halos.sub_start_sid
The location in the snapshot of the first subhalo
- Type:
int
- halos.tau_dyn
Twice the dynamical time at the half-mass radius (= dynamical time at twice the half mass radius for isothermal sphere).
- Type:
float
- halos.temperature
The temperature as derived from the virial speed.
- Type:
float
- halos.vel
Velocity of the halo
- Type:
float[3]
- class halos.C_halo_output(parameters)
This class contains the attributes and methods for the halo output files.
- halo_file
HDF5 file for halo output
- Type:
obj : File
- i_rec
Counter for how many records have been created.
- Type:
int
- io_buffer
Storage for halo records prior to outputting.
- Type:
obj : D_gal[n_rec]
- n_rec
Number records to be buffered before outputting.
- Type:
int
- dataset
HDF5 dataset to which the data is output.
- Type:
obj : HDF5 dataset
- __init__(parameters)
Opens the halo output file. Creates the halo output buffer. Creates the HDF5 halo dataset.
- Parameters:
parameters (obj : C_parameters) – Contains the global run parameters.
- Return type:
None
- append(halos, parameters)
Extracts the quantities desired for halo_output and adds them to the io buffer, flushing if required.
- Parameters:
halos (obj : C_halo[]) – list of C_halo objects to be output.
parameters (obj : C_parameters) – The global run parameters.
- close()
Empties the halo io buffer, closes the halo dataset, and closes the halo output file.
- flush()
Writes io buffer to the HDF5 dataset and resets.
- halos.F_halos_create_header_file()
Creates a C struct definition that matches the subhalo dtype. Writes out to code/subs.h
- halos.F_halos_initialise(halos_this_snap, graph_ID, snap_ID, graph, parameters)
Read in the halos properties from the graph, including ranges for decendants, subhalos and galaxies.
- Parameters:
halos_this_snap (obj : D_halo[n_halo]) – The properties of halos in this graph/snapshot
graph_ID (str) – The graph_ID (from HDF5 group).
snap_ID (int) – The snapshot ID currently being processed.
graph (an instance of the class C_graph) – The graph containing this halo.
parameters (an instance of the class C_parameters) – The global parameters for this SAM run.
- halos.F_halos_template(parameters)
Define template for new halos
- Parameters:
parameters (obj : C_parameters) – Contains the global run parameters.
- Returns:
template – A one row numpy structured array with dtype D_halo
- Return type:
obj : D_halo
Subhalos
Subhalo numpy structured array dtype definition and template for initialisation, and python class for output.
All physical quantities are in internal code units.
Methods now moved to subs.c
- subs.graph_ID
The graph_ID within the input file.
- Type:
int
- subs.snap_ID
The snapshot ID currently being processed.
- Type:
int
- subs.halo_gid
The host halo location within the graph.
- Type:
int
- subs.halo_sid
The host halo location within the snapshot.
- Type:
int
- subs.sub_gid
The subhalo location within the graph.
- Type:
int
- subs.sub_sid
The subhalo location within the snapshot.
- Type:
int
- subs.b_done
Whether or not the subhalo has been fully processed.
- Type:
bool
- subs.desc_end_gid
The index relative to the graph at which this subhalo’s descendents end.
- Type:
int
- subs.desc_halo_sid
The index relative to the next snapshot of the descendant of the host halo of this subhalo.
- Type:
int
- subs.desc_start_gid
The index relative to the graph at which this subhalo’s descendents start.
- Type:
int
- subs.gal_central_sid
The location in the current galaxy array of the most massive galaxy in the subhalo.
- Type:
int
- subs.gal_end_sid
The location in the current galaxy array of the last galaxy in the subhalo (+1 because of python indexing)
- Type:
int
- subs.gal_next_sid
Galaxy counter used when updating galaxies.
- Type:
int
- subs.gal_start_sid
The location in the current galaxy array of the first galaxy in the subhalo
- Type:
int
- subs.half_mass_radius
The radius containing half the total mass in the DM-only sim
- Type:
float
- subs.half_mass_virial_speed
The circular speed at the half-mass radius
- Type:
float
- subs.mass
The DM-only mass of the subhalo.
- Type:
float
- subs.mass_baryon
Mass of baryons within the subhalo, inclusive of galaxies
- Type:
float
- subs.mass_gas_hot
The mass of hot gas
- Type:
float
- subs.mass_metals_gas_hot
The mass of metals in hot gas
- Type:
float
- subs.mass_metals_stars
The mass of metals in stars
- Type:
float
- subs.mass_stars
The mass of stars
- Type:
float
- subs.n_desc
The number of direct descendants.
- Type:
int
- subs.n_dt
Number of times that this halo has been processed this snapshot
- Type:
int
- subs.n_gal
The number of galaxies in the subhalo.
- Type:
int
- subs.pos
The position of the subhalo.
- Type:
float[3]
- subs.rms_speed
The rms speed of the subhalo in the DM-only sim.
- Type:
float
- subs.tau_dyn
The dynamical time at twice the half-mass radius.
- Type:
float
- subs.temperature
The virial temperature as derived from the virial speed.
- Type:
float
- subs.vel
The velocity of the subhalo.
- Type:
float[3]
- class subs.C_sub_output(parameters)
This class contains the attributes and methods for the subhalo output files.
- sub_file
HDF5 file for subhalo output
- Type:
obj : File
- i_rec
Counter for how many records have been created.
- Type:
int
- io_buffer
Storage for subhalo records prior to outputting.
- Type:
obj “ D_gal[n_rec]
- n_rec
Number records to be buffered before outputting.
- Type:
int
- dataset
HDF5 dataset to which the data is output.
- Type:
obj : HDF5 dataset
- __init__(parameters)
Opens the subhalo output file. Creates the subhalo output buffer. Creates the HDF5 halo dataset.
- Parameters:
parameters (obj : C_parameters) – Contains the global run parameters.
- append(subs, parameters)
Extracts the quantities desired for halo_output and adds them to the io buffer, flushing if required.
- Parameters:
subs (obj : C_sub[]) – list of C_sub objects to be output.
parameters (obj : C_parameters) – The global run parameters.
- close()
Empties the halo io buffer, closes the halo dataset, and closes the subhalo output file.
- flush()
Writes io buffer to the HDF5 dataset and resets.
- subs.F_subs_create_header_file()
Creates a C struct definition that matches the subhalo dtype. Writes out to code/subs.h
- subs.F_subs_initialise(subs_this_snap, graph_ID, snap_ID, graph, parameters)
Read in the subhalo properties from the graph, including ranges for descendants;
- Parameters:
subs_this_snap (obj : D_sub[n_sub]) – The properties of subhalos in this graph/snapshot
graph_ID (int) – The graph_ID within the input data file.
snap_ID (int) – The snapshot ID currently being processed.
sub_gid (int) – The subhalo ID relative to the graph.
graph (obj : C_graph) – The graph containing this halo.
parameters (obj : C_parameters) – The global parameters for this SAM run.
- subs.F_subs_mass_baryon(sub, gals)
Calculates the total baryonic mass of the subhalo, including galaxies. Returns value rather than setting it because being used as a check on simpler method.
- Parameters:
gals (obj : D_gal[]) – Array of records for the galaxies in this subhalo.
- Returns:
The baryonic mass of the subhalo, inclusive of galaxies.
- Return type:
float
- subs.F_subs_template(parameters)
Define template for new subhalos
- Parameters:
parameters (obj : C_parameters) – Contains the global run parameters.
- Returns:
template – A one row numpy structured array with dtype D_sub
- Return type:
obj : D_sub
Galaxies
Galaxy numpy structured array d_type definition and template for initialisation, and python class for output.
All physical quantities are in internal code units.
- gals.graph_ID
The graph_ID (from HDF5 group).
- Type:
int
- gals.snap_ID
The snapshot ID currently being processed.
- Type:
int
- gals.halo_gid
The halo ID relative to the graph.
- Type:
int
- gals.halo_sid
The halo ID relative to the snapshot.
- Type:
int
- gals.sub_gid
The subhalo ID relative to the graph
- Type:
int
- gals.sub_sid
The subhalo ID relative to the snapshot.
- Type:
int
- gals.gal_gid
The galaxy location relative to the start of this graph in the output file.
- Type:
int
- gals.b_exists
Whether or not the galaxy exists (it may have merged with another galaxy).
- Type:
bool
- gals.desc_gid
The index relative to the graph of this galaxy’s descendant.
- Type:
int
- gals.first_prog_gid
The index relative to the graph of this galaxy’s first progenitor.
- Type:
int
- gals.mass_gas_cold
The mass of cold gas, inclusive of metals.
- Type:
float
- gals.mass_metals_gas_cold
The mass of metals in the cold gas.
- Type:
float
- gals.mass_metals_stars_bulge
The mass of metals in bulge stars.
- Type:
float
- gals.mass_metals_stars_disc
The mass of metals in disc stars.
- Type:
float
- gals.mass_stars_bulge
The mass of bulge stars, inclusive of metals.
- Type:
float
- gals.mass_stars_disc
The mass of disc stars, inclusive of metals.
- Type:
float
- gals.next_prog_gid
The index relative to the graph of the next progenitor of the descendant galaxy.
- Type:
int
- gals.radius_gas_cold
The disc scale radius for the cold gas.
- Type:
float
- gals.radius_stars_bulge
The half mass radius for the bulge stars (Jaffe profile).
- Type:
float
- gals.radius_stars_disc
The disc scale radius for the stellar disc.
- Type:
float
- gals.SFR_dt
The star formation rate in the last galaxy timestep
- Type:
float
- gals.SFR_snap
The star formation rate averaged over the last snapshot
- Type:
float
- gals.v_vir
The half-mass circular speed of the host subhalo (or halo, if no subhalo).
- Type:
float
- class gals.C_gal_output(parameters)
This class contains the attributes and methods for the galaxy output file.
- gal_file
HDF5 file for galaxy output
- Type:
obj : File
- i_rec
Counter for how many records have been created.
- Type:
int
- io_buffer
Storage for subhalo records prior to outputting.
- Type:
obj “ D_gal[n_rec]
- n_rec
Number records to be buffered before outputting.
- Type:
int
- dataset
HDF5 dataset to which the data is output.
- Type:
obj : HDF5 dataset
- __init__(parameters)
Opens the galaxy output file. Creates the galaxy output buffer. Creates the HDF5 galaxy dataset.
- Parameters:
parameters (obj : C_parameters) – Contains the global run paramters.
- append(gals, parameters)
Extracts the quantities desired for halo_output and adds them to the io buffer, flushing if required.
- Parameters:
gals (obj: D_gal[n_gal]) – Array of D_gal records to be output
parameters (obj : C_parameters) – Contains the global run paramters.
- close()
Empties the halo io buffer, closes the halo dataset, and closes the halo output file
- flush()
Writes io buffer to the HDF5 dataset and resets.
- gals.F_gals_create_header_file()
Creates a C struct definition that matches the galaxy dtype. Writes out to code/gals.h
- gals.F_gals_template(parameters)
Creates a template for the galaxies
- Parameters:
parameters (obj : C_parameters) – Contains the global run parameters.
- Returns:
template – A one row numpy structured array with dtype D_gal
- Return type:
obj : D_gal
SAM routines (python initialisation)
Cooling
A class to generate and store the cooling tables. Other cooling routines are now ported to cooling.c
- class cooling.C_cooling(parameters)
Class to generate and store the cooling tables.
- log10_T_table
Temperatures associated with cooling table entries.
- Type:
obj : np.array[]
- log10_Z_table
Metallicities associated with cooling table entries.
- Type:
obj : np.array[]
- log10_Lambda_table
Cooling table in units such as to simplify cooling formula in code.
- Type:
np.array[,]
- F_create_header_file()
Writes out the cooling tables as const C arrays.
A more obvious way to do this would be to write out the tables as binary files, then read them back in as const arrays in the C cooling routine the first time that it is called: that would be quicker and more accurate. I am doing it this way instead because: * It makes the C-code cleaner (but this routine less so). * We don’t need high accuracy. * I don’t think that the speed difference will be very great.
Note that a trailing comma seems to be permitted in C array initialisation, which simplifies things.
- __init__(parameters)
Reads in the cooling function and tabulates it. Normalises it such that tau_cool=T/Lambda in code units. Also, the temperature lookup is adjusted to code units. Metallicities are always assumed to be absolute (ie not relative to solar).
Star formation histories
Class to store SFH information. Function to merger SFH bins has been moved to C.
- class sfh.C_sfh(parameters)
Class to generate and store the generic star formation history tables.
- F_create_header_file(parameters)
Creates a header file for the SFH containing parameters and fixed arrays describing the time bins.
- parameters
Instance of class containing global parameters
- Type:
obj : C_parameters
- __init__(parameters)
Generates the reference structure for storing the star formation histories in logarithmic bins (for each snapshot/time step combination). In the code galaxy structures are adjusted with respect to this structure at each step.
- Parameters:
parameters (obj : C_parameters) – Instance of class containing global parameters
- n_bin
Number of SFH bins required for output (need n_bin+1 for code execution)
- Type:
int
- t
Time to present (i.e. z=0) at the low-z edge of the SFH bin (code units)
- Type:
obj : np.float[n_snap][n_bin]
- dt
Time width of the SFH bin (code units)
- Type:
obj : np.float[n_snap][n_bin]
- n_t
Total number of galaxy timesteps taken in the code
- Type:
int
- i_dt_snap
Index of first galaxy timestep in each snapshot
- Type:
obj : np.int[n_snap]
- n_level
Number of levels in the SFH bin merging hierarchy
- Type:
int
- level
Level in the merging hierarchy of each SFH bin
- Type:
obj : np.int[n_dt,n_bin|n_bin+1]
- n_bin_in_level
Number of SFH bins in each level of the merging hierarchy
- Type:
np.int[n_dt,n_level]
- i_bin
Number of SFH bins used at each galaxy timestep
- Type:
obj : np.int[n_dt]
- __repr__(n_step=[0, 7])
Prints out the structure of entries in the SFH arrays. Useful mainly as a check that things have been implemented properly. Would be nice to produce graphics at some point.
- Parameters:
n_step (obj : [int,int]) – Tuple containing the range of entries (galaxy timesteps) to be printed out
SAM routines (C functions)
To be written: need to work out how to do the equivalent of automodule for C routines.