-
Notifications
You must be signed in to change notification settings - Fork 10
/
lemnatec-dataset-downloader
58 lines (39 loc) · 2.03 KB
/
lemnatec-dataset-downloader
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
import argparse
from dsf.data import lemnatec
def options():
parser = argparse.ArgumentParser(description='Retrieve data from a LemnaTec database.',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-e", "--exp", help="Experiment name/Measurement label.", required=True)
parser.add_argument("-d", "--db", help="Database name.", required=True)
parser.add_argument("-c", "--config", help="JSON config file.", required=True)
parser.add_argument("-o", "--outdir", help="Output directory for results.", required=True)
args = parser.parse_args()
return args
def main():
# Read user options
args = options()
# Read the database connetion configuration file
config = lemnatec.load_config(filename=args.config, database=args.db, experiment=args.exp)
# Open an SFTP connection to the database server
sftp = lemnatec.open_sftp_connection(config=config)
# Open a database connection to the PostgreSQL server
db = lemnatec.open_database_connection(config=config)
# Initialize the dataset directory if it does not exist
lemnatec.init_dataset(dataset_dir=args.outdir, config=config)
# Load the dataset metadata
meta = lemnatec.load_dataset(dataset_dir=args.outdir)
# Query the database for snapshot metadata and update the local metadata
meta = lemnatec.query_snapshots(db=db, metadata=meta, experiment=config.experiment, config=config)
# Query the database for image metadata and update the local metadata
meta = lemnatec.query_images(db=db, metadata=meta, experiment=config.experiment, config=config)
# Update the local metadata file
lemnatec.save_dataset(dataset_dir=args.outdir, metadata=meta)
# Transfer the image data to the local directory
lemnatec.transfer_images(metadata=meta, sftp=sftp, dataset_dir=args.outdir, config=config)
# Close the SFTP connection
sftp.close()
# Close the database connection
db.close()
if __name__ == "__main__":
main()