Skip to content

Commit

Permalink
add readthedocs documentation and sphinx builder
Browse files Browse the repository at this point in the history
  • Loading branch information
kartikmandar committed Nov 8, 2024
1 parent 861276f commit 401231c
Show file tree
Hide file tree
Showing 15 changed files with 324 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
__pycache__/
files/loaded-data/
.vscode/
docs/build/
19 changes: 19 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.11"

python:
install:
- requirements: docs/requirements.txt
- method: pip
path: .

sphinx:
configuration: docs/source/conf.py

formats:
- pdf
- epub
20 changes: 20 additions & 0 deletions docs/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)
35 changes: 35 additions & 0 deletions docs/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
4 changes: 4 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sphinx
sphinx-rtd-theme
sphinx-autodoc-typehints
stingray
21 changes: 21 additions & 0 deletions docs/source/DataLoading.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
DataLoading package
===================

Submodules
----------

DataLoading.DataIngestion module
--------------------------------

.. automodule:: modules.DataLoading.DataIngestion
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: modules.DataLoading
:members:
:undoc-members:
:show-inheritance:
21 changes: 21 additions & 0 deletions docs/source/Home.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Home package
============

Submodules
----------

Home.HomeContent module
-----------------------

.. automodule:: modules.Home.HomeContent
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: modules.Home
:members:
:undoc-members:
:show-inheritance:
69 changes: 69 additions & 0 deletions docs/source/QuickLook.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
QuickLook package
=================

Submodules
----------

QuickLook.AverageCrossSpectrum module
-------------------------------------

.. automodule:: modules.QuickLook.AverageCrossSpectrum
:members:
:undoc-members:
:show-inheritance:

QuickLook.AveragePowerSpectrum module
-------------------------------------

.. automodule:: modules.QuickLook.AveragePowerSpectrum
:members:
:undoc-members:
:show-inheritance:

QuickLook.Bispectrum module
---------------------------

.. automodule:: modules.QuickLook.Bispectrum
:members:
:undoc-members:
:show-inheritance:

QuickLook.CrossSpectrum module
------------------------------

.. automodule:: modules.QuickLook.CrossSpectrum
:members:
:undoc-members:
:show-inheritance:

QuickLook.LightCurve module
---------------------------

.. automodule:: modules.QuickLook.LightCurve
:members:
:undoc-members:
:show-inheritance:

QuickLook.PowerColors module
----------------------------

.. automodule:: modules.QuickLook.PowerColors
:members:
:undoc-members:
:show-inheritance:

QuickLook.PowerSpectrum module
------------------------------

.. automodule:: modules.QuickLook.PowerSpectrum
:members:
:undoc-members:
:show-inheritance:

Module contents
---------------

.. automodule:: modules.QuickLook
:members:
:undoc-members:
:show-inheritance:
39 changes: 39 additions & 0 deletions docs/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

import os
import sys
sys.path.insert(0, os.path.abspath('../../'))

project = 'Stingray Explorer'
copyright = '2024, Kartik Mandar'
author = 'Kartik Mandar'
release = '0.1'

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

extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon', # For Google-style docstrings
'sphinx.ext.viewcode', # Adds links to source code
'sphinx.ext.autosummary', # Generate summaries automatically
]
autosummary_generate = True # Enables automatic summary generation


templates_path = ['_templates']
exclude_patterns = []



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

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
28 changes: 28 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. StingrayExplorer documentation master file, created by
sphinx-quickstart on Fri Nov 8 15:00:39 2024.
You can adapt this file completely to your liking, but it should at least
contain the root `toctree` directive.
StingrayExplorer documentation
==============================

Add your content using ``reStructuredText`` syntax. See the
`reStructuredText <https://www.sphinx-doc.org/en/master/usage/restructuredtext/index.html>`_
documentation for details.


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

modules
DataLoading
Home
QuickLook

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

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`
6 changes: 6 additions & 0 deletions docs/source/modules.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
modules
=======

.. toctree::
:maxdepth: 4

Empty file added modules/DataLoading/__init__.py
Empty file.
Empty file added modules/Home/__init__.py
Empty file.
63 changes: 61 additions & 2 deletions modules/QuickLook/PowerSpectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
"#9edae5",
]

log_binned = False

# Create a warning handler
def create_warning_handler():
warning_handler = WarningHandler()
Expand Down Expand Up @@ -228,6 +230,62 @@ def create_holoviews_plots_no_colorbar(df, label, dt, norm, color_key=None):
else:
return plot

def create_rebinned_holoviews_plots(df, label, dt, norm, color_key=None, log_binned=False):
"""
Create a HoloViews plot for rebinned power spectrum data.
Parameters:
df (pd.DataFrame): DataFrame containing rebinned frequency and power values.
label (str): Label for the plot.
dt (float): Time binning parameter.
norm (str): Normalization parameter.
color_key (str, optional): Color key for the plot.
log_binned (bool): If True, applies a logarithmic scale to the x-axis.
Returns:
hv.Overlay or hv.DynamicMap: The generated HoloViews plot.
"""
# Create the initial plot from the DataFrame
plot = df.hvplot(x="Frequency", y="Power", shared_axes=False, label=label)

# Check if color_key is provided for individual plot colors
if color_key:
if rasterize_checkbox.value:
return hd.rasterize(
plot,
aggregator=hd.ds.mean("Power"),
color_key=color_key,
line_width=3,
pixel_ratio=2,
).opts(
tools=["hover"],
cmap=[color_key],
width=600,
height=600,
colorbar=True,
logx=log_binned # Apply log scale only if log_binned is True
)
else:
return plot.opts(logx=log_binned) # Apply log scale only if log_binned is True
else:
if rasterize_checkbox.value:
return hd.rasterize(
plot,
aggregator=hd.ds.mean("Power"),
line_width=3,
pixel_ratio=2,
).opts(
tools=["hover"],
width=600,
height=600,
cmap="Viridis",
colorbar=True,
logx=log_binned # Apply log scale only if log_binned is True
)
else:
return plot.opts(logx=log_binned) # Apply log scale only if log_binned is True


def create_dataframe_panes(df, title):
return pn.FlexBox(
pn.pane.Markdown(f"**{title}**"),
Expand Down Expand Up @@ -258,12 +316,13 @@ def create_dataframe(selected_event_list_index, dt, norm):

def rebin_powerspectrum(ps):
rebin_size = rebin_size_input.value

log_binned = False # Initialize flag for logarithmic rebinning
if linear_rebin_checkbox.value:
# Perform linear rebinning
rebinned_ps = ps.rebin(rebin_size, method="mean")
return rebinned_ps
elif log_rebin_checkbox.value:
log_binned = True # Set flag to indicate log rebinning
# Perform logarithmic rebinning
rebinned_ps = ps.rebin_log(f=rebin_size)
return rebinned_ps
Expand Down Expand Up @@ -347,7 +406,7 @@ def generate_powerspectrum(event=None):
"Power": rebinned_ps.power,
})
rebinned_label = f"Rebinned {event_list_name} (dt={dt}, norm={norm})"
rebinned_plot_hv = create_holoviews_plots(rebinned_df, rebinned_label, dt, norm)
rebinned_plot_hv = create_rebinned_holoviews_plots(rebinned_df, rebinned_label, dt, norm, log_binned=log_binned)

# Check if the user wants to plot rebin with the original
if rebin_with_original_checkbox.value:
Expand Down
Empty file added modules/QuickLook/__init__.py
Empty file.

0 comments on commit 401231c

Please sign in to comment.