-
Notifications
You must be signed in to change notification settings - Fork 0
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
create workflow ci #6
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# This workflow will install Python dependencies, run tests and lint with a single version of Python | ||
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions | ||
|
||
name: Python application | ||
|
||
on: push | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python 3.6 | ||
uses: actions/setup-python@v1 | ||
with: | ||
python-version: 3.6 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Lint with flake8 | ||
run: | | ||
pip install flake8 | ||
# stop the build if there are Python syntax errors or undefined names | ||
flake8 . --count --select=E9,F63,F7,F82,F401,E711,F403,F841 --show-source --statistics | ||
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | ||
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | ||
- name: Test with pytest | ||
run: | | ||
pip install pytest | ||
# pytest | ||
python setup.py test |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,36 @@ | ||
import numpy as np | ||
import numpy | ||
import matplotlib.pyplot | ||
from mpl_toolkits.mplot3d import Axes3D | ||
|
||
|
||
def prepare_quaternion_array_for_plotting(q_ary, rotate_axis='x'): | ||
""" Converting all attitudes to points on a sphere """ | ||
"""Converting all attitudes to points on a sphere.""" | ||
ary = None | ||
if len(q_ary.shape) == 1: | ||
ary = numpy.empty((3, q_ary.shape[0])) | ||
for i, q in enumerate(q_ary): | ||
ary[:,i] = q.to_unit_vector(rotate_axis)[:,0] | ||
ary[:, i] = q.to_unit_vector(rotate_axis)[:, 0] | ||
elif len(q_ary.shape) == 2: | ||
ary = numpy.empty((3, q_ary.shape[1])) | ||
for i, q in enumerate(q_ary): | ||
ary[:,i] = q[0].to_unit_vector(rotate_axis)[:,0] | ||
ary[:, i] = q[0].to_unit_vector(rotate_axis)[:, 0] | ||
else: | ||
raise InputError("expected 1- or 2-D array") | ||
raise Exception("expected 1- or 2-D array") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fair I couldn't find a deceleration for InputError. I'll change these. I too dislike base Exceptions. |
||
return ary | ||
|
||
|
||
def scatter(q_ary, rotate_axis='x', fig = None, axes = None, **kwargs): | ||
""" Plot an array of quaternions as scatter points on a sphere """ | ||
|
||
def scatter(q_ary, rotate_axis='x', fig=None, axes=None, **kwargs): | ||
"""Plot an array of quaternions as scatter points on a sphere.""" | ||
if fig is None: | ||
fig = matplotlib.pyplot.figure() | ||
if axes is None: | ||
axes = fig.add_subplot(111, projection='3d') | ||
|
||
ary = prepare_quaternion_array_for_plotting(q_ary, rotate_axis = rotate_axis) | ||
ary = prepare_quaternion_array_for_plotting(q_ary, rotate_axis=rotate_axis) | ||
|
||
return axes.scatter(ary[0,:], ary[1,:], ary[2,:], **kwargs) | ||
return axes.scatter(ary[0, :], ary[1, :], ary[2, :], **kwargs) | ||
|
||
|
||
def plot(q_ary, t = None, rotate_axis='x', fig = None, axes = None, **kwargs): | ||
def plot(q_ary, t=None, rotate_axis='x', fig=None, axes=None, **kwargs): | ||
""" | ||
Plot an array of quaternions using lines on the surface of a sphere. | ||
|
||
|
@@ -41,7 +39,6 @@ def plot(q_ary, t = None, rotate_axis='x', fig = None, axes = None, **kwargs): | |
displayed blue. | ||
|
||
""" | ||
|
||
if fig is None: | ||
fig = matplotlib.pyplot.figure() | ||
if axes is None: | ||
|
@@ -53,14 +50,19 @@ def plot(q_ary, t = None, rotate_axis='x', fig = None, axes = None, **kwargs): | |
tc = (t - t.min()) / (t.max() - t.min()) | ||
c = numpy.vstack((tc, numpy.zeros_like(tc), -tc + 1.0)) | ||
|
||
for i in range(1,ary.shape[1]): | ||
axes.plot(ary[0,i-1:i+1], ary[1,i-1:i+1], ary[2,i-1:i+1], c = tuple(c[:,i]), **kwargs) | ||
for i in range(1, ary.shape[1]): | ||
axes.plot(ary[0, i - 1:i + 1], | ||
ary[1, i - 1:i + 1], | ||
ary[2, i - 1:i + 1], | ||
c=tuple(c[:, i]), **kwargs) | ||
Comment on lines
-56
to
+57
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't love this type of change. It's going to make some code absolutely unreadable. I realize that expressions should be space-separated in general, but these are expressions within bracket notation. |
||
else: | ||
return axes.plot(ary[0,:], ary[1,:], ary[2,:], **kwargs) | ||
return axes.plot(ary[0, :], ary[1, :], ary[2, :], **kwargs) | ||
|
||
|
||
def plot_frame(q, r = numpy.zeros((3,1)), fig = None, axes = None, axis_size = 1.0): | ||
def plot_frame(q, r=numpy.zeros((3, 1)), fig=None, axes=None, axis_size=1.0): | ||
""" | ||
Plot a quaternion as a coordinate frame, with red, green, and blue | ||
Plot a quaternion as a coordinate frame, with red, green, and blue. | ||
|
||
referring to x, y, and z. | ||
|
||
Also accepts an optional position to move the frame to (post-rotation). | ||
|
@@ -70,21 +72,21 @@ def plot_frame(q, r = numpy.zeros((3,1)), fig = None, axes = None, axis_size = 1 | |
if axes is None: | ||
axes = fig.add_subplot(111, projection='3d') | ||
|
||
xh = numpy.zeros((3,2)) | ||
xh = numpy.zeros((3, 2)) | ||
yh = numpy.zeros_like(xh) | ||
zh = numpy.zeros_like(xh) | ||
xh[0,1] = axis_size | ||
yh[1,1] = axis_size | ||
zh[2,1] = axis_size | ||
xh[0, 1] = axis_size | ||
yh[1, 1] = axis_size | ||
zh[2, 1] = axis_size | ||
Comment on lines
-73
to
+80
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as with the array indexing. I don't think this change substantially improves readability. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, I'm going to push back on the second part of this one a bit more because it doesn't actually appear in pep8: https://stackoverflow.com/questions/31741418/pep8-space-after-a-comma/37064013#37064013 I think there should be spaces after commas except within array notation. The examples in pep8 do show spaces after commas, even though this isn't specifically enumerated; but they don't show multi-dimensional array indexing notation. Thoughts? |
||
|
||
# Transform the frame (rotate it and then move it) | ||
T = q.to_matrix() | ||
txh = np.dot(T, xh) + r | ||
tyh = np.dot(T, yh) + r | ||
tzh = np.dot(T, zh) + r | ||
axes.plot(txh[0,:], txh[1,:], txh[2,:], c='r') | ||
axes.plot(tyh[0,:], tyh[1,:], tyh[2,:], c='g') | ||
axes.plot(tzh[0,:], tzh[1,:], tzh[2,:], c='b') | ||
txh = numpy.dot(T, xh) + r | ||
tyh = numpy.dot(T, yh) + r | ||
tzh = numpy.dot(T, zh) + r | ||
|
||
axes.plot(txh[0, :], txh[1, :], txh[2, :], c='r') | ||
axes.plot(tyh[0, :], tyh[1, :], tyh[2, :], c='g') | ||
axes.plot(tzh[0, :], tzh[1, :], tzh[2, :], c='b') | ||
|
||
return axes |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -11,19 +11,18 @@ | |||||
from math import sqrt, cos, sin, pi | ||||||
import numpy as np | ||||||
|
||||||
def randu(symmetric_range = 1.0): | ||||||
|
||||||
def randu(symmetric_range=1.0): | ||||||
""" | ||||||
Generate a uniform random number with mean 0 and range | ||||||
(-symmetric_range, +symmetric_range). Default argument (1.0) | ||||||
gives mean 0 and range (-1, 1). | ||||||
""" | ||||||
|
||||||
return (np.random.rand() * 2.0 - 1.0) * symmetric_range | ||||||
|
||||||
def uniform_random_axis(max_theta = 2.0 * pi, z_range = 1.0): | ||||||
""" | ||||||
Generate a unit random axis from a uniform distribution. | ||||||
""" | ||||||
|
||||||
def uniform_random_axis(max_theta=2.0 * pi, z_range=1.0): | ||||||
"""Generate a unit random axis from a uniform distribution.""" | ||||||
if max_theta == 0.0: | ||||||
theta = 0.0 | ||||||
else: | ||||||
|
@@ -55,11 +54,9 @@ def rand( | |||||
|
||||||
""" | ||||||
if axis is not None and angle is not None: | ||||||
raise StandardError("expected non-fixed angle or non-fixed axis or both") | ||||||
raise Exception("expected non-fixed angle or non-fixed axis or both") | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
if axis is None: | ||||||
axis = axis_generator(**axis_generator_kwargs) | ||||||
if angle is None: | ||||||
angle = angle_generator() | ||||||
return pq.Quat.from_angle_axis(angle, *axis) | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import os | ||
import sys | ||
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
|
||
import pyquat as pq | ||
import pyquat.wahba.esoq as pq_esoq | ||
import pyquat.random as pqr | ||
from pyquat import Quat | ||
# import os | ||
# import sys | ||
# sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) | ||
# | ||
# import pyquat as pq | ||
# import pyquat.wahba.esoq as pq_esoq | ||
# import pyquat.random as pqr | ||
# from pyquat import Quat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not clear on what this does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an abomination to use the things imported from the _pyquat. I regret it already, but I'm not sure how to do this any better.
Unused imports are bad, but the unused imports here are kinda-sorta necessary to load the context for the other things downrange that use this init as the conduit into the cython.
Cython itself didn't have any particularly clear patterns on how to explicitly import without leaving unused imports, or having unclear context.