Skip to content

Commit

Permalink
added OECM
Browse files Browse the repository at this point in the history
  • Loading branch information
ebenetce committed Oct 23, 2024
1 parent 6298ba5 commit 5b0c559
Show file tree
Hide file tree
Showing 8 changed files with 274 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info>
<Category UUID="FileClassCategory">
<Label UUID="design"/>
</Category>
</Info>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<Info location="OECMconnection.m" type="File"/>
16 changes: 14 additions & 2 deletions tbx/IAMDataExplorer/+iam/+data/BANKOFCANADAconnection.m
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
obj.IA = ia;

rl.run_id = ones(height(rl),1);
myRuns = configureDictionary('string','double');
current = 0;
for i = 1 : height(rl)
if isKey(myRuns, rl.CL_SCENARIO(i))
rl.run_id(i) = myRuns(rl.CL_SCENARIO(i));
else
current = current + 1;
myRuns(rl.CL_SCENARIO(i)) = current;
rl.run_id(i) = current;
end
end

rl.unit = data_raw{ia, "CL_UNIT"};

rl.model = repmat("CL", height(rl), 1);
Expand Down Expand Up @@ -164,12 +176,12 @@
end

function runs = getRunsList(obj)
runs = obj.TimeseriesList;
runs = unique(obj.TimeseriesList(:,{'scenario', 'model','run_id'}), 'stable', 'rows');
end

function value = getDocumentation(~, ~, ~)

value = struct('description','Please visit the <a href="https://www.bankofcanada.ca/2022/01/climate-transition-scenario-data/" target="_blank">official LIMITS Website</a> for details ');
value = struct('description','Please visit the <a href="https://www.bankofcanada.ca/2022/01/climate-transition-scenario-data/" target="_blank">official Bank of Canada Website</a> for details ');

end

Expand Down
250 changes: 250 additions & 0 deletions tbx/IAMDataExplorer/+iam/+data/OECMconnection.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
classdef OECMconnection < iam.data.Connection

% Copyright 2021-2022 The MathWorks, Inc.

properties (Dependent)
Environment
end

properties (SetAccess = private)
Url (1,1) string
TimeseriesList
end

properties (Access = private)
RawData
IA
IC
YEARS
end

properties (SetAccess = private)
Config struct = struct( ...
'name', "OECM", 'env', "boc",'productName', "OECM", ...
'database', "OECM", "welcome", "Welcome to the One Earth Climate Model");

ConnectionProperties
end

properties (Constant, Access = private)
ENVIRONMENT = "OECM";
end

properties
AllEnvironments
end

methods

function obj = OECMconnection(url)

arguments
url (1,1) string = "https://www.uts.edu.au/sites/default/files/2022-05/"
end

obj.Url = url;

try
globalR = obj.Url + "/OECM_Global_2022_04_22_Results_All_CSV.xlsx";
opts = detectImportOptions(globalR, Range = 'A2', ReadVariableNames = true, TextType = 'string', VariableNamingRule='preserve');
opts = opts.setvaropts("Remarks", "Type","string");
data_raw = readtable(globalR,opts);
data_raw.REGION = repmat("GLOBAL", height(data_raw),1);

data_rawEurope = readtable(obj.Url + "OECM_OECD_Europe_2022_04_22_Results_All_CSV.xlsx", opts);
data_rawEurope.REGION = repmat("EUROPE", height(data_rawEurope),1);

data_rawNA = readtable(obj.Url + "OECM_OECD_North_America_2022_04_22_Results_All_CSV.xlsx", opts);
data_rawNA.REGION = repmat("North America", height(data_rawNA),1);

data_raw = [data_raw; data_rawEurope; data_rawNA];
catch e
error('iam:data:OECMconnection:UnableToGetData', "Unable to get the raw data." + e.message)
end

