Skip to content

Commit

Permalink
Allow reading multiple cube files from a folder (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
yakutovicha authored Dec 17, 2024
1 parent 51cb60a commit e678007
Showing 1 changed file with 28 additions and 7 deletions.
35 changes: 28 additions & 7 deletions cubehandler/cli/commands/shrink.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
from pathlib import Path

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)
@click.argument(
"input_path",
type=click.Path(exists=True, file_okay=True, dir_okay=True),
required=True,
)
@click.argument(
"output_path", type=click.Path(file_okay=True, dir_okay=True), required=True
)
@click.option("-p", "--prefix", default="reduced_")
def shrink(input_path, output_path, prefix):
inp = Path(input_path)
out = Path(output_path)

def run_reduction(inp, out):
cube = Cube.from_file(inp)
cube.reduce_data_density(points_per_angstrom=2)
# cube.rescale_data() # Rescaling happens below when low_precision is True
cube.write_cube_file(out, low_precision=True)

if inp.is_file():
run_reduction(inp, out)
elif inp.is_dir():
out.mkdir(exist_ok=True)
for file in inp.glob("*cube"):
out_file = out / (prefix + file.name)
run_reduction(file.absolute(), out_file)

0 comments on commit e678007

Please sign in to comment.