Skip to content

Commit

Permalink
Use subcommands; can now 'write' or 'show'
Browse files Browse the repository at this point in the history
  • Loading branch information
jepler committed Apr 26, 2022
1 parent 41ecde7 commit 81b0a32
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 27 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,16 @@ When a fluxengine-style CSV file with decoder information is supplied, the inter

* Use a commandline like
```
python -mfluxvis --tracks 35 --diameter 108 --stride 2 dos33.scp dos33.png
python -mfluxvis --tracks 35 --diameter 108 --stride 2 write dos33.scp dos33.png
```
or
```
python -mfluxvis --tracks 35 --diameter 108 --stride 2 show dos33.scp
```

# Credits

Flux reading is done via embedded copies of
[greaseweazle](https://github.com/keirf/greaseweazle) and
[a2rchery](https://github.com/a2-2am/a2rchery). Thanks to @keirf and @a2-4am
for these tools! See the source code for additional information.
Binary file modified etc/disk.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified etc/diskcolor.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions etc/update-img.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#!/bin/sh
set -x
set -e
c1541 -format example,ds d64 disk.d64

find fluxvis -name \*.py | while read l; do c1541 -attach disk.d64 -write "$l" "`echo ${l##*/} | tr A-Z a-z`"; done
find fluxvis -name \*.py | while read l; do
fn=$(echo $l | sha256sum | cut -b -16)
c1541 -attach disk.d64 -write "$l" "$fn"
done

~/src/fluxengine/fluxengine write commodore1541 --no-verify -d disk.scp -i disk.d64 --drive.rotational_period_ms 200
~/src/fluxengine/fluxengine read commodore1541 -s disk.scp -o disk.d64 --decoder.write_csv_to disk.csv --drive.rotational_period_ms 200 -c 0-34
python3 -mfluxvis disk.scp etc/disk.jpg --oversample 3 --resolution 640 --stride 2 --tracks 35 --diameter 108
python3 -mfluxvis disk.scp etc/diskcolor.jpg --oversample 3 --resolution 640 --stride 2 --tracks 35 --diameter 108 --location disk.csv
python3 -mfluxvis --oversample 3 --resolution 640 --stride 2 --tracks 35 --diameter 108 write disk.scp etc/disk.jpg
python3 -mfluxvis --oversample 3 --resolution 640 --stride 2 --tracks 35 --diameter 108 --location disk.csv write disk.scp etc/diskcolor.jpg
79 changes: 57 additions & 22 deletions fluxvis/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@

import click
from skimage.io import imsave
import matplotlib.pyplot as plt
from . import open_flux, process


@click.command()
@click.group()
@click.pass_context
@click.option(
"--slices",
default=4000,
Expand Down Expand Up @@ -40,10 +42,8 @@
type=click.Path(exists=True),
help="fluxengine decoder location information saved with --decoder.write_csv_to=",
)
@click.argument("input_file", type=click.Path(exists=True))
@click.argument("output_file", type=click.Path())
def main(
input_file,
ctx,
side,
tracks,
start,
Expand All @@ -55,26 +55,61 @@ def main(
resolution,
linear,
oversample,
output_file,
): # pylint: disable=redefined-builtin,too-many-arguments,too-many-locals, invalid-name, too-many-branches,too-many-statements
"""Visualize INPUT (any file readable by greaseweazle, including scp and
KryoFlux) to OUTPUT (any file supported by skimage including png and jpg)
"""
flux = open_flux(input_file)
density = process(
flux,
side,
tracks,
start,
stride,
linear,
slices,
stacks,
location,
diameter,
resolution,
oversample,
"""Commandline interface to visualize flux"""
ctx.ensure_object(dict)
ctx.obj.update(
{
"side": side,
"tracks": tracks,
"start": start,
"stride": stride,
"linear": linear,
"slices": slices,
"stacks": stacks,
"location": location,
"diameter": diameter,
"resolution": resolution,
"oversample": oversample,
}
)


@main.command()
@click.pass_context
@click.argument("input_file", type=click.Path(exists=True))
def view(ctx, input_file):
"""Render a flux image to the screen
INPUT_FILE may be any flux format recognized by the embedded copy of
greaseweazle (.scp, etc) or an a2r file."""
flux = open_flux(input_file)
density = process(flux, **ctx.obj)

fig, axis = plt.subplots()
fig.set_dpi(96)
fig.set_size_inches(density.shape[0] / 96, density.shape[1] / 96)
fig.set_frameon(False)
fig.set_tight_layout(True)
plt.axis("off")
axis.imshow(density)
plt.show()


@main.command()
@click.pass_context
@click.argument("input_file", type=click.Path(exists=True))
@click.argument("output_file", type=click.Path())
def write(ctx, input_file, output_file):
"""Render a flux image to a file
INPUT_FILE may be any flux format recognized by the embedded copy of
greaseweazle (.scp, etc) or an a2r file.
OUTPUT_FILE may be any image format recognized by scikit_img including PNG,
GIF, and JPG"""
flux = open_flux(input_file)
density = process(flux, **ctx.obj)
imsave(output_file, density)


Expand Down

0 comments on commit 81b0a32

Please sign in to comment.