data_raw.MODEL = repmat("OECM", height(data_raw),1);
idx = ismissing(data_raw.Sector);
data_raw.Sector(idx) = data_raw.Sector(find(idx)-1);
data_raw.VARIABLE = data_raw.Sector + "|" + data_raw.Subsector + "|" + data_raw.Description;
data_raw.SCENARIO = data_raw.Label;
idx = data_raw.SCENARIO == "IEA WEO 21";
data_raw.MODEL(idx) = "IEA";
idx = ismissing(data_raw.SCENARIO);
data_raw.SCENARIO(idx) = "TOTAL";
data_raw.Description = strtrim(data_raw.Description) + " " + strtrim(data_raw.Remarks);
data_raw.UNIT = data_raw.Unit;
data_raw.Unit = [];
data_raw.Sector = [];
data_raw.Subsector = [];
data_raw.Index = [];
data_raw.Label = [];
data_raw.run_id = ones(height(data_raw),1);
myRuns = configureDictionary('string','double');
current = 0;
for i = 1 : height(data_raw)
if isKey(myRuns, data_raw.MODEL(i) + data_raw.SCENARIO(i))
data_raw.run_id(i) = myRuns(data_raw.MODEL(i) + data_raw.SCENARIO(i));
else
current = current + 1;
myRuns(data_raw.MODEL(i) + data_raw.SCENARIO(i)) = current;
data_raw.run_id(i) = current;
end
end

% data_raw = movevars(data_raw, ["MODEL", "SCENARIO", "VARIABLE", "run_id", "UNIT"])

% data_raw.VARIABLE = string(data_raw.CL_VARIABLE ) + "|" + string(data_raw.CL_SECTOR );
% data_raw.CL_GEOGRAPHY = string(data_raw.CL_GEOGRAPHY);
% data_raw.CL_SCENARIO = string(data_raw.CL_SCENARIO);
% data_raw.CL_UNIT = string(data_raw.CL_UNIT);
% data_raw.CL_SECTOR = string(data_raw.CL_SECTOR);

obj.RawData = data_raw;

data_raw = data_raw(:, ["MODEL", "SCENARIO", "REGION", "VARIABLE", "run_id", "UNIT"]);

[data_raw,ia,ic] = unique(data_raw(:,["MODEL", "SCENARIO", "REGION", "VARIABLE", 'run_id', 'UNIT' ]), 'stable', 'rows');

obj.IC = ic;
obj.IA = ia;
%
% data_raw.run_id = ones(height(data_raw),1);
% data_raw.unit = data_raw{ia, "CL_UNIT"};

% data_raw.model = repmat("CL", height(data_raw), 1);

obj.TimeseriesList = data_raw;
obj.TimeseriesList.Properties.VariableNames = {'model', 'scenario', 'region', 'variable', 'run_id', 'unit'};
end

function ts = getBulkData(obj, varargin)

p = inputParser();

func = @(x) isstring(x) | ischar(x);
addParameter(p, 'models', '', func)
addParameter(p, 'scenarios', '', func)
addParameter(p, 'runs', [], @isnumeric)
addParameter(p, 'variables', '', func)
addParameter(p, 'regions', '', func)
addParameter(p, 'years', '', func)
addParameter(p, 'units', '', func)
addParameter(p, 'timeslices', '', func)

parse(p, varargin{:});

idx = true(height(obj.TimeseriesList), 1);
if ~isempty(p.Results.models)
idx = idx & ismember(obj.TimeseriesList.model, p.Results.models);
end

if ~isempty(p.Results.scenarios)
idx = idx & ismember(obj.TimeseriesList.scenario, p.Results.scenarios);
end

if ~isempty(p.Results.runs)
idx = idx & ismember(obj.TimeseriesList.run_id, p.Results.runs);
end

if ~isempty(p.Results.variables)
idx = idx & ismember(obj.TimeseriesList.variable, p.Results.variables);
end

if ~isempty(p.Results.regions)
idx = idx & ismember(obj.TimeseriesList.region, p.Results.regions);
end

