Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output Struct Overhaul #445

Open
wants to merge 15 commits into
base: v4-prep
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ ignore =
N815
# Docstring in imperative mood. This should *not* be the case for @property's, but can't ignore them atm.
D401
# Module shadowing a builtin
A005
max-line-length = 88
max-complexity = 70
docstring-convention=numpy
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test_build_macos.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
env:
PYTHON: ${{ matrix.python-version }}
CC: gcc
name: Testing
name: Test MacOS Build
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -46,7 +46,6 @@ jobs:
uses: conda-incubator/setup-miniconda@v3
with:
# auto-update-conda: true
mamba-version: "*"
channels: conda-forge,defaults
python-version: ${{ matrix.python-version }}
environment-file: ci/macos-latest-env.yml
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/test_suite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ jobs:
uses: conda-incubator/setup-miniconda@v3
with:
# auto-update-conda: true
mamba-version: "*"
channels: conda-forge,defaults
python-version: ${{ matrix.python-version }}
environment-file: ci/${{ matrix.os }}-env.yml
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/test_suite_nointegration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
PYTHON: ${{ matrix.python-version }}
OS: ${{ matrix.os }}
CC: gcc
name: Testing
name: Sans Integration Tests
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
Expand All @@ -45,7 +45,6 @@ jobs:
uses: conda-incubator/setup-miniconda@v3
with:
# auto-update-conda: true
mamba-version: "*"
channels: conda-forge,defaults
python-version: ${{ matrix.python-version }}
environment-file: ci/${{ matrix.os }}-env.yml
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __getattr__(cls, name):
out = subprocess.run(["python", "setup.py", "--version"], capture_output=True)

try:
from py21cmfast import cache_tools
from py21cmfast.io import cache_tools
except ImportError:
raise

Expand Down
42 changes: 17 additions & 25 deletions docs/faqs/misc.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,14 @@ To make the current configuration permanent, simply use the ``write`` method::
>>> p21.config['direc'] = 'my_own_cache'
>>> p21.config.write()

Global Parameters
-----------------
There are a bunch of "global" parameters that are used throughout the C code. These are
parameters that are deemed to be constant enough to not expose them through the
regularly-used input structs, but nevertheless may necessitate modification from
time-to-time. These are accessed through the ``global_params`` object::

>>> from py21cmfast import global_params

Help on the attributes can be obtained via ``help(global_params)`` or
`in the docs <../reference/_autosummary/py21cmfast.inputs.html>`_. Setting the
attributes (which affects them everywhere throughout the code) is as simple as, eg::

>>> global_params.Z_HEAT_MAX = 30.0

If you wish to use a certain parameter for a fixed portion of your code (eg. for a single
run), it is encouraged to use the context manager, eg.::

>>> with global_params.use(Z_HEAT_MAX=10):
>>> run_lightcone(...)

How can I read a Coeval object from disk?
-----------------------------------------

The simplest way to read a :class:`py21cmfast.outputs.Coeval` object that has been
written to disk is by doing::

import py21cmfast as p21c
coeval = p21c.Coeval.read("my_coeval.h5")
coeval = p21c.Coeval.from_file("my_coeval.h5")

However, you may want to read parts of the data, or read the data using a different
language or environment. You can do this as long as you have the HDF5 library (i.e.
Expand All @@ -84,9 +63,6 @@ structure of the file yourself interactively. But here is an example using h5py:
# the CosmoParams, FlagOptions and AstroParams are accessed the same way.
print(dict(fl['user_params'].attrs))

# print a dict of all globals used for the coeval
print(dict(fl['_globals'].attrs))

# Get the redshift and random seed of the coeval box
redshift = fl.attrs['redshift']
seed = fl.attrs['random_seed']
Expand Down Expand Up @@ -122,3 +98,19 @@ while the globally averaged quantities are in the ``global_quantities`` group::
redshifts = fl['node_redshifts']

plt.plot(redshifts, global_Tb)

Can I instantiate my own OutputStruct objects?
-------------------------------------------
Usually, you create instances of an :class:`py21cmfast.wrapper.outputs.OutputStruct`
object by running either :func:`py21cmfast.run_coeval` or some lower-level function,
like :func:`py21cmfast.compute_initial_conditions`. However, it's possible you want to
switch out a simulation step from ``21cmFAST`` and insert your own, but then go on using
that box in further ``21cmFAST`` simulation components. The way to do this is as follows,
using the ``InitialConditions`` as an example::

ics = p21c.InitialConditions.new(inputs=p21c.InputParameters())
ics.set('lowres_density', my_computed_value)

You would use this ``.set()`` method on each of the fields you needed to set. Now this
data should be properly shared with the backend C-code, and the object can be used
in subsequent steps within ``21cmFAST``.
Loading
Loading