Skip to content

Commit

Permalink
Merge pull request #31 from alexlib/pyptv3
Browse files Browse the repository at this point in the history
First Python 3 compatible version
  • Loading branch information
alexlib authored Apr 18, 2019
2 parents ecd10a2 + 36a2610 commit 8838533
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 86 deletions.
44 changes: 17 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
# Config file for automatic testing at travis-ci.org

language: python
- "2.7"
sudo: false
python:
- 2.7
- 3.6
before_install:
- sudo apt-get -qq update
- sudo apt-get install -y build-essential git libgl1-mesa-glx libgl1-mesa-dev libglu1-mesa-dev
- sudo apt-get clean
- sudo apt-get autoclean
install:
- wget https://repo.continuum.io/miniconda/Miniconda2-latest-Linux-x86_64.sh -O miniconda.sh;
- bash miniconda.sh -b -p $HOME/miniconda
- export PATH="$HOME/miniconda/bin:$PATH"
- hash -r
- conda config --set always_yes yes
- conda update -q conda
- conda clean --all
- conda install numpy=1.16.1
- conda install cython
- conda install swig
- pip install chaco scikit-image enable nose future
- pip install optv
- pip install --user coveralls
- conda install conda-build
- conda build .
- conda install --use-local pyptv
- conda info -a
- sudo apt-get install -y build-essential
- sudo apt-get install -y python-dev swig
- sudo apt-get -y install python-qt4-gl libx11-dev libpcre3 libpcre3-dev freeglut3-dev libgtk2.0-dev
- sudo apt-get -y install libgl1-mesa-glx libglu1-mesa-dev libgl1-mesa-dev mesa-common-dev
script:
- virtualenv --python=python venv
- source venv/bin/activate
- python -m pip install -U pip
- pip install -U wheel
- pip install numpy==1.16.1
- pip install optv==0.2.5
- pip install nose
- pip install scikit-image
- python setup.py install
- cd tests
- nosetests -v
after_success:
- coveralls
- nosetests --verbose
16 changes: 8 additions & 8 deletions pyptv/calibration_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ def __init__(self, active_path):
self.n_cams = int(f.readline())


self.camera = [PlotWindow() for i in xrange(self.n_cams)]
for i in xrange(self.n_cams):
self.camera = [PlotWindow() for i in range(self.n_cams)]
for i in range(self.n_cams):
self.camera[i].name = "Camera" + str(i + 1)
self.camera[i].cameraN = i
self.camera[i].py_rclick_delete = ptv.py_rclick_delete
Expand Down Expand Up @@ -431,7 +431,7 @@ def _button_showimg_fired(self):
self.cpar, self.spar, self.vpar, self.track_par, self.tpar, \
self.cals, self.epar = ptv.py_start_proc_c(self.n_cams)

self.tpar.read('parameters/detect_plate.par')
self.tpar.read(b'parameters/detect_plate.par')

print(self.tpar.get_grey_thresholds())

Expand All @@ -447,7 +447,7 @@ def _button_showimg_fired(self):
print(self.MultiParams.plane_name[i])

self.pass_raw_orient = True
self.status_text = "Multiplane calibration."
self.status_text = b"Multiplane calibration."


# read calibration images
Expand Down Expand Up @@ -568,7 +568,7 @@ def _button_init_guess_fired(self):
for i_cam in range(self.n_cams):
cal = Calibration()
tmp = self.cpar.get_cal_img_base_name(i_cam)
cal.from_file(tmp + '.ori', tmp + '.addpar')
cal.from_file(tmp + b'.ori', tmp + b'.addpar')
self.cals.append(cal)

for i_cam in range(self.n_cams):
Expand Down Expand Up @@ -779,7 +779,7 @@ def _button_fine_orient_fired(self):
# combined information

targs = TargetArray(len(all_detected))
for tix in xrange(len(all_detected)):
for tix in range(len(all_detected)):
targ = targs[tix]
det = all_detected[tix]