idxA = find(idx);
tlist = obj.TimeseriesList(idx, :);

data = struct([]);
for num = 1 : numel(idxA)

idxC = ismember(obj.IC, idxA(num));
rawdata = obj.RawData(idxC, :);

valuesIdx = startsWith(rawdata.Properties.VariableNames, '2');

data(num).model = tlist.model(num);
data(num).scenario = tlist.scenario(num);
data(num).variable = tlist.variable(num);
data(num).region = tlist.region(num);
data(num).runId = tlist.run_id(num);
data(num).version = [];
data(num).unit = tlist.unit(num);
data(num).years = str2double(rawdata.Properties.VariableNames(valuesIdx));
data(num).values = timetable( datetime(data(num).years', 1,1), rawdata{:,valuesIdx}', DimensionNames = {'Year', 'Variables'});

end

ts = iam.IAMTimeseries(data);

end

function params = getRunDetails(obj, runId)
idx = obj.TimeseriesList.run_id == runId;
params = obj.TimeseriesList.variable(idx);
end

function refs = getRefs(obj)

models = obj.getAllModels;
ID = (1 : numel(models))';
Name = models;
refs.models = table(ID,Name);

scenarios = obj.getAllScenarios;
ID = (1 : numel(scenarios))';
Name = scenarios;
refs.scenarios = table(ID,Name);

vars = unique(obj.TimeseriesList.variable);
ID = (1 : numel(vars))';
Name = vars;
refs.variables = table(ID,Name);

reg = unique(obj.TimeseriesList.region);
ID = (1 : numel(reg))';
Name = reg;
refs.regions = table(ID,Name);

end

function runs = getRunsList(obj)
runs = unique(obj.TimeseriesList(:,{'scenario', 'model','run_id'}), 'stable', 'rows');
end

function value = getDocumentation(~, ~, ~)

value = struct('description','Please visit the <a href="https://www.bankofcanada.ca/2022/01/climate-transition-scenario-data/" target="_blank">official LIMITS Website</a> for details ');

end

end

methods
function value = get.Environment(obj)
value = obj.ENVIRONMENT;
end

function response = getAllModels(obj)
response = unique(obj.TimeseriesList.model);
end

function response = getAllScenarios(obj)
response = unique(obj.TimeseriesList.scenario);
end

function value = getEnvironments(obj)
productName = obj.Config.productName;
env = obj.Config.env;
uiUrl = obj.Url;
name = obj.Config.name;
scheme = "";

value = table(productName, env, uiUrl, name, scheme);
end

end

end
2 changes: 1 addition & 1 deletion tbx/IAMDataExplorer/+iam/@IAMTimeseries/IAMTimeseries.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@
function lst = getRunList(obj)
lst = table( ...
[obj.Model]',[obj.Scenario]',[obj.Variable]',[obj.Region]',[obj.RunId]',[obj.Version]', ...
'VariableNames',{'Model','Scenario','Variable','Region','RunId','Verison'}...
'VariableNames',{'Model','Scenario','Variable','Region','RunId','Version'}...
);
end

Expand Down
Binary file modified tbx/IAMDataExplorer/+iam/DataExplorer.mlapp
Binary file not shown.
Binary file modified tbx/IAMDataExplorer/app/IAMDataExplorer.mlapp
Binary file not shown.
2 changes: 1 addition & 1 deletion tests/tUserInterfaces.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function tGuestLogin(testCase)
function tBoC(testCase)
testCase.choose(testCase.App.BOCTab);
testCase.press(testCase.App.LoginButton_3)
h = findall(0,'Type','figure', 'Name','IAM Explorer');
h = findall(0,'Type','figure', 'Name','IAM Explorer');feature f
t = h.RunningAppInstance;
testCase.verifyNotEmpty(t);
testCase.verifyTrue(isvalid(h));
Expand Down

0 comments on commit 5b0c559

Please sign in to comment.