linefinder.select module

Used to create an id file to track the IDs of.

@author: Zach Hafen @contact: zachary.h.hafen@gmail.com @status: Development

class linefinder.select.IDSampler(out_dir, tag, n_samples=100000, ignore_child_particles=False, ignore_duplicates=False, reference_snum_for_duplicates=600, p_types=None, snapshot_kwargs=None)[source]

Bases: object

choose_particles_to_sample()[source]

Choose which particles to subsample. This is done by subtracting out any IDs that we don’t want to use for some reason (e.g. if we’re ignoring IDs that have duplicates).

Modifies:
self.ids_to_sample (np.ndarray) : An array of the IDs to sample. self.child_ids_to_sample (np.ndarray, optional) : An array of the child IDs to sample.
choose_sample_inds()[source]

Select the indices of the target IDs to sample.

Modifies:
self.sample_inds (np.array of ints) : Indices of the target IDs to sample.
copy_and_open_full_ids()[source]

Copy the full id file and save them.

Modifies:
self.f (h5py file) : Opens and creates the file.
identify_child_particles()[source]

Get the IDs and Child IDs of all particles that have non-zero Child IDs.

Returns:A set of all the IDs and Child IDs that have non-zero Child IDs.
Return type:child_particles (set)
identify_duplicate_ids()[source]

Get all IDs that have duplicates at the latest snapshot. This draws data from the same sample as the original.

Returns:A set of all IDs that have duplicates at snum_end.
Return type:duplicate_ids (set)
sample_ids()[source]

Sample a saved ID file for a subset, which can then be run through particle tracking.

save_sampled_ids()[source]

Save the IDs, now that we have the indices of the IDs we want sampled.

Modifies:
self.f (h5py file) : Replaces target_ids and target_child_ids with sampled versions.
class linefinder.select.IDSelector(out_dir, tag, snum_start, snum_end, snum_step, p_types, snapshot_kwargs, n_processors=1)[source]

Bases: object

format_selected_ids(selected_ids)[source]

Format the data back into arrays.

Returns:Array of selected IDs child_ids (np.array, optional) : Array of selected child IDS
Return type:ids (np.array)
get_selected_ids(data_filters)[source]

Get a set of all ids that match a set of data filters.

Parameters:data_filters (list of dicts) – The data filters to apply.
Returns:Set of selected ids.
Return type:selected_ids (set)
get_selected_ids_jug(data_filters)[source]

Parallel version of self.get_selected_ids(). Requires a lot of memory, because it will have multiple snapshots open at once.

Parameters:data_filters (list of dicts) – The data filters to apply.
Returns:Set of selected ids.
Return type:selected_ids (set)
get_selected_ids_parallel(data_filters)[source]

Parallel version of self.get_selected_ids(). Requires a lot of memory, because it will have multiple snapshots open at once.

Parameters:data_filters (list of dicts) – The data filters to apply.
Returns:Set of selected ids.
Return type:selected_ids (set)
get_selected_ids_snapshot(args)[source]

Get the IDs for a particular snapshot. Formatted this way primarily for parallelization.

Parameters:args (data_filters, kwargs) – Information needed to get the IDs out for a snapshot.
Returns:The IDs in a snapshot that fit the required condition.
Return type:selected_ids_snapshot (set)
save_selected_ids(selected_ids_formatted, data_filters)[source]
select_ids(data_filters={})[source]

Save a set of all ids that match a set of data filters to a file.

Parameters:data_filters (dict of dicts) – The data filters to apply.
select_ids_jug(data_filters={})[source]

Save a set of all ids that match a set of data filters to a file.

Parameters:data_filters (dict of dicts) – The data filters to apply.
class linefinder.select.SnapshotIDSelector(**kwargs)[source]

Bases: galaxy_dive.analyze_data.particle_data.ParticleData

add_hubble_flow()

Correct for hubble flow movement.

Modifies:
self.data[‘V’] : Accounts for hubble flow, relative to origin
base_data_shape

Property for simulation redshift.

calc_HI_den()

Calculate the HI density in cgs (cm^-3).

calc_H_den()

Calculate the H density in cgs (cm^-3). Assume the H fraction is ~0.75

calc_abs_phi(vector='total gas ang momentum')

The angle (in degrees) from some vector, but don’t mirror it around 90 degrees (e.g. 135 -> 45 degrees, 180 -> 0 degrees).

calc_ang_momentum()

Calculate the angular momentum.

calc_classifications()

Get the classification for each particle, using data from the Angles-Alcazar+16 pipeline. Uses classes from the tracked_particle_data_handling.py module.

Parameters (include in data_p) ‘tracked_p_data_dir’ : Directory containing the tracked-particle data. ‘tracked_p_file_tag’ : Identifying tag for the tracked-particle data.

calc_enriched_metal_mass()

Calculate the metal mass that comes from enrichment, not counting mass that’s at the metallicity floor. Assumes that the there will always be at least one particle in the simulation that’s at the metallicity floor.

calc_inds()

Calculate the indices the data are located at, prior to any masks.

calc_metal_mass()
calc_mu()

we track this with metal species now, could do better…

calc_num_den()

Calculate the number density (it’s just a simple conversion…).

calc_phi(normal_vector='total ang momentum')

Calculate the angle (in degrees) from some vector. By default the vector is the total angular momentum.

calc_pressure()

Calculate the pressure in units of K/cm^3.

calc_radial_distance()

Calculate the distance from the origin for a given particle.

