Skip to content

Commit 737b770

Browse files
committed
Updates to documentation
1 parent eb7ec64 commit 737b770

File tree

11 files changed

+160
-53
lines changed

11 files changed

+160
-53
lines changed

docs/source/collection_ref.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Collections within a single file can always be loaded with :py:func:`opencosmo.o
88
:members:
99
:exclude-members: open,read,close,write
1010
:undoc-members:
11+
:member-order: bysource
1112

1213

1314
.. autoclass:: opencosmo.StructureCollection

docs/source/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# -- General configuration ---------------------------------------------------
1515
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
1616

17-
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_rtd_theme"]
17+
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_rtd_theme", "sphinxcontrib.autodoc_pydantic"]
1818

1919
templates_path = ["_templates"]
2020
exclude_patterns = []

docs/source/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ The OpenCosmo Python Toolkit provides utilities for reading, writing and manipul
3939
io_ref
4040
dataset_ref
4141
collection_ref
42+
parameters_ref
4243

4344

docs/source/parameters_ref.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Simulation Parameters
2+
=====================
3+
4+
You can access the parameters of the simulation any dataset is drawn from with :py:attr:`opencosmo.Dataset.simulation`. All datasets regardless of simulation will have the parameters in :py:class:`opencosmo.parameters.SimulationParameters`. Hydrodynamic simulations will additionally contain the parameters in :py:class:`opencosmo.parameters.SubgridParameters`
5+
6+
7+
.. autoclass:: opencosmo.parameters.SimulationParameters
8+
:members:
9+
:undoc-members:
10+
:exclude-members: model_config,empty_string_to_none,cosmology_parameters
11+
:member-order: bysource
12+
13+
14+
.. autoclass:: opencosmo.parameters.HydroSimulationParameters
15+
:members:
16+
:undoc-members:
17+
:exclude-members: model_config
18+
:member-order: bysource
19+
20+
.. autoclass:: opencosmo.parameters.SubgridParameters
21+
:members:
22+
:undoc-members:
23+
:exclude-members: model_config
24+
:member-order: bysource

opencosmo/collection/collection.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ def cosmology(self) -> dict[str, Cosmology]:
183183
"""
184184
Get the cosmologies of the simulations in the collection
185185
186-
Returns:
186+
Returns
187187
--------
188188
cosmologies: dict[str, astropy.cosmology.Cosmology]
189189
"""
@@ -194,7 +194,7 @@ def redshift(self) -> dict[str, float]:
194194
"""
195195
Get the redshift slices for the simulations in the collection
196196
197-
Returns:
197+
Returns
198198
--------
199199
redshifts: dict[str, float]
200200
"""
@@ -205,7 +205,7 @@ def simulation(self) -> dict[str, SimulationParameters]:
205205
"""
206206
Get the simulation parameters for the simulations in the collection
207207
208-
Returns:
208+
Returns
209209
--------
210210
simulation_parameters: dict[str, opencosmo.parameters.SimulationParameters]
211211
"""
@@ -254,6 +254,27 @@ def select(self, *args, **kwargs) -> SimulationCollection:
254254
"""
255255
return self.__map("select", *args, **kwargs)
256256

257+
def take(self, n: int, at: str = "random") -> SimulationCollection:
258+
"""
259+
Take a subest of rows from all datasets or collections in this collection.
260+
This method will delegate to the underlying method in
261+
:class:`opencosmo.Dataset`, or :class:`opencosmo.StructureCollection` depending
262+
on the context. As such, behavior may vary depending on what this collection
263+
contains. See their documentation for more info.
264+
265+
Parameters
266+
----------
267+
n: int
268+
The number of rows to take
269+
at: str, default = "random"
270+
The method to use to take rows. Must be one of "start", "end", "random".
271+
272+
"""
273+
if any(len(ds) < n for ds in self.values()):
274+
raise ValueError(f"Not all datasets in this collection have at least {n} rows!")
275+
return self.__map("take", n, at)
276+
277+
257278
def with_units(self, convention: str) -> SimulationCollection:
258279
"""
259280
Transform all datasets or collections to use the given unit convention. This
@@ -268,15 +289,6 @@ def with_units(self, convention: str) -> SimulationCollection:
268289
"""
269290
return self.__map("with_units", convention)
270291

271-
def take(self, *args, **kwargs) -> SimulationCollection:
272-
"""
273-
Take a subest of rows from all datasets or collections in this collection.
274-
This method will delegate to the underlying method in
275-
:class:`opencosmo.Dataset`, or :class:`opencosmo.Collection` depending on the
276-
context. As such, behaviormay vary depending on what this collection contains.
277-
"""
278-
279-
return self.__map("take", *args, **kwargs)
280292

281293

282294
def open_single_dataset(

opencosmo/dataset/dataset.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -73,32 +73,21 @@ def cosmology(self) -> Cosmology:
7373
return self.__header.cosmology
7474

7575
@property
76-
def dtype(self) -> str:
76+
def redshift(self) -> float:
7777
"""
78-
Get the data type of this dataset
78+
The redshift slice this dataset was drawn from
7979
8080
Returns
8181
-------
82-
dtype: str
83-
"""
84-
return self.__header.file.data_type
85-
86-
@property
87-
def redshift(self) -> float:
88-
"""
89-
Get the redshift slice this dataset was drawn from
90-
91-
Returns:
92-
--------
93-
redshift: gloat
82+
redshift: float
9483
9584
"""
9685
return self.__header.file.redshift
9786

9887
@property
9988
def simulation(self) -> SimulationParameters:
10089
"""
101-
Get the parameters of the simulation this dataset is drawn
90+
The parameters of the simulation this dataset is drawn
10291
from.
10392
10493
Returns

opencosmo/link/collection.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def __repr__(self):
5959
dtype_str = ", ".join(self.__handlers.keys())
6060
return f"Collection of {structure_type} with linked datasets {dtype_str}"
6161

62+
def __len__(self):
63+
return len(self.__properties)
64+
6265
@classmethod
6366
def open(
6467
cls, file: File, datasets_to_get: Optional[Iterable[str]] = None

opencosmo/parameters/simulation.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ def empty_string_to_none(v):
8080

8181
class SimulationParameters(BaseModel):
8282
box_size: float = Field(ge=0, description="Size of the simulation box (Mpc/h)")
83-
z_ini: float = Field(ge=0.01, description="Initial redshift")
84-
z_end: float = Field(ge=0.0, description="Final redshift")
83+
z_ini: float = Field(ge=0.01, description="Initial redshift of the simulation")
84+
z_end: float = Field(ge=0.0, description="Final redshift of the simulation")
8585
n_gravity: Optional[int] = Field(
86-
ge=2, description="Number of gravity-only particles (per dimension)"
86+
ge=2,
87+
description=
88+
"Number of gravity-only particles (per dimension). "
89+
"In hydrodynamic simulations, this parameter will be replaced with \"n_dm\""
8790
)
8891
n_steps: int = Field(ge=1, description="Number of time steps")
89-
pm_grid: int = Field(ge=2, description="Grid resolution (per dimension)")
92+
pm_grid: int = Field(ge=2, description="Number of grid points (per dimension)")
9093
offset_gravity_ini: Optional[float] = Field(
9194
description="Lagrangian offset for gravity-only particles"
9295
)
@@ -104,6 +107,11 @@ def empty_string_to_none(cls, data):
104107

105108
@cached_property
106109
def step_zs(self) -> list[float]:
110+
"""
111+
Get the redshift of the steps in this simulation. Outputs such that
112+
redshift[step_number] returns the redshift for that step. Keep in
113+
mind that steps go from high z -> low z.
114+
"""
107115
a_ini = 1 / (1 + self.z_ini)
108116
a_end = 1 / (1 + self.z_end)
109117
# Steps are evenly spaced in log(a)
@@ -123,9 +131,9 @@ class SubgridParameters(BaseModel):
123131
agn_kinetic_eps: float = Field(description="AGN feedback efficiency")
124132
agn_kinetic_jet_vel: float = Field(description="AGN feedback velocity")
125133
agn_nperh: float = Field(description="AGN sphere of influence")
126-
agn_seed_mass: float = Field(description="AGN seed mass")
134+
agn_seed_mass: float = Field(description="AGN seed mass (Msun / h)")
127135
wind_egy_w: float = Field(description="Wind mass loading factor")
128-
wind_kappa_w: float = Field(description="Wind belovity")
136+
wind_kappa_w: float = Field(description="Wind velocity")
129137

130138

131139
class HydroSimulationParameters(SimulationParameters):
@@ -142,6 +150,6 @@ class HydroSimulationParameters(SimulationParameters):
142150
description="Lagrangian offset for dark matter particles"
143151
)
144152
subgrid_parameters: SubgridParameters = Field(
145-
description="Parameters for subgrid physics",
153+
description="Parameters for subgrid hydrodynamic physics",
146154
exclude=True,
147155
)

poetry.lock

Lines changed: 69 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ optional = true
3131
[tool.poetry.group.docs.dependencies]
3232
sphinx = "^8.1.3"
3333
sphinx-rtd-theme = "^3.0.2"
34+
autodoc-pydantic = "^2.2.0"
3435

3536

3637
[tool.poetry.group.mpi]

0 commit comments

Comments
 (0)