Skip to content

Commit

Permalink
fix setup.sh script
Browse files Browse the repository at this point in the history
  • Loading branch information
SachinVel committed Oct 22, 2024
1 parent 0c2ef13 commit ae855e1
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 9 deletions.
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: epic_env
name: epic_env2
channels:
- conda-forge
- defaults
Expand Down
4 changes: 4 additions & 0 deletions geoEpic/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -38,6 +41,7 @@
"soil": "usda",
"sites": "generate",
"workspace": "run",
"init":"init"
}

class DispatchError(Exception):
Expand Down
36 changes: 36 additions & 0 deletions geoEpic/initialize.py
Original file line number Diff line number Diff line change
@@ -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()

20 changes: 12 additions & 8 deletions installation_scripts/setup.sh
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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."

0 comments on commit ae855e1

Please sign in to comment.