1
|
|
|
import os |
|
|
|
|
2
|
|
|
# import diff_classifier.imagej as ij |
3
|
|
|
import boto3 |
|
|
|
|
4
|
|
|
import os.path as op |
|
|
|
|
5
|
|
|
|
6
|
|
|
|
7
|
|
|
def download_s3(remote_fname, local_fname, bucket_name="ccurtis7.pup"): |
8
|
|
|
""" |
9
|
|
|
Download a file from S3 to our local file-system |
10
|
|
|
|
11
|
|
|
Parameters |
12
|
|
|
---------- |
13
|
|
|
remote_fname: string |
14
|
|
|
Name of remote file in S3 bucket. |
15
|
|
|
local_fname: string |
16
|
|
|
Desired name to be stored on local computer. |
17
|
|
|
bucket_name: string |
18
|
|
|
Bucket name on S3. |
19
|
|
|
""" |
20
|
|
|
if not os.path.exists(local_fname): |
21
|
|
|
s3 = boto3.resource('s3') |
|
|
|
|
22
|
|
|
b = s3.Bucket(bucket_name) |
|
|
|
|
23
|
|
|
b.download_file(remote_fname, local_fname) |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
def upload_s3(local_fname, remote_fname, bucket_name="ccurtis7.pup"): |
27
|
|
|
""" |
28
|
|
|
Upload a file from local file-system to S3. |
29
|
|
|
|
30
|
|
|
Parameters |
31
|
|
|
---------- |
32
|
|
|
local_fname: string |
33
|
|
|
Name of local file stored on computer. |
34
|
|
|
remote_fname: string |
35
|
|
|
Desired name to be stored in S3 bucket. |
36
|
|
|
bucket_name: string |
37
|
|
|
Bucket name on S3. |
38
|
|
|
""" |
39
|
|
|
|
40
|
|
|
s3 = boto3.resource('s3') |
|
|
|
|
41
|
|
|
b = s3.Bucket(bucket_name) |
|
|
|
|
42
|
|
|
b.upload_file(local_fname, remote_fname) |
43
|
|
|
|
44
|
|
|
|
45
|
|
|
# def partition_and_store(remote_fname, local_dir, bucket_name="ccurtis7.pup"): |
46
|
|
|
# """ |
47
|
|
|
# Download image from S3, partition, and upload partitions to S3. |
48
|
|
|
|
49
|
|
|
# Parameters |
50
|
|
|
# ---------- |
51
|
|
|
# remote_fname: string |
52
|
|
|
# Target filename in S3 bucket. |
53
|
|
|
# local_dir: string |
54
|
|
|
# Local directory to store downloaded file. |
55
|
|
|
# bucket_name: string |
56
|
|
|
# Bucket name on S3. |
57
|
|
|
|
58
|
|
|
# Returns |
59
|
|
|
# ------- |
60
|
|
|
# remote_names: list of strings. |
61
|
|
|
# Names of partitioned images in S3. |
62
|
|
|
# """ |
63
|
|
|
# remote_dir, remote_file = op.split(remote_fname) |
64
|
|
|
# download_s3(remote_fname, op.join(local_dir, remote_file)) |
65
|
|
|
# names = ij.partition_im(op.join(local_dir, remote_file)) |
66
|
|
|
|
67
|
|
|
# remote_names = [] |
68
|
|
|
# for file in names: |
69
|
|
|
# local_file = op.split(file)[1] |
70
|
|
|
# upload_s3(op.join(local_dir, local_file), op.join(remote_dir, local_file)) |
71
|
|
|
# remote_names.append(op.join(remote_dir, local_file)) |
72
|
|
|
# return remote_names |
73
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.