1
1
"""CSA header reader from SPM spec"""
2
2
3
- import numpy as np
4
3
import struct
5
4
5
+ import numpy as np
6
+
6
7
from .structreader import Unpacker
7
8
from .utils import find_private_section
8
9
@@ -167,7 +168,7 @@ def read(csa_str):
167
168
168
169
169
170
def write (csa_header ):
170
- ''' Write string from CSA header `csa_header`
171
+ """ Write string from CSA header `csa_header`
171
172
172
173
Parameters
173
174
----------
@@ -180,18 +181,14 @@ def write(csa_header):
180
181
-------
181
182
csa_str : str
182
183
byte string containing CSA header information
183
- '''
184
+ """
184
185
result = []
185
186
if csa_header ['type' ] == 2 :
186
187
result .append (b'SV10' )
187
188
result .append (csa_header ['unused0' ])
188
189
if not 0 < csa_header ['n_tags' ] <= 128 :
189
- raise CSAWriteError ('Number of tags `t` should be '
190
- '0 < t <= 128' )
191
- result .append (struct .pack ('2I' ,
192
- csa_header ['n_tags' ],
193
- csa_header ['check' ])
194
- )
190
+ raise CSAWriteError ('Number of tags `t` should be 0 < t <= 128' )
191
+ result .append (struct .pack ('2I' , csa_header ['n_tags' ], csa_header ['check' ]))
195
192
196
193
# Build list of tags in correct order
197
194
tags = list (csa_header ['tags' ].items ())
@@ -204,14 +201,17 @@ def write(csa_header):
204
201
vr = tag_dict ['vr' ]
205
202
n_items = tag_dict ['n_items' ]
206
203
assert n_items < 100
207
- result .append (struct .pack ('64si4s3i' ,
208
- make_nt_str (tag_name ),
209
- vm ,
210
- make_nt_str (vr ),
211
- tag_dict ['syngodt' ],
212
- n_items ,
213
- tag_dict ['last3' ])
214
- )
204
+ result .append (
205
+ struct .pack (
206
+ '64si4s3i' ,
207
+ make_nt_str (tag_name ),
208
+ vm ,
209
+ make_nt_str (vr ),
210
+ tag_dict ['syngodt' ],
211
+ n_items ,
212
+ tag_dict ['last3' ],
213
+ )
214
+ )
215
215
216
216
# Figure out the number of values for this tag
217
217
if vm == 0 :
@@ -356,7 +356,7 @@ def nt_str(s):
356
356
357
357
358
358
def make_nt_str (s ):
359
- ''' Create a null terminated byte string from a unicode object.
359
+ """ Create a null terminated byte string from a unicode object.
360
360
361
361
Parameters
362
362
----------
@@ -366,5 +366,5 @@ def make_nt_str(s):
366
366
-------
367
367
result : bytes
368
368
s encoded as latin-1 with a null char appended
369
- '''
369
+ """
370
370
return s .encode ('latin-1' ) + b'\x00 '
0 commit comments