Skip to content

Commit f7c6727

Browse files
committed
Shorten camels-us install; support local and remote image path; fix bugs
1 parent 6c88f6a commit f7c6727

File tree

3 files changed

+26
-20
lines changed

3 files changed

+26
-20
lines changed

dist/neuralhydrology_demo1/install_demo1.sh

+9-9
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ help()
1111
"
1212
}
1313

14-
if [[n $# -lt 2 ]]; then
14+
if [[ $# -lt 2 ]]; then
1515
help
1616
exit 0
1717
fi
1818

1919
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
2020
DATA_DIR=$(realpath $1)
2121
EXP_DIR=$(realpath $2)
22-
CAMELS_SCRIPT="wget-camels-20250127T1907.sh"
2322

2423
# Create directories
2524
mkdir -p ${EXP_DIR}
@@ -31,19 +30,20 @@ echo "Pulling container image ${DEMO_IMAGE} (6 GB) ..."
3130
docker pull ${DEMO_IMAGE}
3231

3332
# Download CAMELS-US
34-
echo "Downloading CAMEL-US dataset (14 GB) ..."
35-
wget_script=${SOURCE_DIR}/.install/${CAMELS_SCRIPT}
36-
cp ${wget_script} ${DATA_DIR}
37-
cd ${DATA_DIR} && "./${CAMELS_SCRIPT}"
33+
echo "Downloading CAMEL-US dataset (3.2 GB) ..."
34+
zip_filename="basin_timeseries_v1p2_metForcing_obsFlow.zip"
35+
zip_url="https://gdex.ucar.edu/dataset/camels/file/${zip_filename}"
36+
cd ${DATA_DIR} && wget ${zip_url}
37+
3838

3939
# Unzip contents
4040
echo "Unzipping data ..."
41-
cd ${DATA_DIR} && unzip basin_timeseries_v1p2_metForcing_obsFlow.zip
41+
cd ${DATA_DIR} && unzip ${zip_filename}
4242

4343
# Generate .args.txt file
44-
ARGS_FILE=${SCRIPT_DIR}/app/demo1/.args.txt
44+
ARGS_FILE=${SCRIPT_DIR}/app/.args.txt
4545
echo "--data_dir" > ${ARGS_FILE}
46-
echo ${DATA_DIR} >> ${ARGS_FILE}/basin_dataset_public_v1p2
46+
echo ${DATA_DIR}/basin_dataset_public_v1p2 >> ${ARGS_FILE}
4747
echo "--experiments_dir" >> ${ARGS_FILE}
4848
echo ${EXP_DIR} >> ${ARGS_FILE}
4949

neuralhydrology/demo1.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,18 @@ def main():
4242
print('Exiting')
4343
sys.exit(2)
4444

45-
# name_tag = f'{IMAGE_NAME}:{IMAGE_TAG}'
46-
runner = DemoRun(IMAGE_NAME, args.data_dir, verbose=args.verbose)
45+
image = IMAGE_NAME if args.local_image_build else f'{IMAGE_REGISTRY_USER}/{IMAGE_NAME}'
46+
runner = DemoRun(image, args.data_dir, verbose=args.verbose)
4747
if not runner.is_image_available():
48+
print()
4849
if args.local_image_build:
49-
print(f'container image not available: {IMAGE_NAME}')
50-
sys.exit(1)
50+
print(f'Container image not found: {image}')
5151
else:
52-
print('Future: add code to fetch image')
53-
sys.exit(1)
52+
print('Container image not found')
53+
print(f'In a terminal run `docker pull {image}` and rerun this script')
54+
sys.exit(1)
5455

55-
print('Image was found!')
56+
print(f'Container image was found: {image}')
5657
runner.execute(
5758
args.basin_id,
5859
pathlib.Path(args.experiments_dir),

neuralhydrology/package_demo1.py

+9-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
rm -rf neuralhydrology_demo1/app/demo1/__pycache__/ && tar zcf neuralhydrology_demo1.tgz neuralhydrology_demo1/
99
"""
1010

11+
import os
1112
import pathlib
1213
import shutil
1314
import tarfile
@@ -19,7 +20,8 @@
1920
# Delete any existing tgz and app files
2021
tgz_file = source_dir / 'dist/neuralhydrology_demo1.tgz'
2122
tgz_file.unlink(missing_ok=True)
22-
shutil.rmtree(app_dir)
23+
if app_dir.exists():
24+
shutil.rmtree(app_dir)
2325

2426
# Copy source files to app dir
2527
app_dir.mkdir(parents=True, exist_ok=True)
@@ -38,7 +40,10 @@
3840
shutil.copy2(from_path, app_sub_dir)
3941

4042
# Generate tgz file
41-
tgz_path = source_dir.parent / 'dist/neuralhydrology_demo1.tgz'
42-
with tarfile.open(tgz_path, 'w:gz') as tar:
43-
tar.add(dist_dir)
43+
dist_dir = source_dir.parent / 'dist'
44+
os.chdir(dist_dir)
45+
tgz_file = 'neuralhydrology_demo1.tgz'
46+
with tarfile.open(tgz_file, 'w:gz') as tar:
47+
tar.add('neuralhydrology_demo1')
48+
tgz_path = dist_dir / tgz_file
4449
print(f'Wrote {tgz_path}')

0 commit comments

Comments
 (0)