Python reference¶
Generated from the type stubs bitvf/__init__.pyi and bitvf/io.pyi,
whose docstrings are the ones an IDE shows. Types of otswap in the
signatures are documented in otswap’s reference.
bitvf¶
Errors¶
- exception bitvf.Error¶
Raised by every bitvf function on invalid input or failure.
An error raised by otswap inside a bitvf call reaches the caller as an
Errorwhose message is"otswap: "followed by otswap’s own.Erroris unrelated tootswap.Error: anexcept otswap.Errordoes not catch it, and catchingbitvf.Errorcatches every error of a bitvf call but aTypeErrorfor a wrong number of positional arguments or an unknown keyword, andKeyboardInterrupt.
Configuration¶
- class bitvf.LengthUnit(*args, **kwds)¶
Unit of a length the user chooses.
- COORDINATE = 1¶
The same length unit as the tracer coordinates.
- MPS = 0¶
Multiples of the mean particle separation. In the box it is the box mps; in a lightcone it is mps(z) at each cell’s redshift.
- class bitvf.Smoothing(*, sigma: float = 1.0, unit: LengthUnit = LengthUnit.MPS)¶
Gaussian smoothing of the divergence field before the watershed.
Each cell takes the weighted mean of the divergence of the cells around it, itself included. The weight of a cell is its tracer weight (
DivergenceGrid.weight) times exp(-r^2 / (2 sigma^2)), r the distance between the two cell centres. A cell whose weights sum to at most 1e-12 times the largest tracer weight of the grid takes 0; this includes a filled cell (weight 0) whose surrounding cells hold no weight. A larger sigma merges small basins into larger ones; sigma = 0 disables the smoothing. With sigma > 0 the smoothed field and the smoothed weight are kept beside the divergence and the weight (DivergenceGrid.divergence_smoothed,weight_smoothed).Box: the cells around are those within floor(3.5 sigma / s) cells along each axis, s the cell side, cut at the faces of the grid: a cube, not a sphere. When 3.5 sigma / s lies within 1e-9 relative of an integer, that integer is taken instead, so that a cell side rounded by one ulp gives the same cube. Below sigma = s / 3.5 the cube holds the cell alone. In
LengthUnit.MPS, sigma is multiplied by the box mps.Lightcone: the cells around are those whose centre lies closer than 4 sigma, with the same weights. Masked cells (
DivergenceGrid.masked) enter no mean and take 0. InLengthUnit.MPS, sigma is multiplied by mps(z) at the redshift of the centre of the shell of the cell being smoothed.Each field is a keyword of the constructor and a read/write attribute, converted to its type when set; its rules are checked by the search that reads it.
reprgives the constructor call; two smoothings compare equal when both fields are equal.- sigma: float¶
Width of the Gaussian, in
unit; default 1. Must be finite and non-negative; 1 mps is a reasonable starting value. A positive sigma must be between about 1e-162 and 1e154 in coordinate units; use 0 to disable the smoothing.
- unit: LengthUnit¶
Unit of
sigma; defaultLengthUnit.MPS.
- class bitvf.Config(*, smoothing: Smoothing = Smoothing(), divergence_cell_size: float | None = None, keep_divergence: bool = False, keep_assignment: bool = False, n_realizations_mean: int = 1, verbosity: Verbosity = 'normal')¶
Free parameters of the void finder: the
configof every search.Nothing here depends on the geometry. Voids and overdense basins are always both found. Every field is a keyword of the constructor, with the default of the C++ struct, and a read/write attribute. A value is converted to the field’s type when it is stored, and raises
Errorif it cannot be; its rules are checked by the call that reads it, which refuses it with the library’s message. Each call works on its own copy, so the object passed is never changed.reprgives the constructor call; two configs compare equal when every field is equal.- divergence_cell_size: float | None¶
Side of the divergence-grid cell, in units of the mean particle separation; None, the default, for min(1, (20 / n_realizations)^(1/3)): 1 up to 20 realizations, (20 / n_realizations)^(1/3) above. A search on a mean displacement file runs with one realization, so its default is 1. Must be positive when set, and None when a grid is reused.
Result.configholds the value used. Unrelated tootswap.Config.cell_size, which affects speed only: this one changes the result.
- keep_assignment: bool¶
Fill
Result.assignment, where each tracer ended up; default False, since it holds one entry per tracer in several arrays.
- keep_divergence: bool¶
Fill
Result.divergencewith the grid and the divergence field; default False, since it holds one entry per cell in several arrays.
- n_realizations_mean: int¶
Realizations averaged into each displacement given; default 1, for the displacements of single realizations. For the
otswap.Resultread from a mean displacement file (otswap.io.read_displacement_mean), itsn_realizations_mean. A record only, written as the keyword NRECMEAN of bitvf’s files; no computation reads it. Must be at least 1, at most 4294967295.
- class bitvf.BoxConfig(*, ot: otswap.Config = otswap.Config(), limits: Box | None = None, mps: float | None = None, rsd: BoxRsd | None = None, voids: Config = Config(), keep_reconstructions: bool = False)¶
The parameters of
run_box.Every field is a keyword of the constructor and a read/write attribute. The nested configurations
ot,rsdandvoidsread as references into this BoxConfig, socfg.voids.keep_divergence = Truechangescfg; assigning one copies it in.reprgives the constructor call; two compare equal when every field is equal.- keep_reconstructions: bool¶
Keep the otswap results and the corrected catalogue in
BitVFResult; default False.
- limits: otswap.BoxLimits | None¶
The box of the run, given to
otswap.reconstruct_boxas limits on both reconstructions; a pair of corners is accepted (seeBox). None, the default, for the bounding box of the tracers, or of the tracers and the randoms when randoms are given.
- mps: float | None¶
The mean particle separation, in coordinate units, given to both reconstructions. None, the default: otswap computes it on each from the volume of the box and the tracers inside it.
- ot: otswap.Config¶
The reconstruction, used for both reconstructions of a run with correction, with the same seed; default
otswap.Config(). A seed of 0 is replaced by one drawn at random before the first reconstruction, and both use it; theconfigof the reconstruction records it.
- class bitvf.BoxRsd(*, axis: int | None, redshift: float, bias: float, sigma: float, correction: otswap.CorrectionConfig = otswap.CorrectionConfig(), zspace_voids: bool = False)¶
Correction of redshift-space distortions in a box, as
otswap.real_space_boxapplies it: thersdofBoxConfig.axis,redshift,biasandsigmahave no default: each is a required keyword of the constructor. Fields are read/write attributes, converted when set and checked byrun_box.reprgives the constructor call; two compare equal when every field is equal.- axis: int | None¶
The line of sight, 0, 1 or 2 for x, y or z. None is accepted here and refused by
run_box.
- correction: otswap.CorrectionConfig¶
The weighting of the neighbour average, and what the correction prints, passed to
otswap.real_space_boxunchanged; defaultotswap.CorrectionConfig(). A reference into this BoxRsd; assigning one copies it in.
- redshift: float¶
The redshift of the box, at which the growth rate f is read from the distance table; inside the table’s range.
- class bitvf.LightconeConfig(*, ot: otswap.Config = otswap.Config(), n_bins: int, cut: otswap.RedshiftCut | tuple[float, float] | None = None, rsd: LightconeRsd | None = None, voids: Config = Config(), keep_reconstructions: bool = False)¶
The parameters of
run_lightcone.n_binshas no default: it is a required keyword of the constructor. Every field is a read/write attribute. The nested configurationsot,cut,rsdandvoidsread as references into this LightconeConfig, socfg.voids.keep_divergence = Truechangescfg; assigning one copies it in.reprgives the constructor call; two compare equal when every field is equal.- cut: otswap.RedshiftCut¶
The closed range of observed redshift of the run, given to both reconstructions and to every search: the tracers outside keep their row and are skipped, the randoms outside are removed. A
(min, max)pair is accepted, and None for no cut, the default.
- keep_reconstructions: bool¶
Keep the otswap results and the corrected catalogue in
BitVFResult; default False.
- n_bins: int¶
The redshift bins of the mps(z) profile of each reconstruction; at least 1. 30 is a reasonable starting value.
- ot: otswap.Config¶
The reconstruction, used for both reconstructions of a run with correction, with the same seed; default
otswap.Config(). A seed of 0 is replaced by one drawn at random before the first reconstruction, and both use it; theconfigof the reconstruction records it.
- rsd: LightconeRsd | None¶
The correction of redshift-space distortions; None, the default, for one reconstruction and one search, no correction. A reference into this LightconeConfig; assigning one copies it in.
- class bitvf.LightconeRsd(*, bias: otswap.BiasTable, sigma: float, correction: otswap.CorrectionConfig = otswap.CorrectionConfig(), second_pass_randoms: SecondPassRandoms = SecondPassRandoms.RESAMPLE, zspace_voids: bool = False)¶
Correction of redshift-space distortions in a lightcone, as
otswap.real_space_lightconeapplies it: thersdofLightconeConfig.biasandsigmahave no default: each is a required keyword of the constructor. Fields are read/write attributes, converted when set and checked byrun_lightcone.reprgives the constructor call; two compare equal when every field is equal.- bias: otswap.BiasTable¶
The linear bias of the tracers as a function of redshift; positive at the redshift of every tracer kept.
- correction: otswap.CorrectionConfig¶
The weighting of the neighbour average, and what the correction prints, passed to
otswap.real_space_lightconeunchanged; defaultotswap.CorrectionConfig(). A reference into this LightconeRsd; assigning one copies it in.
- second_pass_randoms: SecondPassRandoms¶
The randoms of the second reconstruction.
RESAMPLE, the default, gives them the redshift distribution of the corrected tracers;NONEkeeps the observed one;EXTERNALtakes randoms built for the real-space sample and given torun_lightcone.
- class bitvf.SecondPassRandoms(*args, **kwds)¶
The randoms of the second, real-space, reconstruction of
run_lightcone.- EXTERNAL = Ellipsis¶
Randoms given to
run_lightconefor the second reconstruction.
- NONE = Ellipsis¶
The first reconstruction’s randoms, unchanged.
- RESAMPLE = Ellipsis¶
The first reconstruction’s randoms, with redshifts drawn from the corrected tracers.
Void finder, box¶
- bitvf.find_voids_box(tracers: numpy.typing.ArrayLike | otswap.Result, displacement: numpy.typing.ArrayLike | None = None, valid: numpy.typing.ArrayLike | None = None, *, mps: float | None = None, box: Box | None = None, config: Config = Config(), ids: numpy.typing.ArrayLike | None = None, grid: DivergenceGrid | None = None) Result¶
Find voids and overdense basins in a box.
The divergence of the displacement field is computed on a grid of cubic cells (
DivergenceGrid), smoothed (Config.smoothing) and divided by a watershed into basins around its local minima: the voids, below 0, and the overdense basins, at or above 0 (BasinCatalog).Two forms. With arrays,
tracersanddisplacementare required, and so ismps. With anotswap.Resultofotswap.reconstruct_boxas the first argument, the tracers, displacements, validity, mps, box and ids are read from it, and none ofdisplacement,valid,mps,boxandidsmay be given: the grid is built onotswap.Result.box, and the tracers flagged inotswap.Result.outside_boxare skipped. Given the same arrays andotswap.Result.boxasbox, both forms give the same result.The
otswap.Resultmay be the mean of a reconstruction, read from a mean displacement file byotswap.io.read_displacement_mean(one realization,n_realizations_meanthe number averaged; setConfig.n_realizations_meanto it, so that bitvf’s files record it). Its box is the file’s box keywords, with or without BOXLIM; a mean file without box keywords holds no box limits and is refused. The divergence is not linear in the displacement, so a search on the mean of R realizations does not give the result of the search on the R realizations.- Parameters:
tracers (array_like, shape (N, 3), or otswap.Result) – Cartesian coordinates of the tracers, the start of their displacements, in coordinate units; or a box reconstruction.
displacement (array_like, shape (R, N, 3)) – Displacements of R realizations, R at least 1; a tracer plus its displacement is the random matched to it. Every valid displacement of a tracer the search reads must be finite; the others, and those of the tracers skipped outside the box, are not read.
valid (array_like, shape (R, N), optional) – Validity of each displacement, bool or numbers 0 and 1. If omitted, every displacement is valid.
mps (float) – Mean particle separation, in coordinate units; finite and positive. Use
otswap.Result.mpsof the reconstruction, or pass the reconstruction itself. Withgrid, it must equalgrid.mps.box (BoxLimits or ((x0, y0, z0), (x1, y1, z1)), optional) – The box limits. Given, the tracers outside them keep their row but are skipped (
TracerAssignment.in_box,Counts.tracers_outside_box), and the grid is built on them; pass the limits the reconstruction used, or a valid displacement ending outside the grid is an error. If omitted, the grid covers the tracers and the endpoints of their valid displacements in every realization, so that displacements from any source can be searched.config (Config, optional) – The parameters of the search.
ids (array_like of int, shape (N,), optional) – The identity of each tracer, any 64-bit integer, no value twice, copied into
Result.ids.grid (DivergenceGrid, optional) – A box grid to reuse (
Result.divergence,box_grid,io.read_divergence);config.divergence_cell_sizemust then be None. Its cells are used, and its mps sets the smoothing in mps and thedelta_2mpsradius; with a reconstruction, the grid’s mps wins over the reconstruction’s. Densities come from this search’s own counts. Tracers outside every cell are excluded (Result.outside_grid,Counts.tracers_outside_grid).
- Returns:
Result – The voids and overdense basins,
Result.mpsthe mps used.- Raises:
Error – On the arrays: if
tracersis not of shape (N, 3) or is empty, ifdisplacementis not of shape (R, N, 3) with R at least 1, ifvalidis given empty, is not of shape (R, N) or holds a value other than 0 and 1, if a coordinate oftracersor a component of a displacement read is not finite, ifidsis not one integer per tracer or holds a value twice; ifdisplacementormpsis left out with arrays, or one ofdisplacement,valid,mps,boxandidsis given with a reconstruction.Error – If
mpsis not finite and positive; if a bound ofboxis not finite or a lower bound is not below the upper one.Error – On
config: ifsmoothing.sigmais not finite and non-negative, or is positive but, in coordinate units, below about 1e-162 or above about 1e154; ifdivergence_cell_sizeis set and not finite and positive, or set withgrid; ifn_realizations_meanis 0.Error – On
grid: if it is not a box grid, or a field that defines the cells is inconsistent; ifmpsdiffers fromgrid.mps, bit for bit.Error – On the reconstruction: if it is not a box result, or is malformed: no objects,
n_realizationsorn_realizations_mean0, a mean (n_realizations_meanabove 1) of several realizations,valid_realizationsof the wrong length or aboven_realizationsxn_realizations_mean, or no box.Error – On the data: if the search reads more than 4294967295 tracers; if no valid displacement is left to read; with
boxorgrid, if a valid displacement read ends outside every cell of the grid, which means the arrays do not come from one reconstruction in that box; if the grid would hold more cells than an int64 index can address; if the divergence is 0 or positive in every cell, so that no void can be found.
Notes
Prints as
Verbositydescribes, with the call linebitvf: findVoidsBox: ...; with a reconstruction andgrid, the"detailed"report states both mps.
- bitvf.find_voids_box_from_divergence(grid: DivergenceGrid, tracers: numpy.typing.ArrayLike, *, config: Config = Config(), ids: numpy.typing.ArrayLike | None = None) Result¶
Find voids and overdense basins in a box from a divergence computed earlier, with the tracers given.
The field before smoothing (
grid.divergence) is smoothed withconfig.smoothing, in units of the grid’s mps, split into basins and catalogued asfind_voids_boxdoes; a different sigma is the usual reason for the call. With the tracers of the search that produced the grid and the same smoothing, the voids, the overdense basins, the smoothed divergence, the smoothed weight and the assignment but itsusedflags equal that search’s bit for bit, sigma = 0 included.The tracers are read as with a reused grid: those outside the grid’s box limits (
grid.limits) are skipped, those inside but outside every cell are excluded (Result.outside_grid). When the grid holdsn_tracers, the tracers read in every cell must match it.- Parameters:
grid (DivergenceGrid) – A box grid holding the fields that define its cells,
divergenceandweight: fromio.read_divergence, orResult.divergenceof a search withkeep_divergence. Its other per-cell fields are not read:divergence_smoothedandweight_smoothedof the result are computed from these withconfig.smoothing.tracers (array_like, shape (N, 3)) – Cartesian coordinates of the tracers, in coordinate units; at least one.
config (Config, optional) – The parameters of the search;
divergence_cell_sizemust be None.ids (array_like of int, shape (N,), optional) – The identity of each tracer, no value twice.
- Returns:
Result – No displacement enters the call:
TracerAssignment.usedis empty,Counts.displacementsandCounts.tracers_usedare 0. The grid’sn_displacements,n_realizationsandn_realizations_meanare copied into the result, so the files written from it record those of the field;Result.limitsis the grid’s limits,Result.mpsits mps,Result.config.divergence_cell_sizeitscell_size_mps.- Raises:
Error – If
tracersis not of shape (N, 3), is empty, or a coordinate is not finite; ifidsis not one integer per tracer or holds a value twice.Error – On
configasfind_voids_box; ifdivergence_cell_sizeis set.Error – On
gridas on a grid to reuse infind_voids_box; ifdivergenceorweightdoes not hold one entry per cell, or an entry of either is not finite; if its limits are not valid.Error – On the tracers: if the search reads more than 4294967295 tracers; if none is left to read; if the count of a cell differs from the grid’s
n_tracers. If the smoothed divergence is 0 or positive in every cell.
Notes
Prints as
Verbositydescribes, the grid line as “outside the divergence grid”, the call linebitvf: findVoidsBoxFromDivergence: ....
- bitvf.find_voids_box_from_field(centres: numpy.typing.ArrayLike, values: numpy.typing.ArrayLike, *, config: Config = Config(), weights: numpy.typing.ArrayLike | None = None, mps: float | None = None) Result¶
Find voids and overdense basins in a field given at the centres of the cells of a box lattice, without tracers.
The lattice is inferred from the centres. On each axis, the coordinates are sorted and split into nodes at the gaps larger than half the largest gap; with n nodes from min to max, the spacing is (max - min) / (n - 1). The spacings of the axes with more than one node must agree within 1e-6 relative: the cell side s is the spacing of the axis with the most nodes, x before y before z on a tie. Each centre must lie within 1e-6 s of its node on every axis, and each node of the nx * ny * nz must hold exactly one centre. The grid spans min - s / 2 to max + s / 2 on each axis, without padding; nx, ny, nz need not be equal. The cells of the result are the cells of the lattice, not the rows of the input, and the order of the input does not change the result.
The field is smoothed with
config.smoothing, as the divergence offind_voids_box, withweightsas the tracer weight, and split into basins at 0: seeds below 0 start voids, those at or above 0 overdense basins. A field with another convention, such as a density or a density contrast with voids above 0, must be shifted or flipped before the call.- Parameters:
centres (array_like, shape (n, 3)) – Cartesian coordinates of the cell centres, in any order.
values (array_like, shape (n,)) – The field at each centre, in the order of
centres.config (Config, optional) – The parameters of the search.
divergence_cell_sizemust be None,keep_assignmentFalse andn_realizations_mean1: none applies without tracers. Withoutmps, a positivesmoothing.sigmamust be inLengthUnit.COORDINATE.weights (array_like, shape (n,), optional) – The weight of each cell in the smoothing, non-negative, in the order of
centres, used as given: a cell whose weights sum to at most 1e-12 times the largest weight takes 0 (seeSmoothing). If omitted, every cell has weight 1.mps (float, optional) – A mean particle separation, in coordinate units. Given, it is the unit of a sigma in
LengthUnit.MPSand is recorded inResult.mps, with the cell size in units of it inResult.config.divergence_cell_size.
- Returns:
Result – A field result (see
Result). The catalogues holdcentre,radius,radius_ext,edge_flagandcontaminationasfind_voids_boxcomputes them, on the faces of the inferred grid, andfield_centre. WithConfig.keep_divergence,Result.divergenceholds the grid, the field as given (divergence) and, with sigma > 0, smoothed (divergence_smoothed), the weights as given and, with sigma > 0, their smoothed mean (weight_smoothed), the basin indices, the cell centres and volumes.- Raises:
Error – On the arrays: if
centresis not of shape (n, 3), is empty, or a coordinate is not finite; ifvaluesdoes not hold one finite entry per centre; ifweightsis given empty, does not hold one entry per centre, or an entry is negative or not finite.Error – If
mpsis given and not finite and positive.Error – On
configasfind_voids_box; ifdivergence_cell_sizeis set,keep_assignmentis set orn_realizations_meanis not 1; if a positivesmoothing.sigmais inLengthUnit.MPSwithoutmps; ifsmoothing.sigmais positive and every weight is 0.Error – On the lattice: if every axis has one node; if the spacings of two axes differ by more than 1e-6 relative; if a centre lies farther than 1e-6 s from its node; if a node holds two centres, or none. If the field, smoothed when a smoothing is set, is 0 or positive in every cell.
Notes
A bitvf divergence file is valid input, read with
io.read_field: its cell centres,divergenceandweightwith the smoothing of the search that wrote it give back that search’s basins. Theircentre,radiusandradius_extcan differ from that search’s by a few ulp: the grid’s lower face and s are inferred from the centres read and may differ from the original grid’s by rounding.Prints the call line
bitvf: findVoidsBoxFromField: ....
- bitvf.box_grid(reconstruction: otswap.Result | None = None, *, box: Box | None = None, mps: float | None = None, cell_size: float | None = None) DivergenceGrid¶
The grid
find_voids_boxbuilds, bit for bit, so that several searches can share it.Two forms:
box_grid(box=..., mps=..., cell_size=...), all three required, the grid built on box limits; orbox_grid(reconstruction), the grid built onotswap.Result.boxwithotswap.Result.mps.Only the fields that define the cells are set:
geometry,lower,upper,n_cells_axis,n_cells,cell_size,cell_size_mpsandmps.limits, the realization counts and every per-cell field are left None, 0 or empty: records of a search, which a reuse ignores. The grid passes the checks of a grid to reuse.- Parameters:
reconstruction (otswap.Result, optional) – A box result of
otswap.reconstruct_box.box (BoxLimits or ((x0, y0, z0), (x1, y1, z1)), optional) – The box limits the grid is built on, as the
boxoffind_voids_box. Not withreconstruction.mps (float, optional) – Mean particle separation, in coordinate units; finite and positive. Not with
reconstruction.cell_size (float, optional) – The cell side in units of mps, as
Config.divergence_cell_size; finite and positive. Withreconstruction, if omitted, the default for its realizations, min(1, (20 / n_realizations)^(1/3)).
- Returns:
DivergenceGrid
- Raises:
Error – If neither a reconstruction nor all of
box,mpsandcell_sizeare given, orboxormpsis given with a reconstruction.Error – If a bound of
boxis not finite or a lower bound is not below the upper one; ifmpsorcell_sizeis not finite and positive; if the grid would hold more cells than an int64 index can address.Error – If the reconstruction is not a box result, has no realization, its box is missing or invalid, or its mps is not finite and positive.
- bitvf.watershed_box(field: numpy.typing.ArrayLike, *, verbosity: Verbosity = 'normal') Partition¶
Split a field on a box grid into basins by steepest descent.
The descent is that of the void finder (
BasinCatalog): each cell flows to the neighbour, among the 26 cut at the faces of the grid, where the field drops the most, ties to the lowest row; a cell with no strictly smaller neighbour is a seed. Seeds below 0 start voids, seeds at or above 0 overdense basins; each kind is numbered by ascending seed row. A field with another convention must be shifted or flipped before the call. No smoothing, no fill and no centres: the field is used as given. A field with no cell below 0 gives no void, and no error. The result does not depend on the number of threads.- Parameters:
field (array_like, shape (nx, ny, nz)) – The value of each cell, in any memory order; each count at least 1, not necessarily equal.
verbosity ({“silent”, “normal”, “detailed”}, optional) –
At
"normal", one line with its time:bitvf: watershedBox: <V> voids and <O> overdense basins on <nx> x <ny> x <nz> cells in <T> s
and at
"detailed", before it, the cells in voids and in overdense basins, and how many of each lie in the cores.
- Returns:
Partition
- Raises:
Error – If
fieldis not three-dimensional, a count is 0, or an entry is not finite.
Void finder, lightcone¶
- bitvf.find_voids_lightcone(tracers_sky: numpy.typing.ArrayLike, displacement: numpy.typing.ArrayLike, randoms_sky: numpy.typing.ArrayLike, valid: numpy.typing.ArrayLike | None = None, *, mask: otswap.Mask, distances: otswap.DistanceTable, mps_profile: otswap.MpsProfile, angle_unit: AngleUnit, config: Config = Config(), redshift_cut: RedshiftCutArg | None = None, ids: numpy.typing.ArrayLike | None = None, grid: DivergenceGrid | None = None) Result¶
Find voids and overdense basins in a lightcone, from sky positions or from an
otswap.Result.The divergence of the displacement field is computed on a grid of shells in comoving distance, declination rings and right-ascension sectors, smoothed (
config.smoothing) and divided by a watershed into basins around its local minima: the voids, below 0, and the overdense basins, at or above 0. The observer is at the origin.A tracer on an unobserved pixel of the mask, or with a redshift outside the cut, keeps its row but is skipped (
TracerAssignment.in_maskandin_cut,Counts.tracers_outside_maskandtracers_outside_redshift_cut); a random there is removed. A cell whose centre falls on an unobserved pixel is masked (DivergenceGrid.masked): it holds no divergence and belongs to no basin. Withoutgrid, the grid covers the tracers and randoms kept, with cellsconfig.divergence_cell_sizetimes mps(z) wide at the centre of each shell, by defaultmin(1, (20 / R)**(1/3))for R realizations. Any finite right ascension is accepted and folded into [0, 2 pi).- Parameters:
tracers_sky (array_like, shape (N, 3)) – Right ascension and declination in
angle_unit, and the observed redshift, which must lie inside the distance table. A declination must lie in [-90, 90] degrees.displacement (array_like, shape (R, N, 3)) – Cartesian displacements of R realizations, in the unit of
distances, from the tracers’ Cartesian positions (otswap.to_cartesianoftracers_sky). Every valid displacement of a tracer kept must be finite.randoms_sky (array_like, shape (M, 3)) – The randoms, as
tracers_sky: required. They describe the survey, set the extent of a new grid with the tracers, and give the expected counts ofdelta_2mps. Pass those of the reconstruction. With anotswap.Result, the second positional argument.valid (array_like, shape (R, N), optional) – 0 or 1 for each displacement; if omitted, all valid.
mask (otswap.Mask) – The observed pixels of the survey; that of the reconstruction, or a stricter one.
distances (otswap.DistanceTable) – The redshift-distance table; coordinates are in its distance unit. Required with arrays; an
otswap.Resultcarries its own.mps_profile (otswap.MpsProfile) – The mean particle separation as a function of redshift (
otswap.Result.mps_profileof the reconstruction): the cell size of each shell, a smoothing in mps, the densities. Required with arrays. Withgridit must equal the grid’s profile.angle_unit ({“deg”, “rad”}) – The unit of
tracers_skyandrandoms_sky, and of the sky arrays of the result.config (Config, optional) – The parameters of the search.
redshift_cut (otswap.RedshiftCut or (min, max), optional) – The closed range of observed redshift searched; pass the cut of the reconstruction. Arrays only; the default cuts nothing.
ids (array_like of int, shape (N,), optional) – The identity of each tracer; arrays only. As
find_voids_box.grid (DivergenceGrid, optional) – A lightcone grid to reuse, built with the same distance table, whose mps profile sets the smoothing and the densities. Tracers kept but outside every cell are excluded (
Result.outside_grid).config.divergence_cell_sizemust be None with it. It may have been made in the otherangle_unit.
- Returns:
Result – With
Result.geometry"lightcone"andResult.angle_unitthat of the call.- Raises:
Error – If an argument has the wrong type or shape, a declination lies outside [-90, 90] degrees,
angle_unitis neither"deg"nor"rad", an argument that arrays need is missing, or one that the form with anotswap.Resultdoes not take is given.Error – On the data and the configuration, as the library requires: no tracer, valid displacement or random left after the mask, the cut and a reused grid; a redshift outside the distance table; a grid that fails the checks of a grid to reuse; a divergence that is nowhere negative.
- bitvf.find_voids_lightcone_from_cartesian(tracers: numpy.typing.ArrayLike, displacement: numpy.typing.ArrayLike, randoms: numpy.typing.ArrayLike, valid: numpy.typing.ArrayLike | None = None, *, mask: otswap.Mask, distances: otswap.DistanceTable, mps_profile: otswap.MpsProfile, angle_unit: AngleUnit, config: Config = Config(), redshift_cut: RedshiftCutArg | None = None, ids: numpy.typing.ArrayLike | None = None, grid: DivergenceGrid | None = None) Result¶
Find voids and overdense basins in a lightcone, from Cartesian positions with the observer at the origin.
As
find_voids_lightconefrom sky positions. The sky coordinates of every row are computed first withotswap.to_skyanddistances; they alone decide the mask, the redshift cut and the cell of every tracer and random. Every row must be finite, must not lie at the origin and must lie within the distance table, rows on unobserved pixels or outside the cut included.- Parameters:
tracers (array_like, shape (N, 3)) – x, y, z, in the unit of
distances.displacement, valid, mask, distances, mps_profile, config, redshift_cut, ids, grid – As
find_voids_lightcone.randoms (array_like, shape (M, 3)) – As
tracers, for the randoms: required.angle_unit ({“deg”, “rad”}) – The unit of the sky arrays of the result; no argument is a sky array.
- Returns:
Result – As
find_voids_lightcone.
- bitvf.lightcone_grid(tracers_sky: otswap.Result, randoms_sky: numpy.typing.ArrayLike, *, mask: otswap.Mask, angle_unit: AngleUnit, cell_size: float | None = None) DivergenceGrid¶
The grid
find_voids_lightconebuilds, bit for bit, from anotswap.Resultor from arrays, with the same selection of the tracers and randoms and the same checks, those of the displacements included with a reconstruction.One grid can be shared by several searches (
grid), by the two passes of a pipeline or by a set of mocks. Only the fields that define the cells are set (n_cells,distance_mintodec_max,cell_size_mps,mps_profile); every per-cell array is empty and the realization counts are 0.- Parameters:
tracers_sky, randoms_sky, mask, distances, mps_profile, redshift_cut – As
find_voids_lightcone;tracers_skymay be anotswap.Result.cell_size (float, optional) – The cell size in units of mps(z), as
Config.divergence_cell_size; finite and positive. Required with arrays, where a reasonable starting value ismin(1, (20 / R)**(1/3)), R the number of realizations the search will read. With anotswap.Result, empty for the default,min(1, (20 / R)**(1/3)), R the realizations of the result.angle_unit ({“deg”, “rad”}) – The unit of
tracers_skyandrandoms_sky, and of the angle fields of the grid.
- Returns:
DivergenceGrid – With
geometry"lightcone".
Pipeline, box¶
- bitvf.run_box(tracers: numpy.typing.ArrayLike, randoms: numpy.typing.ArrayLike | None = None, *, config: BoxConfig = BoxConfig(), distances: otswap.DistanceTable | None = None, ids: numpy.typing.ArrayLike | None = None) BitVFResult¶
Reconstruct a box and find its voids, with the correction of redshift-space distortions when
config.rsdis set.The run:
Checks every argument and every field of
configthat can be checked before any work, so that an invalid run fails before the reconstruction.Fixes the box:
config.limits, or the bounding box of the tracers, or of the tracers and the randoms when randoms are given.Without randoms, draws
config.ot.n_realizations* N of them, uniformly in the box, N the tracers inside it.Reconstructs with
otswap.reconstruct_box: the randoms, the box as limits,config.mpswhen given.
Without
config.rsd, it then searches that reconstruction withfind_voids_box, which reads its mps. Withconfig.rsd, after step 4:With
BoxRsd.zspace_voids, searches the first reconstruction (BitVFResult.zspace_voids).Builds the grid of the first reconstruction,
box_grid(first, cell_size=config.voids.divergence_cell_size): the grid of every search of the run.Corrects the tracers with
otswap.real_space_box.Selects, in input order, the tracers corrected whose corrected position lies in a cell of that grid. The others keep their row and are flagged: unmoved by the correction (including the tracers outside the box) in
Result.uncorrected, moved outside every cell inResult.outside_grid.Reconstructs the selected tracers at their corrected positions, with the randoms of the first reconstruction, the same box as limits,
config.mpswhen given, and the same seed.Searches that reconstruction on the grid of step 6, with the smoothing and the
delta_2mpsradius from the first reconstruction’s mps, which isResult.mps. A tracer moved outside the box but into a cell is skipped (TracerAssignment.in_box).Returns the search with one row per input tracer.
The box always reaches otswap as limits, so
Result.limitsholds it, and the files record it, also whenconfig.limitsis None.- Parameters:
tracers (array_like, shape (N, 3)) – Cartesian coordinates, in coordinate units; in redshift space with a correction.
randoms (array_like, shape (M, 3), optional) – Cartesian coordinates of the randoms, at least
config.ot.n_realizations* N inside the box; those outside it are dropped by otswap. They go to the reconstructions only. If omitted, bitvf draws them: from the seed s =config.ot.seed+ 1299709, modulo 2^32, a seed of 0 counting as the one drawn to replace it, recorded inResult.random_seedof every pass and in the keyword RANDSEED of bitvf’s files; s alone reproduces them.config (BoxConfig, optional) – The parameters of the run.
distances (otswap.DistanceTable, optional) – A table carrying the growth rate at
BoxRsd.redshift; required withconfig.rsd, not read without it.ids (array_like of int, shape (N,), optional) – The tracers’ identity, no value twice; if omitted, the rows. They go to the reconstruction and to
Result.ids.
- Returns:
BitVFResult – The voids, and as
configasks the redshift-space voids, the two reconstructions and the corrected catalogue. Invoids, a row excluded from the second pass carries -1 in every index, NaN inTracerAssignment.distance, False inusedand, inin_box, the first reconstruction’s value (False for a tracer outside the box limits, True otherwise), and one flag,uncorrectedbeforeoutside_grid;Result.countscounts the input rows.- Raises:
Error – If an argument or a field of
configis invalid, asfind_voids_boxandotswap.reconstruct_boxrequire: shapes asfind_voids_box,randomsgiven empty.Error – If
config.rsdis set withoutdistances; if a field ofconfig.rsdis invalid (axisNone or not 0, 1 or 2,biasnot finite and positive,sigmanot finite and non-negative) or the distance table cannot give the growth rate atredshift, checked before the first reconstruction.Error – If the bounding box spans no volume; if randoms are to be drawn and no tracer lies inside the box; with a correction, if no tracer is selected for the second reconstruction.
Error – From otswap, the message starting with
"otswap: "; from each search, asfind_voids_box.
Notes
Prints otswap’s report lines at
config.ot.verbosity, the correction’s atBoxRsd.correction.verbosity, and the searches’ and the pipeline’s atconfig.voids.verbosity: at"detailed", after drawing the randoms and after step 8:bitvf: drew <n> randoms in <box> with seed <s> in <t> s bitvf: second pass on <k> of <N> tracers: <u> uncorrected, <g> outside the first pass's grid in <t> s
and at
"normal", last, with the time of the whole call:bitvf: runBox: <V> voids and <O> overdense basins from <N> tracers in <T> s
Pipeline, lightcone¶
- bitvf.run_lightcone(tracers_sky: numpy.typing.ArrayLike, randoms_sky: numpy.typing.ArrayLike, randoms_sky_second_pass: numpy.typing.ArrayLike | None = None, *, mask: otswap.Mask, distances: otswap.DistanceTable, angle_unit: AngleUnit, config: LightconeConfig, ids: numpy.typing.ArrayLike | None = None) BitVFResult¶
Reconstruct a lightcone and find its voids, with the correction of redshift-space distortions and a second reconstruction in real space when
config.rsdis set.The run:
Checks every argument and every field of
configthat can be checked before any work. With a correction, the factor of the correction is computed at the observed redshifts of the tracers kept, so that a table without growth rate or an unusable bias fails here.Reconstructs with
otswap.reconstruct_lightcone: the randoms, the mask,config.n_bins, the distance table,config.otandconfig.cut.Without
config.rsd, searches that reconstruction withfind_voids_lightconeand returns.
With
config.rsd, after step 2:Builds the grid of the first reconstruction with
config.voids.divergence_cell_size: the grid of every search of the run.With
LightconeRsd.zspace_voids, searches the first reconstruction on it (BitVFResult.zspace_voids).Corrects the tracers with
otswap.real_space_lightcone; the correction moves a tracer in redshift only.Selects, in input order, the tracers corrected whose corrected redshift lies inside
config.cutand whose corrected position lies in a cell of the grid. The others keep their row and are flagged: unmoved by the correction inResult.uncorrected, moved outside the cut inResult.outside_cut, moved outside every cell inResult.outside_grid.Reconstructs the selected tracers at their corrected redshifts, with the randoms of
LightconeRsd.second_pass_randoms, the same mask, cut, bins and seed.Searches that reconstruction on the grid of step 4, with the first reconstruction’s mps(z) profile for the smoothing and the densities.
Returns the search with one row per input tracer.
- Parameters:
tracers_sky (array_like, shape (N, 3)) – Right ascension and declination in
angle_unit, and the observed redshift, in redshift space.randoms_sky (array_like, shape (M, 3)) – The randoms, as
tracers_sky: required. Every systematic belongs in them. At leastconfig.ot.n_realizationstimes the tracers kept are needed.randoms_sky_second_pass (array_like, shape (K, 3), optional) – The randoms of the second reconstruction, with
SecondPassRandoms.EXTERNALand only then.mask (otswap.Mask) – The observed pixels of the survey, for both reconstructions and every search.
distances (otswap.DistanceTable) – The redshift-distance table, carrying the growth rate when
config.rsdis set.angle_unit ({“deg”, “rad”}) – The unit of the sky arrays given and of those of
BitVFResult.voidsandzspace_voids. The otswap objects the result holds are in radians whatever it is.config (LightconeConfig) – The parameters of the run; required, since
n_binshas no default.ids (array_like of int, shape (N,), optional) – The tracers’ identity, no value twice; if omitted, the rows.
- Returns:
BitVFResult – The voids, and as
configasks the redshift-space voids, the reconstructions and the corrected catalogue. Invoids, an excluded row carries -1 in every index, NaN inTracerAssignment.distanceand False inused, and one flag,uncorrectedbeforeoutside_cutbeforeoutside_grid;in_maskandin_cutare the first reconstruction’s.Result.countscounts the input rows.- Raises:
Error – If an argument or a field of
configis invalid, asfind_voids_lightconeandotswap.reconstruct_lightconerequire; ifrandoms_sky_second_passis given empty, without a correction, or withoutEXTERNAL; if no tracer is selected at step 7; withEXTERNAL, if fewer randoms remain than needed.Error – From otswap, the message starting with
"otswap: ".
Notes
Prints otswap’s report lines at
config.ot.verbosity, the correction’s atLightconeRsd.correction.verbosity, and the searches’ and the pipeline’s atconfig.voids.verbosity, the last line, at"normal", being:bitvf: runLightcone: <V> voids and <O> overdense basins from <N> tracers in <T> s
Results¶
- class bitvf.Result¶
Output of one void search. Read-only.
Given the same inputs, every field but
elapsed_secondsis the same bit for bit whatever the number of threads.A result of
find_voids_box_from_field, a field result, holds no tracer:n_tracersandn_realizationsare 0, which tells it from the result of every other search, and so are the counts; the per-tracer flags,assignment, and the catalogue columnsdelta_av,delta_2mpsandn_tracersare empty;limitsis None;mpsis NaN when none was given.- property angle_unit: Literal['deg', 'rad'] | None¶
The unit of the sky arrays, that of the call that made the result; None for a box.
- property assignment: TracerAssignment | None¶
Where each tracer ended up, with
Config.keep_assignment; None otherwise.
- property config: Config¶
The configuration the search ran with,
divergence_cell_sizeset to the value used: a new copy on each access, so changing it changes nothing in the result.
- property distances: otswap.DistanceTable | None¶
Lightcone only; None in a box.
- property divergence: DivergenceGrid | None¶
The grid and the divergence field, with
Config.keep_divergence; None otherwise. With a reused grid, its cells with this search’s values.
- property elapsed_seconds: float¶
Wall time of the call, in seconds; the only field that differs between two runs on the same inputs.
- property geometry: Literal['box', 'lightcone']¶
The geometry of the search.
- property ids: numpy.typing.NDArray[numpy.int64]¶
The identity of each tracer, shape (n_tracers,), as given. Each access returns a new read-only copy on each access; 0..n_tracers-1 when none were set. No computation reads it.
- property limits: otswap.BoxLimits | None¶
The box limits of the search, those given, the reconstruction’s, or the grid’s for
find_voids_box_from_divergence; the tracers outside them were skipped. None without limits.
- property mps: float¶
The mean particle separation the search used, in coordinate units: the one given, the reconstruction’s, or a reused grid’s. NaN for a field result given none.
- property mps_profile: otswap.MpsProfile | None¶
Lightcone only; None in a box.
- property outside_cut: numpy.typing.NDArray[numpy.bool_]¶
Lightcone only; shape (0,) in a box.
- property outside_grid: numpy.typing.NDArray[numpy.bool_]¶
True for a tracer outside the reused grid, excluded from this search, row kept, shape (n_tracers,). In the real-space pass of
run_box: corrected, but outside the first pass’s grid. Shape (0,) when no grid was reused, which reads as all False. A tracer carries at most one ofuncorrectedandoutside_grid.
- property overdense: BasinCatalog¶
The overdense basins.
- property random_seed: int | None¶
The seed
run_boxderived and used to draw the randoms, which alone reproduces them; None when it drew none.
- property redshift_cut: otswap.RedshiftCut | None¶
In a lightcone, the closed range of observed redshift the search kept; None in a box.
- property uncorrected: numpy.typing.NDArray[numpy.bool_]¶
Real-space pass of
run_boxwith a correction, shape (n_tracers,): True for a tracer the correction left unmoved, excluded from the second reconstruction and from this search, row kept. Shape (0,) elsewhere, which reads as all False.
- property voids: BasinCatalog¶
The voids.
- class bitvf.BasinCatalog¶
One catalogue of watershed basins: the voids, or the overdense basins.
The columns are the same for both kinds. Row b is basin b, numbered from 0 in the order of the index of its seed cell, a local minimum of the divergence (smoothed when a smoothing is set): below 0 for a void, at or above 0 for an overdense basin. In a box every cell belongs to exactly one basin. The order does not depend on the number of threads.
The core of a void is the part of the void where the divergence is below 0; the extended void is the whole basin. In a box the core and the extended basin of an overdense basin coincide.
Each cell flows to the neighbour where the divergence drops the most (the largest decrease, not divided by the distance), among its neighbours (box: the 26 cells that share a face, an edge or a corner with it; lightcone: the unmasked cells whose centres are closer than r (s_i + s_j) / 2, r = (sqrt(3) + 2) / 2, s_i and s_j the sides of the two cells, about 1.87 times their mean), when that value is strictly below its own; among equal smallest values, the neighbour with the lowest cell row. A cell with no strictly smaller neighbour is a seed. A basin is the seed and every cell whose flow reaches it. In a box the grid is not periodic: a cell on a face has fewer neighbours.
Read-only; every array has one row per basin.
- property centre: numpy.typing.NDArray[numpy.float64]¶
Cartesian centre, shape (n_basins, 3), in coordinate units. It is the seed cell’s centre x0, shifted by
s * sum_n div_n (x_n - x0) / sum_n |div_n|over the seed’s neighbouring cells n, with div the field the watershed split (the smoothed divergence, or the divergence when sigma is 0) and s = -1 for a void, +1 for an overdense basin (towards lower divergence in a void, higher in an overdense basin), and kept inside the seed cell.
- property centre_sky: numpy.typing.NDArray[numpy.float64]¶
Sky coordinates of the centre, lightcone only, shape (n_basins, 3): right ascension and declination in the
angle_unitof the call that made the result, right ascension in [0, 2 pi) or [0, 360), and the redshift; shape (0, 3) in a box. In degrees, a read-only copy made once, with otswap’s conversion.
- property contamination: numpy.typing.NDArray[numpy.float64]¶
Fraction of the basin’s surface on the boundary, shape (n_basins,): in a box, the faces of its cells on the faces of the grid, over those faces plus the faces its cells share with cells of other basins; 1 for a basin that fills the grid. In a lightcone, the area its cells share with masked cells plus their area on the border, over that area plus the area they share with cells of other basins; 0 when that sum is not positive.
- property delta_2mps: numpy.typing.NDArray[numpy.float64]¶
Density contrast within 2 mps of the centre, the sphere closed, shape (n_basins,): n_t over its volume, divided by the mean density mps^-3, minus 1, with n_t the tracers the search reads (inside the box limits and the reused grid) in the sphere. In a lightcone, within 2 mps(z) at the centre’s redshift, n_t / (n_r N_t / N_r) - 1, with n_t and n_r the tracers and randoms in the sphere and N_t / N_r the ratio of the tracers to the randoms over the whole search (
Counts.randoms); NaN when no random lies in the sphere. 30 randoms per tracer, the minimum the reconstruction needs with otswap’s default of 30 realizations, is a reasonable start. Shape (0,) after a field search.
- property delta_av: numpy.typing.NDArray[numpy.float64]¶
Mean density contrast of the tracers in the core, shape (n_basins,): the tracers starting in its cells (
n_tracers) over its volume, divided by the mean density mps^-3 (mps(z)^-3 in a lightcone), minus 1. Shape (0,) after a field search.
- property edge_flag: numpy.typing.NDArray[numpy.uint8]¶
Contact with the boundary, shape (n_basins,). 0 is none; 1 only the extended basin touches it; 2 the core already touches it. The boundary is, in a box, the faces of the grid, with or without box limits; in a lightcone, the masked cells and the border of the grid. In a box, a basin touches it when one of its cells lies on a face of the grid. In a lightcone, when one of its cells shares a face with a masked cell, or lies on the border: the first shell unless it is the central sphere, the last shell, the first and the last declination ring of a shell unless its edge is on a pole, and the first and the last sector of a ring that is not a full circle.
- property field_centre: numpy.typing.NDArray[numpy.float64]¶
the field the watershed split, smoothed when a smoothing was applied, at
centre, interpolated trilinearly between the eight nearest cell centres, the point first clamped per axis to the range of the centres; at a cell centre, that cell’s value. Shape (0,) otherwise.- Type:
After
find_voids_box_from_fieldonly, shape (n_basins,)
- property n_tracers: numpy.typing.NDArray[numpy.uint64]¶
Tracers starting in the cells of the core, the count behind
delta_av, shape (n_basins,). Shape (0,) after a field search.
- property radius: numpy.typing.NDArray[numpy.float64]¶
Radius of the sphere with the volume of the core, in coordinate units, shape (n_basins,).
- property radius_ext: numpy.typing.NDArray[numpy.float64]¶
Radius of the sphere with the volume of the extended basin, in coordinate units, shape (n_basins,).
- class bitvf.DivergenceGrid¶
The grid of the void finder and the divergence field on it.
Read-only: it comes from
Result.divergence(withConfig.keep_divergence),box_gridorio.read_divergence, and can be passed back tofind_voids_boxasgrid, bit for bit. A reuse reads only the fields that define the cells (cell_size,lower,upper,n_cells_axis,n_cells),cell_size_mpsandmps, checks that they are consistent, and raisesErrorotherwise; the per-cell results, the limits and the realization counts of the search that filled the grid are ignored.Box: cubic cells of side
cell_size; cell (i, j, k) spans lower + (i, j, k) * cell_size to lower + (i + 1, j + 1, k + 1) * cell_size. The grid is built on the box limits of the search, or without them on the bounding box of the tracers read and of the endpoints of their valid displacements; from a reconstruction, on its box (otswap.Result.box). It is padded by 0.1 mps on each side. With E the padded extent and s the cell side, an axis needs floor(E / s + 1) cells; the largest count is used on all three axes, so the grid is a cube of cells even when the box is not. On each axis, with n the count and S = n s - E the slack, the padded box’s lower face moves down by S / 2, which islower, and its upper face up by S / 4, which isupper. With limits the grid overhangs them.Per-cell arrays have shape
n_cells_axis(centre: plus 3), C order, so thata[i, j, k]is the cell (i, j, k); shape (0,) when not filled (every per-cell array of abox_gridgrid). The lightcone fields are NaN, (0,) or None in a box.- property angle_unit: Literal['deg', 'rad'] | None¶
The unit of the angle fields (
ra_mintodec_max, thecell_ra_*andcell_dec_*arrays,centre_sky): that of the call that made the grid, or ofio.read_divergence; None for a box. In degrees the fields are copies made with otswap’s factor, so they matchnumpy.rad2deg; the library holds radians.
- property cell_dec_max: numpy.typing.NDArray[numpy.float64]¶
Lightcone only, in
angle_unit, shape (n_cells,); (0,) in a box and in a grid read from a file.
- property cell_dec_min: numpy.typing.NDArray[numpy.float64]¶
Lightcone only, in
angle_unit, shape (n_cells,); (0,) in a box and in a grid read from a file.
- property cell_distance_max: numpy.typing.NDArray[numpy.float64]¶
Lightcone only; shape (0,) in a box.
- property cell_distance_min: numpy.typing.NDArray[numpy.float64]¶
Lightcone only; shape (0,) in a box.
- property cell_ra_max: numpy.typing.NDArray[numpy.float64]¶
Lightcone only, in
angle_unit, shape (n_cells,); (0,) in a box and in a grid read from a file.
- property cell_ra_min: numpy.typing.NDArray[numpy.float64]¶
Lightcone only, in
angle_unit, shape (n_cells,); (0,) in a box and in a grid read from a file.
- property cell_size: float¶
The cell side, in coordinate units,
cell_size_mps * mps; it defines the cells. Afterfind_voids_box_from_field, the spacing of the centres inferred along the axis with the most nodes. NaN in a lightcone.
- property cell_size_mps: float¶
a record of the choice beside
cell_size, which a search reusing the grid reports inResult.config. NaN after a field search given no mps.- Type:
Config.divergence_cell_sizeused, in units of the mps
- property centre: numpy.typing.NDArray[numpy.float64]¶
Cartesian centre of each cell, in coordinate units, shape (nx, ny, nz, 3).
- property centre_sky: numpy.typing.NDArray[numpy.float64]¶
Right ascension and declination of each cell centre in
angle_unit, and the redshift, shape (n_cells, 3). Lightcone only; shape (0, 3) in a box.
- property divergence: numpy.typing.NDArray[numpy.float64]¶
The divergence of each cell, before smoothing, shape (nx, ny, nz); what the watershed splits with sigma = 0.
- property divergence_smoothed: numpy.typing.NDArray[numpy.float64]¶
The divergence after smoothing (see
Smoothing), what the watershed splits, shape (nx, ny, nz), with sigma > 0; shape (0,) with sigma = 0.
- property geometry: Literal['box', 'lightcone']¶
The geometry of the grid.
- property limits: otswap.BoxLimits | None¶
The box limits of the search that filled the grid; None without limits. A record: a search reusing the grid does not read it, its own limits apply.
- property lower: tuple[float, float, float]¶
The x, y, z of the lower grid face, in coordinate units. Defines the cells.
- property masked: numpy.typing.NDArray[numpy.bool_]¶
Lightcone only; shape (0,) in a box.
- property mps: float¶
The mean particle separation the grid was built with, in coordinate units; the smoothing in mps and the
delta_2mpsradius of a search that reuses the grid follow it. NaN after a field search given no mps.
- property mps_profile: otswap.MpsProfile | None¶
Lightcone only; None in a box.
- property n_cells_axis: tuple[int, int, int]¶
The cells along x, y, z, (nx, ny, nz), which defines the cells; equal on the three axes but after
find_voids_box_from_field, where they may differ.
- property n_displacements: numpy.typing.NDArray[numpy.uint64]¶
Displacement ends counted in each cell, before the fill, shape (nx, ny, nz): a valid displacement that leaves its tracer’s cell counts 1 there and 1 in the cell it ends in; one that ends in its tracer’s cell counts 2 there. A point on a face between two cells belongs to the upper one, and a displacement that starts or ends on a face, an edge or a vertex, or runs along a face, is counted as that of the same tracer moved one ulp into its cell. Shape (0,) after a field search.
- property n_realizations: int¶
The realizations of the search that filled the grid (keyword NREC). A record; 0 after
find_voids_box_from_fieldand in abox_gridgrid.
- property n_realizations_mean: int¶
Config.n_realizations_meanof the search that filled the grid (keyword NRECMEAN). A record; 0 afterfind_voids_box_from_fieldand in abox_gridgrid.
- property n_tracers: numpy.typing.NDArray[numpy.uint64]¶
Tracers starting in each cell, shape (nx, ny, nz). Shape (0,) after a field search.
- property overdense_index: numpy.typing.NDArray[numpy.int64]¶
Row of the cell’s overdense basin in
Result.overdense, shape (nx, ny, nz); -1 none.
- property upper: tuple[float, float, float]¶
The x, y, z of the upper face of the padded box as placed, in coordinate units. Defines the cells. It lies below the last cell face, lower + n_cells_axis * cell_size; it is stored as built.
- property void_index: numpy.typing.NDArray[numpy.int64]¶
Row of the cell’s void in
Result.voids, shape (nx, ny, nz); -1 none.
- property volume: numpy.typing.NDArray[numpy.float64]¶
Volume of each cell, in coordinate units cubed, shape (nx, ny, nz); uniform in a box.
- property weight: numpy.typing.NDArray[numpy.float64]¶
Tracer weight of each cell, the weight of the smoothing, shape (nx, ny, nz): n_displacements / n_realizations where a displacement contributed. A cell that no displacement contributed to is empty: it keeps a weight of 0, and takes the mean divergence of nearby cells that hold a value, weighted by 1 / r^2, r the distance between the cell centres. Box: the neighbours within one cell along each axis, or within two when fewer than three of those hold a value, in passes that each read the values left by the previous one, until no cell is empty. Lightcone: the neighbouring cells (as
BasinCatalog) that hold a value, when at least three do; the passes repeat until one fills no cell, and a masked cell is never filled. With its weight of 0, a filled value enters no smoothed mean; with sigma = 0 the watershed reads it as it is.
- property weight_smoothed: numpy.typing.NDArray[numpy.float64]¶
Smoothed tracer weight of each cell, shape (nx, ny, nz), with sigma > 0: the mean of
weightover the cells of the smoothing (seeSmoothing) with the Gaussian alone as weight, sum K w / sum K, K = exp(-r^2 / (2 sigma^2)). It shows how much of a cell’s smoothed divergence comes from displacements; the watershed does not read it. The sum of K over the cube is the product of the three sums of the 1-D kernel along the axes, each cut at the faces. Shape (0,) with sigma = 0.
- class bitvf.TracerAssignment¶
Where each input tracer ended up, one row per input row, shape (N,) each. Filled in
Result.assignmentwithConfig.keep_assignment. Read-only.- property cell_index: numpy.typing.NDArray[numpy.int64]¶
Flat row of the cell the tracer starts in; -1 when outside the grid or left out.
numpy.unravel_index(row, grid.n_cells_axis)gives (i, j, k).
- property distance: numpy.typing.NDArray[numpy.float64]¶
Distance from the centre of the tracer’s basin, its void or its overdense basin, in coordinate units; NaN for a tracer in no basin (not read by the search).
- property in_box: numpy.typing.NDArray[numpy.bool_]¶
False for a tracer outside the box limits, which was skipped; all True without limits. Shape (0,) in a lightcone.
- property in_cut: numpy.typing.NDArray[numpy.bool_]¶
False when the tracer lies outside the redshift cut, and so was skipped. Shape (0,) in a box.
- property in_mask: numpy.typing.NDArray[numpy.bool_]¶
False when the tracer falls on an unobserved pixel of the mask. Shape (0,) in a box.
- property overdense_index: numpy.typing.NDArray[numpy.int64]¶
Row of the tracer’s overdense basin in
Result.overdense; -1 none.
- property used: numpy.typing.NDArray[numpy.bool_]¶
True when at least one valid displacement of the tracer entered the divergence. Shape (0,) after
find_voids_box_from_divergence, which reads no displacement.
- property void_index: numpy.typing.NDArray[numpy.int64]¶
Row of the tracer’s void in
Result.voids; -1 none.
- class bitvf.Counts¶
What the void finder counted: the counts its report prints. Read-only. Every count is 0 in a field result.
- property displacements_rejected: int¶
In a lightcone, the valid displacements of the tracers read that were rejected (a start or end in a masked cell, an end outside every cell, a path too close to the observer). 0 in a box.
- property randoms: int¶
In a lightcone, the randoms the search reads (N_r of
delta_2mps), kept by the mask and the redshift cut and inside the grid. 0 in a box.
- property randoms_outside_grid: int¶
In a lightcone with a reused grid, the randoms outside it, removed. 0 in a box.
- property randoms_outside_mask: int¶
In a lightcone, the randoms on unobserved pixels of the mask, removed. 0 in a box.
- property randoms_outside_redshift_cut: int¶
In a lightcone, of the randoms on observed pixels, those outside the redshift cut, removed. 0 in a box.
- property tracers_in_masked_cells: int¶
In a lightcone, the tracers on an observed pixel whose cell is masked. They keep their cell but are in no basin. 0 in a box.
- property tracers_outside_box: int¶
With box limits, the tracers outside them, skipped (
TracerAssignment.in_box).
- property tracers_outside_cut: int¶
corrected, but moved outside the redshift cut, and excluded (
Result.outside_cut). 0 in a box.- Type:
Real-space pass of
run_lightconewith a correction
- property tracers_outside_grid: int¶
With a reused grid, the tracers outside it, excluded (
Result.outside_grid). In the real-space pass ofrun_box: corrected, but outside the first pass’s grid.
- property tracers_outside_mask: int¶
In a lightcone, the tracers on unobserved pixels of the mask, and so skipped (
TracerAssignment.in_mask), whether or not they lie inside the redshift cut. 0 in a box.
- property tracers_outside_redshift_cut: int¶
In a lightcone, of the tracers on observed pixels, those outside the redshift cut, and so skipped (
TracerAssignment.in_cut). A tracer both masked and outside the cut counts only intracers_outside_mask. 0 in a box.
- class bitvf.Partition¶
The basins of a field, as
watershed_boxfinds them, with no catalogue. Read-only.- property overdense_cells: numpy.typing.NDArray[numpy.uint64]¶
Cells of each overdense basin, shape (n_overdense,).
- property overdense_core_cells: numpy.typing.NDArray[numpy.uint64]¶
Cells of each overdense basin’s core, where the field is at or above 0, shape (n_overdense,).
- property overdense_index: numpy.typing.NDArray[numpy.int64]¶
Row of each cell’s overdense basin, -1 none; int64, the shape of the field.
- property overdense_seed: numpy.typing.NDArray[numpy.int64]¶
Flat row of each overdense basin’s seed cell, ascending, shape (n_overdense,).
- property void_cells: numpy.typing.NDArray[numpy.uint64]¶
Cells of each extended void, shape (n_voids,).
- property void_core_cells: numpy.typing.NDArray[numpy.uint64]¶
Cells of each void’s core, where the field is below 0, shape (n_voids,).
- property void_index: numpy.typing.NDArray[numpy.int64]¶
Row of each cell’s void, -1 none; int64, the shape of the field, (nx, ny, nz).
- property void_seed: numpy.typing.NDArray[numpy.int64]¶
Flat row of each void’s seed cell, ascending, shape (n_voids,);
numpy.unravel_index(row, field.shape)gives (i, j, k).
- class bitvf.BitVFResult¶
Output of
run_boxandrun_lightcone. Read-only.The otswap objects it holds are made in C++: a lightcone’s sky arrays (
tracers_sky,lagrangian_sky,sky) are in radians whatever theangle_unitof the call, and theirangle_unitreads"rad".voidsandzspace_voidsreport the call’s unit.Given the same inputs and a seed other than 0, every field but the searches’
elapsed_secondsis the same bit for bit whatever the number of threads.- property real_space: otswap.RealSpaceCatalog | None¶
the corrected catalogue, one row per input tracer.
- Type:
With
keep_reconstructionsand a correction
- property reconstruction: otswap.Result | None¶
the reconstruction the voids were found on. With a correction its rows are the second reconstruction’s tracers only, and its ids are their identity among the input’s.
- Type:
With
keep_reconstructions
- property voids: Result¶
The voids of the run, those of the real-space pass with a correction and of the only pass without. Its per-tracer columns have one row per input tracer, in input order.
- property zspace_reconstruction: otswap.Result | None¶
the first, redshift-space, reconstruction, one row per input tracer.
- Type:
With
keep_reconstructionsand a correction
Aliases¶
- bitvf.Verbosity: TypeAlias = Literal['silent', 'normal', 'detailed']¶
What a search prints, to
sys.stdout, each line starting withbitvf::"silent": nothing;"normal": what the box limits and a reused grid left out, then one line per call with its time:bitvf: kept <k> of <N> tracers: <b> outside the box [<x0>, <x1>] x [<y0>, <y1>] x [<z0>, <z1>] bitvf: kept <k'> of <k> tracers: <g> outside the reused grid bitvf: moved <m> tracer(s) onto the box edge bitvf: findVoidsBox: <V> voids and <O> overdense basins from <N> tracers in <T> s; <W> without a valid displacement
The box line is printed when the search has box limits (given, the reconstruction’s, or the reused grid’s); the grid line whenever a grid is reused, even with no tracer outside it, and by
find_voids_box_from_divergenceas “outside the divergence grid”. The moved line is printed by the search of a reconstruction without box limits, when <m> is not 0: a tracer outside the measured box by rounding is moved onto its edge. <W> counts the tracers read without a valid displacement. The call lines of the other searches arebitvf: findVoidsBoxFromDivergence: <V> voids and <O> overdense basins from <N> tracers in <T> sandbitvf: findVoidsBoxFromField: <V> voids and <O> overdense basins on <nx> x <ny> x <nz> cells in <T> s. In a lightcone the lines are:bitvf: kept <k> of <N> tracers: <m> on unobserved pixels, <c> outside the redshift cut bitvf: kept <k> of <M> randoms: <m> on unobserved pixels, <c> outside the redshift cut bitvf: grid of <C> cells in <S> shells, cell size <s> mps (<source>), distances [<d0>, <d1>], RA [<a0>, <a1>] deg, Dec [<b0>, <b1>] deg (<from>) in <t> s bitvf: kept <k'> of <k> tracers: <g> outside the reused grid bitvf: <n> tracers start in a masked cell, in no basin bitvf: divergence of the valid displacements of <u> tracers, <r> displacements rejected (masked cells, outside or below the grid) in <t> s bitvf: filled <f> cells in <p> passes, <e> left empty in <t> s bitvf: findVoidsLightcone: <V> voids and <O> overdense basins from <N> tracers in <T> s; <W> without a valid displacement
The redshift cut appears in the selection lines only when it has a finite bound; the grid line adds “, central sphere included” when the grid has one, its source is default, given or reused, and it ends “(from the tracers and randoms)” or “(from the reused grid)”; the reused-grid line is printed whenever a grid is reused; the masked-cell, divergence and fill lines only when <n>, <r> or <e> is not 0 (
Counts.tracers_in_masked_cells,displacements_rejected). The call line namesfindVoidsLightconeFromCartesianfor that function; <W> counts the tracers kept and inside the grid without a valid displacement."detailed": as"normal", with one line per step of the search in the order it runs, each with its time: the mean particle separation and its source, the grid, its cell side and the box it covers, the smoothing sigma, the basins found by the watershed.
Each line is printed as soon as its step finishes. A call that raises leaves the lines of the steps it finished, and never prints its call line. Every count printed can be read from the object returned (
Result.counts,BasinCatalog.n_basins); step times and descriptive values (mps, cell side, box, sigma) appear only in the lines. Times have two decimals.
- bitvf.AngleUnit: TypeAlias = Literal['deg', 'rad']¶
The unit of right ascension and declination, degrees or radians.
- bitvf.RedshiftCutArg: TypeAlias = Union[otswap.RedshiftCut, tuple[float, float]]¶
A closed range of observed redshift, an
otswap.RedshiftCutor a(min, max)pair.
- bitvf.Box: TypeAlias = Union[otswap.BoxLimits, tuple[ArrayLike, ArrayLike]]¶
Box limits, an
otswap.BoxLimitsor a pair of corners ((x0, y0, z0), (x1, y1, z1)), in coordinate units. Each bound must be finite, with each lower bound below the upper one. Closed: a point on a face is inside.
bitvf.io¶
The columns and keywords of each file are on the Lightcone file formats and Box file formats pages.
Writers¶
- class bitvf.io.Product(*args, **kwds)¶
The products, each with its file-name stem.
- DIVERGENCE = 2¶
Stem
divergence.
- GALAXIES = 3¶
Stem
galaxies.
- OVERDENSE = 1¶
Stem
overdense_basins.
- VOIDS = 0¶
Stem
voids.
- bitvf.io.Path: TypeAlias = Union[str, os.PathLike[str]]¶
A file name or location, a
stror anos.PathLike.
- bitvf.io.file_name(product: Product, directory: Path, name: str, *, zspace: bool) str¶
The conventional name of the file of a product.
<directory>/<stem>_[zspace_]<name>, with the stem of the product. A/is added only whendirectoryis not empty and does not end in one; an empty directory gives<stem>_[zspace_]<name>.- Parameters:
product (Product) – The product, which sets the stem.
directory (str or os.PathLike) – The folder of the file; empty for none.
name (str) – The rest of the name; its extension sets the format.
zspace (bool) – True only for the redshift-space pass of a run with correction, whose files then do not collide with those of the real-space pass.
- Returns:
str
- Raises:
Error – If
nameis empty, or an argument is not of its type.
- bitvf.io.write_voids(file: Path, result: bitvf.Result) None¶
Write the voids, one row per void (
Result.voids).Columns: index (K); in a lightcone centreRA and centreDec, in degrees, and centreRed; centreX, centreY, centreZ; radius, radiusExt; deltaAv; delta2Mps; edgeFlag (J; 0 none, 1 extended basin only, 2 core); contamination; nTracers (K). A field result has no deltaAv, delta2Mps and nTracers, and has fieldCentre after contamination. Keywords as in the module description, the row count NBASINS. ASCII: 9 significant digits.
- bitvf.io.write_overdense(file: Path, result: bitvf.Result) None¶
Write the overdense basins, one row per basin (
Result.overdense), with the columns, keywords and errors ofwrite_voids.- Parameters:
file (str or os.PathLike) – The file to write; its extension sets the format.
result (bitvf.Result) – A box or lightcone result.
- bitvf.io.write_divergence(file: Path, result: bitvf.Result) None¶
Write the divergence grid, one row per cell (
Result.divergence).Columns: index (K); cellX, cellY, cellZ, the cell centre; in a lightcone cellRA, cellDec (degrees), cellRed, cellDist (the distance of the centre), cellRAMin, cellRAMax, cellDecMin, cellDecMax (degrees), cellDistMin and cellDistMax, which describe the cells and are not read back as the grid; divergence, before smoothing; divergenceSmoothed, only with sigma > 0 (
DivergenceGrid.divergence_smoothed); volume, in coordinate units cubed; weight; weightSmoothed, only with sigma > 0 (DivergenceGrid.weight_smoothed); nDispl (K), the displacement ends counted; nTracers (K); voidIndex (K); overdenseIndex (K); in a lightcone masked (J), 1 on an unobserved pixel. Rows in the order of the cells, in a box cell (i, j, k) row (i * ny + j) * nz + k. A field result has no nDispl and nTracers. ASCII: 17 significant digits.Keywords as in the module description, the row count NCELLS, followed by the record of the grid: LOWERX, LOWERY, LOWERZ, UPPERX, UPPERY, UPPERZ, CELLSIDE, in coordinate units, and NCELLX, NCELLY, NCELLZ. With MPS and CELLSIZE they hold every field that defines the cells, so the grid read back by
read_divergenceis the same bit for bit, and the file can be searched again with another smoothing (find_voids_box_from_divergence,find_voids_box_from_field).A lightcone file has, after the common keywords, the record of the grid: DISTMIN, DISTMAX, in coordinate units, and RAMIN, RAMAX, DECMIN, DECMAX, in degrees, with CELLSIZE. The mps(z) profile follows in a second table, HDU MPSPROF in FITS and the twin file
<stem>.mps.<ext>in ASCII (otswap.io.twin_file), with columns redshift, MPS and nTracers (J), 17 digits, and keywords PRODUCT (divergence mps profile), BITVFV, ZMIN, ZMAX and MPSREPR. It holds no GEOMETRY.- Parameters:
file (str or os.PathLike) – The file to write; its extension sets the format.
result (bitvf.Result) – A box or lightcone result of a search with
Config.keep_divergence.
- Raises:
Error – If the result holds no divergence grid.
Error – If the grid fails the checks of a grid to reuse, the message starting with
"writeDivergence: cannot write the divergence: "; or if the result is malformed, the message starting with"writeDivergence: ".Error – If the file cannot be written: the message starts with
"otswap: ".
- bitvf.io.write_galaxies(file: Path, result: bitvf.Result) None¶
Write where each tracer ended up, one row per input tracer, in input order (
Result.assignment).Columns: id (K),
Result.ids; cellIndex (K); voidIndex (K); overdenseIndex (K); distance, from the centre of the tracer’s basin, NaN for a tracer in no basin; inMask (J), only for a lightcone; inCut (J), only in a lightcone with a boundedResult.redshift_cut; inBox (J), only whenResult.limitsis set; used (J), except afterfind_voids_box_from_divergence; uncorrected (J), outsideGrid (J) and outsideCut (J), only when those flags are filled. Keywords as in the module description, the row count NOBJECTS. ASCII: 9 significant digits.- Parameters:
file (str or os.PathLike) – The file to write; its extension sets the format.
result (bitvf.Result) – A box or lightcone result of a search with
Config.keep_assignment.
- Raises:
Readers¶
- bitvf.io.read_divergence(file: Path, *, angle_unit: str | None = None) bitvf.DivergenceGrid¶
Read a divergence file written by
write_divergence.Every field the writer wrote is read back bit for bit, in both formats: the cells (
lower,upper,cell_size,n_cells_axis,n_cells,mps,cell_size_mps), the box limits,n_realizations,n_realizations_meanand every per-cell column,divergence_smoothedandweight_smoothedwhen the file has them. The grid passes the checks of a grid to reuse, so it can be passed tofind_voids_boxasgrid, or searched again withfind_voids_box_from_divergence.A lightcone file gives a lightcone grid: the record that defines the cells (distance, right-ascension and declination limits, cell size), the mps(z) profile of its second part, and the per-cell columns, with
masked. The file holds angles in degrees; the grid reports them inangle_unit, equal to the grid that was written up to the rounding of the right-ascension and declination limits, so that a tracer within rounding of such an edge can change cell. It can be passed tofind_voids_lightconeasgrid; the library has no search of a lightcone from a divergence file.- Parameters:
file (str or os.PathLike) – A divergence file, ASCII or FITS.
angle_unit ({“deg”, “rad”}, optional) – The unit of a lightcone grid’s angles: required for a lightcone file, an error for a box file, which holds no angles.
- Returns:
DivergenceGrid
- Raises:
Error – If
angle_unitis neither"deg"nor"rad".Error – If
angle_unitis given for a box file, or missing for a lightcone file.Error – If the file cannot be read, or lacks a column: the message starts with
"otswap: ".Error – If it has no PRODUCT keyword, its PRODUCT is not divergence, or GEOMETRY is not box or lightcone; if a keyword of the other geometry is present; if a keyword of the grid record is missing, not a number, or not a whole number in range; if NREC or NRECMEAN is 0 or missing (a field result’s file: read it with
read_field); if BOXLIM holds anything but 1, or BOXLIM and the six box keywords do not come together.Error – If the rows are not NCELLS, index is not 0 to NCELLS - 1 in order, a count is negative, a basin index is below -1, or (lightcone) masked is not 0 or 1: the message names the data row, counted from 1 among the data rows (comment and blank lines do not count), as “data row k (from 1)”. If the grid fails the checks of a grid to reuse.
- bitvf.io.read_field(file: Path, *, centres: Sequence[str], value: str, weight: str | None = None, delimiter: str = ' ', comment: str = '#') Field¶
Read a field at cell centres from a table, for
find_voids_box_from_field, in the order of the rows.The columns are read as
otswap.io.readreads them: in FITS by name, from the table of HDU 2; in ASCII by name, from the last line starting with###before the data, or by 0-based index given as digits alone. Every value read must be finite;find_voids_box_from_fieldchecks the rest. A bitvf divergence file is valid input:f = bitvf.io.read_field("divergence.fits", centres=["cellX", "cellY", "cellZ"], value="divergence", weight="weight")
- Parameters:
file (str or os.PathLike) – The table, ASCII or FITS.
centres (sequence of three str) – The columns of x, y and z of the centres.
value (str) – The column of the field.
weight (str, optional) – The column of the weights; if omitted,
Field.weightsis None.delimiter (str, optional) – One character, the separator of the columns of an ASCII file; ignored for FITS.
comment (str, optional) – One character, the one that starts a comment line of an ASCII file; ignored for FITS.
- Returns:
Field
- Raises:
Error – If
centresis not three column names, ordelimiterorcommentis not a single character.Error – If the file cannot be read, a column is missing or named twice: the message starts with
"otswap: ".Error – If a value read is not finite: the message names the file, the data row, from 1, and the column as selected.
- class bitvf.io.Field¶
A field at the centres of cells, for
find_voids_box_from_field. Read-only.- property centres: numpy.typing.NDArray[numpy.float64]¶
The centre of each cell, in coordinate units, shape (n, 3).
- property values: numpy.typing.NDArray[numpy.float64]¶
The field at each centre, shape (n,).
- property weights: numpy.typing.NDArray[numpy.float64] | None¶
The weight of each cell, shape (n,); None when no weight column was named, so that it passes straight to
weights=.