Template Script - Download Results

Contents

Template Script - Download Results#

This script provides a template for retrieving simulation results from the Flow360 platform using a specified Case ID. It facilitates the download of surface and volume data to a local directory and subsequently extracts the compressed files.

 1"""
 2Download volume, surface, acoustic and other types of output files to the directory it is run from.
 3"""
 4
 5import os
 6import tarfile
 7import timeit
 8
 9import click
10
11import flow360 as fl
12from flow360.log import log
13
14# Enter case specific settings here.
15case_id = "ENTER CASE ID HERE"
16download_surfaces = True
17download_volumes = True
18
19
20case = fl.Case.from_cloud(case_id)
21destination = os.path.join(os.getcwd(), case.name)
22
23results = case.results
24
25if os.path.exists(destination):
26    overwrite_bool = click.confirm(
27        f"Directory '{destination}' already exists, downloading might overwrite some of its content, do you want to continue?",
28        default=True,
29        abort=True,
30    )
31log.info("Beginning downloading")
32# Download only specific data sets
33results.download(
34    surface=download_surfaces, volume=download_volumes, destination=destination, overwrite=True
35)
36
37# Extract tar.gz files
38tar_gz_files = [f for f in os.listdir(destination) if f.endswith(".tar.gz")]
39for tar_gz_file in tar_gz_files:
40    start = timeit.default_timer()
41    file_path = os.path.join(destination, tar_gz_file)
42    log.info(f"Processing: {file_path}")
43
44    with tarfile.open(file_path, "r:gz") as tar:
45        result_name = tar_gz_file[:-7]
46        tar.extractall(path=os.path.join(destination, result_name))
47
48    os.remove(file_path)
49    log.info(f"  Removed: {file_path}")
50    log.info(f"Extracting files for {tar_gz_file} done")
51log.info("Downloading successful")

Notes#

  • Boolean flags (download_surfaces, download_volumes) control which result types are retrieved.

  • Downloaded .tar.gz archives are automatically extracted into subdirectories, and the original archives are removed.