1 | #MSUB -r moistc_rmssp126 |
---|
2 | #MSUB -o moistc_rmssp126.out_%I |
---|
3 | #MSUB -e moistc_rmssp126.out_%I |
---|
4 | #MSUB -n 1 |
---|
5 | #MSUB -T 36000 |
---|
6 | #MSUB -q xlarge |
---|
7 | #MSUB -c 8 |
---|
8 | #MSUB -Q normal |
---|
9 | #MSUB -A gen0239 |
---|
10 | #MSUB -m store,work,scratch |
---|
11 | ##MSUB -A ls3cmip6 |
---|
12 | set -vx |
---|
13 | #!/bin/bash |
---|
14 | |
---|
15 | # Script to create nudging files for soil moisture climatology derived from 30 year running mean |
---|
16 | # This creates running mean climatology of the soil moisture with daily frequency, starting with |
---|
17 | # the historical siumlation and then using one scenario. |
---|
18 | # |
---|
19 | # 1. Daily output for the years 1980-2014 from the simulation CM61-LR-hist-03.1910 and for the years |
---|
20 | # 2015-210O from sceanario simulation CM61-LR-scen-ssp126 or CM61-LR-scen-585 are used |
---|
21 | # 2. The variable moistc is first splitted into moistc_1, moistc_2, moistc_3 to remove the axes on soiltiles. |
---|
22 | # 3. For years with 366 days, the 31 of decembre is removed to enable making the median over all years. |
---|
23 | # 4. For each year in the intervall 1994-2085, the median is calculated using 30years in total with the current year in the middle. |
---|
24 | # For the first 15 years 1980-1995: the median for the first 30years will be used => running median for year 1994 |
---|
25 | # For the last 15 years 2085-2100: the median for the last 30years will be used => running meadian for year 2085 |
---|
26 | # 5. For each year, the last day is duplicated to have 366 days in each file. |
---|
27 | # |
---|
28 | # $HeadURL$ |
---|
29 | # $Date$ |
---|
30 | # $Revision$ |
---|
31 | ####################################################################################################################### |
---|
32 | date |
---|
33 | JobName=CM61-LR-hist-03.1910 |
---|
34 | ssp=ssp126 |
---|
35 | #ssp=ssp585 |
---|
36 | JobNameScen=CM61-LR-scen-${ssp} |
---|
37 | mkdir run_moistc_rm_${JobName}_${JobNameScen} |
---|
38 | cd run_moistc_rm_${JobName}_${JobNameScen} |
---|
39 | |
---|
40 | echo Start |
---|
41 | # 1. historical r1: CM61-LR-hist-03.1910 |
---|
42 | simulpathHist=/ccc/store/cont003/gencmip6/p86caub/IGCM_OUT/IPSLCM6/PROD/historical/CM61-LR-hist-03.1910/SRF/Output/DA |
---|
43 | simulpathScen=/ccc/store/cont003/gencmip6/oboucher/IGCM_OUT/IPSLCM6/PROD/${ssp}/${JobNameScen}/SRF/Output/DA |
---|
44 | |
---|
45 | allpackHist=" 19800101_19891231 19900101_19991231 20000101_20091231 20100101_20141231 " |
---|
46 | allpackScen=" 20150101_20241231 20250101_20341231 20350101_20441231 20450101_20541231 20550101_20641231 20650101_20741231 20750101_20841231 20850101_20941231 20950101_21001231 " |
---|
47 | |
---|
48 | # 2. Extract moistc |
---|
49 | # First from historical simulation and then also from scenario simulation |
---|
50 | echo Extract variable moistc from packed files |
---|
51 | # float moistc(time_counter, soiltyp, solay, lat, lon) |
---|
52 | |
---|
53 | for pack in ${allpackHist} ; do |
---|
54 | echo Treat file ${simulpathHist}/${JobName}_${pack}_DA_sechiba_out_2.nc |
---|
55 | ncks -v moistc ${simulpathHist}/${JobName}_${pack}_DA_sechiba_out_2.nc moistc_${pack}_DA_sechiba_out_2.nc |
---|
56 | done |
---|
57 | |
---|
58 | for pack in ${allpackScen} ; do |
---|
59 | echo Treat file ${simulpathScen}/${JobNameScen}_${pack}_DA_sechiba_out_2.nc |
---|
60 | ncks -v moistc ${simulpathScen}/${JobNameScen}_${pack}_DA_sechiba_out_2.nc moistc_${pack}_DA_sechiba_out_2.nc |
---|
61 | done |
---|
62 | |
---|
63 | |
---|
64 | echo Separate into variables per soiltile, for historical and scenario |
---|
65 | for pack in ${allpackHist} ${allpackScen} ; do |
---|
66 | ncks -d soiltyp,0,0 moistc_${pack}_DA_sechiba_out_2.nc moistc1_${pack}_DA_sechiba_out_2.nc |
---|
67 | ncks -d soiltyp,1,1 moistc_${pack}_DA_sechiba_out_2.nc moistc2_${pack}_DA_sechiba_out_2.nc |
---|
68 | ncks -d soiltyp,2,2 moistc_${pack}_DA_sechiba_out_2.nc moistc3_${pack}_DA_sechiba_out_2.nc |
---|
69 | |
---|
70 | ncrename -v moistc,moistc_1 moistc1_${pack}_DA_sechiba_out_2.nc |
---|
71 | ncrename -v moistc,moistc_2 moistc2_${pack}_DA_sechiba_out_2.nc |
---|
72 | ncrename -v moistc,moistc_3 moistc3_${pack}_DA_sechiba_out_2.nc |
---|
73 | done |
---|
74 | |
---|
75 | |
---|
76 | echo "Remove dimension soiltyp (which is now 1) by averaging over the dimension. Put all variables in the same file." |
---|
77 | |
---|
78 | for pack in ${allpackHist} ${allpackScen} ; do |
---|
79 | for soiltyp in 1 2 3 ; do |
---|
80 | ncwa -A -a soiltyp moistc${soiltyp}_${pack}_DA_sechiba_out_2.nc moistc_allsoil_${pack}_DA_sechiba_out_2.nc |
---|
81 | done |
---|
82 | ncatted -a long_name,moistc_1,m,c,"Soil Moisture profile for soil tile 1" moistc_allsoil_${pack}_DA_sechiba_out_2.nc |
---|
83 | ncatted -a long_name,moistc_2,m,c,"Soil Moisture profile for soil tile 2" moistc_allsoil_${pack}_DA_sechiba_out_2.nc |
---|
84 | ncatted -a long_name,moistc_3,m,c,"Soil Moisture profile for soil tile 3" moistc_allsoil_${pack}_DA_sechiba_out_2.nc |
---|
85 | done |
---|
86 | |
---|
87 | echo "Separate per year" |
---|
88 | for pack in ${allpackHist} ${allpackScen} ; do |
---|
89 | cdo splityear moistc_allsoil_${pack}_DA_sechiba_out_2.nc moistc_ |
---|
90 | done |
---|
91 | |
---|
92 | |
---|
93 | # 3. Remove one time step in leap years |
---|
94 | echo "Remove last time step (31 of december) from leap years" |
---|
95 | allleap=" 1980 1984 1988 1992 1996 2000 2004 2008 2012 " |
---|
96 | allleapScen=" 2016 2020 2024 2028 2032 2036 2040 2044 2048 2052 2056 2060 2064 2068 2072 2076 2080 2084 2088 2092 2096 " |
---|
97 | for year in $allleap ${allleapScen} ; do |
---|
98 | mv moistc_${year}.nc moistc_${year}.leap.nc |
---|
99 | ncks -d time_counter,0,364 moistc_${year}.leap.nc moistc_${year}.365.nc |
---|
100 | cp moistc_${year}.365.nc moistc_${year}.nc |
---|
101 | done |
---|
102 | |
---|
103 | # 4. Calculate running median over 30 years |
---|
104 | echo "Calculate median" |
---|
105 | |
---|
106 | # For the first 15 years 1980-1995: take median for the first 30years => running median for year 1994 |
---|
107 | # For the last 15 years 2085-2100: take median for the last 30years => running meadian for year 2085 |
---|
108 | # For the years in between, take the median using 14 years before, the current year and 15 years after |
---|
109 | |
---|
110 | # Calculate here the running median for the years 1994-2085 |
---|
111 | year=1994 |
---|
112 | lastyear=2085 |
---|
113 | while [ ${year} -le ${lastyear} ] ; do |
---|
114 | echo year=${year} |
---|
115 | # Determine the list of files for 14 years before, the current year and 15 years after current year |
---|
116 | y1=$(( ${year} - 15 )) |
---|
117 | y2=$(( ${year} + 15 )) |
---|
118 | filelist="" |
---|
119 | while [ ${y1} -le ${y2} ] ; do |
---|
120 | filelist="$filelist moistc_${y1}.nc " |
---|
121 | let y1=${y1}+1 |
---|
122 | done |
---|
123 | echo for year=$year filelist= $filelist |
---|
124 | |
---|
125 | echo "Calculate median for year=$year using files: $filelist " |
---|
126 | cdo enspctl,50 $filelist moistc_30yrm_${year}.nc |
---|
127 | |
---|
128 | |
---|
129 | # 5. Duplicate last day to make a file with 366days |
---|
130 | echo "Duplicate last day to make a file with 366days" |
---|
131 | # Extract last day |
---|
132 | cdo seltimestep,365 moistc_30yrm_${year}.nc moistc_clim_365.nc |
---|
133 | # Switch time axis one day ahead |
---|
134 | ncatted -O -a units,time_counter,m,c,"seconds since 1850-01-02 00:00:00" moistc_clim_365.nc |
---|
135 | # Merge with clim file |
---|
136 | ncrcat moistc_30yrm_${year}.nc moistc_clim_365.nc moistc_30yrm_${year}.nc |
---|
137 | |
---|
138 | let year=${year}+1 |
---|
139 | done |
---|
140 | |
---|
141 | |
---|
142 | echo End |
---|
143 | |
---|