Commit b495474c authored by Jorn Baayen's avatar Jorn Baayen

Pass data unit tests.

parent 8910f2e9
......@@ -30,13 +30,13 @@ def load(fname, delimiter=',', with_time=False):
# Read the first line, this should be a header. Count columns by
# counting separator.
sample_csvfile = csvfile.readline()
n_semicolon = sample_csvfile.count(';')
n_semicolon = sample_csvfile.count(b';')
# We actually only need one number to evaluate if commas are used as decimal separator, but
# certain csv writers don't use a decimal when the value has no meaningful decimal
# (e.g. 12.0 becomes 12) so we read the next 1024 bytes to make sure we catch a number.
sample_csvfile = csvfile.read(1024)
# Count the commas
n_comma_decimal = sample_csvfile.count(',')
n_comma_decimal = sample_csvfile.count(b',')
# If commas are used as decimal separator, we need additional
# converters.
if n_comma_decimal:
......
......@@ -2,7 +2,7 @@
import numpy as np
from casadi import if_else, logic_and, Function, nlpsol, SX, vertcat, inf, sum2
from bspline import BSpline
from .bspline import BSpline
class BSpline1D(BSpline):
......@@ -105,9 +105,9 @@ class BSpline1D(BSpline):
xpt = SX.sym('xpt')
ypt = SX.sym('ypt')
sq_diff = Function('sq_diff', [xpt, ypt], [
(ypt - bspline([c, xpt])[0])**2])
sq_diff = sq_diff.map('sq_diff', N)
f = sum2(sq_diff([SX(x), SX(y)])[0])
(ypt - bspline(c, xpt)[0])**2])
sq_diff = sq_diff.map('sq_diff', 'serial', N)
f = sum2(sq_diff(SX(x), SX(y))[0])
# Setup Curvature Constraints
delta_c_max = np.full(num_knots - 1, inf)
......@@ -124,11 +124,11 @@ class BSpline1D(BSpline):
max_slope_slope = np.full(num_test_points, -epsilon)
else:
min_slope_slope = np.full(num_test_points, epsilon)
monotonicity_constraints = vertcat(
c[i + 1] - c[i] for i in range(num_knots - 1))
monotonicity_constraints = vertcat(*[
c[i + 1] - c[i] for i in range(num_knots - 1)])
x_linspace = np.linspace(x[0], x[-1], num_test_points)
curvature_constraints = vertcat(
bspline_prime_prime([c, SX(x)])[0] for x in x_linspace)
curvature_constraints = vertcat(*[
bspline_prime_prime(c, SX(x))[0] for x in x_linspace])
g = vertcat(monotonicity_constraints, curvature_constraints)
lbg = np.concatenate((delta_c_min, min_slope_slope))
ubg = np.concatenate((delta_c_max, max_slope_slope))
......@@ -136,13 +136,12 @@ class BSpline1D(BSpline):
# Perform mini-optimization problem to calculate the the values of c
nlp = {'x': c, 'f': f, 'g': g}
my_solver = "ipopt"
solver = nlpsol("solver", my_solver, nlp, {
'print_time': 0, 'print_level': 0})
solver = nlpsol("solver", my_solver, nlp, {'print_time': 0})
sol = solver(lbg=lbg, ubg=ubg)
stats = solver.getStats()
stats = solver.stats()
return_status = stats['return_status']
if return_status not in ['Solve_Succeeded', 'Solved_To_Acceptable_Level', 'SUCCESS']:
raise Exception("Spline fitting failed with status {}".format(return_status))
# Return the new tck tuple
return (t, sol['x'].get(), k)
return (t, sol['x'], k)
# cython: embedsignature=True
from casadi import if_else, logic_and
from bspline import BSpline
from .bspline import BSpline
class BSpline2D(BSpline):
......
......@@ -22,5 +22,5 @@
<pi:event date="2013-05-20" flag="0" time="05:00:00" value="5.4175" />
<pi:event date="2013-05-20" flag="0" time="06:00:00" value="5.4175" />
<pi:event date="2013-05-20" flag="0" time="07:00:00" value="5.4175" />
<pi:event date="2013-05-20" time="08:00:00" value="-999.0" /><pi:event date="2013-05-20" time="09:00:00" value="12345.0" /><pi:event date="2013-05-20" time="10:00:00" value="12345.0" /></pi:series>
<pi:event date="2013-05-20" time="08:00:00" value="-999.0" /><pi:event date="2013-05-20" time="09:00:00" value="12345.0" /></pi:series>
</pi:TimeSeries>
\ No newline at end of file
......@@ -5,7 +5,7 @@ import os
import numpy as np
from datetime import datetime
from data_path import data_path
from .data_path import data_path
class TestCSV(TestCase):
......
......@@ -8,7 +8,7 @@ import os
import datetime
import copy
from data_path import data_path
from .data_path import data_path
class TestPI(TestCase):
......
......@@ -10,7 +10,7 @@ from unittest import TestCase
import rtctools.data.pi as pi
from data_path import data_path
from .data_path import data_path
class TestDiag(TestCase):
......
from unittest import TestCase, expectedFailure
from casadi import SX, SXFunction, linspace
from casadi import SX, Function, linspace
import numpy as np
import rtctools.data.interpolation.bspline1d
......
from data_path import data_path
from .data_path import data_path
from test_case import TestCase
from rtctools.optimization.collocated_integrated_optimization_problem import CollocatedIntegratedOptimizationProblem
......
from data_path import data_path
from .data_path import data_path
from test_case import TestCase
from rtctools.optimization.collocated_integrated_optimization_problem import CollocatedIntegratedOptimizationProblem
......
from data_path import data_path
from .data_path import data_path
from test_case import TestCase
from rtctools.optimization.optimization_problem import OptimizationProblem
......
from data_path import data_path
from .data_path import data_path
from test_case import TestCase
from rtctools.optimization.collocated_integrated_optimization_problem import CollocatedIntegratedOptimizationProblem
......
from data_path import data_path
from .data_path import data_path
from test_case import TestCase
from rtctools.optimization.collocated_integrated_optimization_problem import CollocatedIntegratedOptimizationProblem
......
from data_path import data_path
from .data_path import data_path
from test_case import TestCase
from rtctools.optimization.collocated_integrated_optimization_problem import CollocatedIntegratedOptimizationProblem
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment