Skip to content
Snippets Groups Projects
Commit 8ff7659f authored by Luke Simons's avatar Luke Simons
Browse files

Added get_mds_node_info.m and tcv_get_ids_dataset_description.m

parent a39c66b1
No related branches found
No related tags found
1 merge request!196Resolve "Add dataset_description IDS"
Pipeline #265708 passed
function [ids_dataset_description,ids_dataset_description_description] = ...
tcv_get_ids_dataset_description(shot, ids_dataset_description_empty, gdat_params,varargin)
%
% [ids_dataset_description,ids_dataset_description_description] = ...
% tcv_get_ids_dataset_description(shot, ids_dataset_description_empty,varargin);
%
% Get the TCV IMAS dataset_description data
%
% ids_dataset_description_empty should at least be the empty dataset_description ids structure
% in input
%
% gdat_params: gdat_data.gdat_params to get all params passed from original
% call, in particular error_bar options
%
% Date: 24/04/25
% Author: L. Simons
% Initialise structure with default ids_properties
% shot=70777; gdat_params=[]; varargin={};
% aa=gdat([],'ids','source','dataset_description'); ids_dataset_description_empty=aa.dataset_description;
if exist('gdat_params')
[ids_dataset_description, ~] = tcv_ids_headpart(shot, ids_dataset_description_empty, ...
'dataset_description','homogeneous_time',1,'gdat_params',gdat_params, ...
varargin{:});
else
[ids_dataset_description, ~] = tcv_ids_headpart(shot,ids_dataset_description_empty,'dataset_description','homogeneous_time',0,varargin{:});
end
ids_dataset_description_description = struct();
% homogenous_time=2 , only static and constant information
ids_dataset_description.ids_properties.homogeneous_time=2;
% Get username
username = getenv('USERNAME'); % Works on Windows
if isempty(username)
username = getenv('USER'); % Works on Unix/Linux/Mac
end
% Define uri
backend='mdsplus';
run=1;
imas_version_number=getenv('IMAS_VERSION');
version=num2str(imas_version_number(1));
uri = sprintf('imas:%s?user=%s;shot=%d;run=%d;database=%s;version=%s', ...
backend, username, shot, run, database,version);
ids_dataset_description.uri=uri;
% Define type
% FIXME: Not sure what the condition should be here... To be discussed
if strcmp(gdat_params.data_request,'ids')
ids_dataset_description.type.name='experimental';
ids_dataset_description.type.index=1;
ids_dataset_description.type.description='Data coming from an experiment';
else
ids_dataset_description.type.name='simulation';
ids_dataset_description.type.index=2;
ids_dataset_description.type.description='Data coming from a simulation';
end
% Define data_entry
ids_dataset_description.machine='tcv';
ids_dataset_description.pulse=shot;
% Attempt to fill information about pulse time
% FIXME: How to get pulse_time_end? Simply = pulse_time_begin + X seconds?
[pulse_time_begin,pulse_time_begin_epoch]= ...
get_mds_node_info('\VSYSTEM:TIMERS.VALUES',shot);
ids_dataset_description.pulse_time_begin=pulse_time_begin;
ids_dataset_description.pulse_time_begin_epoch.seconds=pulse_time_begin_epoch;
ids_dataset_description.pulse_time_begin_epoch.nanoseconds=pulse_time_begin_epoch.*1e9;
% ids_dataset_description.pulse_time_end_epoch.seconds=
% ids_dataset_description.pulse_time_end_epoch.nanoseconds=
% ids_dataset_description.pulse_processing_time_begin=node_time
%% Simulation metadata
% FIXME: How do we hope to get this information?
% ids_dataset_description.simulation.comment_before=?
% ids_dataset_description.simulation.comment_after=?
% ids_dataset_description.simulation.time_begin=?
% ids_dataset_description.simulation.time_step=?
% ids_dataset_description.simulation.time_end=?
% ids_dataset_description.simulation.time_restart=?
% ids_dataset_description.simulation.time_current=?
% ids_dataset_description.simulation.time_begun=?
% ids_dataset_description.simulation.time_ended=?
% ids_dataset_description.simulation.time_workflow=?
end
function [node_time, node_epoch_time, node_owner] = get_mds_node_info(node_str, shot)
%GET_MDS_NODE_INFO Retrieves insertion time and owner of a node in MDSplus
%
% [node_time, node_owner] = GET_MDS_NODE_INFO(node_str, shot)
% Inputs:
% node_str - String path to the MDSplus node
% (e.g. '\\RESULTS::CXRS_001:TI')
% shot - Shot number to open
%
% Outputs:
% node_time - Time the node data was inserted
% node_owner - (Optional) Owner info of the node
% Open the shot
mdsopen('tcv_shot',shot);
try
% Time inserted
tdi_time = sprintf('times(getnci("%s","TIME_INSERTED"))', node_str);
mds_node_time = mdsvalue(tdi_time);
% Convert the timestamp (returned as a string) to MATLAB datetime
dt = datetime(mds_node_time, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss.SSSSSS', 'TimeZone', 'UTC');
% Format it to ISO 8601 with Zulu (UTC) time
time_str = datestr(dt, 'yyyy-mm-ddTHH:MM:SS');
node_time = [time_str 'Z'];
% Convert to Unix Epoch time (seconds since Jan 1, 1970 UTC)
node_epoch_time = posixtime(datetime(mds_node_time, 'InputFormat', 'dd-MMM-yyyy HH:mm:ss.SSSSSS', 'TimeZone', 'UTC'));
% Owner
tdi_owner = sprintf('owner_ascii("%s")', node_str);
node_owner = mdsvalue(tdi_owner);
catch
warning('Failed to read time of node, returning empty strings..');
node_time='';
node_owner='';
mdsclose;
end
% Always close MDS connection
mdsclose;
end
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment