Skip to content

Commit

Permalink
python3 compatibility (#176)
Browse files Browse the repository at this point in the history
  • Loading branch information
1ozturkbe authored and bqpd committed Sep 17, 2019
1 parent f3027d7 commit 98a8298
Show file tree
Hide file tree
Showing 25 changed files with 60 additions and 34 deletions.
9 changes: 5 additions & 4 deletions gpkitmodels/GP/aircraft/engine/DF70/fitDF70.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import pandas as pd
import numpy as np
from numpy import logspace, log, log10
Expand All @@ -24,7 +25,7 @@
K = 2

cstrt, rmserror = fit(x, y, K, Type)
print "RMS error = %.4f" % rmserror
print("RMS error = %.4f" % rmserror)
yfit = cstrt.evaluate(x)

fig, ax = plt.subplots()
Expand All @@ -50,7 +51,7 @@
K = 2

cstrt, rmserror = fit(x,y,K,Type)
print "RMS error = %.4f" % rmserror
print("RMS error = %.4f" % rmserror)
yfit = cstrt.evaluate(x)

fig, ax = plt.subplots()
Expand All @@ -73,7 +74,7 @@
Type = 'SMA'
K = 1
cstrt, rmserror = fit(x,y,K,Type)
print "RMS error = %.4f" % rmserror
print("RMS error = %.4f" % rmserror)
yfit = cstrt.evaluate(x)

fig, ax = plt.subplots()
Expand Down Expand Up @@ -106,7 +107,7 @@

A = np.vstack([x, np.ones(len(x))]).T
m, c = np.linalg.lstsq(A, y)[0]
print "Equation: y = %.4gx + %.4f" % (m, c)
print("Equation: y = %.4gx + %.4f" % (m, c))
fig, ax = plt.subplots()
ax.plot(x, y, 'o', label='RCV Engine Data', markerfacecolor="None")
ax.plot(x, m*x + c, label='Fitted Line')
Expand Down
1 change: 1 addition & 0 deletions gpkitmodels/GP/aircraft/engine/df70.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" engine_model.py "
from builtins import zip
from gpkit import Model, Variable, units

class DF70(Model):
Expand Down
1 change: 1 addition & 0 deletions gpkitmodels/GP/aircraft/engine/gas_engine.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" engine_model.py "
from builtins import zip
from gpkit import Model, Variable, units
import os
import pandas as pd
Expand Down
5 changes: 2 additions & 3 deletions gpkitmodels/GP/aircraft/fuselage/cylindrical_fuselage.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
" cylindrical fuselage.py "
import numpy as np
from gpkit import Variable, Model
from fuel_tank import FuelTank
from fuselage_skin import FuselageSkin
from .fuel_tank import FuelTank
from .fuselage_skin import FuselageSkin

class Fuselage(Model):
"The thing that carries the fuel, engine, and payload"
Expand Down Expand Up @@ -88,4 +88,3 @@ def setup(self, static, state):
]

return constraints

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" fuselage drag fits "
from builtins import zip
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
Expand Down
8 changes: 4 additions & 4 deletions gpkitmodels/GP/aircraft/motor/motor_test.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
from gpkit import Model, parse_variables, SignomialsEnabled, SignomialEquality, units
from motor import Propulsor, Motor, MotorPerf
from gpkitmodels.GP.aircraft.motor.motor import Propulsor, Motor, MotorPerf
from gpkitmodels.GP.aircraft.prop.propeller import Propeller, ActuatorProp
from gpkitmodels.SP.aircraft.prop.propeller import BladeElementProp
from gpkitmodels.GP.aircraft.wing.wing_test import FlightState
from gpkitmodels.SP.aircraft.prop.propeller import BladeElementProp

