Skip to content

Commit 6dc33cf

Browse files
Implement mobie upload
1 parent 0c628da commit 6dc33cf

File tree

2 files changed

+80
-15
lines changed

2 files changed

+80
-15
lines changed

scripts/data_transfer/README.md

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,30 @@
55
Current approach to the data transfer:
66
- Log in to SCC login node:
77
$
8-
- Go to `/scratch1/projects/cca/data/moser`
8+
- Go to "/scratch1/projects/cca/data/moser"
99
- Create subfolder <NAME> for cochlea to be copied
10-
- Log in via
11-
```
12-
$ smbclient \\\\wfs-medizin.top.gwdg.de\\ukon-all\$\\ukon100 -U GWDG\\pape41"
13-
```
10+
- Log in via $ smbclient \\\\wfs-medizin.top.gwdg.de\\ukon-all\$\\ukon100 -U GWDG\\pape41"
1411
- Go to the folder with the cochlea to copy (cd works)
1512
- Copy the folder via:
1613
- recurse ON
1714
- prompt OFF
1815
- mget *
1916
- Copy this to HLRN by logging into it and running
20-
```
21-
$ rsync -e "ssh -i ~/.ssh/id_rsa_hlrn" -avz [email protected]:/scratch1/projects/cca/data/moser/<NAME> /mnt/lustre-emmy-hdd/projects/nim00007/data/moser/lightsheet/volumes/<NAME>
22-
```
17+
$ rsync pape41:/scratch1/projects/cca/data/moser/<NAME>
18+
$ rsync -e "ssh -i ~/.ssh/id_rsa_hlrn" -avz [email protected]:/scratch1/projects/cca/data/mose
19+
r/<NAME> /mnt/lustre-grete/usr/u12086/moser/lightsheet/<NAME>
2320
- Remove on SCC
2421

2522
## Next files
2623

2724
- UKON100\archiv\imaging\Lightsheet\Huiskengroup_CTLSM\2024\M171_2R_converted_n5
28-
- unclear what the converted data is
29-
- UKON100\archiv\imaging\Lightsheet\Huiskengroup_CTLSM\2024\155_1L_converted_n5\BDVexport.n5
30-
- Copied to SCC, rsync in progress.
25+
- UKON100\archiv\imaging\Lightsheet\Huiskengroup_CTLSM\2024\155_1L_converted_n5
3126
- UKON100\archiv\imaging\Lightsheet\Huiskengroup_CTLSM\2024\MLR151_2R_converted_n5
32-
- unclear what the converted data is
3327
- UKON100\archiv\imaging\Lightsheet\Huiskengroup_CTLSM\2024\G11_1L_converted_n5
34-
- unclear what the converted data is
3528

3629
## Improvements
3730

3831
Try to automate via https://github.com/jborean93/smbprotocol see `sync_smb.py` for ChatGPT's inital version.
39-
Connection not possible from HLRN.
4032

4133
## Transfer Back
4234

scripts/prediction/upload_to_s3.py

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,74 @@
1-
# TODO find suitable bucket
1+
import os
2+
3+
import s3fs
4+
5+
from mobie.metadata import add_remote_project_metadata
6+
from tqdm import tqdm
7+
8+
# Using incucyte s3 as a temporary measure.
9+
MOBIE_FOLDER = "/mnt/lustre-emmy-hdd/projects/nim00007/data/moser/lightsheet/mobie"
10+
SERVICE_ENDPOINT = "https://s3.gwdg.de/"
11+
BUCKET_NAME = "incucyte-general/lightsheet"
12+
13+
# For MoBIE:
14+
# https://s3.gwdg.de/incucyte-general/lightsheet
15+
16+
17+
def read_s3_credentials(credential_file):
18+
key, secret = None, None
19+
with open(credential_file) as f:
20+
for line in f:
21+
if line.startswith("aws_access_key_id"):
22+
key = line.rstrip("\n").strip().split(" ")[-1]
23+
if line.startswith("aws_secret_access_key"):
24+
secret = line.rstrip("\n").strip().split(" ")[-1]
25+
if key is None or secret is None:
26+
raise ValueError(f"Invalid credential file {credential_file}")
27+
return key, secret
28+
29+
30+
def create_s3_target(url, anon=False, credential_file=None):
31+
client_kwargs = {"endpoint_url": url}
32+
if credential_file is not None:
33+
key, secret = read_s3_credentials(credential_file)
34+
fs = s3fs.S3FileSystem(key=key, secret=secret, client_kwargs=client_kwargs)
35+
else:
36+
fs = s3fs.S3FileSystem(anon=anon, client_kwargs=client_kwargs)
37+
return fs
38+
39+
40+
def remote_metadata():
41+
add_remote_project_metadata(MOBIE_FOLDER, BUCKET_NAME, SERVICE_ENDPOINT)
42+
43+
44+
def upload_data():
45+
target = create_s3_target(
46+
SERVICE_ENDPOINT,
47+
credential_file="./credentials.incucyte"
48+
)
49+
to_upload = []
50+
for root, dirs, files in os.walk(MOBIE_FOLDER):
51+
dirs.sort()
52+
for ff in files:
53+
if ff.endswith(".xml"):
54+
to_upload.append(os.path.join(root, ff))
55+
56+
print("Uploading", len(to_upload), "files to")
57+
58+
for path in tqdm(to_upload):
59+
rel_path = os.path.relpath(path, MOBIE_FOLDER)
60+
target.put(
61+
path, os.path.join(BUCKET_NAME, rel_path)
62+
)
63+
64+
65+
# FIXME: access via s3 is not working due to permission issues.
66+
# Maybe this is not working due to bdv fileformat?!
67+
# Make an issue in MoBIE.
68+
def main():
69+
# remote_metadata()
70+
upload_data()
71+
72+
73+
if __name__ == "__main__":
74+
main()

0 commit comments

Comments
 (0)