From ae855e15ba0049023fe278277dbf641cafeb8e74 Mon Sep 17 00:00:00 2001 From: Sachin Velmurugan Date: Tue, 22 Oct 2024 10:34:30 -0700 Subject: [PATCH] fix setup.sh script --- environment.yml | 2 +- geoEpic/dispatcher.py | 4 ++++ geoEpic/initialize.py | 36 +++++++++++++++++++++++++++++++++++ installation_scripts/setup.sh | 20 +++++++++++-------- 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 geoEpic/initialize.py diff --git a/environment.yml b/environment.yml index d78088c..713872c 100644 --- a/environment.yml +++ b/environment.yml @@ -1,4 +1,4 @@ -name: epic_env +name: epic_env2 channels: - conda-forge - defaults diff --git a/geoEpic/dispatcher.py b/geoEpic/dispatcher.py index d1efbaa..39b70bc 100644 --- a/geoEpic/dispatcher.py +++ b/geoEpic/dispatcher.py @@ -4,6 +4,9 @@ # Mapping of modules and functions to their respective relative paths script_paths = { + "init" : { + "init" : "initialize.py" + }, "utility": { "crop_csb": "utils/crop_csb.py", "gee": "gee/fetch.py" @@ -38,6 +41,7 @@ "soil": "usda", "sites": "generate", "workspace": "run", + "init":"init" } class DispatchError(Exception): diff --git a/geoEpic/initialize.py b/geoEpic/initialize.py new file mode 100644 index 0000000..71e96b7 --- /dev/null +++ b/geoEpic/initialize.py @@ -0,0 +1,36 @@ +from geoEpic.io.config_parser import ConfigParser +import os +import urllib.request + +home_dir = os.path.expanduser("~") +metadata_dir = os.path.join(home_dir, 'GeoEPIC_metadata') +root_path = os.path.dirname(__file__) + +def setup_metadata(): + if not os.path.exists(metadata_dir): + os.makedirs(metadata_dir) + # List of files to download + files_to_download = [ + "https://smarslab-files.s3.amazonaws.com/epic-utils/slope_us.tif", + "https://smarslab-files.s3.amazonaws.com/epic-utils/SRTM_1km_US_project.tif", + "https://smarslab-files.s3.amazonaws.com/epic-utils/SSURGO.tif" + ] + # Download the files to the metadata directory + for file_url in files_to_download: + filename = os.path.join(metadata_dir, os.path.basename(file_url)) + urllib.request.urlretrieve(file_url, filename) + else: + print(f"'{metadata_dir}' already exists, skipping file downloads.") + +def update_template_config_file(): + + config = ConfigParser(os.path.join(f'{root_path}/assets/ws_template/config.yml')) + + config.update({'soil' : {'soil_map': f'{home_dir}/GeoEPIC_metadata/SSURGO.tif',}, + 'site': {'elevation': f'{home_dir}/GeoEPIC_metadata/SRTM_1km_US_project.tif', + 'slope': f'{home_dir}/GeoEPIC_metadata/slope_us.tif', + }, }) + +setup_metadata() +update_template_config_file() + diff --git a/installation_scripts/setup.sh b/installation_scripts/setup.sh index d148fdd..93db45a 100755 --- a/installation_scripts/setup.sh +++ b/installation_scripts/setup.sh @@ -1,10 +1,11 @@ #!/bin/bash # Environment name -ENV_NAME="my_project_env" +ENV_NAME="epic_env2" ENV_YML="environment.yml" ANACONDA_INSTALLER="Anaconda3-latest-Linux-x86_64.sh" ANACONDA_URL="https://repo.anaconda.com/archive/$ANACONDA_INSTALLER" +GITHUB_PACKAGE_URL="git+https://github.com/smarsGroup/geo-epic.git" # Function to check if conda is installed function check_conda_installed { @@ -48,13 +49,8 @@ function check_env_exists { # Function to create the environment from environment.yml function create_env { - if [[ -f "$ENV_YML" ]]; then - echo "Creating Conda environment '$ENV_NAME' from '$ENV_YML'..." - conda env create -f "$ENV_YML" - else - echo "Environment file '$ENV_YML' not found. Please ensure the file exists." - exit 1 - fi + echo "Creating Conda environment '$ENV_NAME' ..." + conda env create -f https://raw.githubusercontent.com/smarsGroup/geo-epic/master/environment.yml } # Main script @@ -64,9 +60,17 @@ check_conda_installed # 2. Check if the environment exists, if not create it if ! check_env_exists; then create_env +else + # If environment exists, install the GitHub package via pip + echo "Updaing geo_epic package..." + conda activate "$ENV_NAME" + pip uninstall geo-epic + pip install "$GITHUB_PACKAGE_URL" + conda deactivate fi # 3. Activate the environment echo "Activating environment '$ENV_NAME'..." conda activate "$ENV_NAME" +geo_epic init echo "Environment '$ENV_NAME' is activated."