Skip to content

Commit

Permalink
Add command-line interface (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored Apr 10, 2024
1 parent eab43b2 commit 29db5c3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
Empty file added cubehandler/cli/__init__.py
Empty file.
Empty file.
13 changes: 13 additions & 0 deletions cubehandler/cli/commands/shrink.py
Original file line number Diff line number Diff line change
@@ -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)
15 changes: 15 additions & 0 deletions cubehandler/cli/main.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 0 additions & 1 deletion cubehandler/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ dev = [
"pytest==7.4.4",
"pytest-cov==4.1.0",
]

[project.scripts]
cubehandler = 'cubehandler.cli.main:cli'

0 comments on commit 29db5c3

Please sign in to comment.