calc_radial_velocity()

Calculate the radial velocity.

calc_rho_xy()

Calculate impact parameter in the xy-plane.

calc_rho_xz()

Calculate impact parameter in the xz-plane.

calc_rho_yz()

Calculate impact parameter in the yz-plane.

calc_tangential_velocity()

Calculate the radial velocity.

calc_temp(gamma=1.6666666666666667)

Calculate the temperature from the internal energy.

calc_velocity_magnitude()

Calculate the radial velocity.

center_coords()

Change the location of the origin, if the data isn’t already centered.

Modifies:
self.data[‘P’] : Shifts the coordinates to the center.
center_vel_coords()

Get velocity coordinates to center on the main halo.

Modifies:
self.data[‘V’] : Makes all velocities relative to self.vel_origin
central_mask

This mask is used when, for example, finding the velocity of the center of mass.

dN_halo

Calculate dN_halo/dX/dlog10Mh or dN_halo/dz/dlog10Mh. X is absorption path length (see for example Ribaudo+11)

time_units: ‘abs_length’- dN_halo/dX/dlog10Mh
‘redshift’ - dN_halo/dz/dlog10Mh
R_vir: None - Default, assumes given.
‘BN’ Calculates R_vir from the mass and redshift
dist_to_point(point, units='default')

Calculate the distance to a point for all particles.

point : np array that gives the point

filter_data(data_filters)[source]

Put the filters on the dataset

Parameters:data_filters (list of dicts) – The data filters to apply.
find_duplicate_ids()

Find all the IDs in the particle data set that have duplicates.

Returns:Array of IDs that have duplicates.
Return type:duplicate_ids ( np.ndarray )
format_ids(selected_ids)[source]

Turns the ids into a set to be passed back.

Parameters:selected_ids (np.array or list of np.arrays) – IDs to format into a set.
Returns:IDs as a set.
Return type:ids_set (set)
get_data(data_key, sl=None)

Get the data from within the class. Only for getting the data. No post-processing or changing the data (putting it in particular units, etc.) The idea is to calculate necessary quantities as the need arises, hence a whole function for getting the data.

Parameters:
  • data_key (str) – Key in the data dictionary for the key we want to get
  • sl (slice) – Slice of the data, if requested.
Returns:

Requested data.

Return type:

data (np.ndarray)

get_distance_to_point(point)

This is not unit tested.

Parameters:point (array-like of shape (3,)) – The point you want to find the distance to for each particle.
get_ids()[source]
Returns:IDs for particles that match the filtered requirements. child_ids (optional) : Child IDs for the particles that match the filtered requirements.
Return type:ids
get_position_data(data_key)

Get position data (assuming the data starts with an ‘R’)

Parameters:data_key (str) – Key in the data dictionary for the key we want to get
Returns:Requested data.
Return type:data (np.ndarray)
get_potential(point)

This is not unit tested.

Parameters:point (array-like of shape (3,)) – The point you want to find the potential at
get_processed_data(data_key, data_method=<object object>, *args, **kwargs)

Get post-processed data. (Accounting for fractions, log-space, etc.).

Parameters:
  • data_key (str) – What data to get.
  • data_method (str) – What method to use for getting the data itself. Defaults to using self.get_data
  • **kwargs (*args,) –

    Passed to get_data()

Returns:

Requested data, including formatting.

Return type:

processed_data (np.ndarray)

get_selected_data(*args, **kwargs)

Wrapper for getting masked data.

get_velocity_data(data_key)

Get position data (assuming the data starts with a ‘V’)

Parameters:data_key (str) – Key in the data dictionary for the key we want to get
Returns:Requested data.
Return type:data (np.ndarray)
halo_data

Halo data used.

handle_data_key_error(data_key)

When get_data() fails to data_key in self.data, it passes the data_key to try and generate that data.

Parameters:data_key (str) – Key to try and generate data for
Modifies:
self.data[data_key] (np.array) : If it finds a function to generate the data, it will do so
hubble_z

Property for the hubble function at specified redshift.

iterate_over_method(method_str, iter_arg, iter_values, method_args)

Iterate over a specified method, and get the results out.

Parameters:
  • method_str (str) – Which method to use.
  • iter_arg (str) – Which argument of the method to iterate over.
  • iter_values (list of values) – Which values to change.
  • method_args (dict) – Default args to pass to the method
Returns:

[ method( **used_args ) for used_args in all_variations_of_used_args ]

Return type:

results (list)

length_scale

Property for fiducial simulation length scale.

mask_data(*args, **kwargs)

Wrapper for masking data.

metallicity_scale

Property for fiducial metallicity scale. By default is z_sun However, a more advanced subclass might set this differently, or this might change in the future.

r_scale

Property for scale radius.

r_vir

Property for virial radius.

redshift

Property for simulation redshift.

retrieve_data()
retrieve_halo_data()
select_ids_snapshot(data_filters)[source]

Select the IDs that match specified conditions in a given snapshot.

Parameters:data_filters (list of dicts) – The data filters to apply.
shift(data, data_key)

Shift or multiply the data by some amount. Note that this is applied after logarithms are applied.

data : data to be shifted data_key : Data key for the parameters to be shifted Parameters are a subdictionary of self.kwargs ‘data_key’ : What data key the data is shifted for

total_ang_momentum

Calculate the total angular momentum vector.

v_c

Property for circular velocity.

v_com

Property for the velocity of the center of mass.

velocity_scale

Property for fiducial simulation velocity scale.