From d5196f2aec22114906c5ca4fd345341d5c7b803f Mon Sep 17 00:00:00 2001 From: Aliaksandr Yakutovich Date: Wed, 10 Apr 2024 14:21:35 +0000 Subject: [PATCH] Add command-line interface. --- cubehandler/cli/__init__.py | 0 cubehandler/cli/commands/__init__.py | 0 cubehandler/cli/commands/shrink.py | 13 +++++++++++++ cubehandler/cli/main.py | 15 +++++++++++++++ cubehandler/cube.py | 1 - pyproject.toml | 3 +++ 6 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 cubehandler/cli/__init__.py create mode 100644 cubehandler/cli/commands/__init__.py create mode 100644 cubehandler/cli/commands/shrink.py create mode 100644 cubehandler/cli/main.py diff --git a/cubehandler/cli/__init__.py b/cubehandler/cli/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cubehandler/cli/commands/__init__.py b/cubehandler/cli/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cubehandler/cli/commands/shrink.py b/cubehandler/cli/commands/shrink.py new file mode 100644 index 0000000..17344bb --- /dev/null +++ b/cubehandler/cli/commands/shrink.py @@ -0,0 +1,13 @@ +import click + +from ...cube import Cube + + +@click.command(help="Shrink a cube file.") +@click.argument("input_cube", type=click.Path(exists=True)) +@click.argument("output_cube", type=click.Path()) +def shrink(input_cube, output_cube): + cube = Cube.from_file(input_cube) + cube.reduce_data_density(points_per_angstrom=2) + cube.rescale_data() + cube.write_cube_file(output_cube, low_precision=True) diff --git a/cubehandler/cli/main.py b/cubehandler/cli/main.py new file mode 100644 index 0000000..27eaafd --- /dev/null +++ b/cubehandler/cli/main.py @@ -0,0 +1,15 @@ +import click + +from ..version import __version__ +from .commands import shrink + + +@click.group(help="Cubehandler: a tool to handle cube files.") +@click.version_option( + __version__, package_name="cubehandler", message="cubehandler version %(version)s" +) +def cli(): + pass + + +cli.add_command(shrink.shrink) diff --git a/cubehandler/cube.py b/cubehandler/cube.py index db8f781..96330a6 100644 --- a/cubehandler/cube.py +++ b/cubehandler/cube.py @@ -212,7 +212,6 @@ def reduce_data_density(self, points_per_angstrom=2): def rescale_data(self): """Rescales the data to be between -1 and 1""" self.scaling_factor = max(abs(self.data.min()), abs(self.data.max())) - print("check", self.scaling_factor, abs(self.data.min()), abs(self.data.max())) self.data /= self.scaling_factor self.data = np.round(self.data, decimals=self.low_precision_decimals) diff --git a/pyproject.toml b/pyproject.toml index 9e76a8e..98b285f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,3 +29,6 @@ dev = [ "pytest==7.4.4", "pytest-cov==4.1.0", ] + +[project.scripts] +cubehandler = 'cubehandler.cli.main:cli'