Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B-ASIC - Better ASIC Toolbox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Computer Engineering
B-ASIC - Better ASIC Toolbox
Commits
61be4841
Commit
61be4841
authored
2 years ago
by
Olle Hansson
Browse files
Options
Downloads
Patches
Plain Diff
Added doc and test for signalgenerator FromFile
parent
b11aa808
No related branches found
No related tags found
No related merge requests found
Pipeline
#90331
failed
2 years ago
Stage: test
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
b_asic/GUI/signal_generator_input.py
+5
-0
5 additions, 0 deletions
b_asic/GUI/signal_generator_input.py
b_asic/signal_generator.py
+9
-3
9 additions, 3 deletions
b_asic/signal_generator.py
test/test_signal_generator.py
+13
-0
13 additions, 0 deletions
test/test_signal_generator.py
with
27 additions
and
3 deletions
b_asic/GUI/signal_generator_input.py
+
5
−
0
View file @
61be4841
...
...
@@ -103,6 +103,11 @@ class ZeroPadInput(SignalGeneratorInput):
class
FromFileInput
(
SignalGeneratorInput
):
"""
Class for graphically configuring and generating a
:class:`~b_asic.signal_generators.FromFile` signal generator.
"""
def
__init__
(
self
,
*
args
,
**
kwargs
):
super
().
__init__
(
*
args
,
**
kwargs
)
self
.
file_label
=
QLabel
(
"
Browse
"
)
...
...
This diff is collapsed.
Click to expand it.
b_asic/signal_generator.py
+
9
−
3
View file @
61be4841
...
...
@@ -13,6 +13,7 @@ if you want more information.
from
math
import
pi
,
sin
from
numbers
import
Number
from
pathlib
import
Path
from
typing
import
Optional
,
Sequence
import
numpy
as
np
...
...
@@ -172,12 +173,17 @@ class FromFile(SignalGenerator):
"""
def
__init__
(
self
,
path
)
->
None
:
try
:
Path
(
path
).
resolve
(
strict
=
True
)
except
FileNotFoundError
:
raise
Exception
(
"
Selected input file not found.
"
)
try
:
data
=
np
.
loadtxt
(
path
,
dtype
=
complex
).
tolist
()
self
.
_data
=
data
self
.
_len
=
len
(
data
)
except
FileNotFound
Error
:
self
.
_window
.
logger
.
error
(
f
"
Selected input file not
found
.
"
)
except
Value
Error
:
raise
Exception
(
"
Selected input file
is
not
of the right format
.
"
)
def
__call__
(
self
,
time
:
int
)
->
complex
:
if
0
<=
time
<
self
.
_len
:
...
...
@@ -185,7 +191,7 @@ class FromFile(SignalGenerator):
return
0.0
def
__repr__
(
self
)
->
str
:
return
f
"
ZeroPad
(
{
self
.
_data
}
)
"
return
f
"
FromFile
(
{
self
.
_data
}
)
"
class
Sinusoid
(
SignalGenerator
):
...
...
This diff is collapsed.
Click to expand it.
test/test_signal_generator.py
+
13
−
0
View file @
61be4841
import
os
from
math
import
sqrt
import
pytest
...
...
@@ -5,6 +6,7 @@ import pytest
from
b_asic.signal_generator
import
(
Constant
,
Delay
,
FromFile
,
Gaussian
,
Impulse
,
Sinusoid
,
...
...
@@ -269,3 +271,14 @@ def test_division():
assert
str
(
g
)
==
"
Sinusoid(0.5, 0.25) / (0.5 * Step())
"
assert
isinstance
(
g
,
_DivGenerator
)
def
test_fromfile
():
absolute_path
=
os
.
path
.
dirname
(
__file__
)
relative_path
=
"
../examples/input.csv
"
full_path
=
os
.
path
.
join
(
absolute_path
,
relative_path
)
g
=
FromFile
(
full_path
)
assert
g
(
-
1
)
==
0.0
assert
g
(
0
)
==
0
assert
g
(
1
)
==
1
assert
g
(
2
)
==
0
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment