diff --git a/.gitignore b/.gitignore index c52ee4e..957f3fa 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,5 @@ notebooks/cmb/ .pytest_cache/ tests/__pycache__/ docs/build/ +docs/source/_build/ +docs/source/_static/ diff --git a/docs/source/conf.py b/docs/source/conf.py index 6317ffa..74807a3 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -7,33 +7,26 @@ # https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information import os import sys -import toml module_path = os.path.abspath(os.path.join('..','..','sbm')) -print("module_path: ", module_path) sys.path.insert(0, module_path) -pyproject_path = os.path.abspath(os.path.join('..','..','pyproject.toml')) - -with open(pyproject_path, 'r') as f: - pyproject_data = toml.load(f) project = 'sbm' copyright = '2024, Yusuke Takase' author = "Yusuke Takase" -release = pyproject_data['tool']['poetry']['version'] # -- General configuration --------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration -templates_path = ['_templates'] + extensions = [ 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', 'sphinx.ext.napoleon', 'sphinx.ext.intersphinx', - 'sphinx.ext.autosectionlabel', 'nbsphinx', + 'sphinx.ext.autosectionlabel', 'pydata_sphinx_theme' ] @@ -42,9 +35,9 @@ autosectionlabel_prefix_document = True autoclass_content = "class" +templates_path = ['_templates'] exclude_patterns = [] - # -- Options for HTML output ------------------------------------------------- # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output diff --git a/docs/source/generate_rst.py b/docs/source/generate_rst.py new file mode 100644 index 0000000..a2761e1 --- /dev/null +++ b/docs/source/generate_rst.py @@ -0,0 +1,117 @@ +import sbm +import inspect +import os + +def escape_underscores(name): + return name.replace('_', '\\_') + +def is_special_method(name): + return name.startswith('__') and name.endswith('__') + +def get_classes_and_methods(module): + classes = inspect.getmembers(module, inspect.isclass) + for class_name, class_obj in classes: + escaped_class_name = escape_underscores(class_name) + class_filename = f"sbm.{class_name}.rst" + with open(class_filename, 'w') as class_file: + class_file.write(f"sbm.{escaped_class_name}\n") + class_file.write("=" * len(f"sbm.{escaped_class_name}") + "\n\n") + class_file.write(f".. currentmodule:: sbm\n\n") + class_file.write(f".. autoclass:: {class_name}\n\n") + class_file.write(f" .. automethod:: __init__\n\n") + class_file.write(f" .. rubric:: Methods\n\n") + class_file.write(f" .. autosummary::\n\n") + + methods = inspect.getmembers(class_obj, inspect.isfunction) + for method_name, method_obj in methods: + if is_special_method(method_name): + continue + escaped_method_name = escape_underscores(method_name) + class_file.write(f" ~{class_name}.{method_name}\n") + method_filename = f"sbm.{class_name}.{method_name}.rst" + with open(method_filename, 'w') as method_file: + method_file.write(f"sbm.{escaped_class_name}.{escaped_method_name}\n") + method_file.write("=" * len(f"sbm.{escaped_class_name}.{escaped_method_name}") + "\n\n") + method_file.write(f".. currentmodule:: sbm\n\n") + method_file.write(f".. automethod:: {class_name}.{method_name}\n") + +def get_functions(module): + functions = inspect.getmembers(module, inspect.isfunction) + for function_name, function_obj in functions: + if is_special_method(function_name): + continue + escaped_function_name = escape_underscores(function_name) + function_filename = f"sbm.{function_name}.rst" + with open(function_filename, 'w') as function_file: + function_file.write(f"sbm.{escaped_function_name}\n") + function_file.write("=" * len(f"sbm.{escaped_function_name}") + "\n\n") + function_file.write(f".. currentmodule:: sbm\n\n") + function_file.write(f".. autofunction:: {function_name}\n") + +def generate_reference_rst(module, output_file): + with open(output_file, 'w') as f: + f.write("API Reference\n") + f.write("=============\n\n") + + # Main functions + f.write("Main functions\n") + f.write("--------------\n\n") + f.write(".. toctree::\n") + f.write(".. autosummary::\n") + f.write(" :toctree: generated/\n\n") + + functions = inspect.getmembers(module, inspect.isfunction) + for function_name, function_obj in functions: + if not is_special_method(function_name): + f.write(f" sbm.{function_name}\n") + f.write("\n") + + # Classes + f.write("Classes\n") + f.write("-------\n\n") + f.write(".. toctree::\n") + f.write(" :maxdepth: 2\n\n") + f.write(".. autosummary::\n") + f.write(" :toctree: generated/\n\n") + + classes = inspect.getmembers(module, inspect.isclass) + for class_name, class_obj in classes: + f.write(f" sbm.{class_name}\n") + f.write("\n") + + # Methods + f.write("Methods\n") + f.write("-------\n\n") + f.write(".. toctree::\n") + f.write(" :maxdepth: 2\n\n") + f.write(".. autosummary::\n") + f.write(" :toctree: generated/\n") + f.write(" :recursive:\n\n") + + for class_name, class_obj in classes: + methods = inspect.getmembers(class_obj, inspect.isfunction) + for method_name, method_obj in methods: + if not is_special_method(method_name): + f.write(f" sbm.{class_name}.{method_name}\n") + f.write("\n") + +if __name__ == "__main__": + # Create output directory if it doesn't exist + output_dir = "generated" + if not os.path.exists(output_dir): + os.makedirs(output_dir) + + output_file = "reference.rst" + generate_reference_rst(sbm, output_file) + print(f"{output_file} has been generated successfully.") + + os.chdir(output_dir) + + print("Generating documentation files for sbm module...") + + get_classes_and_methods(sbm) + get_functions(sbm) + + + + print("Documentation files generated successfully.") diff --git a/docs/source/generated/sbm.Configlation.rst b/docs/source/generated/sbm.Configlation.rst new file mode 100644 index 0000000..6803dc4 --- /dev/null +++ b/docs/source/generated/sbm.Configlation.rst @@ -0,0 +1,18 @@ +sbm.Configlation +================ + +.. currentmodule:: sbm + +.. autoclass:: Configlation + + + .. automethod:: __init__ + + + .. rubric:: Methods + + .. autosummary:: + + ~Configlation.__init__ + + \ No newline at end of file diff --git a/docs/source/generated/sbm.Field.conj.rst b/docs/source/generated/sbm.Field.conj.rst new file mode 100644 index 0000000..6869fba --- /dev/null +++ b/docs/source/generated/sbm.Field.conj.rst @@ -0,0 +1,6 @@ +sbm.Field.conj +============== + +.. currentmodule:: sbm + +.. automethod:: Field.conj \ No newline at end of file diff --git a/docs/source/generated/sbm.Field.rst b/docs/source/generated/sbm.Field.rst new file mode 100644 index 0000000..be4695e --- /dev/null +++ b/docs/source/generated/sbm.Field.rst @@ -0,0 +1,19 @@ +sbm.Field +========= + +.. currentmodule:: sbm + +.. autoclass:: Field + + + .. automethod:: __init__ + + + .. rubric:: Methods + + .. autosummary:: + + ~Field.__init__ + ~Field.conj + + \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.create_covmat.rst b/docs/source/generated/sbm.ScanFields.create_covmat.rst new file mode 100644 index 0000000..5948e4a --- /dev/null +++ b/docs/source/generated/sbm.ScanFields.create_covmat.rst @@ -0,0 +1,6 @@ +sbm.ScanFields.create\_covmat +============================= + +.. currentmodule:: sbm + +.. automethod:: ScanFields.create_covmat \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.generate_noise.rst b/docs/source/generated/sbm.ScanFields.generate_noise.rst new file mode 100644 index 0000000..d0c4270 --- /dev/null +++ b/docs/source/generated/sbm.ScanFields.generate_noise.rst @@ -0,0 +1,6 @@ +sbm.ScanFields.generate\_noise +============================== + +.. currentmodule:: sbm + +.. automethod:: ScanFields.generate_noise \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.generate_noise_pdf.rst b/docs/source/generated/sbm.ScanFields.generate_noise_pdf.rst new file mode 100644 index 0000000..fc43ccb --- /dev/null +++ b/docs/source/generated/sbm.ScanFields.generate_noise_pdf.rst @@ -0,0 +1,6 @@ +sbm.ScanFields.generate\_noise\_pdf +=================================== + +.. currentmodule:: sbm + +.. automethod:: ScanFields.generate_noise_pdf \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.get_xlink.rst b/docs/source/generated/sbm.ScanFields.get_xlink.rst index 4e884ab..1f9e7d9 100644 --- a/docs/source/generated/sbm.ScanFields.get_xlink.rst +++ b/docs/source/generated/sbm.ScanFields.get_xlink.rst @@ -1,6 +1,6 @@ -sbm.ScanFields.get_xlink -====================== +sbm.ScanFields.get\_xlink +========================= .. currentmodule:: sbm -.. automethod:: ScanFields.get_xlink +.. automethod:: ScanFields.get_xlink \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.initialize.rst b/docs/source/generated/sbm.ScanFields.initialize.rst new file mode 100644 index 0000000..202b401 --- /dev/null +++ b/docs/source/generated/sbm.ScanFields.initialize.rst @@ -0,0 +1,6 @@ +sbm.ScanFields.initialize +========================= + +.. currentmodule:: sbm + +.. automethod:: ScanFields.initialize \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.map_make.rst b/docs/source/generated/sbm.ScanFields.map_make.rst new file mode 100644 index 0000000..8b90cc4 --- /dev/null +++ b/docs/source/generated/sbm.ScanFields.map_make.rst @@ -0,0 +1,6 @@ +sbm.ScanFields.map\_make +======================== + +.. currentmodule:: sbm + +.. automethod:: ScanFields.map_make \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.rst b/docs/source/generated/sbm.ScanFields.rst index a6e4626..3c0a6e2 100644 --- a/docs/source/generated/sbm.ScanFields.rst +++ b/docs/source/generated/sbm.ScanFields.rst @@ -1,17 +1,28 @@ -sbm.ScanFields -================= +sbm.ScanFields +============== .. currentmodule:: sbm .. autoclass:: ScanFields - + .. automethod:: __init__ - + .. rubric:: Methods .. autosummary:: - + ~ScanFields.__init__ + ~ScanFields.create_covmat + ~ScanFields.generate_noise + ~ScanFields.generate_noise_pdf ~ScanFields.get_xlink + ~ScanFields.initialize + ~ScanFields.load_channel + ~ScanFields.load_det + ~ScanFields.load_full_FPU + ~ScanFields.map_make + ~ScanFields.t2b + + \ No newline at end of file diff --git a/docs/source/generated/sbm.ScanFields.t2b.rst b/docs/source/generated/sbm.ScanFields.t2b.rst new file mode 100644 index 0000000..a792aa8 --- /dev/null +++ b/docs/source/generated/sbm.ScanFields.t2b.rst @@ -0,0 +1,6 @@ +sbm.ScanFields.t2b +================== + +.. currentmodule:: sbm + +.. automethod:: ScanFields.t2b \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.abs_pointing_field.rst b/docs/source/generated/sbm.SignalFields.abs_pointing_field.rst new file mode 100644 index 0000000..e8665b7 --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.abs_pointing_field.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.abs\_pointing\_field +===================================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.abs_pointing_field \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.build_linear_system.rst b/docs/source/generated/sbm.SignalFields.build_linear_system.rst new file mode 100644 index 0000000..447c406 --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.build_linear_system.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.build\_linear\_system +====================================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.build_linear_system \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.diff_gain_field.rst b/docs/source/generated/sbm.SignalFields.diff_gain_field.rst new file mode 100644 index 0000000..d7c0175 --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.diff_gain_field.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.diff\_gain\_field +================================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.diff_gain_field \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.diff_pointing_field.rst b/docs/source/generated/sbm.SignalFields.diff_pointing_field.rst new file mode 100644 index 0000000..1278442 --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.diff_pointing_field.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.diff\_pointing\_field +====================================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.diff_pointing_field \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.get_coupled_field.rst b/docs/source/generated/sbm.SignalFields.get_coupled_field.rst new file mode 100644 index 0000000..9cda92d --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.get_coupled_field.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.get\_coupled\_field +==================================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.get_coupled_field \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.get_field.rst b/docs/source/generated/sbm.SignalFields.get_field.rst new file mode 100644 index 0000000..0ef8605 --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.get_field.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.get\_field +=========================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.get_field \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.hwp_ip_field.rst b/docs/source/generated/sbm.SignalFields.hwp_ip_field.rst new file mode 100644 index 0000000..597a90d --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.hwp_ip_field.rst @@ -0,0 +1,6 @@ +sbm.SignalFields.hwp\_ip\_field +=============================== + +.. currentmodule:: sbm + +.. automethod:: SignalFields.hwp_ip_field \ No newline at end of file diff --git a/docs/source/generated/sbm.SignalFields.rst b/docs/source/generated/sbm.SignalFields.rst new file mode 100644 index 0000000..170b208 --- /dev/null +++ b/docs/source/generated/sbm.SignalFields.rst @@ -0,0 +1,25 @@ +sbm.SignalFields +================ + +.. currentmodule:: sbm + +.. autoclass:: SignalFields + + + .. automethod:: __init__ + + + .. rubric:: Methods + + .. autosummary:: + + ~SignalFields.__init__ + ~SignalFields.abs_pointing_field + ~SignalFields.build_linear_system + ~SignalFields.diff_gain_field + ~SignalFields.diff_pointing_field + ~SignalFields.get_coupled_field + ~SignalFields.get_field + ~SignalFields.hwp_ip_field + + \ No newline at end of file diff --git a/docs/source/generated/sbm.Systematics.rst b/docs/source/generated/sbm.Systematics.rst new file mode 100644 index 0000000..8c6019b --- /dev/null +++ b/docs/source/generated/sbm.Systematics.rst @@ -0,0 +1,18 @@ +sbm.Systematics +=============== + +.. currentmodule:: sbm + +.. autoclass:: Systematics + + + .. automethod:: __init__ + + + .. rubric:: Methods + + .. autosummary:: + + ~Systematics.__init__ + + \ No newline at end of file diff --git a/docs/source/generated/sbm.c2d.rst b/docs/source/generated/sbm.c2d.rst new file mode 100644 index 0000000..5f8b539 --- /dev/null +++ b/docs/source/generated/sbm.c2d.rst @@ -0,0 +1,6 @@ +sbm.c2d +======= + +.. currentmodule:: sbm + +.. autofunction:: c2d \ No newline at end of file diff --git a/docs/source/generated/sbm.d2c.rst b/docs/source/generated/sbm.d2c.rst new file mode 100644 index 0000000..efd9200 --- /dev/null +++ b/docs/source/generated/sbm.d2c.rst @@ -0,0 +1,6 @@ +sbm.d2c +======= + +.. currentmodule:: sbm + +.. autofunction:: d2c \ No newline at end of file diff --git a/docs/source/generated/sbm.forecast.rst b/docs/source/generated/sbm.forecast.rst new file mode 100644 index 0000000..5d3f00f --- /dev/null +++ b/docs/source/generated/sbm.forecast.rst @@ -0,0 +1,6 @@ +sbm.forecast +============ + +.. currentmodule:: sbm + +.. autofunction:: forecast \ No newline at end of file diff --git a/docs/source/generated/sbm.generate_cmb.rst b/docs/source/generated/sbm.generate_cmb.rst new file mode 100644 index 0000000..9304096 --- /dev/null +++ b/docs/source/generated/sbm.generate_cmb.rst @@ -0,0 +1,6 @@ +sbm.generate\_cmb +================= + +.. currentmodule:: sbm + +.. autofunction:: generate_cmb \ No newline at end of file diff --git a/docs/source/generated/sbm.generate_maps.rst b/docs/source/generated/sbm.generate_maps.rst new file mode 100644 index 0000000..8258593 --- /dev/null +++ b/docs/source/generated/sbm.generate_maps.rst @@ -0,0 +1,6 @@ +sbm.generate\_maps +================== + +.. currentmodule:: sbm + +.. autofunction:: generate_maps \ No newline at end of file diff --git a/docs/source/generated/sbm.get_cmap.rst b/docs/source/generated/sbm.get_cmap.rst new file mode 100644 index 0000000..cb038af --- /dev/null +++ b/docs/source/generated/sbm.get_cmap.rst @@ -0,0 +1,6 @@ +sbm.get\_cmap +============= + +.. currentmodule:: sbm + +.. autofunction:: get_cmap \ No newline at end of file diff --git a/docs/source/generated/sbm.get_instrument_table.rst b/docs/source/generated/sbm.get_instrument_table.rst new file mode 100644 index 0000000..d00cd0a --- /dev/null +++ b/docs/source/generated/sbm.get_instrument_table.rst @@ -0,0 +1,6 @@ +sbm.get\_instrument\_table +========================== + +.. currentmodule:: sbm + +.. autofunction:: get_instrument_table \ No newline at end of file diff --git a/docs/source/generated/sbm.load_fiducial_cl.rst b/docs/source/generated/sbm.load_fiducial_cl.rst new file mode 100644 index 0000000..60bfdd9 --- /dev/null +++ b/docs/source/generated/sbm.load_fiducial_cl.rst @@ -0,0 +1,6 @@ +sbm.load\_fiducial\_cl +====================== + +.. currentmodule:: sbm + +.. autofunction:: load_fiducial_cl \ No newline at end of file diff --git a/docs/source/generated/sbm.sim_diff_gain_per_ch.rst b/docs/source/generated/sbm.sim_diff_gain_per_ch.rst index 9d15339..6a2f081 100644 --- a/docs/source/generated/sbm.sim_diff_gain_per_ch.rst +++ b/docs/source/generated/sbm.sim_diff_gain_per_ch.rst @@ -1,6 +1,6 @@ -sbm.sim_diff_gain_per_ch -====================== +sbm.sim\_diff\_gain\_per\_ch +============================ .. currentmodule:: sbm -.. automethod:: sim_diff_gain_per_ch +.. autofunction:: sim_diff_gain_per_ch \ No newline at end of file diff --git a/docs/source/generated/sbm.sim_diff_pointing_per_ch.rst b/docs/source/generated/sbm.sim_diff_pointing_per_ch.rst new file mode 100644 index 0000000..8c5a7cc --- /dev/null +++ b/docs/source/generated/sbm.sim_diff_pointing_per_ch.rst @@ -0,0 +1,6 @@ +sbm.sim\_diff\_pointing\_per\_ch +================================ + +.. currentmodule:: sbm + +.. autofunction:: sim_diff_pointing_per_ch \ No newline at end of file diff --git a/docs/source/generated/sbm.sim_noise_per_ch.rst b/docs/source/generated/sbm.sim_noise_per_ch.rst new file mode 100644 index 0000000..973cc54 --- /dev/null +++ b/docs/source/generated/sbm.sim_noise_per_ch.rst @@ -0,0 +1,6 @@ +sbm.sim\_noise\_per\_ch +======================= + +.. currentmodule:: sbm + +.. autofunction:: sim_noise_per_ch \ No newline at end of file diff --git a/docs/source/index.rst b/docs/source/index.rst index cf0d19a..64e4915 100644 --- a/docs/source/index.rst +++ b/docs/source/index.rst @@ -10,6 +10,7 @@ Welcome to sbm's documentation! :maxdepth: 1 :caption: Contents: + installation reference diff --git a/docs/source/reference.rst b/docs/source/reference.rst index abffaec..a05d9ea 100644 --- a/docs/source/reference.rst +++ b/docs/source/reference.rst @@ -8,7 +8,17 @@ Main functions .. autosummary:: :toctree: generated/ + sbm.c2d + sbm.d2c + sbm.forecast + sbm.generate_cmb + sbm.generate_maps + sbm.get_cmap + sbm.get_instrument_table + sbm.load_fiducial_cl sbm.sim_diff_gain_per_ch + sbm.sim_diff_pointing_per_ch + sbm.sim_noise_per_ch Classes ------- @@ -19,10 +29,11 @@ Classes .. autosummary:: :toctree: generated/ + sbm.Configlation + sbm.Field sbm.ScanFields - - - + sbm.SignalFields + sbm.Systematics Methods ------- @@ -34,4 +45,19 @@ Methods :toctree: generated/ :recursive: + sbm.Field.conj + sbm.ScanFields.create_covmat + sbm.ScanFields.generate_noise + sbm.ScanFields.generate_noise_pdf sbm.ScanFields.get_xlink + sbm.ScanFields.initialize + sbm.ScanFields.map_make + sbm.ScanFields.t2b + sbm.SignalFields.abs_pointing_field + sbm.SignalFields.build_linear_system + sbm.SignalFields.diff_gain_field + sbm.SignalFields.diff_pointing_field + sbm.SignalFields.get_coupled_field + sbm.SignalFields.get_field + sbm.SignalFields.hwp_ip_field + diff --git a/sbm/install_db.py b/sbm/install_db.py index 843fd35..19ac2f4 100644 --- a/sbm/install_db.py +++ b/sbm/install_db.py @@ -1,18 +1,14 @@ #!/usr/bin/env python3 # -*- encoding: utf-8 -*- -from base64 import b64decode -import getpass from pathlib import Path from time import sleep -from github import Github from rich import print from rich.table import Table import tomlkit import os import json import numpy as np -import toml from .scan_fields import ScanFields CONFIG_PATH = Path.home() / ".config" / "sbm_dataset" diff --git a/sbm/pipelines.py b/sbm/pipelines.py index c996e82..2192197 100644 --- a/sbm/pipelines.py +++ b/sbm/pipelines.py @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + import litebird_sim as lbs import numpy as np from multiprocessing import Pool @@ -13,19 +15,22 @@ RESET = '\033[0m' class Configlation: - """ Configuration class for the simulation - - imo (str): imo instance given by the litebird_sim - channel (str): The name of the channel - lbs_base_path (str): The base path of the litebird_sim - imo_version (str): The version of the imo - nside (int): The nside of the healpix map - mdim (int): The dimension to perform the map-making - parallel (bool): If True, the simulation is performed in thread parallel - xlink_threshold (float): The threshold of the cross-linking. - The pixel with the value less than this threshold is ignored when - the map-making is performed. - only_iqu (bool): If True, only I, Q, and U are returned after the map-making + """Configuration class for the simulation. + + Args: + imo (str): imo instance given by the litebird_sim + channel (str): The name of the channel + + Attributes: + lbs_base_path (str): The base path of the litebird_sim + imo_version (str): The version of the imo + nside (int): The nside of the healpix map + mdim (int): The dimension to perform the map-making + parallel (bool): If True, the simulation is performed in thread parallel + xlink_threshold (float): The threshold of the cross-linking. + The pixel with the value less than this threshold is ignored when + the map-making is performed. + only_iqu (bool): If True, only I, Q, and U are returned after the map-making """ def __init__(self, imo, channel): self.imo = imo @@ -40,16 +45,17 @@ def __init__(self, imo, channel): self.use_hwp = None class Systematics: - """ Systematics class for the simulation - - sigma_gain_T (float): The standard deviation of the gain for the top detectors - sigma_gain_B (float): The standard deviation of the gain for the bottom detectors - sigma_rho_T (float): The standard deviation of the pointing for the top detectors - sigma_rho_B (float): The standard deviation of the pointing for the bottom detectors - sigma_chi_T (float): The standard deviation of the polarization angle for the top detectors - sigma_chi_B (float): The standard deviation of the polarization angle for the bottom detectors - syst_seed (int): The seed for the random number generator for the systematics - noise_seed (int): The seed for the random number generator for the noise + """Systematics class for the simulation + + Attributes: + sigma_gain_T (float): The standard deviation of the gain for the top detectors + sigma_gain_B (float): The standard deviation of the gain for the bottom detectors + sigma_rho_T (float): The standard deviation of the pointing for the top detectors + sigma_rho_B (float): The standard deviation of the pointing for the bottom detectors + sigma_chi_T (float): The standard deviation of the polarization angle for the top detectors + sigma_chi_B (float): The standard deviation of the polarization angle for the bottom detectors + syst_seed (int): The seed for the random number generator for the systematics + noise_seed (int): The seed for the random number generator for the noise """ def __init__(self): self.sigma_gain_T = None @@ -93,12 +99,12 @@ def process_pointing(args): def generate_maps(mbs, config, lock=True): - """ Generate the maps with the lock file + """Generate the maps with the lock file Args: mbs (lbs.Mbs): The litebird_sim object - config (Configlation): The configuration class + lock (bool): If True, the lock file is used """ if lock: lockfile = '/tmp/sbm_lockfile' @@ -132,7 +138,7 @@ def sim_diff_gain_per_ch( syst: Systematics, mbsparams: lbs.MbsParameters, ): - """ Simulate the differential gain systematics for each channel + """Simulate the differential gain systematics for each channel The map-making is performed for each detector in the channel Args: @@ -224,7 +230,7 @@ def sim_diff_pointing_per_ch( syst: Systematics, mbsparams: lbs.MbsParameters, ): - """ Simulate the differential pointing systematics for each channel + """Simulate the differential pointing systematics for each channel The map-making is performed for each detector in the channel Args: diff --git a/sbm/scan_fields.py b/sbm/scan_fields.py index 45ba5c1..cb8f529 100755 --- a/sbm/scan_fields.py +++ b/sbm/scan_fields.py @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + import h5py import numpy as np import healpy as hp @@ -83,9 +85,9 @@ def load_det(cls, det_name: str, base_path=DB_ROOT_PATH): """ Load the scan fields data of a detector from a .h5 file Args: - filename (str): name of the *.h5 file containing the scan fields data simulated by Falcons.jl + filename (str): name of the \*.h5 file containing the scan fields data simulated by Falcons.jl - base_path (str): path to the directory containing the *.h5 file + base_path (str): path to the directory containing the \*.h5 file Returns: instance (ScanFields): instance of the ScanFields class containing @@ -118,10 +120,10 @@ def load_det(cls, det_name: str, base_path=DB_ROOT_PATH): @classmethod def load_channel(cls, channel: str, base_path=DB_ROOT_PATH): - """ Load the scan fields data of a channel from the directory containing the *.h5 files + """ Load the scan fields data of a channel from the directory containing the \*.h5 files Args: - base_path (str): path to the directory containing the *.h5 files + base_path (str): path to the directory containing the \*.h5 files channel (str): name of the channel to load the scan fields data from @@ -159,7 +161,7 @@ def _load_channel_task(cls, args): @classmethod def load_full_FPU(cls, channel_list: list, base_path=DB_ROOT_PATH, max_workers=None): """ Load the scan fields data of all the channels in the FPU from - the directory containing the *.h5 files + the directory containing the \*.h5 files Args: base_path (str): path to the directory containing the channel's data @@ -219,7 +221,7 @@ def __add__(self, other): return result def initialize(self, mdim): - """ Initialize the scan fields data """ + """Initialize the scan fields data """ self.hitmap = np.zeros_like(self.hitmap) self.h = np.zeros_like(self.h) self.nside = hp.npix2nside(len(self.hitmap)) @@ -229,15 +231,15 @@ def initialize(self, mdim): self.coupled_fields = np.zeros([self.mdim, self.npix], dtype=np.complex128) def get_xlink(self, spin_n, spin_m): - """ Get the cross-link of the detector for a given spin number + """Get the cross-link of the detector for a given spin number Args: spin_n (int): spin number for which the cross-link is to be obtained spin_m (int): spin number for which the cross-link is to be obtained - If `spin_n` and `spin_m` are 0, the cross-link for the spin number 0 is returned, i.e, - the map which has 1 in the real part and zero in the imaginary part. + If `spin_n` and `spin_m` are 0, the cross-link for the spin number 0 is returned, i.e, + the map which has 1 in the real part and zero in the imaginary part. Returns: xlink (1d-np.ndarray): cross-link of the detector for the given spin numbers @@ -291,18 +293,18 @@ def map_make( only_iqu=True ): """ Get the output map by solving the linear equation Ax=b - This operation gives us an equivalent result of the simple binning map-making aproach + This operation gives us an equivalent result of the simple binning map-making aproach. Args: signal_fields (SignalFields): signal fields data of the detector only_iqu (bool): if True, return only I, Q, U map + If only_iqu is True, the output map has [3, `npix`] shape. + If only_iqu is False, the output map has [len(signal_fields.spin_n_basis), `npix`] shape. + Returns: - if only_iqu == True: - output_map (np.ndarray, [3, `npix`]) - if only_iqu == False: - output_map (np.ndarray, [len(signal_fields.spin_n_basis), `npix`]) + output_map (np.ndarray, [3, `npix`]) """ assert signal_fields.coupled_fields is not None, "No coupled field in the SignalFields.coupled_fields" if np.all(signal_fields.spins_m == 0): diff --git a/sbm/signal_fields.py b/sbm/signal_fields.py index d9e901a..8e64e50 100644 --- a/sbm/signal_fields.py +++ b/sbm/signal_fields.py @@ -1,15 +1,7 @@ -import h5py +# -*- encoding: utf-8 -*- + import numpy as np -import healpy as hp -import os import copy -import matplotlib.pyplot as plt -from multiprocessing import Pool -import pandas as pd -import litebird_sim as lbs -from litebird_sim import Imo -from pathlib import Path -import toml class Field: """ Class to store the field data of detectors """ diff --git a/sbm/tools.py b/sbm/tools.py index 62f9818..3ab7b02 100644 --- a/sbm/tools.py +++ b/sbm/tools.py @@ -1,4 +1,5 @@ -import os +# -*- encoding: utf-8 -*- + from pathlib import Path import numpy as np import pandas as pd diff --git a/sbm/version.py b/sbm/version.py index 89a92c6..a8645f3 100644 --- a/sbm/version.py +++ b/sbm/version.py @@ -1,12 +1,4 @@ # -*- encoding: utf-8 -*- -import toml -import os -import sys -pyproject_path = os.path.abspath(os.path.join('..',"sbm",'pyproject.toml')) - -with open(pyproject_path, 'r') as f: - pyproject_data = toml.load(f) - -__version__ = pyproject_data['tool']['poetry']['version'] -__author__ = pyproject_data['tool']['poetry']['authors'] +__version__ = "0.3.0" +__author__ = "Yusuke Takase"