source: TOOLS/CMIP6_FORCING/SOLAR/process.sh @ 3390

Last change on this file since 3390 was 3390, checked in by oboucher, 5 years ago

small change to script to create OUTPUT directory

  • Property svn:executable set to *
File size: 7.1 KB
Line 
1#--this is a script that does it all
2
3dirout="OUTPUT"
4if [ ! -d "$dirout" ]; then
5mkdir $dirout
6fi
7
8#--first clean up things
9rm -f solarforcing_picontrol_fx_3.1_SSI_regridded_2_TSI_anomaly.nc
10rm -f solarforcing_picontrol_fx_3.1_SSI_regridded_6_TSI_anomaly.nc
11rm -f solarforcing_ref_day_3.1_SSI_regridded_2_TSI_anomaly.nc
12rm -f solarforcing_ref_day_3.1_SSI_regridded_6_TSI_anomaly.nc
13rm -f solarforcing_ext_day_3.1_SSI_regridded_2_TSI_anomaly.nc
14rm -f solarforcing_ext_day_3.1_SSI_regridded_6_TSI_anomaly.nc
15
16#--run matlab script for piControl
17matlab -r "run  CMIP6_piControl_2bands.m, quit"
18matlab -r "run  CMIP6_piControl_6bands.m, quit"
19
20#--run matlab script for Historical and Future
21matlab -r "run  CMIP6_historical_2bands.m, quit"
22matlab -r "run  CMIP6_historical_6bands.m, quit"
23
24#--run matlab script for Future Sensitivity
25matlab -r "run  CMIP6_sensitivity_2bands.m, quit"
26matlab -r "run  CMIP6_sensitivity_6bands.m, quit"
27
28output=${dirout}"/Control"
29if [ ! -d "$output" ]; then
30mkdir $output
31fi
32
33#--as computed by CMIP6 for piControl
34filein2bands=./solarforcing_picontrol_fx_3.1_SSI_regridded_2_TSI_anomaly.nc
35filein6bands=./solarforcing_picontrol_fx_3.1_SSI_regridded_6_TSI_anomaly.nc
36
37cdo duplicate,360 $filein2bands ${output}/solarforcing_v3.1_piControl_ave_2bands_360days.nc
38cdo duplicate,360 $filein6bands ${output}/solarforcing_v3.1_piControl_ave_6bands_360days.nc
39cdo duplicate,365 $filein2bands ${output}/solarforcing_v3.1_piControl_ave_2bands_365days.nc
40cdo duplicate,365 $filein6bands ${output}/solarforcing_v3.1_piControl_ave_6bands_365days.nc
41cdo duplicate,366 $filein2bands ${output}/solarforcing_v3.1_piControl_ave_2bands_366days.nc
42cdo duplicate,366 $filein6bands ${output}/solarforcing_v3.1_piControl_ave_6bands_366days.nc
43
44#--now the same duplication but to match Gregorian calendar
45outputG=${dirout}"/ControlGregorian"
46if [ ! -d "$outputG" ]; then
47mkdir $outputG
48fi
49
50for year in {1850..2500}
51do
52nbdays=`python -c "import calendar ; print 366 if calendar.isleap(${year}) else 365"`
53rm -f ${outputG}/solarforcing_v3.1_piControl_ave_2bands_${year}.nc
54rm -f ${outputG}/solarforcing_v3.1_piControl_ave_6bands_${year}.nc
55ln -s ../Control/solarforcing_v3.1_piControl_ave_2bands_${nbdays}days.nc ${outputG}/solarforcing_v3.1_piControl_ave_2bands_${year}.nc
56ln -s ../Control/solarforcing_v3.1_piControl_ave_6bands_${nbdays}days.nc ${outputG}/solarforcing_v3.1_piControl_ave_6bands_${year}.nc
57done
58
59rm -f ${filein2bands} ${filein6bands}
60
61#--present-day average for unofficial CMIP6 pdControl_ave
62
63filein2bands=./solarforcing_ref_day_3.1_SSI_regridded_2_TSI_anomaly.nc
64filein6bands=./solarforcing_ref_day_3.1_SSI_regridded_6_TSI_anomaly.nc
65
66#year1=1995
67#year2=2004
68year1=1991
69year2=2010
70start_time=`python -c "from datetime import date; print (date($year1,1,1)-date(1850,1,1)).days+1"`
71end_time=`python -c "from datetime import date; print (date($year2,12,31)-date(1850,1,1)).days"`
72echo $year1 $year2 $start_time $end_time
73
74fileout2bands=solarforcing_ref_day_3.1_SSI_regridded_2_TSI_anomaly_${year1}-${year2}.nc
75fileout6bands=solarforcing_ref_day_3.1_SSI_regridded_6_TSI_anomaly_${year1}-${year2}.nc
76
77#--somewhat dirty average as in principle ssi_frac should be weighted by tsi !
78#--note that seltimestep starts with 1
79cdo timmean -seltimestep,$start_time,$end_time $filein2bands $fileout2bands
80cdo timmean -seltimestep,$start_time,$end_time $filein6bands $fileout6bands
81
82#--duplicate 360 365 or 366 values for annual file
83cdo duplicate,360 $fileout2bands ${output}/solarforcing_v3.1_pdControl_ave_2bands_360days.nc
84cdo duplicate,360 $fileout6bands ${output}/solarforcing_v3.1_pdControl_ave_6bands_360days.nc
85cdo duplicate,365 $fileout2bands ${output}/solarforcing_v3.1_pdControl_ave_2bands_365days.nc
86cdo duplicate,365 $fileout6bands ${output}/solarforcing_v3.1_pdControl_ave_6bands_365days.nc
87cdo duplicate,366 $fileout2bands ${output}/solarforcing_v3.1_pdControl_ave_2bands_366days.nc
88cdo duplicate,366 $fileout6bands ${output}/solarforcing_v3.1_pdControl_ave_6bands_366days.nc
89
90#--now the same duplication but to match Gregorian calendar
91for year in {1850..2500}
92do
93nbdays=`python -c "import calendar ; print 366 if calendar.isleap(${year}) else 365"`
94rm -f ${outputG}/solarforcing_v3.1_pdControl_ave_2bands_${year}.nc
95rm -f ${outputG}/solarforcing_v3.1_pdControl_ave_6bands_${year}.nc
96ln -s ../Control/solarforcing_v3.1_pdControl_ave_2bands_${nbdays}days.nc ${outputG}/solarforcing_v3.1_pdControl_ave_2bands_${year}.nc
97ln -s ../Control/solarforcing_v3.1_pdControl_ave_6bands_${nbdays}days.nc ${outputG}/solarforcing_v3.1_pdControl_ave_6bands_${year}.nc
98done
99
100rm -f $fileout2bands $fileout6bands
101
102#--split files for historical
103filein2bands=./solarforcing_ref_day_3.1_SSI_regridded_2_TSI_anomaly.nc
104filein6bands=./solarforcing_ref_day_3.1_SSI_regridded_6_TSI_anomaly.nc
105
106output=${dirout}"/Historical"
107if [ ! -d "$output" ]; then
108mkdir $output
109fi
110
111#--note that the time axis starts from 0 with ncks.... so I put -1 here
112end_time=-1
113
114for year in {1850..2014}
115do
116yearp1=$((year+1))
117nbday=`python -c "from datetime import date; print (date($yearp1,1,1)-date($year,1,1)).days"`
118start_time=$((end_time+1))
119end_time=$((start_time+nbday-1))
120echo $year $yearp1 $start_time $end_time
121rm -f ${output}/solarforcing_v3.1_daily_2bands_${year}.nc
122rm -f ${output}/solarforcing_v3.1_daily_6bands_${year}.nc
123ncks -d time,$start_time,$end_time $filein2bands ${output}/solarforcing_v3.1_daily_2bands_${year}.nc
124ncks -d time,$start_time,$end_time $filein6bands ${output}/solarforcing_v3.1_daily_6bands_${year}.nc
125done 
126
127#--split files for Future
128output=${dirout}"/Future"
129if [ ! -d "$output" ]; then
130mkdir $output
131fi
132
133for year in {2015..2299}
134do
135yearp1=$((year+1))
136nbday=`python -c "from datetime import date; print (date($yearp1,1,1)-date($year,1,1)).days"`
137start_time=$((end_time+1))
138end_time=$((start_time+nbday-1))
139echo $year $yearp1 $start_time $end_time
140rm -f ${output}/solarforcing_v3.1_daily_2bands_${year}.nc
141rm -f ${output}/solarforcing_v3.1_daily_6bands_${year}.nc
142ncks -d time,$start_time,$end_time $filein2bands ${output}/solarforcing_v3.1_daily_2bands_${year}.nc
143ncks -d time,$start_time,$end_time $filein6bands ${output}/solarforcing_v3.1_daily_6bands_${year}.nc
144done
145
146rm -f $filein2bands $filein6bands
147
148#--split files for Future Sensitivity
149filein2bands=./solarforcing_ext_day_3.1_SSI_regridded_2_TSI_anomaly.nc
150filein6bands=./solarforcing_ext_day_3.1_SSI_regridded_6_TSI_anomaly.nc
151
152output=${dirout}"/FutureSensitivity"
153if [ ! -d "$output" ]; then
154mkdir $output
155fi
156
157#--reinitialising end_time to 31/12/2014
158end_time=`python -c "from datetime import date; print (date(2014,12,31)-date(1850,1,1)).days"`
159
160for year in {2015..2299}
161do
162yearp1=$((year+1))
163nbday=`python -c "from datetime import date; print (date($yearp1,1,1)-date($year,1,1)).days"`
164start_time=$((end_time+1))
165end_time=$((start_time+nbday-1))
166echo $year $yearp1 $start_time $end_time
167rm -f ${output}/solarforcing_v3.1_daily_2bands_${year}.nc
168rm -f ${output}/solarforcing_v3.1_daily_6bands_${year}.nc
169ncks -d time,$start_time,$end_time $filein2bands ${output}/solarforcing_v3.1_daily_2bands_${year}.nc
170ncks -d time,$start_time,$end_time $filein6bands ${output}/solarforcing_v3.1_daily_6bands_${year}.nc
171done
172
173rm -f $filein2bands $filein6bands
Note: See TracBrowser for help on using the repository browser.