Skip to content
93 changes: 65 additions & 28 deletions examples/spectral_var/run_cmip7
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
# Add CMIP7 solar variability data (version 4.6) to the GA9 spectral files
# This script creates the following files:
# sp_sw_ga9_cmip7_picontrol_4_6
# sp_sw_ga9_cmip7_ref_mon_4_6
# sp_sw_ga9_cmip7_ref_day_4_6
# sp_sw_ga9_cmip7_scenario_mon_4_6
# sp_sw_ga9_cmip7_scenario_day_4_6

if [ ! $SOCRATES_DATA_DIR ] ; then
SOCRATES_DATA_DIR=.
Expand All @@ -14,34 +14,53 @@ CMIP7_DATA_DIR=${SOCRATES_DATA_DIR}/solarisheppa/cmip7
PICON_FILE='multiple_input4MIPs_solar_CMIP_SOLARIS-HEPPA-CMIP-4-6_gn.nc'
MONTH_FILE='multiple_input4MIPs_solar_CMIP_SOLARIS-HEPPA-CMIP-4-6_gn_185001-202312.nc'
DAILY_FILE='multiple_input4MIPs_solar_CMIP_SOLARIS-HEPPA-CMIP-4-6_gn_18500101-20231231.nc'
FUTURE_MONFILE='multiple_input4MIPs_solar_ScenarioMIP_SOLARIS-HEPPA-ScenarioMIP-4-6_gn_202201-229912.nc'
FUTURE_DAYFILE='multiple_input4MIPs_solar_ScenarioMIP_SOLARIS-HEPPA-ScenarioMIP-4-6_gn_20220101-22991231.nc'

# Download CMIP7 solar variability data
Comment thread
mo-jmanners marked this conversation as resolved.

function check_for_solaris_file () {
file_name="$1"
cloud_loc="$2"
extension="$3"
url_base="https://cloud.iaa.es/index.php/s"
# ret_file_name is the name of the file to be retrieved from SOLARIS website
if [[ "$extension" == "gz" ]]; then
ret_file_name="$file_name.$extension"
else
ret_file_name="$file_name"
fi

# if no file, then act.
if [[ ! -f $file_name ]]; then
# if the file that would be downloaded is absent, download it.
if [[ ! -f $ret_file_name ]]; then
echo "Downloading data from SOLARIS website"
echo " .... ${cloud_loc}/download/$ret_file_name"
wget $url_base/${cloud_loc}/download/$ret_file_name
fi
# if the file that has been downloaded is zipped, unzip it.
if [[ "$extension" == "gz" ]]; then
echo "Gunzipping local data"
gunzip -c $ret_file_name > $file_name
rm $ret_file_name
fi
fi
}

if [[ -r $CMIP7_DATA_DIR ]]; then
echo "Gunzipping data from $CMIP7_DATA_DIR"
gunzip -c ${CMIP7_DATA_DIR}/${PICON_FILE}.gz > ${PICON_FILE}
gunzip -c ${CMIP7_DATA_DIR}/${MONTH_FILE}.gz > ${MONTH_FILE}
gunzip -c ${CMIP7_DATA_DIR}/${DAILY_FILE}.gz > ${DAILY_FILE}
FUTURE_MONFILE=${CMIP7_DATA_DIR}/${FUTURE_MONFILE}
FUTURE_DAYFILE=${CMIP7_DATA_DIR}/${FUTURE_DAYFILE}
else
for i in $(seq 1 3); do
if [[ $i == 1 ]]; then
SOLARIS_FILE=$PICON_FILE
CLOUD_LOC='XaSb85EpGNYqkEw'
elif [[ $i == 2 ]]; then
SOLARIS_FILE=$MONTH_FILE
CLOUD_LOC='n7cacmRBjk5Gb8f'
else
SOLARIS_FILE=$DAILY_FILE
CLOUD_LOC='nJFTPcnFwZ3smTo'
fi
if [[ ! -f $SOLARIS_FILE ]]; then
if [[ ! -f $SOLARIS_FILE.gz ]]; then
echo 'Downloading data from SOLARIS website'
wget https://cloud.iaa.es/index.php/s/${CLOUD_LOC}/download/$SOLARIS_FILE.gz
fi
echo "Gunzipping local data"
gunzip -c $SOLARIS_FILE.gz > $SOLARIS_FILE
fi
done
check_for_solaris_file $PICON_FILE 'XaSb85EpGNYqkEw' "gz"
check_for_solaris_file $MONTH_FILE 'n7cacmRBjk5Gb8f' "gz"
check_for_solaris_file $DAILY_FILE 'nJFTPcnFwZ3smTo' "gz"
check_for_solaris_file $FUTURE_MONFILE 'QWorEALDriYabgN' ""
check_for_solaris_file $FUTURE_DAYFILE 'j7ncYwoHXCtRwRE' ""
fi