Expand Down Expand Up @@ -830,7 +830,7 @@ def _write_ori(self, i_cam):
ori = self.calParams.img_ori[i_cam]
addpar = ori.replace('ori', 'addpar')
print("Saving:", ori, addpar)
self.cals[i_cam].write(ori, addpar)
self.cals[i_cam].write(ori.encode(), addpar.encode())
if self.epar.Examine_Flag and not self.epar.Combine_Flag:
self.save_point_sets(i_cam)

Expand Down Expand Up @@ -898,7 +898,7 @@ def reset_plots(self):

def reset_show_images(self):
for i,cam in enumerate(self.camera):
cam._plot.delplot(*cam._plot.plots.keys()[0:])
cam._plot.delplot(*list(cam._plot.plots.keys())[0:])
cam._plot.overlays = []
# self.camera[i]._plot_data.set_data('imagedata',self.ori_img[i].astype(np.byte))
cam._plot_data.set_data('imagedata', self.cal_images[i].astype(np.byte))
Expand Down
3 changes: 1 addition & 2 deletions pyptv/parameter_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -909,12 +909,11 @@ def _reload(self):
# read manual orientaion parameters
manOriParams = par.ManOriParams(self.n_img, [], path=self.par_path)
manOriParams.read()
nr = manOriParams.nr


for i in range(self.n_img):
for j in range(4): # 4 points per image
exec('self.img_{0}_p{1} = nr[{2}][{3}]'.format(i+1,j+1,i,j))
exec('self.img_{0}_p{1} = manOriParams.nr[{2}][{3}]'.format(i+1,j+1,i,j))


# examine arameters
Expand Down
44 changes: 23 additions & 21 deletions pyptv/ptv.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ def py_start_proc_c(n_cams):

# Control parameters
cpar = ControlParams(n_cams)
cpar.read_control_par('parameters/ptv.par')
cpar.read_control_par(b'parameters/ptv.par')

# Sequence parameters
spar = SequenceParams(num_cams=n_cams)
spar.read_sequence_par('parameters/sequence.par',n_cams)
spar.read_sequence_par(b'parameters/sequence.par',n_cams)

# Volume parameters
vpar = VolumeParams()
vpar.read_volume_par('parameters/criteria.par')
vpar.read_volume_par(b'parameters/criteria.par')

# Tracking parameters
track_par = TrackingParams()
track_par.read_track_par('parameters/track.par')
track_par.read_track_par(b'parameters/track.par')

# Target parameters
tpar = TargetParams(n_cams)
tpar.read('parameters/targ_rec.par')
tpar.read(b'parameters/targ_rec.par')

# Examine parameters, multiplane (single plane vs combined calibration)
epar= par.ExamineParams()
epar.read()

# Calibration parameters
cals =[]
for i_cam in xrange(n_cams):
for i_cam in range(n_cams):
cal = Calibration()
tmp = cpar.get_cal_img_base_name(i_cam)
cal.from_file(tmp+'.ori', tmp+'.addpar')
cal.from_file(tmp + b'.ori', tmp + b'.addpar')
cals.append(cal)

return cpar, spar, vpar, track_par, tpar, cals, epar
Expand Down Expand Up @@ -116,7 +116,7 @@ def py_correspondences_proc_c(exp):
exp.detections, exp.corrected, exp.cals, exp.vpar, exp.cpar)

# Save targets only after they've been modified:
for i_cam in xrange(exp.n_cams):
for i_cam in range(exp.n_cams):
exp.detections[i_cam].write(exp.spar.get_img_base_name(i_cam),frame)

print("Frame " + str(frame) + " had " \
Expand All @@ -129,17 +129,17 @@ def py_determination_proc_c(n_cams, sorted_pos, sorted_corresp, corrected):

# Control parameters
cpar = ControlParams(n_cams)
cpar.read_control_par('parameters/ptv.par')
cpar.read_control_par(b'parameters/ptv.par')

# Volume parameters
vpar = VolumeParams()
vpar.read_volume_par('parameters/criteria.par')
vpar.read_volume_par(b'parameters/criteria.par')

cals =[]
for i_cam in xrange(n_cams):
for i_cam in range(n_cams):
cal = Calibration()
tmp = cpar.get_cal_img_base_name(i_cam)
cal.from_file(tmp+'.ori', tmp+'.addpar')
cal.from_file(tmp + b'.ori', tmp + b'.addpar')
cals.append(cal)


Expand All @@ -149,7 +149,7 @@ def py_determination_proc_c(n_cams, sorted_pos, sorted_corresp, corrected):


flat = np.array([corrected[i].get_by_pnrs(sorted_corresp[i]) \
for i in xrange(len(cals))])
for i in range(len(cals))])
pos, rcm = point_positions(
flat.transpose(1,0,2), cpar, cals, vpar)

Expand Down Expand Up @@ -182,21 +182,22 @@ def py_sequence_loop(exp):
Existing_Target = np.bool(pftVersionParams.Existing_Target)

# sequence loop for all frames
for frame in xrange(spar.get_first(), spar.get_last()+1):
for frame in range(spar.get_first(), spar.get_last()+1):
print("processing frame %d" % frame)

detections = []
corrected = []
for i_cam in xrange(n_cams):
for i_cam in range(n_cams):
if Existing_Target:
targs = read_targets(spar.get_img_base_name(i_cam),frame)
else:
imname = spar.get_img_base_name(i_cam) + str(frame)
imname = spar.get_img_base_name(i_cam) + str(frame).encode()
print(imname)
if not os.path.exists(imname):
print(os.path.abspath(os.path.curdir))
print('{0} does not exist'.format(imname))

img = imread(imname)
img = imread(imname.decode())
# time.sleep(.1) # I'm not sure we need it here
hp = simple_highpass(img, cpar)
targs = target_recognition(hp, tpar, i_cam, cpar)
Expand All @@ -216,7 +217,7 @@ def py_sequence_loop(exp):
detections, corrected, cals, vpar, cpar)

# Save targets only after they've been modified:
for i_cam in xrange(n_cams):
for i_cam in range(n_cams):
detections[i_cam].write(spar.get_img_base_name(i_cam),frame)


Expand All @@ -228,7 +229,7 @@ def py_sequence_loop(exp):
sorted_corresp = np.concatenate(sorted_corresp, axis=1)

flat = np.array([corrected[i].get_by_pnrs(sorted_corresp[i]) \
for i in xrange(len(cals))])
for i in range(len(cals))])
pos, rcm = point_positions(
flat.transpose(1,0,2), cpar, cals, vpar)

Expand All @@ -243,7 +244,8 @@ def py_sequence_loop(exp):
print_corresp = sorted_corresp

# Save rt_is
rt_is = open(default_naming['corres']+'.'+str(frame), 'w')
print(default_naming['corres'])
rt_is = open(default_naming['corres']+b'.'+ str(frame).encode(), 'w')
rt_is.write(str(pos.shape[0]) + '\n')
for pix, pt in enumerate(pos):
pt_args = (pix + 1,) + tuple(pt) + tuple(print_corresp[:,pix])
Expand Down Expand Up @@ -421,7 +423,7 @@ def py_multiplanecalibration(exp):
all_detected = np.vstack(all_detected)

targs = TargetArray(len(all_detected))
for tix in xrange(len(all_detected)):
for tix in range(len(all_detected)):
targ = targs[tix]
det = all_detected[tix]

Expand Down
14 changes: 7 additions & 7 deletions pyptv/pyptv_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,25 @@ def run_batch(new_seq_first, new_seq_last):

# Control parameters
cpar = ControlParams(n_cams)
cpar.read_control_par('parameters/ptv.par')
cpar.read_control_par(b'parameters/ptv.par')

# Sequence parameters
spar = SequenceParams(num_cams=n_cams)
spar.read_sequence_par('parameters/sequence.par',n_cams)
spar.read_sequence_par(b'parameters/sequence.par',n_cams)
spar.set_first(new_seq_first)
spar.set_last(new_seq_last)

# Volume parameters
vpar = VolumeParams()
vpar.read_volume_par('parameters/criteria.par')
vpar.read_volume_par(b'parameters/criteria.par')

# Tracking parameters
track_par = TrackingParams()
track_par.read_track_par('parameters/track.par')
track_par.read_track_par(b'parameters/track.par')

# Target parameters
tpar = TargetParams()
tpar.read('parameters/targ_rec.par')
tpar.read(b'parameters/targ_rec.par')

#

Expand All @@ -80,7 +80,7 @@ def run_batch(new_seq_first, new_seq_last):
for i_cam in range(n_cams):
cal = Calibration()
tmp = cpar.get_cal_img_base_name(i_cam)
cal.from_file(tmp+'.ori', tmp+'.addpar')
cal.from_file(tmp+b'.ori', tmp+b'.addpar')
cals.append(cal)


Expand Down Expand Up @@ -165,7 +165,7 @@ def main(exp_path, first, last, repetitions=1):

try:
exp_path = os.path.abspath(exp_path)
print('exp_path= %s' % exp_path)
print('exp_path is %s' % exp_path)
os.chdir(exp_path)
print(os.getcwd())
except:
Expand Down
12 changes: 6 additions & 6 deletions pyptv/pyptv_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

# pyPTV specific imports
import parameters as par
from parameter_gui import Experiment, Paramset
from parameter_gui import Experiment, Paramset, Calib_Params
from calibration_gui import CalibrationGUI
from directory_editor import DirectoryEditorDialog
from quiverplot import QuiverPlot
Expand Down Expand Up @@ -369,7 +369,7 @@ def configure_cal_par(self, editor, object):
print(len(experiment.paramsets))
if paramset.c_params is None:
# TODO: is it possible that control reaches here? If not, probably the if should be removed.
paramset.c_params = par.Calib_Params()
paramset.c_params = par.CalOriParams() # this is a very questionable line
else:
paramset.c_params._reload()
paramset.c_params.edit_traits(kind='modal')
Expand Down Expand Up @@ -601,7 +601,7 @@ def sequence_action(self, info):
"""

extern_sequence = info.object.plugins.sequence_alg
if extern_sequence != 'default':
if extern_sequence is not 'default':
try:
# change to pyptv folder, look for tracking module
sys.path.append(software_path)
Expand All @@ -624,7 +624,7 @@ def track_no_disp_action(self, info):
""" track_no_disp_action uses ptv.py_trackcorr_loop(..) binding to call tracking without display
"""
extern_tracker = info.object.plugins.track_alg
if extern_tracker != 'default':
if extern_tracker is not 'default':
try:
os.chdir(software_path) # change to software path, to load tracking module
track = __import__(extern_tracker) # import choosen tracker from software dir
Expand Down Expand Up @@ -1053,7 +1053,7 @@ def clear_plots(self, remove_background=True):
index = None

for i in range(len(self.camera_list)):
plot_list = self.camera_list[i]._plot.plots.keys()
plot_list = list(self.camera_list[i]._plot.plots.keys())
# if not remove_background:
# index=None
try:
Expand Down Expand Up @@ -1158,7 +1158,7 @@ def main():
else:
print(
'Please provide an experimental directory as an input, fallback to a default\n')
exp_path = '../../2D_jet'
exp_path = '/Users/alex/Documents/OpenPTV/test_cavity'

if not os.path.isdir(exp_path):
raise OSError("Wrong experimental directory %s " % exp_path)
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
optv
numpy==1.16.1
scikit-image
chaco
enable
future
optv==0.2.5

Loading

0 comments on commit 8838533

Please sign in to comment.