diff --git a/doc/conf.py b/doc/conf.py index 691a432619d5acd255324a30e337f7c4d6305f59..782acf1a7f8bfe4d20b40195a07d40da623ca294 100644 --- a/doc/conf.py +++ b/doc/conf.py @@ -21,11 +21,11 @@ from pkg_resources import get_distribution # -- Project information ----------------------------------------------------- -version = get_distribution('km3irf').version -short_version = '.'.join(version.split('.')[:2]) -project = 'km3irf {}'.format(short_version) -copyright = '{0}, Tamas Gal'.format(date.today().year) -author = 'Tamas Gal' +version = get_distribution("km3irf").version +short_version = ".".join(version.split(".")[:2]) +project = "km3irf {}".format(short_version) +copyright = "{0}, Tamas Gal".format(date.today().year) +author = "Tamas Gal" # -- General configuration --------------------------------------------------- @@ -33,32 +33,34 @@ author = 'Tamas Gal' # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom # ones. extensions = [ - 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinx.ext.viewcode', - 'autoapi.extension', 'numpydoc', - 'sphinx_gallery.gen_gallery' + "sphinx.ext.autodoc", + "sphinx.ext.autosummary", + "sphinx.ext.viewcode", + "autoapi.extension", + "numpydoc", + "sphinx_gallery.gen_gallery", ] # Add any paths that contain templates here, relative to this directory. -templates_path = ['_templates'] +templates_path = ["_templates"] # List of patterns, relative to source directory, that match files and # directories to ignore when looking for source files. # This pattern also affects html_static_path and html_extra_path. -exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store', 'version.py'] +exclude_patterns = ["_build", "Thumbs.db", ".DS_Store", "version.py"] # AutoAPI autoapi_type = "python" -autoapi_dirs = ['../src/km3irf'] +autoapi_dirs = ["../src/km3irf"] autoapi_options = ["members", "undoc-members", "show-module-summary"] autoapi_include_summaries = True # Gallery sphinx_gallery_conf = { - 'backreferences_dir': 'gen_modules', - 'default_thumb_file': '_static/default_gallery_thumbnail.png', - 'examples_dirs': '../examples', # path to your example scripts - 'gallery_dirs': - 'auto_examples', # path to where to save gallery generated output + "backreferences_dir": "gen_modules", + "default_thumb_file": "_static/default_gallery_thumbnail.png", + "examples_dirs": "../examples", # path to your example scripts + "gallery_dirs": "auto_examples", # path to where to save gallery generated output } # -- Options for HTML output ------------------------------------------------- @@ -66,11 +68,11 @@ sphinx_gallery_conf = { # The theme to use for HTML and HTML Help pages. See the documentation for # a list of builtin themes. # -html_theme = 'sphinx_rtd_theme' +html_theme = "sphinx_rtd_theme" html_theme_path = [sphinx_rtd_theme.get_html_theme_path()] # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, # so a file named "default.css" will overwrite the builtin "default.css". -html_static_path = ['_static'] +html_static_path = ["_static"] html_title = "km3irf {}".format(version) diff --git a/src/km3irf/__init__.py b/src/km3irf/__init__.py index ab1f2f1a3c4f9d51e0a02c0d7b388ac5ecee6fc0..bcb15951a0adbf12dc69d9944830cb2d52b54697 100644 --- a/src/km3irf/__init__.py +++ b/src/km3irf/__init__.py @@ -3,4 +3,5 @@ from pkg_resources import get_distribution, DistributionNotFound version = get_distribution(__name__).version from .calc import Calculator -# from .data import list_data \ No newline at end of file + +# from .data import list_data diff --git a/src/km3irf/utils.py b/src/km3irf/utils.py index 85bdeda8a018755747cd05d78aef4d00c8ae7cae..4279cea8063dae3a7e69ddf5850e667e9b8b3f0f 100644 --- a/src/km3irf/utils.py +++ b/src/km3irf/utils.py @@ -1,13 +1,15 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- +from cmath import inf from .calc import Calculator from astropy.io import fits -from os import path +from os import path, listdir from glob import glob from os.path import getsize from prettytable import PrettyTable from importlib_resources import files -data_dir = path.join(path.dirname(__file__), 'data') + +data_dir = path.join(path.dirname(__file__), "data") def print_multiplication_table(base): @@ -17,31 +19,41 @@ def print_multiplication_table(base): print("{} x {} = {}".format(base, i, calculator.multiply(base, i))) -def merge_fits(aeff_fits=path.join(data_dir, "aeff.fits"), - psf_fits=path.join(data_dir, "psf.fits"), - edisp_fits=path.join(data_dir, "edisp.fits"), - bkg_fits=path.join(data_dir, "bkg_nu.fits"), - output_file='all_in_one.fits'): - """Merge separated fits files into one, which can be used in gammapy""" +def merge_fits( + aeff_fits=path.join(data_dir, "aeff.fits"), + psf_fits=path.join(data_dir, "psf.fits"), + edisp_fits=path.join(data_dir, "edisp.fits"), + bkg_fits=path.join(data_dir, "bkg_nu.fits"), + output_file="all_in_one.fits", +): + """ + Merge separated fits files into one, which can be used in gammapy + + aeff_fits: path to Aeff .fits file + psf_fits: path to PSF .fits file + edisp_fits: path to Edisp .fits file + bkg_fits: path to Background .fits file + output_file: name of the merged .fits file in data foledr of the package + """ hdu_list = [] hdu_list.append(fits.PrimaryHDU()) - file_aeff = fits.open(aeff_fits) + file_aeff = fits.open(aeff_fits) hdu_list.append(file_aeff[1]) - hdu_list[1].name = 'EFFECTIVE AREA' + hdu_list[1].name = "EFFECTIVE AREA" file_psf = fits.open(psf_fits) hdu_list.append(file_psf[1]) - hdu_list[2].name = 'POINT SPREAD FUNCTION' + hdu_list[2].name = "POINT SPREAD FUNCTION" file_edisp = fits.open(edisp_fits) hdu_list.append(file_edisp[1]) - hdu_list[3].name = 'ENERGY DISPERSION' + hdu_list[3].name = "ENERGY DISPERSION" file_bkg = fits.open(bkg_fits) hdu_list.append(file_bkg[1]) - hdu_list[4].name = 'BACKGROUND' - + hdu_list[4].name = "BACKGROUND" + new_fits_file = fits.HDUList(hdu_list) new_fits_file.writeto(path.join(data_dir, output_file), overwrite=True) @@ -50,16 +62,23 @@ def merge_fits(aeff_fits=path.join(data_dir, "aeff.fits"), file_edisp.close() file_bkg.close() -def list_data(): - """Prints the table with content of data folder""" - tab = PrettyTable(["File Path","Size, KB"], align="l") - # data_path = path.join(f"{files('km3irf')}","data","*.fits") - data_path = path.join(data_dir,"*.fits") - # for file in glob(f"{files('km3irf')}/data/*.fits", recursive=True): - for file in glob(data_path, recursive=True): - #add row with file name and size in KB - tab.add_row([file, round(getsize(filename=file)/float(1<<10), 2)]) - print(tab) +def list_data(print_tab=False): + """ + Return dictionary with names and pathes in the data folder + + print_tab: print a table with content, default False + """ + tab = PrettyTable(["File Path", "Size, KB"], align="l") + data_path = path.join(data_dir, "*.fits") + info = {} + + for file, i in zip(glob(data_path, recursive=True), listdir(data_dir)): + tab.add_row([file, round(getsize(filename=file) / float(1 << 10), 2)]) + info.update({i: file}) + + if print_tab: + print(tab) + + return info -# merge_fits() \ No newline at end of file diff --git a/tests/test_is_mandatory.py b/tests/test_is_mandatory.py index d0ff27466e13ac33b00af975f5f7a2bdfdff9ab2..25695ab0ff60d93ccdaba79606d70be64c475aa7 100644 --- a/tests/test_is_mandatory.py +++ b/tests/test_is_mandatory.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 + def test_is_mandatory(): assert 2 == 5 - 3