Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reading multiple cube files from a folder. #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()
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)
Loading