ec2_post_init
Populate STScI EC2 instances with ease
astroconda.inc.sh
Go to the documentation of this file.
1## @file
2## @brief Astroconda control functions
3## @details
4## @section astroconda_hst_example HST Example
5## @include pipeline/hst.sh
6##
7## @section astroconda_jwst_example JWST Example
8## @include pipeline/jwst.sh
9##
10## @section astroconda_data_analysis_example Data Analysis Example
11## @include pipeline/data_analysis.sh
12
13(( $EC2PINIT_ASTROCONDA_INCLUDED )) && return
14EC2PINIT_ASTROCONDA_INCLUDED=1
15source ec2pinit.inc.sh
16
17## URL to astroconda releases Git repository (or local file system)
18ac_releases_repo="https://github.com/astroconda/astroconda-releases"
19
20## Path where ec2pinit will store the astroconda releases repository
21ac_releases_path="$ec2pinit_tempdir/$(basename $ac_releases_repo)"
22
23
24## @fn ac_platform()
25## @brief Get astroconda platform string
26## @details The value returned is the platform suffix of a pipeline release
27## file name.
28## @retval platform if supported platform is detected
29## @retval "unknown" if platform is not supported
31 case $(sys_platform) in
32 Linux)
33 echo linux ;;
34 Win*)
35 echo windows ;;
36 Darwin)
37 echo macos ;;
38 *)
39 echo unknown ;;
40 esac
41}
42
43
44## @fn ac_releases_clone()
45## @brief Clone the astroconda-releases repository
46## @details The destination is $ec2pinit_tempdir
47## @see config.sh
49 if [ ! -d "$ac_releases_path" ]; then
50 io_info "ac_releases_clone: Cloning astroconda releases repository"
51 git clone $ac_releases_repo $ac_releases_path >&2
52 fi
53}
54
55
56## @fn ac_releases_pipeline_exists()
57## @brief Check if a named pipeline exists in astroconda-releases
58## @retval path if pipeline exists
59## @retval "" if pipeline does not exist
61 local pattern="$1"
62
64 find $ac_releases_path -maxdepth 1 -type d -name ''$pattern''
65}
66
67
68## @fn ac_releases_pipeline_release_exists()
69## @brief Check if a named release exists in a astroconda-releases pipeline
70## @param pipeline_name Pipeline name
71## @param pipeline_release Pipeline release name
72## @retval path if release exists
73## @retval "" if release does not exist
75 local pipeline_name="$1"
76 local pipeline_release="$2"
77 result=$(find "$(ac_releases_pipeline_exists $pipeline_name)" -maxdepth 1 -name ''$pipeline_release'')
78 if [ -n "$result" ]; then
79 readlink -f $result
80 fi
81}
82
83
84## @fn ac_releases_data_analysis()
85## @brief Get path to data analysis release file
86## @param series Pipeline release name
87## @retval latest_path if series is undefined
88## @retval path if series is found
90 local series="$1"
91 local pipeline="de"
92 if [ -z "$series" ]; then
93 # get implicit latest in the release series
94 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
95 -name ''latest-$(ac_platform)*.yml'' \
96 | sort -V | tail -n 1)
97 else
98 # get the latest release for the requested series
99 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
100 -wholename ''\*$series/latest-$(ac_platform).yml'' \
101 | sort -V | tail -n 1)
102 fi
103 if [ -n "$release" ]; then
104 readlink -f "$release"
105 fi
106}
107
108
109## @fn ac_releases_data_analysis_environ()
110## @brief Generate conda environment name
111## @param series Pipeline release name
112## @retval environment_name if series exists
113## @retval 1 if release cannot be found
115 local series="$1"
116 local filename=$(ac_releases_data_analysis "$series")
117 if [ -z "$filename" ]; then
118 return 1
119 fi
120 sed "s/-/_/g;s/_$(ac_platform).*//g" <<< $(basename $filename)
121}
122
123
124## @fn ac_releases_jwst()
125## @brief Get path to JWST pipeline release file(s)
126## @details JWST splits its installation into two files. This function returns
127## two strings separated by new lines.
128## @param series Pipeline release name
129## @retval latest_path if series is undefined
130## @retval paths if series is found
132 local series="$1"
133 local pipeline="jwstdp"
134 if [ -z "$series" ]; then
135 # get implicit latest in the release series
136 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
137 -name ''*.txt'' -and \( -not -name ''*macos*'' \) \
138 | sort -V | tail -n 2)
139 else
140 # get the latest release for the requested series
141 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
142 -wholename ''\*$series/*.txt'' -and \‍( -not -wholename ''\*$series/\*macos\*.txt'' \‍) \
143 | sort -V | tail -n 2)
144 fi
145 echo "$release"
146}
147
148
149## @fn ac_releases_jwst_environ()
150## @brief Generate conda environment name
151## @param series Pipeline release name
152## @retval environment_name if series exists
153## @retval 1 if release cannot be found
154ac_releases_jwst_environ() {
155 local series="$1"
156 local pipeline="jwstdp"
157 if [ -z "$series" ]; then
158 # get implicit latest in the release series
159 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
160 -maxdepth 1 \
161 -type d \
162 -not -wholename ''*/utils*'' \
163 | sort -V | tail -n 1)
164 else
165 # get the latest release for the requested series
166 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
167 -type d \
168 -wholename ''\*/$series'' \
169 | sort -V | tail -n 1)
170 fi
171 printf "JWSTDP_%s" $(basename $release)
172}
173
174
175## @fn ac_releases_hst()
176## @brief Get path to HST pipeline release file
177## @details HST provides a platform dependent YAML configuration
178## @param series Pipeline release name
179## @retval latest_path if series is undefined
180## @retval path if series is found
182 local series="$1"
183 local pipeline="caldp" # no one will ever use hstdp
184 if [ -z "$series" ]; then
185 # get implicit latest in the release series
186 release=$(find "$(ac_releases_pipeline_exists $pipeline)" \
187 -name ''latest-$(ac_platform)*.yml'' \
188 | sort -V | tail -n 1)
189 else
190 # get the latest release for the requested series
191 release=$(find -L "$(ac_releases_pipeline_exists $pipeline)" \
192 -wholename ''\*$series/latest-$(ac_platform).yml'' \
193 | sort -V | tail -n 1)
194 fi
195 if [ -n "$release" ]; then
196 readlink -f "$release"
197 fi
198}
199
200
201## @fn ac_releases_hst_environ()
202## @brief Generate conda environment name
203## @param series Pipeline release name
204## @retval environment_name if series exists
205## @retval 1 if release cannot be found
207 local series="$1"
208 local filename=$(ac_releases_hst "$series")
209 if [ -z "$filename" ]; then
210 return 1
211 fi
212 sed "s/_$(ac_platform).*//" <<< $(basename $filename)
213}
214
215
216## @fn ac_releases_install_hst()
217## @brief Install the HST pipeline
218## @param version pipeline release version
220 local version="$1"
221 if [ -z "$version" ]; then
222 io_error "ac_releases_install_hst: release version required"
223 return 1
224 fi
225 local release_file=$(ac_releases_hst $version)
226 local release_name=$(ac_releases_hst_environ $version)
227 io_info "ac_releases_install_hst: Creating $release_name environment"
228 conda env create -n $release_name --file $release_file
229}
230
231
232## @fn ac_releases_install_jwst()
233## @brief Install the JWST pipeline
234## @param version pipeline release version
236 local version="$1"
237 if [ -z "$version" ]; then
238 io_error "ac_releases_install_jwst: release version required" >&2
239 return 1
240 fi
241 release_file=($(ac_releases_jwst $version_jwst))
242 release_name=$(ac_releases_jwst_environ $version_jwst)
243 io_info "ac_releases_install_jwst: Creating $release_name environment"
244 conda create -n $release_name --file ${release_file[0]}
245 io_info "ac_releases_install_jwst: Activating $release_name environment"
246 conda activate $release_name
247 io_info "ac_releases_install_jwst: Installing dependencies: ${release_file[1]}"
248 python -m pip install -r ${release_file[1]}
249 conda deactivate
250}
251
252
253## @fn ac_releases_install_data_analysis()
254## @brief Install the data analysis pipeline
255## @param version pipeline release version
257 local version="$1"
258 if [ -z "$version" ]; then
259 io_error "ac_releases_install_data_analysis: release version required"
260 return 1
261 fi
262 local release_file=$(ac_releases_data_analysis $version)
263 local release_name=$(ac_releases_data_analysis_environ $version)
264 io_info "ac_releases_install_data_analysis: Creating $release_name environment"
265 conda env create -n $release_name --file $release_file
266}
io_info(...)
Print a message.
Definition: io.inc.sh:29
io_error(...)
Print an error message.
Definition: io.inc.sh:59
ac_releases_install_data_analysis(version)
Install the data analysis pipeline.
ac_releases_pipeline_release_exists(pipeline_name, pipeline_release)
Check if a named release exists in a astroconda-releases pipeline.
ac_releases_install_hst(version)
Install the HST pipeline.
ac_releases_jwst_environ(series)
Generate conda environment name.
ac_releases_pipeline_exists()
Check if a named pipeline exists in astroconda-releases.
ac_releases_hst(series)
Get path to HST pipeline release file.
ac_releases_data_analysis_environ(series)
Generate conda environment name.
ac_platform()
URL to astroconda releases Git repository (or local file system)
ac_releases_jwst(series)
Get path to JWST pipeline release file(s)
ac_releases_hst_environ(series)
Generate conda environment name.
ac_releases_clone()
Clone the astroconda-releases repository.
ac_releases_data_analysis(series)
Get path to data analysis release file.
ac_releases_install_jwst(version)
Install the JWST pipeline.
sys_platform()
Get system platform (Linux, Darwin, etc)
Definition: system.inc.sh:80