From 4af3ead2c15ec81a4a3f6df8956a3369927f004e Mon Sep 17 00:00:00 2001 From: Lexy Andati Date: Wed, 14 Sep 2022 21:55:00 +0200 Subject: [PATCH 1/3] Update readme Add long and short versions of parameters Dump output to current dir unless otherwise through output prefix Bump version --- HISTORY.rst | 8 +++++++- README.rst | 15 +++++++++------ smops/__init__.py | 2 +- smops/smooth.py | 47 ++++++++++++++++++++++++----------------------- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/HISTORY.rst b/HISTORY.rst index 63e63b2..54106e0 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -2,7 +2,13 @@ History ======= -0.1.0 (2022-09-12) +0.1.2 (2022-09-14) ------------------ +* Change name from smops to sade +* Added `output-prefix` argument +* Removed `output-dir` argument + +0.1.0 (2022-09-12) +------------------ * First release on PyPI. diff --git a/README.rst b/README.rst index 338600a..bb4035e 100644 --- a/README.rst +++ b/README.rst @@ -7,7 +7,7 @@ smops :target: https://pypi.python.org/pypi/smops -smops - (aka Smooth Operator) is a python package for interpolating channelised FITS model images over larger user-specified frequency channesl. i.e if you give smops 4 channel model fits images, it will return 16 model images. For example: +smops (aka Smooth Operator) is a python package for interpolating channelised FITS model images onto user-specified higher resolution frequency grid. For example, you can give smops a set of 4 per-subband model FITS images, and ask it to return 16 model images, which can then be fed back into e.g. wsclean_ for a predict operation. Usage: .. code-block:: bash @@ -18,20 +18,22 @@ Its options are: .. code-block:: python - usage: smops [-h] [-od] [-nthreads] [-stokes] [-mem] --ms -ip -co [-order] + usage: smops [-h] [-v] [-op] [-j] [-s] [-mem] -ms -ip -co [-order] Refine model images in frequency optional arguments: -h, --help show this help message and exit - -od , --output-dir Where to put the output files. - -nthreads Number of threads to use while writing out images - -stokes Which stokes model to extrapolate. Write as single string e.g IQUV. Required when there are multiple Stokes + -v, --version show program's version number and exit + -op , --output-prefix + What to prefix the new interpolated model name with. + -j , --num-threads Number of threads to use while writing out output images + -s , --stokes Which stokes model to extrapolate. Write as single string e.g IQUV. Required when there are multiple Stokes images in a directory. Default 'I'. -mem , --max-mem Approximate memory cap in GB Required arguments: - --ms Input MS. Used for getting reference frequency + -ms , --ms Input MS. Used for getting reference frequency -ip , --input-prefix The input image prefix. The same as the one used for wsclean -co , --channels-out @@ -58,3 +60,4 @@ It was created with Cookiecutter_ and the `audreyr/cookiecutter-pypackage`_ proj .. _`@o-smirnov`: https://github.com/o-smirnov .. _`@landmanbester`: https://github.com/landmanbester .. _`@ratt-ru`: https://github.com/ratt-ru +.. _wsclean: https://gitlab.com/aroffringa/wsclean \ No newline at end of file diff --git a/smops/__init__.py b/smops/__init__.py index 70e4100..604ee99 100644 --- a/smops/__init__.py +++ b/smops/__init__.py @@ -2,4 +2,4 @@ __author__ = AUTHOR = """L Andati""" __email__ = EMAIL = 'landati@duck.com' -__version__ = VERSION = '0.1.1' +__version__ = VERSION = '0.1.2' diff --git a/smops/smooth.py b/smops/smooth.py index f3f0bad..565daa7 100644 --- a/smops/smooth.py +++ b/smops/smooth.py @@ -23,7 +23,7 @@ GB = 2**30 MAX_MEM = None -def configure_logger(out_dir): +def configure_logger(out_dir="."): formatter = logging.Formatter( datefmt='%H:%M:%S %d.%m.%Y', fmt="%(asctime)s : %(name)s - %(levelname)s - %(message)s") @@ -32,7 +32,7 @@ def configure_logger(out_dir): os.makedirs(out_dir) l_handler = logging.FileHandler( - os.path.join(out_dir, "smooth-operator.log"), mode="w") + os.path.join(out_dir, "sade.log"), mode="w") l_handler.setLevel(logging.INFO) l_handler.setFormatter(formatter) @@ -51,22 +51,24 @@ def configure_logger(out_dir): def get_arguments(): parser = argparse.ArgumentParser(description="Refine model images in frequency") parser.add_argument("-v", "--version", action='version', version=f'%(prog)s {VERSION}') - parser.add_argument("-od", "--output-dir", dest="output_dir", - default="smooth-ops", metavar="", - help="Where to put the output files.") - parser.add_argument("-nthreads", dest="nthreads", default=10, metavar="", - type=int, help="Number of threads to use while writing out images") - parser.add_argument("-stokes", dest="stokes", + # parser.add_argument("-od", "--output-dir", dest="output_dir", + # default="sade-output", metavar="", + # help="Where to put the output files.") + parser.add_argument("-op", "--output-prefix", dest="output_pref", + default="sade-interp-model", metavar="", + help="What to prefix the new interpolated model name with.") + parser.add_argument("-j", "--num-threads", dest="nthreads", default=10, metavar="", + type=int, help="Number of threads to use while writing out output images") + parser.add_argument("-s", "--stokes", dest="stokes", default="I", metavar="", type=str, help="""Which stokes model to extrapolate. Write as single string e.g IQUV. Required when there are multiple Stokes images in a directory. Default 'I'.""") parser.add_argument("-mem", "--max-mem", dest="max_mem", default=None, type=int, metavar="", - help="Approximate memory cap in GB" - ) + help="Approximate memory cap in GB") reqs = parser.add_argument_group("Required arguments") - reqs.add_argument("--ms", dest="ms_name", required=True, metavar="", + reqs.add_argument("-ms", "--ms", dest="ms_name", required=True, metavar="", help="Input MS. Used for getting reference frequency") reqs.add_argument("-ip", "--input-prefix", dest="input_prefix", required=True, metavar="", @@ -304,7 +306,7 @@ def gen_fits_file_from_template(template_fits, center_freq, cdelt, new_data, out return -def write_model_out(chan_num, chan_id, temp_fname, output_dir, cdelt, models, freqs): +def write_model_out(chan_num, chan_id, temp_fname, out_pref, cdelt, models, freqs): """ Write the new models output @@ -319,8 +321,8 @@ def write_model_out(chan_num, chan_id, temp_fname, output_dir, cdelt, models, fr naming purposes. temp_fname: str Name of the template file that will be used - output_dir: str - Where the output will be dumped + out_pref: str + Prefix of the output models cdelt: float Channel width for this channel models: n-d array @@ -332,9 +334,7 @@ def write_model_out(chan_num, chan_id, temp_fname, output_dir, cdelt, models, fr """ # snitch.info(f"Channel number: {chan_num}, id: {chan_id}") - outname = os.path.basename(temp_fname) - outname = re.sub(r"-(\d){4}-", "-"+f"{chan_id}".zfill(4)+"-", outname) - outname = os.path.join(output_dir, outname) + outname = out_pref + '-' + f"{chan_id}".zfill(4) + "-model.fits" gen_fits_file_from_template( temp_fname, freqs[chan_id], cdelt, models[chan_num], outname) @@ -344,9 +344,12 @@ def main(): args = get_arguments().parse_args() global snitch, MAX_MEM - output_dir = args.output_dir + # output_dir = args.output_dir + # if not os.path.isdir(output_dir): + # snitch.info(f"Creating output directory: {output_dir}") + # os.makedirs(output_dir) - snitch = configure_logger(output_dir) + snitch = configure_logger() if args.max_mem is not None: MAX_MEM = args.max_mem @@ -355,9 +358,7 @@ def main(): snitch.info(f"Setting memory cap to: {MAX_MEM} GB") - if not os.path.isdir(output_dir): - snitch.info(f"Creating output directory: {output_dir}") - os.makedirs(output_dir) + ref_freq = get_ms_ref_freq(args.ms_name) @@ -426,7 +427,7 @@ def main(): with ThreadPoolExecutor(args.nthreads) as executor: results = executor.map( partial(write_model_out, temp_fname=images_list[0], - output_dir=output_dir, cdelt=new_cdelt, + out_pref=args.output_pref, cdelt=new_cdelt, models=data, freqs=out_freqs), chan_range, chan_ids) From 9497888951df1fb369c7bab8c392a77fe65395a3 Mon Sep 17 00:00:00 2001 From: Lexy Andati Date: Wed, 14 Sep 2022 22:01:16 +0200 Subject: [PATCH 2/3] Migrating to sade --- .github/ISSUE_TEMPLATE.md | 2 +- .github/workflows/test.yml | 4 ++-- CONTRIBUTING.rst | 24 ++++++++++++------------ Makefile | 8 ++++---- README.rst | 12 ++++++------ {smops => sade}/__init__.py | 2 +- {smops => sade}/smooth.py | 2 +- setup.cfg | 8 ++++---- setup.py | 4 ++-- tox.ini | 2 +- 10 files changed, 34 insertions(+), 34 deletions(-) rename {smops => sade}/__init__.py (75%) rename {smops => sade}/smooth.py (99%) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 7061eca..400ce6d 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -1,4 +1,4 @@ -* smops version: +* sade version: * Python version: * Operating System: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2d273d5..0db6362 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,8 +20,8 @@ jobs: python-vresion: ${{ matrix.python-version }} - name: Display Python version run: python -c "import sys; print(sys.version)" - - name: Install smops + - name: Install sade run: | python -m pip install --upgrade pip pip install . - smops -v \ No newline at end of file + sade -v \ No newline at end of file diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst index c0c3b9b..b89d6d9 100644 --- a/CONTRIBUTING.rst +++ b/CONTRIBUTING.rst @@ -15,7 +15,7 @@ Types of Contributions Report Bugs ~~~~~~~~~~~ -Report bugs at https://github.com/mulan-94/smops/issues. +Report bugs at https://github.com/mulan-94/sade/issues. If you are reporting a bug, please include: @@ -38,14 +38,14 @@ and "help wanted" is open to whoever wants to implement it. Write Documentation ~~~~~~~~~~~~~~~~~~~ -smops could always use more documentation, whether as part of the -official smops docs, in docstrings, or even on the web in blog posts, +sade could always use more documentation, whether as part of the +official sade docs, in docstrings, or even on the web in blog posts, articles, and such. Submit Feedback ~~~~~~~~~~~~~~~ -The best way to send feedback is to file an issue at https://github.com/mulan-94/smops/issues. +The best way to send feedback is to file an issue at https://github.com/mulan-94/sade/issues. If you are proposing a feature: @@ -57,17 +57,17 @@ If you are proposing a feature: Get Started! ------------ -Ready to contribute? Here's how to set up `smops` for local development. +Ready to contribute? Here's how to set up `sade` for local development. -1. Fork the `smops` repo on GitHub. +1. Fork the `sade` repo on GitHub. 2. Clone your fork locally:: - $ git clone git@github.com:your_name_here/smops.git + $ git clone git@github.com:your_name_here/sade.git 3. Install your local copy into a virtualenv. Assuming you have virtualenvwrapper installed, this is how you set up your fork for local development:: - $ mkvirtualenv smops - $ cd smops/ + $ mkvirtualenv sade + $ cd sade/ $ python setup.py develop 4. Create a branch for local development:: @@ -79,7 +79,7 @@ Ready to contribute? Here's how to set up `smops` for local development. 5. When you're done making changes, check that your changes pass flake8 and the tests, including testing other Python versions with tox:: - $ flake8 smops tests + $ flake8 sade tests $ python setup.py test or pytest $ tox @@ -103,7 +103,7 @@ Before you submit a pull request, check that it meets these guidelines: your new functionality into a function with a docstring, and add the feature to the list in README.rst. 3. The pull request should work for Python 3.5, 3.6, 3.7 and 3.8, and for PyPy. Check - https://travis-ci.com/mulan-94/smops/pull_requests + https://travis-ci.com/mulan-94/sade/pull_requests and make sure that the tests pass for all supported Python versions. Tips @@ -111,7 +111,7 @@ Tips To run a subset of tests:: -$ pytest tests.test_smops +$ pytest tests.test_sade Deploying diff --git a/Makefile b/Makefile index 342085a..bfaffd0 100644 --- a/Makefile +++ b/Makefile @@ -48,7 +48,7 @@ clean-test: ## remove test and coverage artifacts rm -fr .pytest_cache lint/flake8: ## check style with flake8 - flake8 smops tests + flake8 sade tests lint: lint/flake8 ## check style @@ -59,15 +59,15 @@ test-all: ## run tests on every Python version with tox tox coverage: ## check code coverage quickly with the default Python - coverage run --source smops -m pytest + coverage run --source sade -m pytest coverage report -m coverage html $(BROWSER) htmlcov/index.html docs: ## generate Sphinx HTML documentation, including API docs - rm -f docs/smops.rst + rm -f docs/sade.rst rm -f docs/modules.rst - sphinx-apidoc -o docs/ smops + sphinx-apidoc -o docs/ sade $(MAKE) -C docs clean $(MAKE) -C docs html $(BROWSER) docs/_build/html/index.html diff --git a/README.rst b/README.rst index bb4035e..aa40c81 100644 --- a/README.rst +++ b/README.rst @@ -1,24 +1,24 @@ ===== -smops +sade ===== -.. image:: https://img.shields.io/pypi/v/smops.svg - :target: https://pypi.python.org/pypi/smops +.. image:: https://img.shields.io/pypi/v/sade.svg + :target: https://pypi.python.org/pypi/sade -smops (aka Smooth Operator) is a python package for interpolating channelised FITS model images onto user-specified higher resolution frequency grid. For example, you can give smops a set of 4 per-subband model FITS images, and ask it to return 16 model images, which can then be fed back into e.g. wsclean_ for a predict operation. Usage: +sade (aka Smooth Operator) is a python package for interpolating channelised FITS model images onto user-specified higher resolution frequency grid. For example, you can give sade a set of 4 per-subband model FITS images, and ask it to return 16 model images, which can then be fed back into e.g. wsclean_ for a predict operation. Usage: .. code-block:: bash - smops --ms /ms/used/togen/images.ms -ip prefix-used-for-those-images -co 16 -order 4 + sade --ms /ms/used/togen/images.ms -ip prefix-used-for-those-images -co 16 -order 4 Its options are: .. code-block:: python - usage: smops [-h] [-v] [-op] [-j] [-s] [-mem] -ms -ip -co [-order] + usage: sade [-h] [-v] [-op] [-j] [-s] [-mem] -ms -ip -co [-order] Refine model images in frequency diff --git a/smops/__init__.py b/sade/__init__.py similarity index 75% rename from smops/__init__.py rename to sade/__init__.py index 604ee99..8962c62 100644 --- a/smops/__init__.py +++ b/sade/__init__.py @@ -1,4 +1,4 @@ -"""Top-level package for smops.""" +"""Top-level package for sade.""" __author__ = AUTHOR = """L Andati""" __email__ = EMAIL = 'landati@duck.com' diff --git a/smops/smooth.py b/sade/smooth.py similarity index 99% rename from smops/smooth.py rename to sade/smooth.py index 565daa7..3ffc092 100644 --- a/smops/smooth.py +++ b/sade/smooth.py @@ -17,7 +17,7 @@ from dask import compute -from smops import VERSION +from sade import VERSION GB = 2**30 diff --git a/setup.cfg b/setup.cfg index ace1794..74fcbc1 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,16 +1,16 @@ # https://setuptools.pypa.io/en/latest/userguide/declarative_config.html? # https://setuptools.pypa.io/en/latest/references/keywords.html [metadata] - name = smops - version = attr: smops.VERSION + name = sade + version = attr: sade.VERSION author = L. Andati email = landati@duck.com description = Python script for interpolating FITS model images over frequency long_description = file: README.rst, CHANGELOG.rst, LICENSE.rst - keywords = smops, model frequency interpolation, FITS images + keywords = sade, model frequency interpolation, FITS images license = MIT license license_files = file: LICENSE.rst - url = https://github.com/mulan-94/smops + url = https://github.com/mulan-94/sade python_requires = >=3.8 classifiers= Development Status :: 4 - Beta diff --git a/setup.py b/setup.py index 4d2a125..ed2a81a 100644 --- a/setup.py +++ b/setup.py @@ -8,8 +8,8 @@ setup( entry_points={ 'console_scripts': [ - 'smops=smops.smooth:main', + 'sade=sade.smooth:main', ], }, - packages=find_packages(include=['smops', 'smops.*']), + packages=find_packages(include=['sade', 'sade.*']), ) diff --git a/tox.ini b/tox.ini index f877d9e..6e03bf8 100644 --- a/tox.ini +++ b/tox.ini @@ -10,7 +10,7 @@ python = [testenv:flake8] basepython = python deps = flake8 -commands = flake8 smops tests +commands = flake8 sade tests [testenv] setenv = From 770da787ce64c90541885c70b09a0bac3ff002fb Mon Sep 17 00:00:00 2001 From: Lexy Andati Date: Wed, 14 Sep 2022 22:39:33 +0200 Subject: [PATCH 3/3] Url will point to smops till further notice --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 74fcbc1..6a38605 100644 --- a/setup.cfg +++ b/setup.cfg @@ -10,7 +10,7 @@ keywords = sade, model frequency interpolation, FITS images license = MIT license license_files = file: LICENSE.rst - url = https://github.com/mulan-94/sade + url = https://github.com/mulan-94/smops python_requires = >=3.8 classifiers= Development Status :: 4 - Beta