Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
65 changes: 65 additions & 0 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: GitHub Pages

permissions:
contents: read
pages: write
id-token: write

on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
- cron: "0 0 * * 0"

jobs:
build:
runs-on: ubuntu-20.04
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: "3.11"

- uses: s-weigand/setup-conda@v1
with:
update-conda: true
python-version: "3.11"
conda-channels: anaconda, conda-forge

- name: Install dependencies
run: |
python -m pip install -r doc/pages_requirements.txt
python -m pip install .

- name: Build documentation
run: |
# cp examples/*.ipynb docs
cd doc
make clean
make html
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: 'doc/build/html'

deploy:
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
needs: build
steps:
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
*.pyc
*.egg-info
build/
build/
doc/build/
doc/source/api/
51 changes: 34 additions & 17 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,34 @@ Backend agnostic astropy-like cosmology
The primary intention for this package is for use with :code:`GWPopulation`
but the main functionality can be used externally.

Installation and contribution
-----------------------------

Currently installation is only available from source

.. code-block:: console

$ pip install git+https://github.com/ColmTalbot/wcosmo.git

for development you should follow a standard fork-and-pull workflow.

- First create a new fork at :code:`github.com/UserName/wcosmo`.
- Clone your fork

.. code-block:: console

$ git clone git@github.com:UserName/wcosmo.git

or use a GitHub codespace.
- Install the local version with

.. code-block:: console

$ python -m pip install .

- Make any desired edits and push to your fork.
- Open a pull request into :code:`git@github.com:ColmTalbot/wcosmo.git`.

Basic usage
-----------

Expand All @@ -14,21 +42,9 @@ To import an astropy-like cosmology (without units)
from wcosmo import FlatwCDM
cosmology = FlatwCDM(H0=70, Om0=0.3, w0=-1)

To use this in :code:`GWPopulation`

.. code-block:: python

import gwpopulation as gwpop
from wcosmo.models import CosmoModel, PowerLawRedshift

model = CosmoModel(
model_functions=[
gwpop.models.mass.two_component_primary_mass_ratio,
gwpop.models.spin.iid_spin,
PowerLawRedshift(cosmo_model="FlatwCDM"),
],
cosmo_model="FlatwCDM",
)
This code is automatically used in :code:`GWPopulation` when using either
:code:`gwpopulation.experimental.cosmo_models.CosmoModel` and/or
:code:`PowerLawRedshift`

Changing backend
----------------
Expand All @@ -47,6 +63,7 @@ Manual backend setting can be done as follows:
import jax.numpy as jnp
from jax.scipy.linalg.toeplitz import toeplitz

from wcosmo import wcosmo
from wcosmo import wcosmo, utils
wcosmo.xp = jnp
wcosmo.toeplitz = toeplitz
utils.xp = jnp
utils.toeplitz = toeplitz
20 changes: 20 additions & 0 deletions doc/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
8 changes: 8 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. currentmodule:: wcosmo

.. include:: ../README.rst

.. autosummary::

wcosmo.wcosmo
wcosmo.utils
35 changes: 35 additions & 0 deletions doc/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=source
set BUILDDIR=build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
9 changes: 9 additions & 0 deletions doc/pages_requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
ipython_genutils
jinja2
nbsphinx
numpydoc
pandoc
pygments
sphinx
sphinx_rtd_theme
sphinx-nefertiti
32 changes: 32 additions & 0 deletions doc/source/_templates/custom-class-template.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:members:
:show-inheritance:
:inherited-members:

{% block methods %}
.. automethod:: __init__

{% if methods %}
.. rubric:: Methods

.. autosummary::
{% for item in methods %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block attributes %}
{% if attributes %}
.. rubric:: Attributes

.. autosummary::
{% for item in attributes %}
~{{ name }}.{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
68 changes: 68 additions & 0 deletions doc/source/_templates/custom-module-template.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{{ fullname | escape | underline}}

.. currentmodule:: {{ fullname }}

.. automodule:: {{ fullname }}

{% block attributes %}
{% if attributes %}
.. rubric:: Module Attributes

.. autosummary::
:toctree:
{% for item in attributes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block functions %}
{% if functions %}
.. rubric:: {{ _('Functions') }}

.. autosummary::
:toctree:
{% for item in functions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block classes %}
{% if classes %}
.. rubric:: {{ _('Classes') }}

.. autosummary::
:toctree:
:template: custom-class-template.rst
{% for item in classes %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block exceptions %}
{% if exceptions %}
.. rubric:: {{ _('Exceptions') }}

.. autosummary::
:toctree:
{% for item in exceptions %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}

{% block modules %}
{% if modules %}
.. rubric:: Modules

.. autosummary::
:toctree:
:template: custom-module-template.rst
:recursive:
{% for item in modules %}
{{ item }}
{%- endfor %}
{% endif %}
{% endblock %}
39 changes: 39 additions & 0 deletions doc/source/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'wcosmo'
copyright = '2024, Colm Talbot, Amanda Farah'
author = 'Colm Talbot, Amanda Farah'
release = '0.0.0'

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.mathjax',
'sphinx.ext.githubpages',
'sphinx.ext.autosummary',
'numpydoc',
'nbsphinx',
'sphinx.ext.viewcode',
]

templates_path = ['_templates']
exclude_patterns = []

root_doc = 'index'


# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_nefertiti'
html_static_path = ['_static']

autosummary_generate = True
25 changes: 25 additions & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
.. currentmodule:: wcosmo

.. include:: ../../README.rst

.. toctree::
:maxdepth: 2
:caption: Contents:


.. autosummary::
:toctree: api
:template: custom-module-template.rst
:caption: API
:recursive:

wcosmo
utils


Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ packages = ["wcosmo"]

[project.entry-points."gwpopulation.xp"]
wcosmo = "wcosmo.wcosmo"
wcosmo-models = "wcosmo.models"
wcosmo-utils = "wcosmo.utils"

[project.entry-points."gwpopulation.other"]
wcosmo = "wcosmo.wcosmo:scipy.linalg.toeplitz"
wcosmo-utils = "wcosmo.utils:scipy.linalg.toeplitz"
Loading