@@ -26,14 +26,16 @@ ENV_VAR_LIST=(
2626 processDSRA processPSRA
2727)
2828
29- ADD_DATA_PRINT_FUNCNAME=${ADD_DATA_PRINT_FUNCNAME:- true}
30- ADD_DATA_PRINT_LINENO=${ADD_DATA_PRINT_LINENO:- true}
31- ADD_DATA_REDUCE_DISK_USAGE=${ADD_DATA_REDUCE_DISK_USAGE:- true}
29+ : " ${ADD_DATA_PRINT_FUNCNAME:= true} "
30+ : " ${ADD_DATA_PRINT_LINENO:= true} "
31+ : " ${ADD_DATA_REDUCE_DISK_USAGE:= true} "
32+ : " ${ADD_DATA_DRY_RUN:= false} "
3233
33- DSRA_REPOSITORY=OpenDRR/earthquake-scenarios
34- DSRA_BRANCH=master
35- # DSRA_REPOSITORY=OpenDRR/DSRA-processing
36- # DSRA_BRANCH=six-new-scenarios-sep-2022
34+ : " ${PSRA_REPO:= OpenDRR/ seismic-risk-model} "
35+ : " ${PSRA_REPO_REF:= master} "
36+
37+ : " ${DSRA_REPO:= OpenDRR/ earthquake-scenarios} "
38+ : " ${DSRA_REPO_REF:= master} "
3739
3840PT_LIST=(AB BC MB NB NL NS NT NU ON PE QC SK YT)
3941# PT_LIST=(AB MB NB NL NS NT NU ON PE QC SK YT)
@@ -194,7 +196,7 @@ download_luts() {
194196 # on master branch, making into v1.1.0 release on 2023-09-12.
195197 # See https://github.com/OpenDRR/seismic-risk-model/pull/92
196198 RUN fetch_csv seismic-risk-model \
197- scripts/sourceTypes.csv? ref=master
199+ scripts/sourceTypes.csv${PSRA_REPO_REF : + ?ref=$PSRA_REPO_REF }
198200}
199201
200202# run_psql runs PostgreSQL queries from a given input SQL file.
@@ -298,12 +300,10 @@ fetch_psra_csv_from_model() {
298300 model=$1
299301
300302 for PT in " ${PT_LIST[@]} " ; do
301- RUN curl -H " Authorization: token ${GITHUB_TOKEN} " \
302- --retry-all-errors --retry-delay 5 --retry-max-time 0 --retry 360 \
303- -o " ${PT} .json" \
304- -L " https://api.github.com/repos/OpenDRR/seismic-risk-model/contents/$model /output/${PT} ?ref=master"
305-
306- RUN mapfile -t DOWNLOAD_LIST < <( jq -r ' .[].url | select(. | contains(".csv"))' " ${PT} .json" )
303+ RUN readarray -t DOWNLOAD_LIST < <( \
304+ gh api " repos/${PSRA_REPO} /contents/${model} /output/${PT}${PSRA_REPO_REF: +?ref=$PSRA_REPO_REF } " \
305+ -q ' .[].url | select(. | contains(".csv"))' \
306+ )
307307
308308 mkdir -p " $model /$PT "
309309 ( cd " $model /$PT "
@@ -322,8 +322,6 @@ fetch_psra_csv_from_model() {
322322 # (safe for cH_${PT}_hmaps_xref.csv)
323323 RUN sed -i -r $' 1{/^(\xEF\xBB\xBF )?#,/d}' " $FILENAME "
324324 done
325- # TODO: Use a different for ${PT}.json, and keep for debugging
326- RUN rm -f " ${PT} .json"
327325 )
328326 done
329327}
@@ -336,12 +334,10 @@ fetch_psra_csv_from_national_model() {
336334 model=$1
337335 PT=Canada
338336
339- RUN curl -H " Authorization: token ${GITHUB_TOKEN} " \
340- --retry-all-errors --retry-delay 5 --retry-max-time 0 --retry 360 \
341- -o " ${PT} .json" \
342- -L " https://api.github.com/repos/OpenDRR/seismic-risk-model/contents/$model /output/Canada?ref=master"
343-
344- RUN mapfile -t DOWNLOAD_LIST < <( jq -r ' .[].url | select(. | contains(".csv"))' " ${PT} .json" )
337+ RUN readarray -t DOWNLOAD_LIST < <( \
338+ gh api " repos/${PSRA_REPO} /contents/${model} /output/Canada${PSRA_REPO_REF: +?ref=$PSRA_REPO_REF } " \
339+ -q ' .[].url | select(. | contains(".csv"))' \
340+ )
345341
346342 mkdir -p " $model /$PT "
347343 ( cd " $model /$PT "
@@ -360,8 +356,6 @@ fetch_psra_csv_from_national_model() {
360356 # (safe for cH_${PT}_hmaps_xref.csv)
361357 RUN sed -i -r $' 1{/^(\xEF\xBB\xBF )?#,/d}' " $FILENAME "
362358 done
363- # TODO: Use a different for ${PT}.json, and keep for debugging
364- RUN rm -f " ${PT} .json"
365359 )
366360
367361}
@@ -494,7 +488,7 @@ get_git_lfs_pointers_of_csv_files() {
494488 RUN rm -rf " $base_dir "
495489 RUN mkdir -p " $base_dir "
496490 ( cd " $base_dir " && \
497- for repo in ${DSRA_REPOSITORY} OpenDRR/openquake-inputs OpenDRR/seismic-risk-model ; do
491+ for repo in " ${DSRA_REPO} " OpenDRR/openquake-inputs " ${PSRA_REPO} " ; do
498492 RUN git clone --filter=blob:none --no-checkout " https://${GITHUB_TOKEN} @github.com/${repo} .git"
499493 is_dry_run || \
500494 ( RUN cd " $( basename " $repo " ) " && \
@@ -565,14 +559,18 @@ import_exposure_ancillary_db() {
565559import_raw_psra_tables () {
566560 LOG " ## Importing Raw PSRA Tables"
567561
568- LOG " ### Get list of provinces & territories"
569- RUN curl -H " Authorization: token ${GITHUB_TOKEN} " \
570- --retry-all-errors --retry-delay 5 --retry-max-time 0 --retry 360 \
571- -o output.json \
572- -L https://api.github.com/repos/OpenDRR/seismic-risk-model/contents/eDamage/output? ref=master
573-
574- # TODO: Compare PT_LIST with FETCHED_PT_LIST
575- RUN mapfile -t FETCHED_PT_LIST < <( jq -r ' .[].name' output.json)
562+ LOG " ### Get list of provinces & territories from ${PSRA_REPO} "
563+ RUN readarray -t FETCHED_PT_LIST < <( \
564+ gh api " repos/${PSRA_REPO} /contents/eDamage/output${PSRA_REPO_REF: +?ref=$PSRA_REPO_REF } " \
565+ -q ' .[].name' \
566+ )
567+ if [[ " ${PT_LIST[*]} " == " ${FETCHED_PT_LIST[*]} " ]]; then
568+ LOG " PT_LIST and FETCHED_PT_LIST are equal: (${PT_LIST[*]} )"
569+ else
570+ WARN " PT_LIST and FETCHED_PT_LIST differ:"
571+ WARN " Want: (${PT_LIST[*]} )"
572+ WARN " Got : (${FETCHED_PT_LIST[*]} )"
573+ fi
576574
577575 # Disable cDamage. As @wkhchow noted in commit 922c409:
578576 # change cDamage reference to eDamage (cDamage will be removed eventually)
@@ -712,22 +710,19 @@ post_process_psra_tables() {
712710
713711import_earthquake_scenarios () {
714712 LOG " ## Get list of earthquake scenarios"
715- RUN curl -H " Authorization: token ${GITHUB_TOKEN} " \
716- --retry-all-errors --retry-delay 5 --retry-max-time 0 --retry 360 \
717- -o FINISHED.json \
718- -L https://api.github.com/repos/${DSRA_REPOSITORY} /contents/FINISHED? ref=${DSRA_BRANCH}
713+ gh api " repos/${DSRA_REPO} /contents/FINISHED${DSRA_REPO_REF: +?ref=$DSRA_REPO_REF } " > FINISHED.json
719714
720715 # s_lossesbyasset_ACM6p5_Beaufort_r1_299_b.csv → ACM6p5_Beaufort
721- RUN mapfile -t EQSCENARIO_LIST < <( jq -r ' .[].name | scan("(?<=s_lossesbyasset_).*(?=_r1)")' FINISHED.json)
716+ RUN readarray -t EQSCENARIO_LIST < <( jq -r ' .[].name | scan("(?<=s_lossesbyasset_).*(?=_r1)")' FINISHED.json)
722717
723718 # s_lossesbyasset_ACM6p5_Beaufort_r1_299_b.csv → ACM6p5_Beaufort_r1_299_b.csv
724- RUN mapfile -t EQSCENARIO_LIST_LONGFORM < <( jq -r ' .[].name | scan("(?<=s_lossesbyasset_).*r1.*\\.csv")' FINISHED.json)
719+ RUN readarray -t EQSCENARIO_LIST_LONGFORM < <( jq -r ' .[].name | scan("(?<=s_lossesbyasset_).*r1.*\\.csv")' FINISHED.json)
725720
726721 LOG " ## Importing scenario outputs into PostGIS"
727722 for eqscenario in " ${EQSCENARIO_LIST[@]} " ; do
728723 RUN python3 DSRA_outputs2postgres_lfs.py \
729- --dsraRepo=${DSRA_REPOSITORY} \
730- --dsraRepoBranch=${DSRA_BRANCH} \
724+ --dsraRepo=" ${DSRA_REPO} " \
725+ --dsraRepoBranch=" ${DSRA_REPO_REF} " \
731726 --columnsINI=DSRA_outputs2postgres.ini \
732727 --eqScenario=" $eqscenario "
733728 done
@@ -736,14 +731,14 @@ import_earthquake_scenarios() {
736731import_shakemap () {
737732 LOG " ## Importing Shakemap"
738733 # Make a list of Shakemaps in the repo and download the raw csv files
739- mapfile -t DOWNLOAD_URL_LIST < <( jq -r ' .[].url | scan(".*s_shakemap_.*(?<!MMI)\\.csv")' FINISHED.json)
734+ readarray -t DOWNLOAD_URL_LIST < <( jq -r ' .[].url | scan(".*s_shakemap_.*(?<!MMI)\\.csv")' FINISHED.json)
740735 for shakemap in " ${DOWNLOAD_URL_LIST[@]} " ; do
741736 # Get the shakemap
742737 shakemap_filename=$( echo " $shakemap " | cut -f9- -d/ | cut -f1 -d? )
743738 RUN curl -H " Authorization: token ${GITHUB_TOKEN} " \
744739 --retry-all-errors --retry-delay 5 --retry-max-time 0 --retry 360 \
745740 -o " $shakemap_filename " \
746- -L " ${shakemap} ?ref=${DSRA_BRANCH } "
741+ -L " ${shakemap}${DSRA_REPO_REF : + ?ref=$DSRA_REPO_REF } "
747742 is_dry_run || DOWNLOAD_URL=$( jq -r ' .download_url' " $shakemap_filename " )
748743 LOG " $DOWNLOAD_URL "
749744 RUN curl -o " $shakemap_filename " \
@@ -755,7 +750,7 @@ import_shakemap() {
755750 done
756751
757752 # Run Create_table_shakemap_update.sql or Create_table_shakemap_update_ste.sql
758- RUN mapfile -t SHAKEMAP_LIST < <( jq -r ' .[].name | scan("s_shakemap_.*\\.csv")' FINISHED.json)
753+ RUN readarray -t SHAKEMAP_LIST < <( jq -r ' .[].name | scan("s_shakemap_.*\\.csv")' FINISHED.json)
759754 for (( i= 0 ;i< ${# EQSCENARIO_LIST_LONGFORM[@]} ;i++ )) ; do
760755 item=${EQSCENARIO_LIST_LONGFORM[i]}
761756 # echo ${EQSCENARIO_LIST_LONGFORM[i]}
@@ -781,8 +776,8 @@ import_shakemap() {
781776import_rupture_model () {
782777LOG " ## Importing Rupture Model"
783778RUN python3 DSRA_ruptures2postgres.py \
784- --dsraRuptureRepo=${DSRA_REPOSITORY} \
785- --dsraRuptureBranch=${DSRA_BRANCH}
779+ --dsraRuptureRepo=" ${DSRA_REPO} " \
780+ --dsraRuptureBranch=" ${DSRA_REPO_REF} "
786781
787782LOG " ## Generating indicator views"
788783 for item in " ${EQSCENARIO_LIST_LONGFORM[@]} " ; do
0 commit comments