|
16 | 16 |
|
17 | 17 | import numpy as np
|
18 | 18 |
|
19 |
| -from ..nifti1 import data_type_codes, xform_codes, intent_codes |
20 | 19 | from .gifti import (GiftiMetaData, GiftiImage, GiftiLabel,
|
21 | 20 | GiftiLabelTable, GiftiNVPairs, GiftiDataArray,
|
22 | 21 | GiftiCoordSystem)
|
23 | 22 | from .util import (array_index_order_codes, gifti_encoding_codes,
|
24 | 23 | gifti_endian_codes)
|
| 24 | +from ..nifti1 import data_type_codes, xform_codes, intent_codes |
25 | 25 | from ..xmlbasedimages import XmlImageParser
|
26 | 26 |
|
27 | 27 | DEBUG_PRINT = False
|
@@ -94,6 +94,7 @@ def __init__(self):
|
94 | 94 |
|
95 | 95 | # Collecting char buffer fragments
|
96 | 96 | self._char_blocks = None
|
| 97 | + self.buffer_size = None |
97 | 98 |
|
98 | 99 | def StartElementHandler(self, name, attrs):
|
99 | 100 | self.flush_chardata()
|
@@ -311,3 +312,42 @@ def flush_chardata(self):
|
311 | 312 | def pending_data(self):
|
312 | 313 | " True if there is character data pending for processing "
|
313 | 314 | return not self._char_blocks is None
|
| 315 | + |
| 316 | + def _create_parser(self): |
| 317 | + parser = super(GiftiImageParser, self)._create_parser() |
| 318 | + if self.buffer_size is not None: |
| 319 | + parser.buffer_text = True |
| 320 | + parser.buffer_size = self.buffer_size |
| 321 | + return parser |
| 322 | + |
| 323 | + def parse(self, string=None, fname=None, fptr=None, buffer_size=None): |
| 324 | + """ Parse gifti file named `fname`, return image |
| 325 | +
|
| 326 | + Parameters |
| 327 | + ---------- |
| 328 | + fname : str |
| 329 | + filename of gifti file |
| 330 | + buffer_size: None or int, optional |
| 331 | + size of read buffer. None gives default of 35000000 unless on python < |
| 332 | + 2.6, in which case it is read only in the parser. In that case values |
| 333 | + other than None cause a ValueError on execution |
| 334 | +
|
| 335 | + Returns |
| 336 | + ------- |
| 337 | + img : gifti image |
| 338 | + """ |
| 339 | + self.buffer_size = buffer_size |
| 340 | + return super(GiftiImageParser, self).parse(string=string, fname=fname, |
| 341 | + fptr=fptr) |
| 342 | + |
| 343 | + |
| 344 | +class Outputter(GiftiImageParser): |
| 345 | + @np.deprecate_with_doc("Use GiftiImageParser instead.") |
| 346 | + def __init__(self, *args, **kwargs): |
| 347 | + super(Outputter, self).__init__(*args, **kwargs) |
| 348 | + self.img = None |
| 349 | + |
| 350 | + |
| 351 | +@np.deprecate_with_doc("Use GiftiImageParser.parse() instead.") |
| 352 | +def parse_gifti_file(fname=None, fptr=None, buffer_size=None): |
| 353 | + GiftiImageParser().parse(fname=fname, fptr=fptr, buffer_size=buffer_size) |
0 commit comments