linefinder.track module

Tools for tracking particles.

@author: Daniel Angles-Alcazar, Zach Hafen @contact: zachary.h.hafen@gmail.com @status: Development

class linefinder.track.IDFinder[source]

Bases: object

Finds target ids in a single snapshot.

apply_functions(fns, dfid, df)[source]

Calculate and store the results of arbitrary functions of the full snapshot data and the subset of the snapshot data containing the IDs.

Parameters:
  • fns (list of fns) – Functions to apply to the data. Should accept dfid and df as arguments, and modify dfid as desired. Can optionally accept an argument id_finder, which is the active instance of IDFinder, allowing for use in the functions of e.g. self.snum and self.attrs.
  • dfid (pandas DataFrame) – Contains attributes of the selected ID particles. Indexed by the ID.
  • df (pandas DataFrame) – Contains attributes of the full snapshot data. Indexed by the ID.
Returns:

Modified dfid from having the fns applied to it. As a precaution, modifying any of the original columns will raise an error.

Return type:

pandas DataFrame

concatenate_particle_data(verbose=False)[source]

Get all the particle data for the snapshot in one big array, to allow searching through it.

Parameters:verbose (bool) – If True, print additional information.
Modifies:
self.full_snap_data (dict): A dictionary of the concatenated particle data.
find_ids(sdir, snum, p_types, target_ids, target_child_ids=None, custom_fns=None)[source]

Find the information for particular IDs in a given snapshot, ordered by the ID list you pass.

Parameters:
  • sdir (str) – The targeted simulation directory.
  • snum (int) – The snapshot to find the IDs for.
  • p_types (list of ints) – Which particle types to target.
  • target_ids (np.array) – The particle IDs you want to find.
  • target_child_ids (np.array) – The particle child IDs you want to find.
  • custom_fns (list of functions) – If not None, additional derived products you want to calculate for the selected IDs. Arguments should be a pandas DataFrame named dfid that contains the data of the selected IDs, and a pandas DataFrame named df that contains the full snapshot data.
Returns:

Dataframe for the selected IDs, ordered by

target_ids. Contains standard particle information, e.g. position, metallicity, etc.

redshift (float):

Redshift of the snapshot.

attrs (dict):

Dictionary of attributes of the snapshot

Return type:

dfid (pandas.DataFrame)

select_ids()[source]

Function for selecting the targeted ids from the snapshot.

class linefinder.track.ParticleTracker(out_dir, tag, ids_tag=<object object>, sdir=<object object>, p_types=<object object>, snum_start=<object object>, snum_end=<object object>, snum_step=<object object>, n_processors=1, custom_fns=None)[source]

Bases: object

Searches IDs across snapshots, then saves the results.

format_tracked_data(tracked_data_snapshots)[source]

Format data for storage.

Parameters:tracked_data_snapshots (list) – List of unsorted data.
Returns:Formatted data.
attrs (dict) :
Formatted data attributes.
Return type:ptrack (dict)
get_target_ids()[source]

Open the file containing the target ids and retrieve them.

Modifies:
self.target_ids (np.array):
Fills the array.
self.target_child_ids (np.array, optional): Fills the array, if
child_ids are included.
get_tracked_data()[source]

Loop overall redshift snapshots, and get the data.

Returns:Structure to hold particle tracks. Structure is… ptrack [‘varname’] [particle i, snap j, k component]
Return type:ptrack (dict)
get_tracked_data_jug()[source]

Loop overall redshift snapshots, and get the data. This is the parallelized version that uses Jug

Returns:Structure to hold particle tracks. Structure is… ptrack [‘varname’] [particle i, snap j, k component]
Return type:ptrack (dict)
get_tracked_data_parallel()[source]

Loop overall redshift snapshots, and get the data. This is the parallelized version.

Returns:Structure to hold particle tracks. Structure is… ptrack [‘varname’] [particle i, snap j, k component]
Return type:ptrack (dict)
save_particle_tracks()[source]

Loop over all redshifts, get the data, and save the particle tracks.

save_particle_tracks_jug()[source]

Loop over all redshifts, get the data, and save the particle tracks.

write_tracked_data(formatted_data)[source]

Write tracks to a file.

Parameters:
  • formatted_data (dict) – Formatted particle track data.
  • attrs (dict) – Particle track data attributes.