Skip to content

Commit 482e656

Browse files
authored
Merge pull request #4082 from slevis-lmwg/co2_wiemip_matlab_script
matlab script for appending WIEMIP co2 scenario data to TRENDY2025
2 parents 41381b0 + b87e031 commit 482e656

1 file changed

Lines changed: 48 additions & 0 deletions

File tree

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
% prep_co2_wiemip_files.m
2+
%
3+
% Reminder: MODIFY file_raw and file_wiemip below for each individual case
4+
%
5+
% Workflow:
6+
% - Before running this matlab script, I renamed the TRENDY2025 co2 file (fco2_datm_global_simyr_1700-2024_TRENDY_c250625.nc) to the name of the wiemip co2 file (used below)
7+
% - The script, extends CO2 and time vars in the file from 2024 (TRENDY2025) to 2300 (wiemip)
8+
% - and brings in wiemip co2 to the file
9+
% - After running the matlab script, I used nco to append to each file's history, for example:
10+
% ncatted -h -a history,global,o,c,"06/25/2025 21:30: converted by TRENDY2024_Data_Prep.ipynb; 06/04/2026: slevis used matlab script tools/contrib/prep_co2_wiemip_files.m to extend the co2 and time variables from 2024 to 2300 and to append the co2 from WIEMIP_hl_co2_ann_2024_2300.txt" WIEMIP_hl_co2_ann_2024_2300_copied_to_fco2_datm_global_simyr_1700-2024_TRENDY_c250625.nc
11+
%
12+
% More information appears in issues
13+
% github.com/ESCOMP/CTSM/issues/4072
14+
% github.com/ESCOMP/CTSM/issues/3936
15+
%
16+
% slevis 2026/06/03
17+
18+
clear
19+
20+
% get trendy CO2, time, time_bnds
21+
file_trendy = 'fco2_datm_global_simyr_1700-2024_TRENDY_c250625.nc';
22+
co2_trendy = ncread(file_trendy, 'CO2');
23+
time_trendy = ncread(file_trendy, 'time');
24+
time_bnds_trendy = ncread(file_trendy, 'time_bnds');
25+
26+
% extend CO2, time, time_bnds
27+
co2_wiemip = co2_trendy; % orig. to 2024
28+
time_wiemip = time_trendy; % orig. to 2024
29+
time_bnds_wiemip = time_bnds_trendy; % orig. to 2024
30+
for yr = 1:276 % out to 2300
31+
co2_wiemip(:,:,end+1) = co2_wiemip(:,:,end); % dims (lon, lat, time)
32+
time_wiemip(end+1) = time_wiemip(end) + 365; % dims (time)
33+
time_bnds_wiemip(:,end+1) = time_bnds_wiemip(:,end); % dims (bnds, time)
34+
end
35+
% Fix time_bnds preexisting glitch in 2021
36+
time_bnds_wiemip(:,322) = time_bnds_wiemip(:,321); % dims (bnds, time)
37+
38+
% get wiemip co2 for the years 2024-2300
39+
file_raw = '/glade/derecho/scratch/swensosc/WIEMIP/co2/WIEMIP_m_co2_ann_2024_2300.txt';
40+
co2 = readmatrix(file_raw);
41+
co2_wiemip(1,1,325:end) = squeeze(co2(:,2));
42+
43+
% write modified time, time_bnds, and CO2 to the renamed trendy file
44+
file_wiemip = 'WIEMIP_m_co2_ann_2024_2300_copied_to_fco2_datm_global_simyr_1700-2024_TRENDY_c250625.nc';
45+
ncwrite(file_wiemip, 'time', time_wiemip);
46+
ncwrite(file_wiemip, 'time_bnds', time_bnds_wiemip);
47+
ncwrite(file_wiemip, 'CO2', co2_wiemip);
48+

0 commit comments

Comments
 (0)