diff options
Diffstat (limited to 'cli/app/commands/cortex/upload_bytes.py')
| -rw-r--r-- | cli/app/commands/cortex/upload_bytes.py | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/cli/app/commands/cortex/upload_bytes.py b/cli/app/commands/cortex/upload_bytes.py new file mode 100644 index 0000000..5260b8e --- /dev/null +++ b/cli/app/commands/cortex/upload_bytes.py @@ -0,0 +1,33 @@ +import click + +import numpy as np +from PIL import Image +from io import BytesIO +from app.utils.cortex_utils import upload_bytes_to_cortex + +@click.command('') +@click.option('-f', '--folder_id', 'opt_folder_id', required=True, + help='ID of folder on Cortex') +@click.pass_context +def cli(ctx, opt_folder_id): + """ + Test uploading a BytesIO file to Cortex + """ + arr = get_gradation_3d(256, 256, (0, 0, 192), (255, 255, 64), (True, False, False)) + arr = arr.astype(np.uint8) + image = Image.fromarray(arr) + fp = BytesIO() + image.save(fp, format='png') + upload_bytes_to_cortex(opt_folder_id, "test.png", fp, "image/png") + +def get_gradation_2d(start, stop, width, height, is_horizontal): + if is_horizontal: + return np.tile(np.linspace(start, stop, width), (height, 1)) + else: + return np.tile(np.linspace(start, stop, height), (width, 1)).T + +def get_gradation_3d(width, height, start_list, stop_list, is_horizontal_list): + result = np.zeros((height, width, len(start_list)), dtype=np.float) + for i, (start, stop, is_horizontal) in enumerate(zip(start_list, stop_list, is_horizontal_list)): + result[:, :, i] = get_gradation_2d(start, stop, width, height, is_horizontal) + return result |
