11"""
22Utilities for reading and writing parameters files to perform the desired geometrical morphing.
33"""
4- import ConfigParser
4+ try :
5+ import configparser as configparser
6+ except ImportError :
7+ import ConfigParser as configparser
58import os
69
710import numpy as np
@@ -123,15 +126,15 @@ def read_parameters(self, filename='parameters.prm'):
123126
124127 :param string filename: parameters file to be read in.
125128 """
126- if not isinstance (filename , basestring ):
129+ if not isinstance (filename , str ):
127130 raise TypeError ("filename must be a string" )
128131
129132 # Checks if the parameters file exists. If not it writes the default class into filename.
130133 if not os .path .isfile (filename ):
131134 self .write_parameters (filename )
132135 return
133136
134- config = ConfigParser .RawConfigParser ()
137+ config = configparser .RawConfigParser ()
135138 config .read (filename )
136139
137140 self .n_control_points [0 ] = config .getint ('Box info' , 'n control points x' )
@@ -197,7 +200,7 @@ def write_parameters(self, filename='parameters.prm'):
197200
198201 :param string filename: parameters file to be written out.
199202 """
200- if not isinstance (filename , basestring ):
203+ if not isinstance (filename , str ):
201204 raise TypeError ("filename must be a string" )
202205
203206 with open (filename , 'w' ) as output_file :
@@ -280,33 +283,33 @@ def print_info(self):
280283 """
281284 This method prints all the FFD parameters on the screen. Its purpose is for debugging.
282285 """
283- print 'conversion_unit = ' + str (self .conversion_unit ) + '\n '
284- print '(lenght_box_x, lenght_box_y, lenght_box_z) = (' + str (self .lenght_box_x ) + \
285- ', ' + str (self .lenght_box_y ) + ', ' + str (self .lenght_box_z ) + ')'
286- print 'origin_box = ' + str (self .origin_box )
287- print 'n_control_points = ' + str (self .n_control_points )
288- print '(rot_angle_x, rot_angle_y, rot_angle_z) = (' + str (self .rot_angle_x ) + \
289- ', ' + str (self .rot_angle_y ) + ', ' + str (self .rot_angle_z ) + ')'
290- print '\n array_mu_x ='
291- print self .array_mu_x
292- print '\n array_mu_y ='
293- print self .array_mu_y
294- print '\n array_mu_z ='
295- print self .array_mu_z
296- print '\n psi_mapping ='
297- print self .psi_mapping
298- print '\n inv_psi_mapping ='
299- print self .inv_psi_mapping
300- print '\n rotation_matrix ='
301- print self .rotation_matrix
302- print '\n position_vertex_0 ='
303- print self .position_vertex_0
304- print '\n position_vertex_1 ='
305- print self .position_vertex_1
306- print '\n position_vertex_2 ='
307- print self .position_vertex_2
308- print '\n position_vertex_3 ='
309- print self .position_vertex_3
286+ print ( 'conversion_unit = ' + str (self .conversion_unit ) + '\n ' )
287+ print ( '(lenght_box_x, lenght_box_y, lenght_box_z) = (' + str (self .lenght_box_x ) + \
288+ ', ' + str (self .lenght_box_y ) + ', ' + str (self .lenght_box_z ) + ')' )
289+ print ( 'origin_box = ' + str (self .origin_box ) )
290+ print ( 'n_control_points = ' + str (self .n_control_points ) )
291+ print ( '(rot_angle_x, rot_angle_y, rot_angle_z) = (' + str (self .rot_angle_x ) + \
292+ ', ' + str (self .rot_angle_y ) + ', ' + str (self .rot_angle_z ) + ')' )
293+ print ( '\n array_mu_x =' )
294+ print ( self .array_mu_x )
295+ print ( '\n array_mu_y =' )
296+ print ( self .array_mu_y )
297+ print ( '\n array_mu_z =' )
298+ print ( self .array_mu_z )
299+ print ( '\n psi_mapping =' )
300+ print ( self .psi_mapping )
301+ print ( '\n inv_psi_mapping =' )
302+ print ( self .inv_psi_mapping )
303+ print ( '\n rotation_matrix =' )
304+ print ( self .rotation_matrix )
305+ print ( '\n position_vertex_0 =' )
306+ print ( self .position_vertex_0 )
307+ print ( '\n position_vertex_1 =' )
308+ print ( self .position_vertex_1 )
309+ print ( '\n position_vertex_2 =' )
310+ print ( self .position_vertex_2 )
311+ print ( '\n position_vertex_3 =' )
312+ print ( self .position_vertex_3 )
310313
311314 def build_bounding_box (self , shape , tol = 1e-6 , triangulate = False , triangulate_tol = 1e-1 ):
312315 """
@@ -442,7 +445,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
442445
443446 :param string filename: parameters file to be read in. Default value is parameters_rbf.prm.
444447 """
445- if not isinstance (filename , basestring ):
448+ if not isinstance (filename , str ):
446449 raise TypeError ('filename must be a string' )
447450
448451 # Checks if the parameters file exists. If not it writes the default class into filename.
@@ -459,7 +462,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
459462 self .write_parameters (filename )
460463 return
461464
462- config = ConfigParser .RawConfigParser ()
465+ config = configparser .RawConfigParser ()
463466 config .read (filename )
464467
465468 self .basis = config .get ('Radial Basis Functions' , 'basis function' )
@@ -469,7 +472,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
469472 lines = ctrl_points .split ('\n ' )
470473 self .n_control_points = len (lines )
471474 self .original_control_points = np .zeros ((self .n_control_points , 3 ))
472- for line , i in zip (lines , range (0 , self .n_control_points )):
475+ for line , i in zip (lines , list ( range (0 , self .n_control_points ) )):
473476 values = line .split ()
474477 self .original_control_points [i ] = np .array ([float (values [0 ]), float (values [1 ]), float (values [2 ])])
475478
@@ -481,7 +484,7 @@ def read_parameters(self, filename='parameters_rbf.prm'):
481484 " and in the 'deformed control points' section of the parameters file ({0!s})" .format (filename ))
482485
483486 self .deformed_control_points = np .zeros ((self .n_control_points , 3 ))
484- for line , i in zip (lines , range (0 , self .n_control_points )):
487+ for line , i in zip (lines , list ( range (0 , self .n_control_points ) )):
485488 values = line .split ()
486489 self .deformed_control_points [i ] = np .array ([float (values [0 ]), float (values [1 ]), float (values [2 ])])
487490
@@ -493,7 +496,7 @@ def write_parameters(self, filename='parameters_rbf.prm'):
493496
494497 :param string filename: parameters file to be written out.
495498 """
496- if not isinstance (filename , basestring ):
499+ if not isinstance (filename , str ):
497500 raise TypeError ("filename must be a string" )
498501
499502 with open (filename , 'w' ) as output_file :
@@ -540,10 +543,10 @@ def print_info(self):
540543 """
541544 This method prints all the RBF parameters on the screen. Its purpose is for debugging.
542545 """
543- print 'basis function = ' + str (self .basis )
544- print 'radius = ' + str (self .radius )
545- print 'n_control_points = ' + str (self .n_control_points )
546- print '\n original_control_points ='
547- print self .original_control_points
548- print '\n deformed_control_points ='
549- print self .deformed_control_points
546+ print ( 'basis function = ' + str (self .basis ) )
547+ print ( 'radius = ' + str (self .radius ) )
548+ print ( 'n_control_points = ' + str (self .n_control_points ) )
549+ print ( '\n original_control_points =' )
550+ print ( self .original_control_points )
551+ print ( '\n deformed_control_points =' )
552+ print ( self .deformed_control_points )
0 commit comments