-
Notifications
You must be signed in to change notification settings - Fork 2
/
seaIceEmergeDLM_LogitTest.m
166 lines (122 loc) · 4.8 KB
/
seaIceEmergeDLM_LogitTest.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
close all
clear all
addpath(genpath('mcmcstat'))
addpath(genpath('dlmtbx'))
pathOut='assumptionCheckFigures';
SIdata='SIdata.nh.RCP85.mat';
load(SIdata)
splitStr=strsplit(SIdata, '.');
NI=size(nSIF_ensemble,1);
NJ=size(nSIF_ensemble,2);
NM=size(nSIF_ensemble,4);
NY=size(nSIF_ensemble,3);
NBY=size(nSIF_background1850,3);
BGmask=mean(nSIF_background1850,3);
landmask=BGmask<360;
nsam_run = 200;
nsimu_run = 1000;
%%
filename = '/Users/katherinebarnhart/git/cesmEnsembleSeaIce/assumptionCheckPoints.csv';
delimiter = ',';
startRow = 2;
% Format string for each line of text:
% column1: text (%s)
% column2: double (%f)
% column3: double (%f)
% For more information, see the TEXTSCAN documentation.
formatSpec = '%s%f%f%[^\n\r]';
% Open the text file.
fileID = fopen(filename,'r');
% Read columns of data according to format string.
% This call is based on the structure of the file used to generate this
% code. If an error occurs for a different file, try regenerating the code
% from the Import Tool.
dataArray = textscan(fileID, formatSpec, 'Delimiter', delimiter, 'HeaderLines' ,startRow-1, 'ReturnOnError', false);
% Close the text file.
fclose(fileID);
% Post processing for unimportable data.
% No unimportable data rules were applied during the import, so no post
% processing code is included. To generate code which works for
% unimportable data, select unimportable cells in a file and regenerate the
% script.
% Allocate imported array to column variable names
sitename = dataArray{:, 1};
nis = dataArray{:, 2};
njs = dataArray{:, 3};
% Clear temporary variables
clearvars filename delimiter startRow formatSpec fileID dataArray ans;
%%
numRuns=numel(nis);
year_out=zeros(numRuns, 5,2);
levelmean_out=zeros(numRuns, 2+numel(time_ensemble(72:end,:)),2);
levelstd_out=zeros(numRuns, 2+numel(time_ensemble(72:end,:)),2);
slopemean_out=zeros(numRuns, 2+numel(time_ensemble(72:end,:)),2);
slopestd_out=zeros(numRuns, 2+numel(time_ensemble(72:end,:)),2);
tic
for i=1:numRuns
nii = nis(i);
njj = njs(i);
if landmask(nii, njj)==1
try
site=sitename{i};
fprintf(site)
tic
time_ensemble_run=time_ensemble;
nsam=nsam_run;
nsimu=nsimu_run;
fprintf(['nii:',num2str(nii), ' njj: ', num2str(njj) ,'(', num2str(i), '/', num2str(numRuns), ')', '\n'])
BGdata=reshape(nSIF_background1850(nii,njj,:), [1,NBY]);
data=reshape(nSIF_ensemble(nii, njj, :,:), [NY, NM]);
close all
[shiftYearLogit, emergeYear2Logit, emergeYearLogit, levelmeanLogit, levelstdLogit, slopemeanLogit, slopestdLogit] = runDLM_logitTest( data(72:end,:), BGdata, time_ensemble_run(72:end), nsam, nsimu);
hfigs = get(0, 'children');
for m = 1:length(hfigs)
filename=[pathOut '/RegLogitTest.' site '.logit.' num2str(m) '.pdf']; %Bring Figure to foreground
if strcmp(filename, '0') %Skip figure when user types 0
continue
else
saveas(hfigs(m), [filename '.pdf']) %.pdf
end
end
close all
[shiftYear, emergeYear2, emergeYear, levelmean, levelstd, slopemean, slopestd] = runDLM( data(72:end,:), BGdata, time_ensemble_run(72:end), nsam, nsimu);
hfigs = get(0, 'children');
for m = 1:length(hfigs)
filename=[pathOut '/RegLogitTest.' site '.untransformed.' num2str(m) '.pdf']; %Bring Figure to foreground
if strcmp(filename, '0') %Skip figure when user types 0
continue
else
saveas(hfigs(m), [filename '.pdf']) %.pdf
end
end
toc
year_out(i,:,1)=[nii njj shiftYear emergeYear2 emergeYear];
levelmean_out(i,:,1)=[nii njj levelmean'];
levelstd_out(i,:,1)=[nii njj levelstd'];
slopemean_out(i,:,1)=[nii njj slopemean'];
slopestd_out(i,:,1)=[nii njj slopestd'];
year_out(i,:,2)=[nii njj shiftYearLogit emergeYear2Logit emergeYearLogit];
levelmean_out(i,:,2)=[nii njj levelmeanLogit'];
levelstd_out(i,:,2)=[nii njj levelstdLogit'];
slopemean_out(i,:,2)=[nii njj slopemeanLogit'];
slopestd_out(i,:,2)=[nii njj slopestdLogit'];
% save figures for each Location:
close all
catch
disp 'failed'
end
end
end
% compare year chosen:
figure()
hold on
plot(year_out(:,3,1)) % normal, shift
plot(year_out(:,3,2)) % logit transform, shift
plot(year_out(:,5,1)) % normal, emerge
plot(year_out(:,5,2)) % logit transform, emerge
h = gca;
h.XTick =1:numRuns;
h.XTickLabel = sitename;
h.XTickLabelRotation=90;
legend('shift', 'logit shift', 'emerge', 'logit emerge')
hold off