-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
239 lines (193 loc) · 7.63 KB
/
install.sh
File metadata and controls
239 lines (193 loc) · 7.63 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/bash
# ============================================================================
# ERA5 Parallel Downloader - Installation Script
# ============================================================================
#
# This script sets up the ERA5 downloader in your system
#
# Usage:
# bash install.sh
#
# ============================================================================
set -e # Exit on any error
echo "============================================================================"
echo "ERA5 Parallel Downloader - Installation"
echo "============================================================================"
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# ----------------------------------------------------------------------------
# Step 1: Check Python version
# ----------------------------------------------------------------------------
echo -e "${BLUE}[1/6]${NC} Checking Python version..."
if ! command -v python3 &> /dev/null; then
echo -e "${RED}✗${NC} Python 3 not found. Please install Python 3.8 or higher."
exit 1
fi
PYTHON_VERSION=$(python3 -c 'import sys; print(".".join(map(str, sys.version_info[:2])))')
echo -e "${GREEN}✓${NC} Found Python ${PYTHON_VERSION}"
# Check if version is 3.8 or higher
MAJOR=$(echo $PYTHON_VERSION | cut -d. -f1)
MINOR=$(echo $PYTHON_VERSION | cut -d. -f2)
if [ "$MAJOR" -lt 3 ] || ([ "$MAJOR" -eq 3 ] && [ "$MINOR" -lt 8 ]); then
echo -e "${RED}✗${NC} Python 3.8+ required (found ${PYTHON_VERSION})"
exit 1
fi
# ----------------------------------------------------------------------------
# Step 2: Create directory structure
# ----------------------------------------------------------------------------
echo -e "${BLUE}[2/6]${NC} Setting up directory structure..."
TARGET_DIR="/DATA/datasets/era5"
# Check if directory exists
if [ -d "$TARGET_DIR" ]; then
echo -e "${YELLOW}⚠${NC} Directory already exists: $TARGET_DIR"
read -p " Continue and use existing directory? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo " Installation cancelled."
exit 1
fi
else
echo " Creating: $TARGET_DIR"
mkdir -p "$TARGET_DIR"
fi
# Create subdirectories
mkdir -p "$TARGET_DIR/pressure_levels"
mkdir -p "$TARGET_DIR/single_levels"
mkdir -p "$TARGET_DIR/logs"
mkdir -p "$TARGET_DIR/temp"
echo -e "${GREEN}✓${NC} Directory structure created"
# ----------------------------------------------------------------------------
# Step 3: Install Python dependencies
# ----------------------------------------------------------------------------
echo -e "${BLUE}[3/6]${NC} Installing Python dependencies..."
# Check if pip is available
if ! command -v pip3 &> /dev/null; then
echo -e "${RED}✗${NC} pip3 not found. Please install pip."
exit 1
fi
echo " Installing required packages..."
# Install core dependencies
pip3 install --user cdsapi pyyaml
# Install optional dependencies if available
echo " Installing optional packages (for enhanced features)..."
pip3 install --user tqdm colorlog 2>/dev/null || echo " (Some optional packages skipped)"
echo -e "${GREEN}✓${NC} Dependencies installed"
# ----------------------------------------------------------------------------
# Step 4: Copy files to target directory
# ----------------------------------------------------------------------------
echo -e "${BLUE}[4/6]${NC} Installing ERA5 downloader files..."
# Get script directory
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
# Copy main scripts
cp "$SCRIPT_DIR/era5_downloader.py" "$TARGET_DIR/"
cp "$SCRIPT_DIR/validate_config.py" "$TARGET_DIR/"
# Copy configuration files
cp "$SCRIPT_DIR/config_wrf.yaml" "$TARGET_DIR/"
cp "$SCRIPT_DIR/config_surface_only.yaml" "$TARGET_DIR/"
cp "$SCRIPT_DIR/config_year_2025.yaml" "$TARGET_DIR/"
# Copy documentation
cp "$SCRIPT_DIR/README.txt" "$TARGET_DIR/"
cp "$SCRIPT_DIR/requirements.txt" "$TARGET_DIR/"
# Copy SLURM script if on HPC
if command -v sbatch &> /dev/null; then
cp "$SCRIPT_DIR/slurm_download_era5.sh" "$TARGET_DIR/"
chmod +x "$TARGET_DIR/slurm_download_era5.sh"
echo -e "${GREEN}✓${NC} SLURM job script installed"
fi
# Make scripts executable
chmod +x "$TARGET_DIR/era5_downloader.py"
chmod +x "$TARGET_DIR/validate_config.py"
echo -e "${GREEN}✓${NC} Files installed to $TARGET_DIR"
# ----------------------------------------------------------------------------
# Step 5: Check CDS API setup
# ----------------------------------------------------------------------------
echo -e "${BLUE}[5/6]${NC} Checking CDS API configuration..."
CDSAPIRC="$HOME/.cdsapirc"
if [ -f "$CDSAPIRC" ]; then
echo -e "${GREEN}✓${NC} Found CDS API configuration: $CDSAPIRC"
# Test connection
echo " Testing CDS API connection..."
if python3 -c "import cdsapi; cdsapi.Client()" 2>/dev/null; then
echo -e "${GREEN}✓${NC} CDS API connection successful"
else
echo -e "${YELLOW}⚠${NC} CDS API connection failed - check your credentials"
fi
else
echo -e "${YELLOW}⚠${NC} CDS API not configured"
echo ""
echo " To set up CDS API:"
echo " 1. Register at: https://cds.climate.copernicus.eu/"
echo " 2. Get your API key from: https://cds.climate.copernicus.eu/user"
echo " 3. Create $CDSAPIRC with:"
echo ""
echo " url: https://cds.climate.copernicus.eu/api"
echo " key: YOUR_UID:YOUR_API_KEY"
echo ""
echo " 4. Set permissions: chmod 600 $CDSAPIRC"
echo ""
fi
# ----------------------------------------------------------------------------
# Step 6: Validate installation
# ----------------------------------------------------------------------------
echo -e "${BLUE}[6/6]${NC} Validating installation..."
cd "$TARGET_DIR"
# Test if scripts are executable
if [ -x "era5_downloader.py" ] && [ -x "validate_config.py" ]; then
echo -e "${GREEN}✓${NC} Scripts are executable"
else
echo -e "${RED}✗${NC} Scripts are not executable"
exit 1
fi
# Test if configurations are readable
if [ -r "config_wrf.yaml" ]; then
echo -e "${GREEN}✓${NC} Configuration files are readable"
else
echo -e "${RED}✗${NC} Configuration files not found"
exit 1
fi
# Test dry run
echo " Testing dry run..."
if python3 era5_downloader.py -c config_wrf.yaml --dry-run > /dev/null 2>&1; then
echo -e "${GREEN}✓${NC} Dry run successful"
else
echo -e "${YELLOW}⚠${NC} Dry run test failed (may be due to CDS API setup)"
fi
# ----------------------------------------------------------------------------
# Installation complete
# ----------------------------------------------------------------------------
echo ""
echo "============================================================================"
echo -e "${GREEN}Installation Complete!${NC}"
echo "============================================================================"
echo ""
echo "Installation directory: $TARGET_DIR"
echo ""
echo "📋 Next Steps:"
echo ""
echo "1. Review and edit configuration:"
echo " cd $TARGET_DIR"
echo " nano config_wrf.yaml"
echo ""
echo "2. Validate your configuration:"
echo " python3 validate_config.py config_wrf.yaml"
echo ""
echo "3. Start downloading:"
echo " python3 era5_downloader.py -c config_wrf.yaml"
echo ""
echo "4. For full year 2025:"
echo " python3 era5_downloader.py -c config_year_2025.yaml"
echo ""
# Print SLURM instructions if applicable
if command -v sbatch &> /dev/null; then
echo "5. For HPC/SLURM systems:"
echo " sbatch slurm_download_era5.sh config_wrf.yaml"
echo ""
fi
echo "📚 Documentation: $TARGET_DIR/README.txt"
echo ""
echo "============================================================================"