Skip to content

Commit f154d6d

Browse files
author
Dilawar Singh
committed
Dependencies fix during build target. bdist is build by default.
1 parent 2c4f066 commit f154d6d

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ add_custom_command(TARGET bdist POST_BUILD
441441
# Copy python files from source to current binary directory. Make sure to call
442442
# this before building bdist.
443443
file(GLOB_RECURSE PYTHON_SRCS "${CMAKE_SOURCE_DIR}/python/*")
444-
add_custom_target(copy_pymoose DEPENDS ${PYTHON_SRCS}
444+
add_custom_target(copy_pymoose DEPENDS ${PYTHON_SRCS} _moose
445445
COMMAND ${CMAKE_COMMAND} -E copy_directory
446446
${CMAKE_CURRENT_SOURCE_DIR}/python ${CMAKE_CURRENT_BINARY_DIR}/python
447447
COMMENT "Copying required python files from

tests/python/temp.npy

1.98 KB
Binary file not shown.

tests/python/test_nsdf.py

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# test_nsdf.py ---
2+
# Changed from nsdf.py from
3+
# https://github.com/BhallaLab/moose-examples/snippets/nsdf.py
4+
5+
from __future__ import print_function
6+
import numpy as np
7+
from datetime import datetime
8+
import getpass
9+
import os
10+
11+
# Use in-repo moose to install.
12+
import moose
13+
print('using moose from: %s' % moose.__file__)
14+
15+
global nsdf
16+
17+
def setup_model():
18+
"""Setup a dummy model with a PulseGen and a SpikeGen. The SpikeGen
19+
detects the leading edges of the pulses created by the PulseGen
20+
and sends out the event times. We record the PulseGen outputValue
21+
as Uniform data and leading edge time as Event data in the NSDF
22+
file.
23+
24+
"""
25+
global nsdf
26+
simtime = 100.0
27+
dt = 1e-3
28+
model = moose.Neutral('/model')
29+
pulse = moose.PulseGen('/model/pulse')
30+
pulse.level[0] = 1.0
31+
pulse.delay[0] = 10
32+
pulse.width[0] = 20
33+
t_lead = moose.SpikeGen('/model/t_lead')
34+
t_lead.threshold = 0.5
35+
moose.connect(pulse, 'output', t_lead,'Vm');
36+
nsdf = moose.NSDFWriter('/model/writer')
37+
nsdf.filename = 'nsdf_demo.h5'
38+
nsdf.mode = 2 #overwrite existing file
39+
nsdf.flushLimit = 100
40+
moose.connect(nsdf, 'requestOut', pulse, 'getOutputValue')
41+
print('event input', nsdf.eventInput, nsdf.eventInput.num)
42+
print(nsdf)
43+
44+
nsdf.eventInput.num = 1
45+
ei = nsdf.eventInput[0]
46+
print(ei.path)
47+
moose.connect(t_lead, 'spikeOut', nsdf.eventInput[0], 'input')
48+
tab = moose.Table('spiketab')
49+
tab.threshold = t_lead.threshold
50+
clock = moose.element('/clock')
51+
for ii in range(32):
52+
moose.setClock(ii, dt)
53+
moose.connect(pulse, 'output', tab, 'spike')
54+
print(datetime.now().isoformat())
55+
moose.reinit()
56+
moose.start(simtime)
57+
print(datetime.now().isoformat())
58+
np.savetxt('nsdf.txt', tab.vector)
59+
###################################
60+
# Set the environment attributes
61+
###################################
62+
nsdf.stringAttr['title'] = 'NSDF writing demo for moose'
63+
nsdf.stringAttr['description'] = '''An example of writing data to NSDF file from MOOSE simulation. In
64+
this simulation we generate square pules from a PulseGen object and
65+
use a SpikeGen to detect the threshold crossing events of rising
66+
edges. We store the pulsegen output as Uniform data and the threshold
67+
crossing times as Event data. '''
68+
nsdf.stringAttr['creator'] = getpass.getuser()
69+
nsdf.stringVecAttr['software'] = ['python2.7', 'moose3' ]
70+
nsdf.stringVecAttr['method'] = ['']
71+
nsdf.stringAttr['rights'] = ''
72+
nsdf.stringAttr['license'] = 'CC-BY-NC'
73+
# Specify units. MOOSE is unit agnostic, so we explicitly set the
74+
# unit attibutes on individual datasets
75+
nsdf.stringAttr['/data/uniform/PulseGen/outputValue/tunit'] = 's'
76+
nsdf.stringAttr['/data/uniform/PulseGen/outputValue/unit'] = 'A'
77+
eventDataPath = '/data/event/SpikeGen/spikeOut/{}_{}_{}/unit'.format(t_lead.vec.value,
78+
t_lead.getDataIndex(),
79+
t_lead.fieldIndex)
80+
nsdf.stringAttr[eventDataPath] = 's'
81+
82+
if __name__ == '__main__':
83+
setup_model()
84+
# Very basic tests
85+
nsdfFile = 'nsdf.txt'
86+
if not os.path.exists( nsdf.filename ):
87+
raise Exception("Test failed. No files : %s" % nsdfFile)
88+
if not os.path.exists( nsdfFile ):
89+
raise Exception("Test failed. No file : %s" % nsdfFile)
90+
91+
data = np.loadtxt( nsdfFile )
92+
assert len(data) == 60001, "Expected 60001 entries"

0 commit comments

Comments
 (0)