Skip to content

Commit

Permalink
changing matpyuda structured objects to use dictionaries instead of l…
Browse files Browse the repository at this point in the history
…ists for child objects. Also updating matpyuda tests
  • Loading branch information
Stephen Dixon authored and Stephen Dixon committed Aug 1, 2023
1 parent b49e0ff commit 4cc5f2a
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
end
end

// function get_images
// function get_images(obj, signal, source, options)

function result = geometry(obj, signal, source, options)
arguments
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function node = get_node_from_path(input_node, pathstr)
tokens = split(pathstr, "/");
try
node = input_node.children(tokens(1));
catch ME
throw(ME)
end

if length(tokens) > 1
try
node = get_node_from_tokens(node, tokens(2:end));
catch ME
throw(ME)
end
end
end

function node = get_node_from_tokens(input_node, tokens)
try
node = input_node.children(tokens(1));
catch ME
throw(ME)
end

if length(tokens) > 1
try
node = matpyuda.get_node_from_tokens(node, tokens(2:end));
catch ME
throw(ME)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,22 @@
continue
end
if isa(pyuda_object.(name), 'py.pyuda._structured.StructuredData')
s.(name) = matpyuda.get_structured_data2(pyuda_object.(name));
s.(name) = matpyuda.get_structured_data(pyuda_object.(name));
elseif isa(pyuda_object.(name), 'py.list') && isa(pyuda_object.(name){1}, 'py.pyuda._structured.StructuredData')
n_children = length(pyuda_object.(name));
s.(name) = dictionary;
for j = n_children:-1:1
pyuda_struct_list = pyuda_object.(name);
s.(name)(i) = matpyuda.get_structured_data2(pyuda_struct_list{i});
end
item = pyuda_object.(name){j}
if py.hasattr(item, "name")
key = string(item.name);
elseif py.hasattr(item, "label")
key = string(item.label);
elseif py.hasattr(item, "title")
key = string(item.title);
else
key = int2str(j);
end
s.(name)(key) = matpyuda.get_structured_data(item);
else
s.(name) = matpyuda.get_attribute_value(pyuda_object.(name));
end
Expand Down
62 changes: 43 additions & 19 deletions source/wrappers/matlab/pyuda_interface/TestMatpyudaMast.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,32 @@ function test_get_2d_double_signal(testCase)
client.set_property('get_meta', py.True);

data = client.get('ayc_ne', '27999');
% unimplemented
verifyFail(testCase);
assertClass(testCase, data, ?matpyuda.Signal);
verifyEqual(testCase, size(data.data), [89, 130]);
verifyEqual(testCase, length(data.dims), 2);
verifyEqual(testCase, length(data.dims(1).data), 89);
verifyEqual(testCase, length(data.dims(2).data), 130);
verifyEqual(testCase, size(data.errors), [89, 130]);

verifyEqual(testCase, data.label, "electron density");
verifyEqual(testCase, data.units, "m^-3");
verifyEqual(testCase, data.description, "");

assertClass(testCase, data.meta, ?struct);
verifyEqual(testCase, data.meta.exp_number, int32(27999));

end

%function test_get_1d_int_signal(testCase)
%
%end
function test_get_1d_int_signal(testCase)
client = matpyuda.Client();
client.port = 56565;
client.server= "uda2.mast.l";
client.set_property('get_meta', py.True);
data = client.get('EPM/OUTPUT/NUMERICALDETAILS/MAXIMUMITERATIONCOUNT', 45125);
verifyEqual(testCase, length(data.data), 30);
verifyEqual(testCase, data.data,int32([ 0, 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]));
end

%function test_get_2d_int_signal(testCase)
%
Expand All @@ -127,9 +146,11 @@ function test_get_structured(testCase)
client.server= "uda2.mast.l";
client.set_property('get_meta', py.True);

data = client.get('ane', '30420');
% unimplemented
verifyFail(testCase);
data = client.get('ane', '45125');
verifyEqual(testCase, data.children.numEntries, 3);
verifyEqual(testCase, length(data.children('density').data), 80000);
verifyEqual(testCase, length(data.children('CO2').data), 80000);
verifyEqual(testCase, length(data.children('HeNe').data), 80000);
end

function test_get_video(testCase)
Expand All @@ -138,13 +159,15 @@ function test_get_video(testCase)
client.server= "uda2.mast.l";
client.set_property('get_meta', py.True);
data = client.get("NEWIPX::read(shot=47125, ipxtag=rgb, last=0)","");
% unimplemented
verifyFail(testCase);
end

% FOLLOWING TESTS REQUIRE MastClient IMPLEMENTATION TO BE UNCOMMENTED IN MATPYUDA PYTOHN PACKAGE
% ... mast specific stuff eventually needs to move out of this main repo ...
verifyEqual(testCase, size(data.frames(1).k), [480, 640]);
verifyEqual(testCase, length(data.frame_times), 248);
verifyEqual(testCase, data.filter, "(Da/SS)/C-CXRS/He-CXRS");
end

%% FOLLOWING TESTS REQUIRE MastClient IMPLEMENTATION TO BE UNCOMMENTED IN MATPYUDA PYTOHN PACKAGE
%% ... mast specific stuff eventually needs to move out of this main repo ...
%
%function test_mast_client_constructor(testCase)
% try
% client = matpyuda.MastClient();
Expand All @@ -153,7 +176,7 @@ function test_get_video(testCase)
% verifyFail(testCase);
% end
%end

%
%function test_mast_list_signals(testCase)
% client = matpyuda.MastClient();
% client.port = 56565;
Expand All @@ -166,20 +189,21 @@ function test_get_video(testCase)
% verifyEqual(testCase, matlab_list(1).signal_name, string(python_list{1}.signal_name));
%
%end

%
%function test_mast_geometry_data(testCase)
% client = matpyuda.Client();
% client = matpyuda.MastClient();
% client.port = 56565;
% client.server= "uda2.mast.l";
% client.set_property('get_meta', py.True);
%
% data = client.geometry("/magnetics/fluxloops", "47699");
% % unimplemented
% verifyFail(testCase);
% node = matpyuda.get_node_from_path(data.data, "centrecolumn/f_c_a01/data/coordinate");
% verifyEqual(testCase, node.r, 0.2738, "AbsTol", 5e-5);
% verifyEqual(testCase, node.z, 1.2935, "AbsTol", 5e-5);
%end
%
%function test_mast_image_data(testCase)
% client = matpyuda.Client();
% client = matpyuda.MastClient();
% client.port = 56565;
% client.server= "uda2.mast.l";
% client.set_property('get_meta', py.True);
Expand Down

0 comments on commit 4cc5f2a

Please sign in to comment.