Skip to content

Commit

Permalink
Merge pull request #1 from Mulan-94/sade
Browse files Browse the repository at this point in the history
Moving from smops to Sade
  • Loading branch information
Mulan-94 authored Sep 14, 2022
2 parents a56812d + 770da78 commit ca660c5
Show file tree
Hide file tree
Showing 11 changed files with 72 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* smops version:
* sade version:
* Python version:
* Operating System:

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
sade -v
24 changes: 12 additions & 12 deletions CONTRIBUTING.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand All @@ -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:

Expand All @@ -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 [email protected]:your_name_here/smops.git
$ git clone [email protected]: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::
Expand All @@ -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

Expand All @@ -103,15 +103,15 @@ 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
----

To run a subset of tests::

$ pytest tests.test_smops
$ pytest tests.test_sade


Deploying
Expand Down
8 changes: 7 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
23 changes: 13 additions & 10 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,37 +1,39 @@
=====
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 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:
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] [-od] [-nthreads] [-stokes] [-mem] --ms -ip -co [-order]
usage: sade [-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
Expand All @@ -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
4 changes: 2 additions & 2 deletions smops/__init__.py → sade/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Top-level package for smops."""
"""Top-level package for sade."""

__author__ = AUTHOR = """L Andati"""
__email__ = EMAIL = '[email protected]'
__version__ = VERSION = '0.1.1'
__version__ = VERSION = '0.1.2'
49 changes: 25 additions & 24 deletions smops/smooth.py → sade/smooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@


from dask import compute
from smops import VERSION
from sade import VERSION


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")
Expand All @@ -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)

Expand All @@ -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="",
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# 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 = [email protected]
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
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.*']),
)
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ python =
[testenv:flake8]
basepython = python
deps = flake8
commands = flake8 smops tests
commands = flake8 sade tests

[testenv]
setenv =
Expand Down

0 comments on commit ca660c5

Please sign in to comment.