class Propulsor_Test(Model):
"""Propulsor Test Model
Expand Down Expand Up @@ -47,7 +47,7 @@ def setup(self):
def actuator_propulsor_test():
test = Actuator_Propulsor_Test()
test.solve()

def ME_propulsor_test():
test = BladeElement_Propulsor_Test()
sol = test.localsolve()
Expand Down Expand Up @@ -102,6 +102,6 @@ def test():
actuator_propulsor_test()
propulsor_test()
ME_propulsor_test()

if __name__ == "__main__":
test()
3 changes: 2 additions & 1 deletion gpkitmodels/GP/aircraft/prop/arccos_fit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
import unittest
from numpy import log, exp, log10, vstack
from numpy import arccos,arange
Expand All @@ -10,4 +11,4 @@
K = 1

cstrt, rmsErr = fit(x,y,K,"SMA")
print rmsErr
print(rmsErr)
4 changes: 3 additions & 1 deletion gpkitmodels/GP/aircraft/tail/tailpolars/naca_cl0fits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"naca_polarfits.py"
from builtins import zip
from builtins import range
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -85,7 +87,7 @@ def plot_fits(naca_range, re_range):
return fig, ax

if __name__ == "__main__":
Re = range(200, 950, 50)
Re = list(range(200, 950, 50))
NACA = ["0005", "0008", "0009", "0010", "0015", "0020"]
X, Y = fit_setup(NACA, Re) # call fit(X, Y, 4, "SMA") to get fit
F, A = plot_fits(NACA, Re)
Expand Down
3 changes: 2 additions & 1 deletion gpkitmodels/GP/aircraft/wing/arctan_fit.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from gpfit.fit import fit
import os
import matplotlib.pyplot as plt
Expand All @@ -15,7 +16,7 @@ def arctanfit():

cn, err = fit(x, y, 1, "MA")
rm = err
print "RMS error: %.4f" % rm
print("RMS error: %.4f" % rm)

yfit = cn.evaluate(x)
df = cn.get_dataframe()
Expand Down
4 changes: 3 additions & 1 deletion gpkitmodels/GP/aircraft/wing/jho1polars/jho1_polarfits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"jho1_polarfits.py"
from builtins import zip
from builtins import range
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -77,7 +79,7 @@ def plot_fits(re):
return fig, ax, fig1

if __name__ == "__main__":
Re = range(200, 750, 50)
Re = list(range(200, 750, 50))
X, Y = fit_setup(Re) # call fit(X, Y, 4, "SMA") to get fit
F, A, F1 = plot_fits([300, 350, 400, 450, 500])
F.savefig("jho1polarfit1.pdf", bbox_inches="tight")
Expand Down
1 change: 1 addition & 0 deletions gpkitmodels/GP/aircraft/wing/wing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" wing.py "
from builtins import range
from os import sep
from os.path import abspath, dirname
import numpy as np
Expand Down
4 changes: 2 additions & 2 deletions gpkitmodels/GP/materials/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from composite import CFRPFabric, CFRPUD, Kevlar
from foam import FoamHD, FoamLD
from .composite import CFRPFabric, CFRPUD, Kevlar
from .foam import FoamHD, FoamLD

cfrpfabric = CFRPFabric()
cfrpud = CFRPUD()
Expand Down
3 changes: 2 additions & 1 deletion gpkitmodels/SP/SimPleAC/SimPleAC.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from gpkit import Model, Variable, SignomialsEnabled, VarKey, units
import numpy as np
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -97,4 +98,4 @@ def test():
m = SimPleAC()
m.cost = m['W_f']
sol = m.localsolve(verbosity = 4)
print sol.table()
print(sol.table())
4 changes: 2 additions & 2 deletions gpkitmodels/SP/SimPleAC/SimPleAC_multimission.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from builtins import range
import numpy as np
from gpkit import Model, Variable, SignomialsEnabled, SignomialEquality, \
VarKey, units, Vectorize, settings
from SimPleAC_mission import Mission, SimPleAC
from gpkitmodels.SP.SimPleAC.SimPleAC_mission import Mission, SimPleAC
from gpkitmodels.SP.atmosphere.atmosphere import Atmosphere

# SimPleAC with multimission design (updated 5/31/2019, by Berk Ozturk)
Expand Down Expand Up @@ -80,4 +81,3 @@ def test():

m.cost = (m.missions[0]['W_{f_m}']*units('1/N') + m.missions[1]['C_m']*m.missions[1]['t_m'])
sol = m.localsolve(verbosity = 2)

5 changes: 4 additions & 1 deletion gpkitmodels/SP/aircraft/prop/dae51polars/dae51_polarfits.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
"dae51_polarfits.py"
from __future__ import print_function
from builtins import zip
from builtins import range
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -108,7 +111,7 @@ def plot_fits(re, cnstr, x, y):
X, Y = fit_setup(Re) # call fit(X, Y, 4, "SMA") to get fit
np.random.seed(0)
cn, err = fit(X, Y, 3, "SMA")
print "RMS error: %.5f" % err
print("RMS error: %.5f" % err)
df = cn.get_dataframe()
if GENERATE:
path = os.path.dirname(inspect.getfile(ActuatorProp))
Expand Down
1 change: 1 addition & 0 deletions gpkitmodels/SP/aircraft/prop/propeller.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" propeller model "
from builtins import range
from numpy import pi
from gpkit import Model, Variable,Vectorize,parse_variables, SignomialsEnabled, SignomialEquality
from gpkit.constraints.tight import Tight as TCS
Expand Down
3 changes: 2 additions & 1 deletion gpkitmodels/SP/atmosphere/atmosphere.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from __future__ import print_function
from gpkit import Model, Variable, SignomialsEnabled, SignomialEquality, VarKey, units
from gpkit.constraints.bounded import Bounded
from gpkit import Vectorize
Expand Down Expand Up @@ -60,4 +61,4 @@ def setup(self):
m.substitutions.update({'h':5000*units('m')})
m.cost = m['\\mu']*m['\\rho']
sol = m.localsolve(verbosity = 3)
print sol.table()
print(sol.table())
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"get the python code from the markdown file"
from gpkit.tools import mdparse
exec mdparse("moi.md")
exec(mdparse("moi.md"))
2 changes: 1 addition & 1 deletion gpkitmodels/misc/Net Present Value/npv.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"get the python code from the markdown file"
from gpkit.tools import mdparse
exec mdparse("npv.md")
exec(mdparse("npv.md"))
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Below is a Weights breakdown for the Blended wing body. This method is GP Compatible!

from builtins import range
from gpkit import VectorVariable, Variable, Model, units
import numpy as np
from gpkit.tools import te_exp_minus1
Expand Down Expand Up @@ -39,7 +40,7 @@ def secant(x, nterm):
69348874393137901,
15514534163557086905] )
if nterm > 12:
n_extend = np.asarray(range(13, nterm+1))
n_extend = np.asarray(list(range(13, nterm+1)))
E2n_add = (8 * np.sqrt(n_extend/np.pi)
* (4*n_extend/(np.pi * np.exp(1)))**(2*n_extend))
E2n = np.append(E2n, E2n_add)
Expand Down
18 changes: 11 additions & 7 deletions gpkitmodels/tools/fit_constraintset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import print_function
from builtins import str
from builtins import zip
from builtins import range
import numpy as np
from gpkit import ConstraintSet
from gpkit import Variable, NomialArray
from gpkit.small_scripts import unitstr
from xfoilWrapper import blind_call, single_cl
import numpy as np
from .xfoilWrapper import blind_call, single_cl

class FitCS(ConstraintSet):
def __init__(self, df, ivar, dvars, nobounds=False, err_margin=False, airfoil=False):
Expand Down Expand Up @@ -107,7 +111,7 @@ def process_result(self, result, TOL=0.03):
elif "naca" in self.airfoil:
topline = self.airfoil + "\n"
else:
print "Bad airfoil specified"
print("Bad airfoil specified")
else:
runxfoil = False
bndwrn = True
Expand All @@ -128,12 +132,12 @@ def process_result(self, result, TOL=0.03):
try:
x = blind_call(topline, cl, re, 0.0)
if "VISCAL: Convergence failed" in x:
print "Convergence Warning: %s" % failmsg
print("Convergence Warning: %s" % failmsg)
cd, cl = cdgp, 1.0
else:
cd, cl = x[0], x[1]
except:
print "Unable to start Xfoil: %s" % failmsg
print("Unable to start Xfoil: %s" % failmsg)
cd, cl = cdgp, 1.0

err = 1 - cdgp/cd
Expand All @@ -142,7 +146,7 @@ def process_result(self, result, TOL=0.03):
" Xfoil cd=%.6f, GP sol cd=%.6f" %
(", ".join(d.descr["models"]), err, re, cl, cd,
cdgp))
print "Warning: %s" % msg
print("Warning: %s" % msg)
else:
bndwrn = False

Expand All @@ -165,4 +169,4 @@ def process_result(self, result, TOL=0.03):
+ " %s bound. Solution is %.4f but"
" bound is %.4f" %
(direct, num, bnd))
print "Warning: " + msg
print("Warning: " + msg)
2 changes: 2 additions & 0 deletions gpkitmodels/tools/ipynb2module.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

"tool for importing ipython notebooks as modules"
from __future__ import print_function


from builtins import object
import io, os, sys, types

# Import Modules
Expand Down
1 change: 1 addition & 0 deletions gpkitmodels/tools/summing_constraintset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
" helpers.py "
from builtins import zip
import numpy as np
from gpkit import ConstraintSet, Variable

Expand Down
4 changes: 3 additions & 1 deletion gpkitmodels/tools/xfoilWrapper.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import print_function
from builtins import range
import subprocess
import numpy as np
import scipy.optimize as spo
Expand Down Expand Up @@ -68,7 +70,7 @@ def single_cl(CL, Re = 1e7, M = 0.0, airfoil=[], pathname = "/home/ckarcher/Xfoi
elif ('naca' == airfoil.lower()[0:4]) and (len(airfoil)==8):
topline = airfoil + ' \n'
else:
print "Error: Invalid airfoil passed into XFOIL. Defaulting to a NACA0012."
print("Error: Invalid airfoil passed into XFOIL. Defaulting to a NACA0012.")
topline = 'naca0012 \n'

initial_list = np.linspace(sample_min,sample_max,num_samples).tolist()
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
author="MIT Department of Aeronautics and Astronautics",
author_email="gpkit@mit.edu",
url="https://www.github.com/hoburg/gpkit-models",
install_requires=["numpy>=1.12", "scipy", "pint"],
install_requires=["numpy>=1.12", "scipy", "pint", "future"],
version="0.0.0.0",
packages=find_packages(),
package_data={"gpkitmodels": ["GP/aircraft/wing/*.csv",
Expand Down

0 comments on commit 98a8298

Please sign in to comment.