Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify NI-FGEN example and remove its use of numpy and scipy #1817

Merged
merged 17 commits into from
Aug 30, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ All notable changes to this project will be documented in this file.
* ### ALL
* #### Added
* #### Changed
* Fix [#1811](https://github.com/ni/nimi-python/issues/1811): nimi-python uses scipy which keeps us from adding support to Python 3.10
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
* Replaced scipy usage in NI-FGEN examples with hand-crafted functions and dropped scipy installation system-test setup.
* #### Removed
* ### `nidcpower` (NI-DCPower)
* #### Added
Expand Down
1 change: 0 additions & 1 deletion build/templates/tox-system_tests.ini.mako
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ deps =
${module_name}-system_tests: coverage
${module_name}-system_tests: numpy
${module_name}-system_tests: hightime
${module_name}-system_tests: scipy
${module_name}-system_tests: fasteners
${module_name}-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nidcpower/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps =
nidcpower-system_tests: coverage
nidcpower-system_tests: numpy
nidcpower-system_tests: hightime
nidcpower-system_tests: scipy
nidcpower-system_tests: fasteners
nidcpower-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nidigital/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ deps =
nidigital-system_tests: coverage
nidigital-system_tests: numpy
nidigital-system_tests: hightime
nidigital-system_tests: scipy
nidigital-system_tests: fasteners
nidigital-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nidmm/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps =
nidmm-system_tests: coverage
nidmm-system_tests: numpy
nidmm-system_tests: hightime
nidmm-system_tests: scipy
nidmm-system_tests: fasteners
nidmm-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nifake/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ deps =
nifake-system_tests: coverage
nifake-system_tests: numpy
nifake-system_tests: hightime
nifake-system_tests: scipy
nifake-system_tests: fasteners
nifake-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nifgen/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ deps =
nifgen-system_tests: coverage
nifgen-system_tests: numpy
nifgen-system_tests: hightime
nifgen-system_tests: scipy
nifgen-system_tests: fasteners
nifgen-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nimodinst/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps =
nimodinst-system_tests: coverage
nimodinst-system_tests: numpy
nimodinst-system_tests: hightime
nimodinst-system_tests: scipy
nimodinst-system_tests: fasteners
nimodinst-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/niscope/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ deps =
niscope-system_tests: coverage
niscope-system_tests: numpy
niscope-system_tests: hightime
niscope-system_tests: scipy
niscope-system_tests: fasteners
niscope-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nise/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps =
nise-system_tests: coverage
nise-system_tests: numpy
nise-system_tests: hightime
nise-system_tests: scipy
nise-system_tests: fasteners
nise-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/niswitch/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ deps =
niswitch-system_tests: coverage
niswitch-system_tests: numpy
niswitch-system_tests: hightime
niswitch-system_tests: scipy
niswitch-system_tests: fasteners
niswitch-system_tests: pytest-json

Expand Down
1 change: 0 additions & 1 deletion generated/nitclk/tox-system_tests.ini
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ deps =
nitclk-system_tests: coverage
nitclk-system_tests: numpy
nitclk-system_tests: hightime
nitclk-system_tests: scipy
nitclk-system_tests: fasteners
nitclk-system_tests: pytest-json

Expand Down
47 changes: 42 additions & 5 deletions src/nifgen/examples/nifgen_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,52 @@
import argparse
import nifgen
import numpy as np
from scipy import signal

import math
import sys
import time

number_of_points = 256
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved


def equivalent_phase(phase):
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
if phase < 0:
phase += (abs(phase) // (2 * math.pi) + 1) * 2 * math.pi
elif phase > (2 * math.pi):
phase = phase % (2 * math.pi)
return phase # phase in range [0, 2 * PI]


def duty_cycle_is_on(phase, duty_cycle):
# duty_cycle is a decimal in the range [0, 1]
phase = equivalent_phase(phase)
if duty_cycle == 0:
return False
elif phase == 2 * math.pi:
return True
cycle_percentage = phase / (2 * math.pi)
return cycle_percentage <= duty_cycle


def square_wave(t, duty_cycle):
wfm = []
for time in t:
if duty_cycle_is_on(time, duty_cycle):
wfm.append(1.0)
else:
wfm.append(-1.0)
return wfm


def sawtooth_wave(t):
wfm = []
for time in t:
phase = equivalent_phase(time)
cycle_percentage = phase / (2 * math.pi)
wfm.append(-1.0 + (2 * cycle_percentage))
return wfm


def calculate_sinewave():
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
time = np.linspace(start=0, stop=10, num=number_of_points) # np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
amplitude = np.sin(time)
Expand All @@ -32,15 +71,13 @@ def calculate_rampdown():

def calculate_square():
time = np.linspace(start=0, stop=10, num=number_of_points) # np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
square_build = signal.square(t=time, duty=0.5) # signal.square(t, duty=0.5)
square = square_build.tolist() # List of Float
square = square_wave(t=time, duty_cycle=0.5)
return square


def calculate_triangle():
ni-jfitzger marked this conversation as resolved.
Show resolved Hide resolved
time = np.linspace(start=0, stop=1, num=number_of_points) # np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
triangle_build = signal.sawtooth(t=time) # signal.sawtooth(t, width=1)
triangle = triangle_build.tolist() # List of Float
triangle = sawtooth_wave(t=time)
return triangle


Expand Down