lib/PDL/IO/Dcm/Plugins/MRSSiemens.pm

filter: Statementstmt 8.7% 25 / 286 Branchbran 0.0% 0 / 66 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 36.8% 7 / 19 Podpod 100% 11 / 11 totaltotal 10.5% 43 / 407 CC 48 SCAR 57.2
CC
48
Cov
7%
init_dims
702.0
fill_data
132.0
populate_header
30.0
CRAP 303.9
↑ Summary lib/PDL/IO/Dcm/Plugins/MRISiemens.pm »
1 package PDL::IO::Dcm::Plugins::MRSSiemens;
2 #use base 'PDL::IO::Dcm';
3 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use PDL;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use List::Util qw/first/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 #use PDL::NiceSlice;
7 2 ▶use Storable qw/dclone/;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use 5.10.0;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11  
12 2 our @ISA=qw/Exporter/;
13 2 our @EXPORT_OK=qw/read_dcm init_dims populate_header setup_dcm/;
14  
15 2 my @key_list=(qw/Instance Number/, 'Instance Creation Time');
16 2 my @key_list_csa=('EchoNumbers','CoilId','MixingTime','ImageNumber',qw/MultistepIndex AbsTablePosition Actual3DImaPartNumber BandwidthPerPixelPhaseEncode EchoColumnPosition EchoLinePosition EchoPartitionPosition EchoTime InversionTime MiscSequenceParam MultistepIndex PixelBandwidth ProtocolSliceNumber Sed SliceLocation SpectroscopyAcquisitionOut-of-planePhaseSteps TriggerTime t_puls_max/);
17  
18 0 ▶sub setup_dcm {
Subroutine setup_dcm: not called CC=1 SCAR=6.9
Pod documented
19 0 my $opt=shift;
20 0 require PDL::IO::Dcm::Plugins::MRISiemens;
21 # we don't need to duplicate code here.
22 0 my $plugin = 'MRSSiemens';
23 0 $opt=PDL::IO::Dcm::Plugins::MRISiemens::setup_dcm($opt,$plugin);
24 # split on series number by default
25 #$$opt{id}=\&PDL::IO::Dcm::sort_series;
26 0 $$opt{$plugin}->{parser}=\&populate_header;
27 0 $$opt{$plugin}->{key_list}=\@key_list;
28 0 $$opt{$plugin}->{key_list_csa}=\@key_list_csa;
29 0 push @PDL::IO::Dcm::key_list,'0051,100f';
30 #say join ' ',%{$opt};
31 0 $$opt{$plugin}->{Dimensions}=[qw/c fid x y z Channel Echo T/];
32 # if ($$opt{c_phase_t} ) {
33 # if ($$opt{c_phase_set} ) {
34 # $$opt{$plugin}->{Dimensions}=[qw/c fid x y z=partitions*slices T*Set*Phases Echo Channel/];
35 # } else {
36 # $$opt{$plugin}->{Dimensions}=[qw/c fid x y z=partitions*slices T*Phases Echo Channel Set/];
37 # }
38 # }else {
39 # if ($$opt{c_phase_set} ) {
40 # $$opt{$plugin}->{Dimensions}=[qw/c fid x y z=partitions*slices T Echo Channel Set*Phase/];
41 # } else {
42 # $$opt{$plugin}->{Dimensions}=[qw/c fid x y z=partitions*slices T Echo Channel Phase Set /];
43 # }
44 # }
45 0 $$opt{$plugin}->{internal_dims}=[ qw/c fid x y z echo coil t / ];
46 0 $$opt{$plugin}->{dim_order}=byte [0,1,2];
47 # ???? Not sure which dims should be clumped in MRS, let's comment that for the moment
48 0 $$opt{$plugin}->{clump_dims}=[];
49 #push (@{$$opt{clump_dims}},[4,5]) if $$opt{c_phase_set};
50 #push (@{$$opt{clump_dims}},[1,4]) if $$opt{c_phase_t};
51 0 $$opt{$plugin}->{create_data} = \&create_data;
52 0 $$opt{$plugin}->{fill_data} = \&fill_data;
53 0 $$opt{$plugin}->{image_parser} = \&parser;
54 0 $$opt{$plugin}->{init_dims} = \&init_dims;
55 0 $$opt{$plugin}->{read_dcm} = \&read_dcm;
56 0 $opt;
57 }
58  
59  
60 0 ▶sub read_dcm {
Subroutine read_dcm: not called CC=1 SCAR=6.9
Pod documented
61 0 my $dcm=shift;
62 0 my $opt=shift;
63 0 my $pdl=shift;
64 0 $pdl.=pdl(unpack('f*',substr($dcm->getValue ('7fe1,1010','native'),3))); # spectrum
65 0 $pdl->hdr->{plugin}="MRSSiemens";
66 #$pdl->hdr->{raw_dicom}=$dcm->getDicomField;
67 #delete $pdl->hdr->{raw_dicom}->{'7fe1,1010'}; # data
68
69 0 populate_header($dcm,$pdl,$opt);
70 0 my @d;
71 0 push @d,2; # complex
72 0 push @d,$pdl->hdr->{csa}->{SpectroscopyAcquisitionDataColumns}; # vector size
73 0 push @d,$pdl->hdr->{csa}->{Columns}; #
74 0 push @d,$pdl->hdr->{csa}->{Rows}; #
75 0 push @d,$pdl->hdr->{csa}->{NumberOfFrames}; # slices
76 0 $pdl=$pdl->reshape(@d);
77 }
78  
79 0 ▶sub create_data {
Subroutine create_data: not called CC=5 SCAR=32.1
Pod documented
80 0 my $data_ref=shift;
81 0 my $opt=shift;
82 0 my $dims=$$data_ref{dims};
83 0 ▶ next unless eval{$dims->isa('PDL')};
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { $dims->isa("PDL") } } 0 0 0
84 0 ▶ next unless any $dims;
Branch: 1 branch
BranchTrueFalseTotal
unless any($dims) 0 0 0
85 0 ▶ my $ref=$$data_ref{first { not /^dims$/ } (keys %$data_ref)};
Subroutine __ANON__: not called CC=1 SCAR=6.9
86 0 my $plugin='MRSSiemens';
87 0 my $order=$$opt{$plugin}->{dim_order};
88 # mrs data should be 2,fid,x,y,z,...
89 0 my @d;
90 0 push @d,2; # complex
91 0 push @d,$ref->hdr->{csa}->{SpectroscopyAcquisitionDataColumns}; # vector size
92 0 push @d,$ref->hdr->{csa}->{Columns}; # x
93 0 push @d,$ref->hdr->{csa}->{Rows}; # y
94 0 push @d,$ref->hdr->{csa}->{NumberOfFrames}; # slices
95 0 my $data=zeroes(float,@d,$dims);
96 0 my $header=dclone($ref->hdr);
97 2 ▶ use PDL::NiceSlice;
Subroutine BEGIN: called CC=1 SCAR=0.0
98 0 for my $key (@key_list) {
99 0 $header->{dicom}->{$key}=zeroes(list $dims($order));
100 }
101 0 for my $key (@key_list_csa) {
102 #say "key $key dims ",$dims($order);
103 0 $header->{csa}->{$key}=zeroes(list $dims($order));
104 }
105 # get a reference to the header
106 # the diff container holds all fields that are not equal for all dicom instances
107 0 $header->{diff}={};
108 # copy dimensions and create keys for each
109 # prepare geometry and other data structures
110 0 $header->{csa}->{'ImageOrientationPatient'}=zeroes(6,list $dims($order));
111 0 $header->{csa}->{'ImagePositionPatient'}=zeroes(3,list $dims($order));
112 0 $header->{csa}->{'PixelSpacing'}=zeroes(2,list $dims($order));
113 0 $header->{csa}->{'CsiGridShiftVector'}=zeroes(3,list $dims($order));
114 0 $header->{dicom}->{'Image Orientation (Patient)'}=zeroes(6,list $dims($order));
115 0 $header->{dicom}->{'Image Position (Patient)'}=zeroes(3,list $dims($order));
116 0 $header->{dicom}->{'Pixel Spacing'}=zeroes(2,list $dims($order));
117 #say $header->{dicom}->{'Pixel Spacing'};
118 0 $header->{dim_idx}=$$opt{$plugin}->{dim_idx};
119 0 $header->{dcm_key}={};
120 0 $data,$header;
121 }
122  
123 0 ▶sub parser {
Subroutine parser: not called CC=1 SCAR=6.9
Pod documented
124 0 my $data=shift;
125 0 my $opt=shift;
126 0 my $pid=shift;
127 0 my $header=$$data{$pid}->hdr;
128 0 my $plugin=$$opt{plugin};
129 #$DB::single=1;
130 0 $header->{dicom}->{'Image Position (Patient)'} = pdl ($header->{csa}->{'ImagePositionPatient'});
131 0 $header->{dicom}->{'Image Orientation (Patient)'} = pdl($header->{csa}->{'ImageOrientationPatient'});
132 #say $header->{dicom}->{'Pixel Spacing'};
133 0 $header->{dicom}->{'Pixel Spacing'} = pdl($header->{csa}->{'PixelSpacing'});
134
135 }
136  
137  
138 # this is a duplicate to MRISiemens
139 0 ▶sub fill_data {
Subroutine fill_data: not called CC=11 SCAR=48.8
Pod documented
140 0 my $data=shift;
141 0 my $header=$data->hdr;
142 0 my $dcm=shift;
143 0 my $order=$header->{dim_order};
144 0 my $ref=shift;
145 0 my $opt=shift;
146 0 my $plugin=$dcm->hdr->{plugin};
147 0 my $order=$$opt{$plugin}->{dim_order};
148 #print "dcm: ",$dcm->hdr->{dim_idx},", data ",$data->info,"\n";
149 #print $data(0,0,0,0,0,)->info,"\n";
150 #print list( $dcm->hdr->{dim_idx}->($order)-1),"\n";
151 0 ▶ if ($dcm->hdr->{tp}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dcm->hdr->{'tp'}) { } 0 0 0
152 # 2fxyz
153 0 $data(,,,,list( $dcm->hdr->{dim_idx}->($order)-1))
154 .=$dcm->transpose;}
155 0 else {$data(,,,,,list ($dcm->hdr->{dim_idx}->($order)-1)).=$dcm;}
156 # now fill all the header data
157 0 for my $key (@{$$opt{$plugin}->{key_list}}) {
158 0 $dcm->hdr->{dicom}->{$key};
159 $header->{dicom}->{$key}->(list ($dcm->hdr->{dim_idx}->($order)-1))
160 0 .=$dcm->hdr->{dicom}->{$key};
161 }
162 # preserve original info
163 #print "IDX: ",$dcm->hdr->{dim_idx};
164 0 $header->{dim_idx}->{$dcm->hdr->{dcm_key}}=$dcm->hdr->{dim_idx};
165 $header->{dcm_key}->{join ('_',list ($dcm->hdr->{dim_idx}->($order)))}
166 0 =$dcm->hdr->{dcm_key};
167 $header->{dicom}->{'Image Orientation (Patient)'}->(,list ($dcm->hdr->{dim_idx}->($order)-1))
168 0 .=pdl ($dcm->hdr->{csa}->{'ImageOrientationPatient'});
169 #say split /\\/,$dcm->hdr->{dicom}->{'Pixel Spacing'};
170 #say $header->{dicom}->{'Pixel Spacing'}->(,list($dcm->hdr->{dim_idx}->{$order}));
171  
172 #say $header->{dicom}->{'Pixel Spacing'};
173 $header->{dicom}->{'Pixel Spacing'}->(,list $dcm->hdr->{dim_idx}->($order)-1)
174 0 .=pdl ($dcm->hdr->{csa}->{'PixelSpacing'});
175 $header->{dicom}->{'Image Position (Patient)'}->(,list $dcm->hdr->{dim_idx}->($order)-1)
176 0 .=pdl ($dcm->hdr->{csa}->{'ImagePositionPatient'});
177 $header->{csa}->{'CsiGridShiftVector'}->(,list $dcm->hdr->{dim_idx}->($order)-1)
178 0 .=pdl ($dcm->hdr->{csa}->{'CsiGridShiftVector'});
179 0 for my $field (keys %{$dcm->hdr->{dicom}}) {
180 0 ▶ if ($dcm->hdr->{dicom}->{$field} ne $ref->hdr->{dicom}->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dcm->hdr->{"dicom"}{$field} ne $ref->hdr->{"dicom"}{$field}) 0 0 0
181 $header->{diff}->{$field}={}
182 0 ▶ unless ref ($header->{diff}->{$field});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $header->{"diff"}{$field} 0 0 0
183 }
184 }
185 0 for my $key (@key_list_csa) {
186 0 $dcm->hdr->{csa}->{$key};
187 # say "key $key val ",pdl $dcm->hdr->{csa}->{$key};
188 $header->{csa}->{$key}->(list $dcm->hdr->{dim_idx}->($order)-1)
189 0 .=pdl $dcm->hdr->{csa}->{$key};
190 }
191 0 ▶ $header->{diff}->{csa}={} unless ref ($header->{diff}->{csa});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $header->{"diff"}{"csa"} 0 0 0
192 0 for my $field (keys %{$dcm->hdr->{csa}}) {
193 0 ▶ if ($dcm->hdr->{csa}->{$field} ne $ref->hdr->{csa}->{$field}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dcm->hdr->{"csa"}{$field} ne $ref->hdr->{"csa"}{$field}) 0 0 0
194 $header->{diff}->{csa}->{$field}={}
195 0 ▶ unless ref ($header->{diff}->{csa}->{$field});
Branch: 1 branch
BranchTrueFalseTotal
unless ref $header->{"diff"}{"csa"}{$field} 0 0 0
196 }
197 }
198 #say $header->{csa}->{ImagePositionPatient};
199 }
200  
201 =over
202  
203 sub clump_data {
204 # do nothing here
205 @_;
206 }
207  
208 =back
209  
210 =cut
211  
212  
213 0 ▶sub populate_header {
Subroutine populate_header: not called CC=5 SCAR=34.0
Pod documented
214 0 my $dicom =shift;
215 0 my $piddle=shift;
216 0 my $opt=shift;
217 0 my $csa={};
218 0 my @ret;
219 my $iced;
220 # The protocol is in here:
221 #say "populate_header ",$_[1]->info,$_[0]->getValue('0020,0032');
222 0 $piddle->hdr->{csa}={}; # create empty hash
223 0 PDL::IO::Dcm::Plugins::MRISiemens::read_text_hdr($dicom->getValue ('0029,1120','native'),$piddle);
224 0 ▶ die "no vector size " unless $piddle->hdr->{ascconv}->{sSpecPara_lVectorSize};
Branch: 1 branch
BranchTrueFalseTotal
unless $piddle->hdr->{"ascconv"}{"sSpecPara_lVectorSize"} 0 0 0
225 0 PDL::IO::Dcm::Plugins::MRISiemens::read_csa($dicom->getValue ('0029,1110','native'),$piddle);
226 0 PDL::IO::Dcm::Plugins::MRISiemens::read_csa($dicom->getValue ('0029,1120','native'),$piddle);
227 # instance appears to run through echo, coil, t
228 0 my @d;
229 0 my $coilid=$piddle->hdr->{csa}->{CoilId}; # coil
230 0 my $coil= $$opt{coil_index}->{$coilid};
231 0 ▶ unless (defined $coil) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $coil) 0 0 0
232 0 $coil=1+max pdl(values %{$$opt{coil_index}}) ;
233 0 $$opt{coil_index}->{$coil}=$coil;
234 }
235 # apparently EchoNumbers or EchoTrainLength
236 my $echoes=$piddle->hdr->{csa}->{EchoTrainLength}+0 ||
237 0 ▶ $piddle->hdr->{csa}->{EchoNumbers}+0 ;
Condition0%0/3
$piddle->hdr->{'csa'}{'EchoTrainLength'} + 0 || $piddle->hdr->{'csa'}{'EchoNumbers'} + 0
l!l&&r!l&&!r
000
MC/DC0%0/2
$piddle->hdr->{'csa'}{'EchoTrainLength'} + 0 || $piddle->hdr->{'csa'}{'EchoNumbers'} + 0
$piddle->hdr->{'csa'}{'EchoTrainLength'} + 0 $piddle->hdr->{'csa'}{'EchoNumbers'} + 0
Truth table0%0/3
A || B
A= $piddle->hdr->{'csa'}{'EchoTrainLength'} + 0B= $piddle->hdr->{'csa'}{'EchoNumbers'} + 0
ABresult
1X1
011
000
238 0 push @d,($piddle->hdr->{dicom}->{'Instance Number'}-1) % $echoes+ 1; # echo
239 #push @d,$piddle->hdr->{csa}->{EchoNumbers}; # echo
240 #my $coils=grep { /lElementSelected/} keys (%{$piddle->hdr->{ascconv}});
241 # mapping of coil elements and instance, thanks to Chris Rodgers for figuring this out.
242 # I think the instance number is simply the index of the CoilElement list + 1.
243 0 my %clist = map { $_ =~/asList_(\d+)/; ("$1 : ".$piddle->hdr->{ascconv}->{$_});} grep { /ChannelConnected/} keys (%{$piddle->hdr->{ascconv}});
244 0 my %elist = map { $_ =~/asList_(\d+)/; ("$1 : ".$piddle->hdr->{ascconv}->{$_});} grep { /CoilElementID_tElement/} keys (%{$piddle->hdr->{ascconv}});
245 #my $rxdx = sort pdl values %clist;
246 #my $coils=map { $_ =~/asList_(\d+)/; $1;} grep { /lElementSelected/} keys (%{$piddle->hdr->{ascconv}});
247 0 my $t=$piddle->hdr->{dicom}->{'Acquisition Number'}; # coils
248 0 my $coilidx=(floor ($piddle->hdr->{dicom}->{'Instance Number'}-1)/$t/$echoes) +1; # coil
249 0 push @d,$coilidx;
250 0 $piddle->hdr->{coil_element}=$clist{$coilidx};
251 0 push @d,scalar $t; # acquisition
252 #push @d,$piddle->hdr->{ascconv}->{lRepetitions}+1; # t
253 0 $iced=pdl(short,@d);
254 0 delete $piddle->hdr->{raw_dicom}->{'0029,1120'}; # Protocol
255 0 $piddle->hdr->{dim_idx}=$iced;
256 # to make this unique
257 #say "Series Number ",$dicom->getValue('SeriesNumber'), "Instance Number ",$dicom->getValue('InstanceNumber');
258 #say "dims $iced";
259 0 ▶ $piddle->hdr->{dcm_key}=$dicom->getValue('InstanceNumber').'_'.($dicom->getValue('0051,100f')||0);
Condition0%0/2
$dicom->getValue('0051,100f') || 0
l!l
00
MC/DC0%0/1
$dicom->getValue('0051,100f') || 0
$dicom->getValue('0051,100f')
Truth table0%0/2
A
A= $dicom->getValue('0051,100f')
Aresult
11
00
260 #say $piddle->hdr->{dcm_key},": ",$iced,$dicom->getValue ('0020,0032','native');
261 #say "Dims $str pos $iced";
262 #return $str;
263 }
264  
265 0 ▶sub handle_duplicates {
Subroutine handle_duplicates: not called CC=1 SCAR=6.9
Pod documented
266 0 my $stack=shift;
267 0 my $dcm=shift;
268 0 my $opt=shift;
269 0 warn "Duplicates detected in scan ".$dcm->hdr->{dicom}->{"Series Number"}."\n";
270 warn "This entry (". $dcm->hdr->{dim_idx}->($$opt{dim_order}).
271 0 max ($stack->(,,list $dcm->hdr->{dim_idx}->($$opt{dim_order}))).
272 ") is already set! This should not happen, please file a bug report!\n";
273 0 $stack;
274 }
275  
276 0 ▶sub init_dims {
Subroutine init_dims: not called CC=26 SCAR=65.5
Pod documented
277 use PDL::NiceSlice;
278 0 my $self=shift;
279 0 my $opt=shift;
280 # we need these modules, return undef otherwise.
281 0 ▶ require PDL::Dims || return;
Branch: 1 branch
BranchTrueFalseTotal
require PDL::Dims or return 0 0 0
282 0 ▶ require PDL::Transform || return;
Branch: 1 branch
BranchTrueFalseTotal
require PDL::Transform or return 0 0 0
283 0 PDL::Dims->import(qw/is_equidistant dmin dmax vals hpar dinc initdim dimsize drot idx diminfo /);
284 #say "init_dims: ",$self->hdr->{dcm_key};
285 #say "init_dims: ",$self->hdr->{dicom}->{Rows} ;
286 #say "init_dims: hpar ",hpar($self,'dicom','Rows');
287 0 PDL::Transform->import(qw/t_linear/);
288 #say diminfo ($self),$self->hdr->{ascconv}->{sGroupArray_asGroup_1__nSize};
289 # center=inner(rot*scale,dim/2)+Image Position (Patient)
290 # xf=t_linear(matrix=>Pixel Scale*$rot->transpose,post=>Image Position (Patient))
291 0 ▶ if (hpar($self,'ascconv','sGroupArray_asGroup_1__nSize')){
Branch: 1 branch
BranchTrueFalseTotal
if (hpar($self, "ascconv", "sGroupArray_asGroup_1__nSize")) 0 0 0
292 0 warn "Multiple slice groups, support dubious!";
293 }
294 0 say "Dims for scan ",$self->hdr->{dicom}->{"Series Number"};
295 0 my $pos_d=zeroes(3);
296 0 my $fov=zeroes(3);
297 0 $fov(0).=hpar($self,'csa','VoiReadoutFoV');
298 0 $fov(1).=hpar($self,'csa','VoiPhaseFoV');
299 0 $fov(2).=hpar($self,'csa','VoiThickness');
300 0 my $t=hpar($self,'csa','VoiInPlaneRotation');
301 #$v.=hpar($self,'csa','sSliceArray_asSlice_0__sPosition_dSag') ||0; #x
302 0 $pos_d.=pdl (hpar($self,'csa','VoiPosition')); # ||0; #y
303 0 my $nv=pdl (hpar($self,'csa','VoiOrientation')); # ||0; #y
304 0 my $av=pdl([[0,-$nv(2),$nv(1)],[$nv(2),0,-$nv(0)],[-$nv(1),$nv(0),0]])->squeeze;
305 0 my $srot=identity(3)*cos($t)+sin($t)*$av+(1-cos($t))*$nv->transpose*$nv;
306 0 my $rot=identity($self->ndims);
307 0 say $srot;
308 0 my $s=zeroes(3);
309 # This is apparently not so easy to get right ...
310 # May be it has to do with phase encoding direction ...
311 # or software version ..
312 #$s(0).=(hpar($self,'csa','SpectroscopyAcquisitionPhaseColumns')); # ||0; #y
313 #$s(1).=(hpar($self,'csa','SpectroscopyAcquisitionPhaseRows')); # ||0; #y
314 #$s(0).=(hpar($self,'dicom','Columns')); # ||0; #y
315 #$s(1).=(hpar($self,'dicom','Rows')); # ||0; #y
316 0 ▶ $s(0).=hpar($self,'ascconv','sSpecPara_lFinalMatrixSizePhase')||1;
Condition0%0/2
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizePhase') || 1
l!l
00
MC/DC0%0/1
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizePhase') || 1
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizePhase')
Truth table0%0/2
A
A= hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizePhase')
Aresult
11
00
317 0 ▶ $s(1).=hpar($self,'ascconv','sSpecPara_lFinalMatrixSizeRead')||1;
Condition0%0/2
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeRead') || 1
l!l
00
MC/DC0%0/1
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeRead') || 1
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeRead')
Truth table0%0/2
A
A= hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeRead')
Aresult
11
00
318 0 ▶ $s(2).=hpar($self,'ascconv','sSpecPara_lFinalMatrixSizeSlice')||1;
Condition0%0/2
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeSlice') || 1
l!l
00
MC/DC0%0/1
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeSlice') || 1
hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeSlice')
Truth table0%0/2
A
A= hpar($self, 'ascconv', 'sSpecPara_lFinalMatrixSizeSlice')
Aresult
11
00
319 #$s(2).=(hpar($self,'csa','SpectroscopyAcquisitionOut-of-planePhaseSteps')); # ||0; #y
320 0 my $pe=hpar($self,'csa','PhaseEncodingDirection');
321 # Calculate and initialise the transformation
322 0 my @ors=qw/Sag Cor Tra/;
323 0 say $srot;
324 0 $self->hdr->{orientation}=$ors[maximum_ind(abs($srot(2;-)))]; # normal vector lookup
325  
326 0 ▶ if ($self->hdr->{orientation} eq 'Tra'){ # transversal slice
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hdr->{"orientation"} eq "Tra") 0 0 0
327 #say $self->hdr->{orientation}. " Orientation";
328 0 $self->hdr->{sl}='z';
329 0 ▶ if ($pe eq 'COL'){
Branch: 1 branch
BranchTrueFalseTotal
if ($pe eq 'COL') { } 0 0 0
330 0 $self->hdr->{ro}='x';
331 0 $self->hdr->{pe}='y';
332 } else {
333 0 $self->hdr->{ro}='y';
334 0 $self->hdr->{pe}='x';
335 }
336 }
337 0 ▶ if ($self->hdr->{orientation} eq 'Cor'){ # coronal slice
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hdr->{"orientation"} eq "Cor") 0 0 0
338 0 $self->hdr->{sl}='y';
339 0 ▶ if ($pe eq 'COL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pe eq 'COL') { } 0 0 0
340 0 $self->hdr->{ro}='x';
341 0 $self->hdr->{pe}='z';
342 } else {
343 0 $self->hdr->{ro}='z';
344 0 $self->hdr->{pe}='x';
345 }
346 }
347 0 ▶ if ($self->hdr->{orientation} eq 'Sag'){ # sagittal slice
Branch: 1 branch
BranchTrueFalseTotal
if ($self->hdr->{"orientation"} eq "Sag") 0 0 0
348 0 $self->hdr->{sl}='x';
349 0 ▶ if ($pe eq 'COL') {
Branch: 1 branch
BranchTrueFalseTotal
if ($pe eq 'COL') { } 0 0 0
350 0 $self->hdr->{ro}='y';
351 0 $self->hdr->{pe}='z';
352 } else {
353 0 $self->hdr->{ro}='z';
354 0 $self->hdr->{pe}='y';
355 }
356 }
357 # Slice groups! Does that make sense?
358 0 ▶ if ($$opt{split}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt->{'split'}) { } 0 0 0
359 0 my ($sg,$size)=PDL::IO::Dcm::Plugins::MRISiemens::map_slicegroup($self);
360 0 $s(2)*=$size;
361 } else {
362 #$s(2)*=$self->hdr->{csa}->{'NumberOfFrames'};
363 0 $s(2)*=$self->hdr->{ascconv}->{'sSliceArray_lSize'};
364 }
365 #$s(2).=1 if ($s(2)<1);
366 0 say "FOV $fov matrix $s";
367 0 my $inc_d=zeroes(3);
368 0 $inc_d=$fov/$s;
369 #say $srot;
370 0 $rot(2:4,2:4).=$srot;
371 #say "FOV $fov matrix $s, pixels $inc_d";
372 0 ▶ barf $self->hdr->{dicom}->{'Series Number'},": dims don't fit! $s vs. ",$self->shape->(:4) if any($self->shape->(2:4)-$s);
Branch: 1 branch
BranchTrueFalseTotal
if any($self->shape->slice([2, 4]) - $s) 0 0 0
373 #say "Rot: $rot";
374 #if ($pe eq 'COL') {
375 0 initdim($self,'c');
376 0 initdim($self,'fid' ,min=>0,inc=>$self->hdr->{ascconv}->{sRXSPEC_alDwellTime_0_},unit=>'us');
377 0 initdim($self,getx($self->hdr),size=>sclr($s(0)),min=>sclr($pos_d(0)),inc=>sclr($inc_d(0)),unit=>'mm');
378 0 initdim($self,gety($self->hdr),size=>sclr($s(1)),min=>sclr($pos_d(1)),inc=>sclr($inc_d(1)),unit=>'mm');
379 #} else {
380 #initdim($self,getx($self->hdr),size=>$s(0),min=>sclr($pos_d(0)),inc=>sclr($inc_d(0)),unit=>'mm');
381 #initdim($self,gety($self->hdr),size=>$s(1),min=>sclr($pos_d(1)),inc=>sclr($inc_d(1)),unit=>'mm');
382 #}
383 0 initdim($self,getz($self->hdr),size=>sclr($s(2)),min=>sclr($pos_d(2)),inc=>sclr($inc_d(2)),unit=>'mm',);
384 #say "initdim for x,y,z done.";
385 #say "after init dim ",(diminfo ($self));
386 #say "size $s min $pos_d inc $inc_d rot $rot";
387 0 idx($self,'x',sclr(dimsize($self,'x')/2));
388 0 idx($self,'y',sclr(dimsize($self,'y')/2));
389 0 idx($self,'z',sclr(dimsize($self,'z')/2));
390 0 say "Index x ",idx($self,'x');
391 0 say "Dimsize ",dimsize($self);
392 # other dimensions
393 0 for my $n (5..$#{$$opt{MRSSiemens}->{Dimensions}}) { # x,y,z are handled above
394 0 my $dim=$$opt{MRSSiemens}->{Dimensions}->[$n];
395 0 print "Init Dim $dim - $n\n";
396 0 my $str=('(0),' x ($n-2)).','.('(0),' x ($#{$$opt{Dimensions}}-$n));
397 #say "$str ";
398 0 ▶ if ($dim eq 'Echo') {
Branch: 5 branches
BranchTrueFalseTotal
if ($dim eq 'Echo') { } 0 0 0
elsif ($dim eq 'T') { } 0 0 0
elsif ($dim =~ /Channel/) { } 0 0 0
elsif ($dim =~ /Set/) { } 0 0 0
elsif ($dim =~ /Phase/) { } 0 0 0
399 # my $str=('(0),' x ($n-2)).','.('(0),' x ($#{$$opt{Dimensions}}-$n));
400 0 initdim ($self,inc=>0,'echo',unit=>'us',
401 vals=>[list (hpar($self,'csa','EchoTime')->($str))]);
402 }
403 elsif ($dim eq 'T') {
404 # my $str=('(0),' x ($n-2)).','.('(0),' x ($#{$$opt{Dimensions}}-$n));
405 0 my $t=pdl(hpar($self,'dicom','Acquisition Time'))->($str);
406 0 ▶ if (is_equidistant($t,0.003) && $t->nelem>1) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_equidistant($t, 0.003) and $t->nelem > 1) { } 0 0 0
Condition0%0/3
is_equidistant($t, "0.003") and $t->nelem > 1
!ll&&!rl&&r
000
MC/DC0%0/2
is_equidistant($t, "0.003") and $t->nelem > 1
is_equidistant($t, "0.003") $t->nelem > 1
Truth table0%0/3
A and B
A= is_equidistant($t, "0.003")B= $t->nelem > 1
ABresult
0X0
100
111
407 0 initdim ($self,'t',unit=>'s',min=>sclr($t(0)),max=>sclr($t(-1)));
408 0 say "T min ",dmin($self,'t')," max ",dmax($self,'t')," inc ",dinc($self,'t'), $t;
409 } else {
410 0 initdim ($self,'t',inc=>0,unit=>'s',vals=>[list($t)]);
411 0 say "T values :",vals ($self,'t');
412 }
413 } elsif ($dim =~ /Channel/) {
414 0 ▶ my $coil=hpar($self,'csa','ImaCoilString')||'combined';
Condition0%0/2
hpar($self, 'csa', 'ImaCoilString') || 'combined'
l!l
00
MC/DC0%0/1
hpar($self, 'csa', 'ImaCoilString') || 'combined'
hpar($self, 'csa', 'ImaCoilString')
Truth table0%0/2
A
A= hpar($self, 'csa', 'ImaCoilString')
Aresult
11
00
415 0 ▶ if ($self->dim($n)>1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->dim($n) > 1) { } 0 0 0
416 0 initdim ($self,'channel',vals=>[hpar($self,'csa','ImaCoilString')->flat->(:2)]);
417 } else {
418 0 initdim ($self,'channel',vals=>[$coil, size=>1]);
419 }
420 # these are probably not used
421 } elsif ($dim =~ /Set/) {
422 0 initdim ($self,'set'); # This can be anything, no further info easily available
423 } elsif ($dim =~ /Phase/) {
424 0 my $t=hpar($self,'dicom','Trigger Time');
425 #say $t->info;
426 0 $t=$t($str);
427 #say $t;
428 0 ▶ if (is_equidistant($t)) {
Branch: 1 branch
BranchTrueFalseTotal
if (is_equidistant($t)) { } 0 0 0
429 0 initdim ($self,'cphase',unit=>'ms',min=>sclr($t(0)),max=>sclr($t(-1)));
430 #say "Trigger min ",dmin($self,'cphase')," max ",dmax($self,'cphase')," inc ",dinc($self,'cphase'), $t;
431 #say "Trigger ",vals ($self,'cphase');
432 } else {
433 0 initdim ($self,'cphase',unit=>'ms',vals=>[list($t)]);
434 #say "Trigger values :",vals ($self,'cphase');
435 }
436 }
437 }
438 0 drot($self,undef,undef,$rot);
439 0 say "dinc ",dinc( $self);
440 0 say diminfo $self;
441 0 say drot $self;
442 0 my $mat=drot($self) x stretcher (pdl(dinc($self)));
443 0 $mat=$mat->transpose ;#if ($pe_dir =~ /COL/);
444 #say $mat;
445 0 my $xf=t_linear(matrix=>$mat,post=>$pos_d(,0;-));
446 #say "inc ",dinc ($self);
447 ##say diminfo($self);
448 0 hpar($self,'init_transform','matrix',$mat);
449 0 hpar($self,'init_transform','post',$pos_d(,0;-));
450 #barf "initdim fails!" unless ($#{dimname($self)}>2);
451 }
452  
453  
454 0 ▶sub getz {
Subroutine getz: not called CC=3 SCAR=24.8
Pod documented
455 0 my $self=shift;
456 #return 'z';
457 #say "getz ",$self->{orientation};
458 0 ▶ return 'z' if ($self->{orientation}=~/Tra/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"orientation"} =~ /Tra/ 0 0 0
459 0 ▶ return 'x' if ($self->{orientation}=~/Sag/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"orientation"} =~ /Sag/ 0 0 0
460 0 return 'y' # if 'Cor'
461 }
462  
463 0 ▶sub gety {
Subroutine gety: not called CC=2 SCAR=17.9
Pod documented
464 0 my $self=shift;
465 #return 'y';
466 #say "gety ",$self->{orientation};
467 0 ▶ return 'y' if ($self->{orientation}=~/Tra/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"orientation"} =~ /Tra/ 0 0 0
468 #return 'y' if ($self->{orientation}=~/Tra/);
469 0 return 'z' # if 'Sag|Cor'
470 }
471  
472 0 ▶sub getx {
Subroutine getx: not called CC=2 SCAR=17.9
Pod documented
473 0 my $self=shift;
474 #return 'x';
475 #say "getx ",$self->{orientation};
476 0 ▶ return 'x' if ($self->{orientation}=~/Tra|Cor/);
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"orientation"} =~ /Tra|Cor/ 0 0 0
477 0 return 'y' # if 'Sag'
478 }
479  
480  
481  
482 =head1 Specific handling of Simenes MRI data
483  
484 MRI:
485  
486 Key 0029,1010 is the Siemens specific field that contains the ICE
487 mini-headers with dimension information - and position in matrix
488 0029,1120 is deleted from the header, it is big, containing the whole
489 protocol. They are now parsed into the csa header structure. The important
490 part, the Siemens protocol ASCCONV part, is stored in the ascconv key, see
491 read_text_hdr.
492  
493 MRS:
494  
495 In this case, 0029,1110 and 0029,1120 are the proprietary parts of the header.
496  
497  
498 =head1 FUNCTIONS
499  
500 =head2 create_data
501  
502 Plugin-specific code to create the data structure, in patricular dimensions.
503  
504 =head2 fill_data
505  
506 fill the data structure from individual DICOM images (slices, echoes, phases ...).
507  
508 =head2 getx, gety, getz
509  
510 returns name of x .. z dimensions in scanner (or patient?) orientation.
511  
512 =head2 handle_duplicates
513  
514 What to do if two images with the same position in the stack arrive. Throws an
515 error, atm. Should handle duplicate exports
516  
517 =head2 init_dims
518  
519 provides support for PDL::Dims. Useful in combination with PDL::IO::Sereal to
520 have a fully qualified data set.
521  
522 =head2 map_slicegroup
523  
524 returns the number, size and first slice of the current slice group.
525  
526 =head2 parser
527  
528 plugin specific stuff to parse all the headers
529  
530 =head2 populate_header
531  
532 Here happens the vendor/modallity specific stuff like parsing private fields.
533 It is required to return a position vector in the series' piddle.
534  
535 =head2 read_dcm
536  
537 plugin specific stuff to read a DICOM file
538  
539 =head2 setup_dcm
540  
541 sets useful options for this modality.
542  
543 =head2 sort_protid
544  
545 alternative to split based on lProtID (matches raw data key). To activate,
546 after running setup_dcm, point option id to \&sort_protid.
547  
548 =head1 Specific options
549  
550 =over
551  
552 =item Nifti
553  
554 Do we want Nifti output? May be used by your plugin to apply additional steps,
555 eg. more clumps, reorders, setting header fields ...
556  
557 =item c_phase_t
558  
559 Serialize phase and t dimensions
560  
561 =back
562  
563 =cut
564  
565 2 1;
↑ Summary lib/PDL/IO/Dcm/Plugins/MRISiemens.pm »