Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
D
dseries
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dynare
dseries
Commits
5436f91f
Verified
Commit
5436f91f
authored
5 months ago
by
Stéphane Adjemian
Browse files
Options
Downloads
Patches
Plain Diff
Fix compatibility issue with R2018b.
Methods or functions cannot be indexed using {} or . indexing.
parent
181bb997
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#11018
passed
5 months ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/utilities/convert/dseriesA2Q.m
+103
-88
103 additions, 88 deletions
src/utilities/convert/dseriesA2Q.m
with
103 additions
and
88 deletions
src/utilities/convert/dseriesA2Q.m
+
103
−
88
View file @
5436f91f
...
...
@@ -26,110 +26,125 @@ function ts = dseriesA2Q(ds, method)
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if
~
isequal
(
ds
.
freq
,
1
)
error
(
'Conversion only allowed for annual data!'
)
end
dQ
=
dates
(
4
,
[
ds
.
dates
.
year
(
1
)
1
]):
dates
(
4
,
[
ds
.
dates
.
year
(
end
)
4
]);
tdata
=
NaN
(
dQ
.
ndat
,
ds
.
vobs
);
switch
method
case
'equal-per-quarter'
counter
=
1
;
for
i
=
1
:
4
:
dQ
.
ndat
tdata
(
i
:
i
+
3
,:)
=
repmat
(
ds
.
data
(
counter
,:),
[
4
,
1
]);
counter
=
counter
+
1
;
if
~
isequal
(
ds
.
freq
,
1
)
error
(
'Conversion only allowed for annual data!'
)
end
case
'cubic-spline'
for
i
=
1
:
length
(
ds
.
name
)
dAO
=
firstobservedperiod
(
ds
{
ds
.
name
{
i
}})
.
year
(
1
):
lastobservedperiod
(
ds
{
ds
.
name
{
i
}})
.
year
(
1
);
ids
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
1
),
1
);
ide
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
end
),
1
,
'last'
);
qPoints
=
dAO
(
1
):
0.25
:
dAO
(
end
);
tdata
(
ids
+
3
:
ide
,
i
)
=
spline
(
dAO
,
ds
{
ds
.
name
{
i
}}
.
data
,
qPoints
);
% First three datapoints are set to NaN
dQ
=
dates
(
4
,
[
ds
.
dates
.
year
(
1
)
1
]):
dates
(
4
,
[
ds
.
dates
.
year
(
end
)
4
]);
tdata
=
NaN
(
dQ
.
ndat
,
ds
.
vobs
);
switch
method
case
'equal-per-quarter'
counter
=
1
;
for
i
=
1
:
4
:
dQ
.
ndat
tdata
(
i
:
i
+
3
,:)
=
repmat
(
ds
.
data
(
counter
,:),
[
4
,
1
]);
counter
=
counter
+
1
;
end
case
'cubic-spline'
for
i
=
1
:
length
(
ds
.
name
)
dAO
=
get_periods
();
ids
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
1
),
1
);
ide
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
end
),
1
,
'last'
);
qPoints
=
dAO
(
1
):
0.25
:
dAO
(
end
);
tdata
(
ids
+
3
:
ide
,
i
)
=
spline
(
dAO
,
ds
{
ds
.
name
{
i
}}
.
data
,
qPoints
);
% First three datapoints are set to NaN
end
case
'spline-sum'
for
i
=
1
:
length
(
ds
.
name
)
dAO
=
get_periods
();
ids
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
1
),
1
);
ide
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
end
),
1
,
'last'
);
% Normalise the x point to start from 0
dAOTmp
=
dAO
-
(
dAO
(
1
));
dAO
=
[
dAOTmp
dAOTmp
(
end
)
+
[
1
2
]];
qPoints
=
dAO
(
1
):
0.25
:
dAO
(
end
);
% Create cumsum of the data with initial point set to 0
dI
=
[
0
;
cumsum
([
ds
{
ds
.
name
{
i
}}
.
data
;
ds
{
ds
.
name
{
i
}}
.
data
(
end
)])];
% Compute spline
dO
=
spline
(
dAO
,
dI
,
qPoints
)
'
;
% Compute first difference to get flow values
dOF
=
dO
(
2
:
end
)
-
dO
(
1
:
end
-
1
);
% Construct the final data
tdata
(:,
i
)
=
dOF
(
ids
:
ide
);
end
otherwise
error
(
'Unknow method.'
)
end
case
'spline-sum'
for
i
=
1
:
length
(
ds
.
name
)
dAO
=
firstobservedperiod
(
ds
{
ds
.
name
{
i
}})
.
year
(
1
):
lastobservedperiod
(
ds
{
ds
.
name
{
i
}})
.
year
(
1
);
ids
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
1
),
1
);
ide
=
find
(
dQ
.
year
(:,
1
)
==
dAO
(
end
),
1
,
'last'
);
% Normalise the x point to start from 0
dAOTmp
=
dAO
-
(
dAO
(
1
));
dAO
=
[
dAOTmp
dAOTmp
(
end
)
+
[
1
2
]];
qPoints
=
dAO
(
1
):
0.25
:
dAO
(
end
);
% Create cumsum of the data with initial point set to 0
dI
=
[
0
;
cumsum
([
ds
{
ds
.
name
{
i
}}
.
data
;
ds
{
ds
.
name
{
i
}}
.
data
(
end
)])];
% Compute spline
dO
=
spline
(
dAO
,
dI
,
qPoints
)
'
;
% Compute first difference to get flow values
dOF
=
dO
(
2
:
end
)
-
dO
(
1
:
end
-
1
);
% Construct the final data
tdata
(:,
i
)
=
dOF
(
ids
:
ide
);
ts
=
dseries
(
tdata
,
dQ
,
ds
.
name
,
ds
.
tex
);
function
dAO
=
get_periods
()
t1
=
firstobservedperiod
(
ds
{
ds
.
name
{
i
}});
t2
=
lastobservedperiod
(
ds
{
ds
.
name
{
i
}});
dAO
=
t1
.
year
(
1
):
t2
.
year
(
1
);
% TODO: Alternatively we could do the same in one line:
%
% dAO = firstobservedperiod(ds{ds.name{i}}).year(1):lastobservedperiod(ds{ds.name{i}}).year(1);
%
% but this does not work with R2018b. It works with R2021a, I could not test with R2019 and R2020.
% Should be tested if we decide to bump the Matlab version required.
end
otherwise
error
(
'Unknow method.'
)
end
ts
=
dseries
(
tdata
,
dQ
,
ds
.
name
,
ds
.
tex
);
return
% --*-- Unit tests --*--
return
% --*-- Unit tests --*--
%@test:1
ds
=
dseries
(
randn
(
10
,
2
),
'2000Y'
);
%@test:1
ds
=
dseries
(
randn
(
10
,
2
),
'2000Y'
);
try
ts
=
dseriesA2Q
(
ds
,
'equal-per-quarter'
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
try
ts
=
dseriesA2Q
(
ds
,
'equal-per-quarter'
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
ts
.
vobs
==
2
;
t
(
3
)
=
ts
.
nobs
==
40
;
t
(
4
)
=
ts
.
dates
(
1
)
==
dates
(
'2000Q1'
);
end
if
t
(
1
)
t
(
2
)
=
ts
.
vobs
==
2
;
t
(
3
)
=
ts
.
nobs
==
40
;
t
(
4
)
=
ts
.
dates
(
1
)
==
dates
(
'2000Q1'
);
end
T
=
all
(
t
);
%@eof:1
T
=
all
(
t
);
%@eof:1
%@test:2
ds
=
dseries
(
randn
(
10
,
2
),
'2000Y'
);
%@test:2
ds
=
dseries
(
randn
(
10
,
2
),
'2000Y'
);
try
ts
=
dseriesA2Q
(
ds
,
'cubic-spline'
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
try
ts
=
dseriesA2Q
(
ds
,
'cubic-spline'
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
ts
.
vobs
==
2
;
t
(
3
)
=
ts
.
nobs
==
40
;
t
(
4
)
=
ts
.
dates
(
1
)
==
dates
(
'2000Q1'
);
end
if
t
(
1
)
t
(
2
)
=
ts
.
vobs
==
2
;
t
(
3
)
=
ts
.
nobs
==
40
;
t
(
4
)
=
ts
.
dates
(
1
)
==
dates
(
'2000Q1'
);
end
T
=
all
(
t
);
%@eof:2
T
=
all
(
t
);
%@eof:2
%@test:3
ds
=
dseries
(
randn
(
10
,
2
),
'2000Y'
);
%@test:3
ds
=
dseries
(
randn
(
10
,
2
),
'2000Y'
);
try
ts
=
dseriesA2Q
(
ds
,
'spline-sum'
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
try
ts
=
dseriesA2Q
(
ds
,
'spline-sum'
);
t
(
1
)
=
true
;
catch
t
(
1
)
=
false
;
end
if
t
(
1
)
t
(
2
)
=
ts
.
vobs
==
2
;
t
(
3
)
=
ts
.
nobs
==
40
;
t
(
4
)
=
ts
.
dates
(
1
)
==
dates
(
'2000Q1'
);
end
if
t
(
1
)
t
(
2
)
=
ts
.
vobs
==
2
;
t
(
3
)
=
ts
.
nobs
==
40
;
t
(
4
)
=
ts
.
dates
(
1
)
==
dates
(
'2000Q1'
);
end
T
=
all
(
t
);
%@eof:3
T
=
all
(
t
);
%@eof:3
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment