diff --git a/solar/fits/airfoil/polarfits.py b/solar/fits/airfoil/polarfits.py index 1e2e5f4..683c4a6 100644 --- a/solar/fits/airfoil/polarfits.py +++ b/solar/fits/airfoil/polarfits.py @@ -1,4 +1,7 @@ "jho1_polarfits.py" +from __future__ import print_function +from builtins import zip +from builtins import range import numpy as np from numpy import exp import pandas as pd @@ -94,7 +97,7 @@ def plot_fits(cnstr, x, y): X, Y = fit_setup(Re_r, tau_r) # 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() df.to_csv("../../dai1336a.csv", index=False) diff --git a/solar/npod_trade.py b/solar/npod_trade.py index 7d434a3..76d7f85 100644 --- a/solar/npod_trade.py +++ b/solar/npod_trade.py @@ -1,5 +1,7 @@ " number of pods trade study " +from __future__ import print_function # from solar import Mission, Aircraft +from builtins import range import matplotlib.pyplot as plt import pandas as pd import numpy as np @@ -50,16 +52,16 @@ def plot_shear(model, result): S = result(model.mission[1].winggust.S) m = result(model.mission[1].winggust.M) fig, ax = plt.subplots(2) - ax[0].plot(range(20), S) - ax[1].plot(range(20), m) + ax[0].plot(list(range(20)), S) + ax[1].plot(list(range(20)), m) ax[0].grid(); ax[1].grid() fig.savefig("shearandmoment.pdf") S = result(model.mission[1].wingg.S) m = result(model.mission[1].wingg.M) fig, ax = plt.subplots(2) - ax[0].plot(range(20), S) - ax[1].plot(range(20), m) + ax[0].plot(list(range(20)), S) + ax[1].plot(list(range(20)), m) ax[0].grid(); ax[1].grid() fig.savefig("shearandmoment2.pdf") diff --git a/solar/relaxed_constants.py b/solar/relaxed_constants.py index b2f810d..f298679 100644 --- a/solar/relaxed_constants.py +++ b/solar/relaxed_constants.py @@ -1,3 +1,5 @@ +from __future__ import print_function +from builtins import str from gpkit.constraints.relax import ConstantsRelaxed from gpkit.constraints.bounded import Bounded from gpkit import Model @@ -44,8 +46,8 @@ def post_process(sol): bdvars = [d for d in sol.program.varkeys if "Relax" in str(d) and "before" not in str(d) and sol(d).magnitude >= 1.001] if bdvars: - print "GP iteration has relaxed constants" - print sol.program.result.table(varkeys) + print("GP iteration has relaxed constants") + print(sol.program.result.table(varkeys)) return bdvars diff --git a/solar/season.py b/solar/season.py index aa6e2a0..02b53f3 100644 --- a/solar/season.py +++ b/solar/season.py @@ -1,4 +1,6 @@ " run seasonal trade " +from builtins import zip +from builtins import range import sys import numpy as np import pandas as pd @@ -20,7 +22,7 @@ def season(lats): mtows = mtows + [np.nan]*(4-len(mtows)) break V = Aircraft(sp=False) - M = Mission(V, latitude=range(1, l+1, 1), day=d) + M = Mission(V, latitude=list(range(1, l+1, 1)), day=d) M.cost = M[M.aircraft.Wtotal] try: sol = M.solve() @@ -42,7 +44,7 @@ def plot_season(df): colors = ["#014636", "#016c59", "#02818a", "#3690c0", "#67a9cf"] mrks = ["o", "v", "D", "^", "s"] for d, cl, mk in zip(df, colors, mrks): - ax.plot(range(1, 5), df[d], ms=7, lw=2, color=cl, ls="dashed", + ax.plot(list(range(1, 5)), df[d], ms=7, lw=2, color=cl, ls="dashed", marker=mk, label="%s$^{\\circ}$ Lat" % d) ax.set_xlim([0.5, 4.5]) @@ -71,7 +73,7 @@ def test(): GENERATE = False if GENERATE: - DF = season(range(20, 30, 2)) + DF = season(list(range(20, 30, 2))) DF.to_csv("season.generated.csv") else: DF = pd.read_csv("season.generated.csv") diff --git a/solar/sens_chart.py b/solar/sens_chart.py index 69c6115..16731da 100644 --- a/solar/sens_chart.py +++ b/solar/sens_chart.py @@ -17,7 +17,7 @@ def get_highestsens(model, res, varnames=None, N=10): for vname in varnames: sen = res["sensitivities"]["constants"][vname] if hasattr(sen, "__len__"): - val = max(np.abs(sen.values())) + val = max(np.abs(list(sen.values()))) vk = [svk for svk in sen if abs(sen[svk]) == val][0] sen = sum(sen.values()) else: diff --git a/solar/solar.py b/solar/solar.py index d00a55c..171becd 100644 --- a/solar/solar.py +++ b/solar/solar.py @@ -1,6 +1,9 @@ " Simple Solar-Electric Powered Aircraft Model " +from __future__ import division #pylint: disable=invalid-name, too-many-instance-attributes, too-many-locals #pylint: disable=redefined-variable-type, too-many-statements, not-callable +from builtins import range +from past.utils import old_div from os.path import abspath, dirname from os import sep from numpy import hstack @@ -53,7 +56,7 @@ def setup(self, static, state, onDesign=False): PSmin = self.PSmin = state.PSmin constraints = [ - ESirr >= (ESday + E/etacharge/etasolar/Ssolar), + ESirr >= (ESday + old_div(old_div(old_div(E,etacharge),etasolar),Ssolar)), E*etadischarge >= (Poper*tnight + EStwi*etasolar*Ssolar), Poper == PSmin*Ssolar*etasolar] @@ -122,7 +125,7 @@ def setup(self, static, state, onDesign=False): self.wing.substitutions[self.wing.CLstall] = 4 self.wing.substitutions[e] = 0.95 - dvars = [cdht*Sh/Sw, cdvt*Sv/Sw, cftb*Stb/Sw] + dvars = [old_div(cdht*Sh,Sw), old_div(cdvt*Sv,Sw), old_div(cftb*Stb,Sw)] if static.Npod is not 0: with Vectorize(static.Npod): @@ -131,15 +134,15 @@ def setup(self, static, state, onDesign=False): self.flight_models.extend([self.fuse]) cdfuse = self.fuse.Cd Sfuse = static.fuselage.S - dvars.extend(cdfuse*Sfuse/Sw) + dvars.extend(old_div(cdfuse*Sfuse,Sw)) self.fuse.substitutions[self.fuse.mfac] = 1.1 constraints = [cda >= sum(dvars), - Tprop == T/Nprop, + Tprop == old_div(T,Nprop), Qmotor == Qprop, RPMmotor == RPMprop, - CD/mfac >= cda + cdw, - Poper/mpower >= Pavn + Ppay + (Pelec*Nprop), + old_div(CD,mfac) >= cda + cdw, + old_div(Poper,mpower) >= Pavn + Ppay + (Pelec*Nprop), ] return self.flight_models, constraints @@ -264,8 +267,8 @@ def setup(self, Npod=0, sp=False): self.emp.substitutions[self.emp.htail.mh] = 0.1 constraints = [Ssolar*mfsolar <= Sw, - Vh <= Sh*lh/Sw/cmac, - Vv <= Sv*lv/Sw/b, + Vh <= old_div(old_div(Sh*lh,Sw),cmac), + Vv <= old_div(old_div(Sv*lv,Sw),b), d0 <= tau*croot, Wland >= fland*Wtotal, vttau >= minvttau, @@ -288,8 +291,8 @@ def setup(self, Npod=0, sp=False): Volbatt <= Volfuse, Wwing >= self.wing.W + self.solarcells.W, Wcent >= (Wpay + Wavn + self.emp.W + self.motor.W*Nprop - + self.fuselage.W[0] + Wbatt/self.Npod), - Wtotal/mfac >= (Wpay + Wavn + Wland + Wfuse + + + self.fuselage.W[0] + old_div(Wbatt,self.Npod)), + old_div(Wtotal,mfac) >= (Wpay + Wavn + Wland + Wfuse + sum([c.W for c in self.components]) + (Nprop)*sum([c.W for c in self.propulsor])) ]) @@ -301,7 +304,7 @@ def setup(self, Npod=0, sp=False): self.solarcells]]), Wcent >= Wpay + Wavn + self.emp.W + self.motor.W*Nprop, Volbatt <= cmac**2*0.5*tau*b, - Wtotal/mfac >= (Wpay + Wavn + Wland + old_div(Wtotal,mfac) >= (Wpay + Wavn + Wland + sum([c.W for c in self.components]) + Nprop*sum([c.W for c in self.propulsor])) ]) @@ -346,8 +349,8 @@ class Battery(Model): """ @parse_variables(__doc__, globals()) def setup(self): - return [W >= E*minSOC/hbatt/etaRTE/etapack*g, - Volbatt >= E/vbatt] + return [W >= old_div(old_div(old_div(E*minSOC,hbatt),etaRTE),etapack)*g, + Volbatt >= old_div(E,vbatt)] class SolarCells(Model): """solar cell model @@ -441,10 +444,10 @@ def setup(self, latitude, day, esirr, tn): with StdoutCaptured(None): dft, dfd = twi_fits(latitude, day, gen=True) - return [V/mfac >= Vwind, - FCS(df, Vwind/Vwindref, [rho/rhoref, pct], name="wind"), - FCS(dfd, ESday/ESvar, [PSmin/PSvar]), - FCS(dft, EStwi/ESvar, [PSmin/PSvar]), + return [old_div(V,mfac) >= Vwind, + FCS(df, old_div(Vwind,Vwindref), [old_div(rho,rhoref), pct], name="wind"), + FCS(dfd, old_div(ESday,ESvar), [old_div(PSmin,PSvar)]), + FCS(dft, old_div(EStwi,ESvar), [old_div(PSmin,PSvar)]), Vne == N*V, qne == 0.5*rho*Vne**2 ] @@ -523,35 +526,35 @@ def setup(self, aircraft, latitude=35, day=355): if self.aircraft.Npod is not 0 and self.aircraft.Npod is not 1: Nwing, Npod = self.aircraft.wing.N, self.aircraft.Npod - ypod = Nwing/((Npod-1)/2 + 1) - ypods = [ypod*n for n in range(1, (Npod-1)/2+1)] + ypod = old_div(Nwing,(old_div((Npod-1),2) + 1)) + ypods = [ypod*n for n in range(1, old_div((Npod-1),2)+1)] Sgust, Mgust = self.winggust.S, self.winggust.M qgust, Sg, Mg = self.winggust.q, self.wingg.S, self.wingg.M qg = self.wingg.q deta = self.aircraft.wing.planform.deta b = self.aircraft.wing.planform.b - weight = self.aircraft.battery.W/Npod*self.wingg.N + weight = old_div(self.aircraft.battery.W,Npod)*self.wingg.N for i in range(Nwing-1): if i in ypods: with SignomialsEnabled(): constraints.extend([ - Sgust[i] >= (Sgust[i+1] + 0.5*deta[i]*(b/2) + Sgust[i] >= (Sgust[i+1] + 0.5*deta[i]*(old_div(b,2)) * (qgust[i] + qgust[i+1]) - weight), - Sg[i] >= (Sg[i+1] + 0.5*deta[i]*(b/2) + Sg[i] >= (Sg[i+1] + 0.5*deta[i]*(old_div(b,2)) * (qg[i] + qg[i+1]) - weight), - Mgust[i] >= (Mgust[i+1] + 0.5*deta[i]*(b/2) + Mgust[i] >= (Mgust[i+1] + 0.5*deta[i]*(old_div(b,2)) * (Sgust[i] + Sgust[i+1])), - Mg[i] >= (Mg[i+1] + 0.5*deta[i]*(b/2) + Mg[i] >= (Mg[i+1] + 0.5*deta[i]*(old_div(b,2)) * (Sg[i] + Sg[i+1])) ]) else: constraints.extend([ - Sgust[i] >= (Sgust[i+1] + 0.5*deta[i]*(b/2) + Sgust[i] >= (Sgust[i+1] + 0.5*deta[i]*(old_div(b,2)) * (qgust[i] + qgust[i+1])), - Sg[i] >= Sg[i+1] + 0.5*deta[i]*(b/2)*(qg[i] + qg[i+1]), - Mgust[i] >= (Mgust[i+1] + 0.5*deta[i]*(b/2) + Sg[i] >= Sg[i+1] + 0.5*deta[i]*(old_div(b,2))*(qg[i] + qg[i+1]), + Mgust[i] >= (Mgust[i+1] + 0.5*deta[i]*(old_div(b,2)) * (Sgust[i] + Sgust[i+1])), - Mg[i] >= Mg[i+1] + 0.5*deta[i]*(b/2)*(Sg[i] + Sg[i+1]) + Mg[i] >= Mg[i+1] + 0.5*deta[i]*(old_div(b,2))*(Sg[i] + Sg[i+1]) ]) self.submodels = [self.fs, self.aircraftPerf, self.slf, self.loading] @@ -581,21 +584,21 @@ def density(self, c): alpha = 0.0065 # K/m h11k, T11k, p11k, rhosl = 11019, 216.483, 22532, 1.225 #m, K, Pa, kg/m^3 T0, R, gms, n = 288.16, 287.04, 9.81, 5.2561 #K, m^2/K/s^2, m/s^2, - - hrange = [c(self.h).to("m").magnitude*i/(self.N+1) + hrange = [old_div(c(self.h).to("m").magnitude*i,(self.N+1)) for i in range(1, self.N+1)] rho = [] for al in hrange: if al < h11k: T = T0 - alpha*al - rho.append(rhosl*(T/T0)**(n-1)) + rho.append(rhosl*(old_div(T,T0))**(n-1)) else: - p = p11k*exp((h11k - al)*gms/R/T11k) - rho.append(p/R/T11k) + p = p11k*exp(old_div(old_div((h11k - al)*gms,R),T11k)) + rho.append(old_div(old_div(p,R),T11k)) return [rho] def hstep(self, c): " find delta altitude " - return c[self.h]/self.N + return old_div(c[self.h],self.N) @parse_variables(__doc__, globals()) def setup(self, N, aircraft): @@ -616,8 +619,8 @@ def setup(self, N, aircraft): constraints = [ Wtotal <= 0.5*rho*V**2*CL*S, - T >= 0.5*rho*V**2*CD*S + Wtotal*hdot/V, - hdot >= dh/dt, + T >= 0.5*rho*V**2*CD*S + old_div(Wtotal*hdot,V), + hdot >= old_div(dh,dt), t >= sum(hstack(dt)), E >= sum(hstack(Poper*dt))] @@ -641,7 +644,7 @@ def setup(self, state, aircraft, perf): class Mission(Model): "define mission for aircraft" - def setup(self, aircraft, latitude=range(1, 21, 1), day=355): + def setup(self, aircraft, latitude=list(range(1, 21, 1)), day=355): self.aircraft = aircraft self.mission = []