-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.sh
More file actions
184 lines (142 loc) Β· 4.99 KB
/
Copy pathsetup.sh
File metadata and controls
184 lines (142 loc) Β· 4.99 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
#!/bin/bash
# setup.sh - Pre-installation setup script for Streamlit Community Cloud
#
# This script runs before pip installs Python packages, ensuring the Linux
# environment is properly configured for scientific computing and astronomy.
#
# Streamlit Cloud executes this automatically when deploying the app.
set -e # Exit on any error
echo "π Setting up Astro-AI deployment environment..."
# ========================================
# ENVIRONMENT VARIABLES
# ========================================
# Configure scientific computing optimizations
export OPENBLAS_NUM_THREADS=1
export MKL_NUM_THREADS=1
export NUMEXPR_NUM_THREADS=1
# Set up Python optimizations
export PYTHONUNBUFFERED=1
export PYTHONDONTWRITEBYTECODE=1
# Configure matplotlib for headless operation (no GUI)
export MPLBACKEND=Agg
# ========================================
# SYSTEM PACKAGE VERIFICATION
# ========================================
echo "π¦ Verifying system packages installation..."
# Check critical libraries are available
if ! pkg-config --exists fftw3; then
echo "β οΈ Warning: FFTW3 not found - py21cmfast will not be available"
fi
if ! pkg-config --exists gsl; then
echo "β οΈ Warning: GSL not found - advanced simulations may be limited"
fi
if ! pkg-config --exists hdf5; then
echo "β οΈ Warning: HDF5 not found - some data formats may not be supported"
fi
# ========================================
# DIRECTORY SETUP
# ========================================
echo "π Creating application directories..."
# Create cache directories for astronomical data
mkdir -p ~/.astropy/cache
mkdir -p ~/.matplotlib/cache
# Create temporary directories for processing
mkdir -p /tmp/astro-ai-workspace
mkdir -p /tmp/astro-ai-plots
# ========================================
# PERMISSIONS & SECURITY
# ========================================
echo "π Setting up permissions..."
# Ensure cache directories are writable
chmod 755 ~/.astropy/cache
chmod 755 ~/.matplotlib/cache
# Set up secure temp directories
chmod 755 /tmp/astro-ai-workspace
chmod 755 /tmp/astro-ai-plots
# ========================================
# SCIENTIFIC LIBRARY CONFIGURATION
# ========================================
echo "βοΈ Configuring scientific libraries..."
# Configure NumPy/SciPy for optimized performance
cat > ~/.numpy-site.cfg << EOF
[DEFAULT]
library_dirs = /usr/lib/x86_64-linux-gnu
include_dirs = /usr/include
[openblas]
libraries = openblas
library_dirs = /usr/lib/x86_64-linux-gnu
include_dirs = /usr/include/openblas
[fftw]
libraries = fftw3
library_dirs = /usr/lib/x86_64-linux-gnu
include_dirs = /usr/include
EOF
# ========================================
# ASTRONOMICAL DATA SETUP
# ========================================
echo "π Setting up astronomical data environment..."
# Set astropy data download location (if needed)
export ASTROPY_CACHE_DIR=~/.astropy/cache
# Configure any FITS file optimizations
export FITS_CACHE_SIZE=128
# ========================================
# MEMORY & PERFORMANCE OPTIMIZATION
# ========================================
echo "πΎ Configuring memory optimizations..."
# Set memory-efficient defaults for scientific computing
export OMP_NUM_THREADS=1
export NUMBA_NUM_THREADS=1
export VECLIB_MAXIMUM_THREADS=1
# Configure garbage collection for large datasets
export PYTHONGC=1
# ========================================
# LOGGING CONFIGURATION
# ========================================
echo "π Setting up logging..."
# Configure application logging level
export ASTRO_AI_LOG_LEVEL=INFO
# Reduce verbose output from scientific libraries during startup
export ASTROPY_SILENCE_WARNINGS=1
# ========================================
# FINAL VERIFICATION
# ========================================
echo "β
Verifying setup completion..."
# Test Python is available
python3 --version
# Test critical libraries can be found
echo "π Checking library availability:"
ldconfig -p | grep -E "(fftw|gsl|hdf5|openblas)" || echo "Some optional libraries not found"
echo ""
echo "π― Astro-AI environment setup complete!"
echo " Platform: Linux (Streamlit Community Cloud)"
echo " Python: $(python3 --version)"
echo " Ready for pip package installation..."
echo ""
# ========================================
# NOTES FOR MAINTENANCE
# ========================================
#
# This script prepares the Linux environment for:
#
# 1. CORE SCIENTIFIC COMPUTING
# - NumPy/SciPy with optimized BLAS
# - Matplotlib in headless mode
# - Efficient memory usage
#
# 2. ASTRONOMICAL PACKAGES
# - Astropy with proper caching
# - FITS file support via CFITSIO
# - HDF5 data format support
#
# 3. OPTIONAL HEAVY PACKAGES
# - py21cmfast (if FFTW/GSL available)
# - JWST pipeline (if dependencies met)
# - Bagpipes SED fitting
#
# 4. PERFORMANCE OPTIMIZATION
# - Single-threaded operation (Cloud CPU limits)
# - Memory-efficient garbage collection
# - Reduced library verbosity
#
# The app will gracefully fall back to mock modes if heavy
# packages cannot be installed, ensuring reliability.