<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import , division , print_function <EOL> import os . path <EOL> import sys <EOL> try : <EOL> import unittest2 as unittest <EOL> except ImportError : <EOL> import unittest <EOL> import numpy as np <EOL> import quantities as pq <EOL> from neo . core import ( AnalogSignal , Block , RecordingChannel , <EOL> RecordingChannelGroup , Segment ) <EOL> from neo . io import BrainwareDamIO <EOL> from neo . test . iotest . common_io_test import BaseTestIO <EOL> from neo . test . tools import ( assert_same_sub_schema , <EOL> assert_neo_object_is_compliant ) <EOL> from neo . test . iotest . tools import create_generic_reader <EOL> PY_VER = sys . version_info [ <NUM_LIT:0> ] <EOL> def proc_dam ( filename ) : <EOL> '''<STR_LIT>''' <EOL> with np . load ( filename ) as damobj : <EOL> damfile = damobj . items ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] . flatten ( ) <EOL> filename = os . path . basename ( filename [ : - <NUM_LIT:12> ] + '<STR_LIT>' ) <EOL> signals = [ res . flatten ( ) for res in damfile [ '<STR_LIT>' ] ] <EOL> stimIndexes = [ int ( res [ <NUM_LIT:0> , <NUM_LIT:0> ] . tolist ( ) ) for res in damfile [ '<STR_LIT>' ] ] <EOL> timestamps = [ res [ <NUM_LIT:0> , <NUM_LIT:0> ] for res in damfile [ '<STR_LIT>' ] ] <EOL> block = Block ( file_origin = filename ) <EOL> rcg = RecordingChannelGroup ( file_origin = filename ) <EOL> chan = RecordingChannel ( file_origin = filename , index = <NUM_LIT:0> , name = '<STR_LIT>' ) <EOL> rcg . channel_indexes = np . array ( [ <NUM_LIT:1> ] ) <EOL> rcg . channel_names = np . array ( [ '<STR_LIT>' ] , dtype = '<STR_LIT:S>' ) <EOL> block . recordingchannelgroups . append ( rcg ) <EOL> rcg . recordingchannels . append ( chan ) <EOL> params = [ res [ '<STR_LIT>' ] [ <NUM_LIT:0> , <NUM_LIT:0> ] . flatten ( ) for res in damfile [ '<STR_LIT>' ] ] <EOL> values = [ res [ '<STR_LIT>' ] [ <NUM_LIT:0> , <NUM_LIT:0> ] . flatten ( ) for res in damfile [ '<STR_LIT>' ] ] <EOL> params = [ [ res1 [ <NUM_LIT:0> ] for res1 in res ] for res in params ] <EOL> values = [ [ res1 for res1 in res ] for res in values ] <EOL> stims = [ dict ( zip ( param , value ) ) for param , value in zip ( params , values ) ] <EOL> fulldam = zip ( stimIndexes , timestamps , signals , stims ) <EOL> for stimIndex , timestamp , signal , stim in fulldam : <EOL> sig = AnalogSignal ( signal = signal * pq . mV , <EOL> t_start = timestamp * pq . d , <EOL> file_origin = filename , <EOL> sampling_period = <NUM_LIT:1.> * pq . s ) <EOL> segment = Segment ( file_origin = filename , <EOL> index = stimIndex , <EOL> ** stim ) <EOL> segment . analogsignals = [ sig ] <EOL> block . segments . append ( segment ) <EOL> block . create_many_to_one_relationship ( ) <EOL> return block <EOL> class BrainwareDamIOTestCase ( BaseTestIO , unittest . TestCase ) : <EOL> '''<STR_LIT>''' <EOL> ioclass = BrainwareDamIO <EOL> read_and_write_is_bijective = False <EOL> files_to_test = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> files_to_compare = [ '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> for i , fname in enumerate ( files_to_compare ) : <EOL> if fname : <EOL> files_to_compare [ i ] += '<STR_LIT>' % PY_VER <EOL> files_to_download = files_to_test + files_to_compare <EOL> def test_reading_same ( self ) : <EOL> for ioobj , path in self . iter_io_objects ( return_path = True ) : <EOL> obj_reader_base = create_generic_reader ( ioobj , target = False ) <EOL> obj_reader_single = create_generic_reader ( ioobj ) <EOL> obj_base = obj_reader_base ( ) <EOL> obj_single = obj_reader_single ( ) <EOL> try : <EOL> assert_same_sub_schema ( obj_base , obj_single ) <EOL> except BaseException as exc : <EOL> exc . args += ( '<STR_LIT>' + os . path . basename ( path ) , ) <EOL> raise <EOL> def test_against_reference ( self ) : <EOL> for filename , refname in zip ( self . files_to_test , <EOL> self . files_to_compare ) : <EOL> if not refname : <EOL> continue <EOL> obj = self . read_file ( filename = filename ) <EOL> refobj = proc_dam ( self . get_filename_path ( refname ) ) <EOL> try : <EOL> assert_neo_object_is_compliant ( obj ) <EOL> assert_neo_object_is_compliant ( refobj ) <EOL> assert_same_sub_schema ( obj , refobj ) <EOL> except BaseException as exc : <EOL> exc . args += ( '<STR_LIT>' + filename , ) <EOL> raise <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> unittest . main ( ) </s>