echo 'Checking files are at vn4.6'
Expand All @@ -52,12 +71,22 @@ if [[ $PICON_VN != 'source_version = "4.6"' ]]; then
fi
MONTH_VN=`ncdump -h $MONTH_FILE | grep -o 'source_version = ".*"'`
if [[ $MONTH_VN != 'source_version = "4.6"' ]]; then
echo 'Monthly data is not at version 4.6: '$MONTH_VN
echo 'Monthly historical data is not at version 4.6: '$MONTH_VN
exit 1
fi
DAILY_VN=`ncdump -h $DAILY_FILE | grep -o 'source_version = ".*"'`
if [[ $DAILY_VN != 'source_version = "4.6"' ]]; then
echo 'Daily data is not at version 4.6: '$DAILY_VN
echo 'Daily historical data is not at version 4.6: '$DAILY_VN
exit 1
fi
FUTURE_MON_VN=`ncdump -h $FUTURE_MONFILE | grep -o 'source_version = ".*"'`
if [[ $FUTURE_MON_VN != 'source_version = "4.6"' ]]; then
echo 'Monthly future scenario data is not at version 4.6: '$FUTURE_MON_VN
exit 1
fi
FUTURE_DAY_VN=`ncdump -h $FUTURE_DAYFILE | grep -o 'source_version = ".*"'`
if [[ $FUTURE_DAY_VN != 'source_version = "4.6"' ]]; then
echo 'Daily future scenario data is not at version 4.6: '$FUTURE_DAY_VN
exit 1
fi

Expand All @@ -82,7 +111,7 @@ EOF
mv sp_sw_ga9_var sp_sw_ga9_cmip7_picontrol_4_6
rm $PICON_FILE

echo 'Adding monthly solar reference scenario data to spectral file'
echo 'Adding monthly solar reference & future scenario data to spectral file'
prep_spec << EOF > ref_mon.log
Comment thread
r-sharp marked this conversation as resolved.
sp_sw_ga9
a
Expand All @@ -92,14 +121,18 @@ y
-2
6
$MONTH_FILE
3312
6
$FUTURE_MONFILE
2024 1 1
0
0
-1
EOF
mv sp_sw_ga9_var sp_sw_ga9_cmip7_ref_mon_4_6
mv sp_sw_ga9_var sp_sw_ga9_cmip7_scenario_mon_4_6
rm $MONTH_FILE

echo 'Adding daily solar reference scenario data to spectral file'
echo 'Adding daily solar reference & future scenario data to spectral file'
prep_spec << EOF > ref_day.log
sp_sw_ga9
a
Expand All @@ -109,11 +142,15 @@ y
-2
6
$DAILY_FILE
100807
6
$FUTURE_DAYFILE
2024 1 1
0
0
-1
EOF
mv sp_sw_ga9_var sp_sw_ga9_cmip7_ref_day_4_6
mv sp_sw_ga9_var sp_sw_ga9_cmip7_scenario_day_4_6
rm $DAILY_FILE

exit 0