Columns

In OpenCosmo, references to columns are created independently of the datasets that contain them. You can create combinations of columns with basic arithmetic, as well as …

Columns created this way can be added to datasets or collections with the with_new_columns method. The actual values in these columns are evaluated lazily, so it is fine to create these new columns at the beginning of your analysis even if you plan to filter out significant numbers of the rows.

opencosmo.col(name)

Create a reference to a column with a given name. These references can be combined to produce new columns or express queries that operate on the values in a given dataset. For example:

import opencosmo as oc
ds = oc.open("haloproperties.hdf5")
query = oc.col("fof_halo_mass") > 1e14
px = oc.col("fof_halo_mass") * oc.col("fof_halo_com_vx")
ds = ds.with_new_columns(fof_halo_com_px = px).filter(query)

For more advanced usage, see Working with Columns

Parameters:

name (str)

Return type:

Column

class opencosmo.column.Column(lhs, rhs, operation, description=None, output_name=None, _dep_map=None, no_cache=False, _uuid=None)

A column represents a combination of one or more columns that already exist in the dataset through multiplication or division by other columns or scalars, which may or may not have units of their own.

In general this is dangerous, because we cannot necessarily infer how a particular unit is supposed to respond to unit transformations. For the moment, we only allow for combinations of columns that already exist in the dataset.

In general, columns that exist in the dataset are materialized first. Derived columns are then computed from these. The order of creation of the derived columns must be kept constant, in case you get another column which is derived from a derived column.

Parameters:
  • lhs (ColumnOrScalar)

  • rhs (Optional[ColumnOrScalar])

  • operation (Callable)

  • description (Optional[str])

  • output_name (Optional[str])

  • _dep_map (dict[str, UUID] | None)

  • no_cache (bool)

  • _uuid (UUID | None)

bind(name_to_uuid)

Resolve each dependency column name to the UUID of the producer that was producing it at the time this column was registered with a dataset. Returns a new bound Column; does not mutate this instance.

Parameters:

name_to_uuid (dict[str, UUID])

Return type:

Column

combine_on_left(other, operation)

Combine such that this column becomes the lhs of a new derived column.

Parameters:
  • other (str | Column | int | float | Quantity)

  • operation (Callable)

combine_on_right(other, operation)

Combine such that this column becomes the rhs of a new derived column.

Parameters:
  • other (str | Column | int | float | Quantity)

  • operation (Callable)

with_reducer(reducer)

Return a new Column with the given reducer attached to all nested DerivedScalarValue nodes. Does not mutate self.

Parameters:

reducer (Reducer)

Return type:

Column

Provided Column Combinations

There are a number of basic column combinations that are

opencosmo.column.norm_cols(*columns)

Get the euclidian norm of any number of columns. This function takes in the names of the magnitude columns, and produces a Column that can be passed into with_new_columns

This function will never fail, but with_new_columns will if the columns do not have the same units.

Parameters:

*columns (str | Column | Column) – Any number of columns. You can pass in simple column names, columns constructred with opencosmo.col(), or columns created from combinations of other columns

Returns:

new_column – A new derived column that can be passed into with_new_columns

Return type:

Column

opencosmo.column.add_mag_cols(*magnitudes)

Add together any number of magnitude columns to get a total magnitude. This function takes in the names of the magnitude columns, and produces a Column that can be passed into with_new_columns

This function will never fail, but with_new_columns will if you include columns that are not magnitudes.

import opencosmo as oc
from opencosmo.column import add_mag_cols

dataset = oc.open("catalog.hdf5")
mag_total = add_mag_cols("mag_g", "mag_r", "mag_i", "mag_z", "mag_y")

dataset = dataset.with_new_columns(mag_total=mag_total)
Parameters:

*magnitudes (str | Column | Column) – Any number of magnitude columns. You can pass in simple column names, columns constructred with opencosmo.col(), or columns created from combinations of other columns

Returns:

new_column – A new derived column that can be passed into with_new_columns

Return type:

Column

opencosmo.column.offset_3d(coord_name_a, coord_name_b, labels=['x', 'y', 'z'])

Create a derived column that contains the magnitude of the offset between two sets of 3d coordinates. For exmaple, to get the magnitude of the difference between the FoF halo centers and the SOD halo centers:

from opencosmo.column import offset_3d
import opencosmo as oc

dataset = oc.open("haloproperties.hdf5")

offset_column = offset_3d("fof_halo_com", "sod_halo_com")
dataset = dataset.with_new_columns(offset=offset_column)

This function assumes that the columns are named “fof_halo_center_{x, y, z}” and “sod_halo_center_{x, y, z}”, you can choose different labels by setting the labels argument.

This function outputs a derived column that can be passed into with_new_columns will if the columns do not all have the same units.

Parameters:
  • coord_name_a (str) – The base name of the first coordinate

  • coord_name_b (str) – The base name of the second coordinate

  • labels (Iterable[str], default = ["x", "y", "z"]) – The coordinate labels. The names of the columns are assumed to be “{coord_name_a}_{labels}” and “{coord_name_b}_{labels}”