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

Make pyts.io.read usable in python3 #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
9 changes: 5 additions & 4 deletions pyts/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,19 @@
d) Defines several abstract base classes.

"""
from __future__ import division, print_function
from . import pyts_numpy as np
from numpy import float32, complex64
from .misc import lowPrimeFact_near
from os import path
try:
from .tslib import tslib # The file tslib.so contains the module 'tslib'.
except ImportError:
print """
print("""
***Warning***: 'tslib' did not load correctly. pyTurbSim
will produce accurate results, but MUCH less efficiently.
Consider compiling the tslib to improve performance.
"""
""")
tslib = None

dbg = None
Expand Down Expand Up @@ -357,7 +358,7 @@ def n_y(self):

@property
def n_f(self,):
return self.n_t / 2
return self.n_t // 2

@property
def df(self,):
Expand All @@ -369,7 +370,7 @@ def n_p(self,):

@property
def ihub(self,):
return (self.n_z / 2, self.n_y / 2)
return (self.n_z // 2, self.n_y // 2)

@property
def shape(self,):
Expand Down
50 changes: 25 additions & 25 deletions pyts/io/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,31 +94,31 @@ def turbsim(fname):
fname = checkname(fname, ['.bts'])
u_scl = np.zeros(3, np.float32)
u_off = np.zeros(3, np.float32)
fl = file(fname, 'rb')
(junk,
n_z,
n_y,
n_tower,
n_t,
dz,
dy,
dt,
uhub,
zhub,
z0,
u_scl[0],
u_off[0],
u_scl[1],
u_off[1],
u_scl[2],
u_off[2],
strlen) = unpack(e + 'h4l12fl', fl.read(70))
center = z0 + (n_z - 1) * dz / 2.0
#print fname, u_scl, u_off
desc_str = fl.read(strlen) # skip these bytes.
nbt = 3 * n_y * n_z * n_t
dat = np.rollaxis(np.fromstring(fl.read(2 * nbt), dtype=np.int16).astype(
np.float32).reshape([3, n_y, n_z, n_t], order='F'), 2, 1)
with open(fname, 'rb') as fl:
(junk,
n_z,
n_y,
n_tower,
n_t,
dz,
dy,
dt,
uhub,
zhub,
z0,
u_scl[0],
u_off[0],
u_scl[1],
u_off[1],
u_scl[2],
u_off[2],
strlen) = unpack(e + 'h4l12fl', fl.read(70))
center = z0 + (n_z - 1) * dz / 2.0
#print fname, u_scl, u_off
desc_str = fl.read(strlen) # skip these bytes.
nbt = 3 * n_y * n_z * n_t
dat = np.rollaxis(np.fromstring(fl.read(2 * nbt), dtype=np.int16).astype(
np.float32).reshape([3, n_y, n_z, n_t], order='F'), 2, 1)
dat -= u_off[:, None, None, None]
dat /= u_scl[:, None, None, None]
# Create the tsdata object.
Expand Down
4 changes: 2 additions & 2 deletions pyts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from .cohereModels.base import cohereModelBase, cohereObj, cohereUser
from .stressModels.base import stressModelBase, stressObj
from .phaseModels.api import randPhase
import _version as ver
from ._version import *
from .io import write
from numpy import random
from numpy import ulonglong
Expand Down Expand Up @@ -423,7 +423,7 @@ def info(self,):
Model names and initialization parameters.
"""
out = dict()
out['version'] = (ver.__prog_name__, ver.__version__, ver.__version_date__)
out['version'] = (__prog_name__, __version__, __version_date__)
out['RandSeed'] = self.RandSeed
out['StartTime'] = self._starttime
if hasattr(self, '_config'):
Expand Down
2 changes: 1 addition & 1 deletion pyts/phaseModels/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
A uniform-distribution random-phase model.

"""
from main import randPhase
from .main import randPhase
5 changes: 3 additions & 2 deletions pyts/stressModels/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

"""

from __future__ import print_function
from .. import base
np = base.np

Expand Down Expand Up @@ -152,8 +153,8 @@ def check_validity(self,):
# stresses. In the future it may make sense to adjust/modify the
# stresses to make them valid?
if ~(self.validity.all()):
print self.validity.shape
print self.validity
print(self.validity.shape)
print(self.validity)
raise Exception('The input reynolds stresses are inconsistent.')

def calc_phases(self, phases):
Expand Down