NeuralEnsemble/python-neo — pull request #6 by tkf (2012-07-24 16:15:08+00:00)
Title: Add _repr_pretty_ in analogsignal/block/segment

This PR adds `_repr_pretty_` method [1] to NEO objects to make NEO work nicely with IPython.

[1] http://ipython.org/ipython-doc/dev/api/generated/IPython.lib.pretty.html

It is a work in progress. Any advice is welcome.

Sample IPython session:

```python
In [4]:
from neo.io import AxonIO
r = AxonIO(filename=filename)
bl = r.read()

In [5]:
bl.description = 'Sample data File_axon_3.abf'

In [6]:
bl
Out [6]:
Block with 5 segments and 5 groups
description: 'Sample data File_axon_3.abf'
annotations: {'abf_version': 1.8300000429153442}
file_origin: 'test.abf'
rec_datetime: datetime.datetime(1900, 1, 1, 14, 15, 28, 552000)
# Segments
0: Segment with 2 analogs
# Analog signals (N=2)
0: AnalogSignal in 1.0 mV with 20644 float32 values
name: '10Vm '
annotations: {'channel_index': 0}
sampling rate: 20000.0 Hz
time: 0.0 s to 1.0322 s
1: AnalogSignal in 1.0 pA with 20644 float32 values
name: 'ImRK01G1b '
annotations: {'channel_index': 1}
sampling rate: 20000.0 Hz
time: 0.0 s to 1.0322 s
1: Segment with 2 analogs
# Analog signals (N=2)
0: AnalogSignal in 1.0 mV with 20644 float32 values
name: '10Vm '
annotations: {'channel_index': 0}
sampling rate: 20000.0 Hz
time: 360.0 s to 361.0322 s
1: AnalogSignal in 1.0 pA with 20644 float32 values
name: 'ImRK01G1b '
annotations: {'channel_index': 1}
sampling rate: 20000.0 Hz
time: 360.0 s to 361.0322 s
2: Segment with 2 analogs
# Analog signals (N=2)
0: AnalogSignal in 1.0 mV with 20644 float32 values
name: '10Vm '
annotations: {'channel_index': 0}
sampling rate: 20000.0 Hz
time: 720.0 s to 721.0322 s
1: AnalogSignal in 1.0 pA with 20644 float32 values
name: 'ImRK01G1b '
annotations: {'channel_index': 1}
sampling rate: 20000.0 Hz
time: 720.0 s to 721.0322 s
3: Segment with 2 analogs
# Analog signals (N=2)
0: AnalogSignal in 1.0 mV with 20644 float32 values
name: '10Vm '
annotations: {'channel_index': 0}
sampling rate: 20000.0 Hz
time: 1080.0 s to 1081.0322 s
1: AnalogSignal in 1.0 pA with 20644 float32 values
name: 'ImRK01G1b '
annotations: {'channel_index': 1}
sampling rate: 20000.0 Hz
time: 1080.0 s to 1081.0322 s
4: Segment with 2 analogs
# Analog signals (N=2)
0: AnalogSignal in 1.0 mV with 20644 float32 values
name: '10Vm '
annotations: {'channel_index': 0}
sampling rate: 20000.0 Hz
time: 1440.0 s to 1441.0322 s
1: AnalogSignal in 1.0 pA with 20644 float32 values
name: 'ImRK01G1b '
annotations: {'channel_index': 1}
sampling rate: 20000.0 Hz
time: 1440.0 s to 1441.0322 s

In [7]:
bl.segments[0].analogsignals[0]
Out [7]:
AnalogSignal in 1.0 mV with 20644 float32 values
name: '10Vm '
annotations: {'channel_index': 0}
sampling rate: 20000.0 Hz
time: 0.0 s to 1.0322 s
```

In Out [6] and Out [7], you can see useful information instead of something like \ or \.