Skip to content

Commit e7e1d46

Browse files
authored
Merge pull request #1092 from effigies/enh/gifti_reprs
ENH: Add GIFTI object __repr__ methods
2 parents 87aa8b6 + e1db333 commit e7e1d46

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

nibabel/gifti/gifti.py

+18
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,9 @@ class GiftiLabelTable(xml.XmlSerializable):
9595
def __init__(self):
9696
self.labels = []
9797

98+
def __repr__(self):
99+
return f"<GiftiLabelTable {self.labels!r}>"
100+
98101
def get_labels_as_dict(self):
99102
self.labels_as_dict = {}
100103
for ele in self.labels:
@@ -153,6 +156,13 @@ def __init__(self, key=0, red=None, green=None, blue=None, alpha=None):
153156
self.blue = blue
154157
self.alpha = alpha
155158

159+
def __repr__(self):
160+
chars = 255 * np.array(
161+
[self.red or 0, self.green or 0, self.blue or 0, self.alpha or 0]
162+
)
163+
r, g, b, a = chars.astype('u1')
164+
return f'<GiftiLabel {self.key}="#{r:02x}{g:02x}{b:02x}{a:02x}">'
165+
156166
@deprecate_with_version(
157167
'get_rgba method deprecated. '
158168
"Use the rgba property instead.",
@@ -235,6 +245,11 @@ def __init__(self, dataspace=0, xformspace=0, xform=None):
235245
else:
236246
self.xform = xform
237247

248+
def __repr__(self):
249+
src = xform_codes.label[self.dataspace]
250+
dst = xform_codes.label[self.xformspace]
251+
return f"<GiftiCoordSystem {src}-to-{dst}>"
252+
238253
def _to_xml_element(self):
239254
coord_xform = xml.Element('CoordinateSystemTransformMatrix')
240255
if self.xform is not None:
@@ -375,6 +390,9 @@ def __init__(self,
375390
self.ext_offset = ext_offset
376391
self.dims = [] if self.data is None else list(self.data.shape)
377392

393+
def __repr__(self):
394+
return f"<GiftiDataArray {intent_codes.label[self.intent]}{self.dims}>"
395+
378396
@property
379397
def num_dim(self):
380398
return len(self.dims)

0 commit comments

Comments
 (0)