Use f-strings where possible

cell_data
Jan Petykiewicz 3 years ago
parent ff5ffb2f40
commit 7340d41f10

@ -48,7 +48,7 @@ def draw_polygons(self,
surface = numpy.delete(range(3), surface_normal) surface = numpy.delete(range(3), surface_normal)
for i, polygon in enumerate(polygons): for i, polygon in enumerate(polygons):
malformed = 'Malformed polygon: (%i)' % i malformed = f'Malformed polygon: ({i})'
if polygon.shape[1] not in (2, 3): if polygon.shape[1] not in (2, 3):
raise GridError(malformed + 'must be a Nx2 or Nx3 ndarray') raise GridError(malformed + 'must be a Nx2 or Nx3 ndarray')
if polygon.shape[1] == 3: if polygon.shape[1] == 3:
@ -106,9 +106,9 @@ def draw_polygons(self,
# evaluate on the meshgrid # evaluate on the meshgrid
eps_i = eps[i](x0, y0, z0) eps_i = eps[i](x0, y0, z0)
if not numpy.isfinite(eps_i).all(): if not numpy.isfinite(eps_i).all():
raise GridError('Non-finite values in eps[%u]' % i) raise GridError(f'Non-finite values in eps[{i}]')
raise GridError('Unsupported eps[{}]: {}'.format(i, type(eps[i])))
elif numpy.size(eps[i]) != 1: elif numpy.size(eps[i]) != 1:
raise GridError(f'Unsupported eps[{i}]: {type(eps[i])}')
else: else:
# eps[i] is scalar non-callable # eps[i] is scalar non-callable
eps_i = eps[i] eps_i = eps[i]
@ -232,7 +232,7 @@ def draw_slab(self,
if len(center) == 3: if len(center) == 3:
center = center[surface_normal] center = center[surface_normal]
else: else:
raise GridError('Bad center: {}'.format(center)) raise GridError(f'Bad center: {center}')
# Find center of slab # Find center of slab
center_shift = self.center center_shift = self.center
@ -331,7 +331,7 @@ def draw_extrude_rectangle(self,
if s == 0: if s == 0:
raise GridError('0 is not a valid polarity') raise GridError('0 is not a valid polarity')
if direction not in range(3): if direction not in range(3):
raise GridError('Invalid direction: {}'.format(direction)) raise GridError(f'Invalid direction: {direction}')
if rectangle[0, direction] != rectangle[1, direction]: if rectangle[0, direction] != rectangle[1, direction]:
raise GridError('Rectangle entries along extrusion direction do not match.') raise GridError('Rectangle entries along extrusion direction do not match.')

@ -279,7 +279,7 @@ class Grid:
for i in range(3): for i in range(3):
if len(self.exyz[i]) != len(pixel_edge_coordinates[i]): if len(self.exyz[i]) != len(pixel_edge_coordinates[i]):
warnings.warn('Dimension {} had duplicate edge coordinates'.format(i), stacklevel=2) warnings.warn(f'Dimension {i} had duplicate edge coordinates', stacklevel=2)
if isinstance(periodic, bool): if isinstance(periodic, bool):
self.periodic = [periodic] * 3 self.periodic = [periodic] * 3
@ -288,10 +288,10 @@ class Grid:
if len(self.shifts.shape) != 2: if len(self.shifts.shape) != 2:
raise GridError('Misshapen shifts: shifts must have two axes! ' raise GridError('Misshapen shifts: shifts must have two axes! '
' The given shifts has shape {}'.format(self.shifts.shape)) f' The given shifts has shape {self.shifts.shape}')
if self.shifts.shape[1] != 3: if self.shifts.shape[1] != 3:
raise GridError('Misshapen shifts; second axis size should be 3,' raise GridError('Misshapen shifts; second axis size should be 3,'
' shape is {}'.format(self.shifts.shape)) f' shape is {self.shifts.shape}')
if (numpy.abs(self.shifts) > 1).any(): if (numpy.abs(self.shifts) > 1).any():
raise GridError('Only shifts in the range [-1, 1] are currently supported') raise GridError('Only shifts in the range [-1, 1] are currently supported')

@ -46,7 +46,7 @@ def ind2pos(self,
low_bound = -0.5 low_bound = -0.5
high_bound = -0.5 high_bound = -0.5
if (ind < low_bound).any() or (ind > self.shape - high_bound).any(): if (ind < low_bound).any() or (ind > self.shape - high_bound).any():
raise GridError('Position outside of grid: {}'.format(ind)) raise GridError(f'Position outside of grid: {ind}')
if round_ind: if round_ind:
rind = numpy.clip(numpy.round(ind).astype(int), 0, self.shape - 1) rind = numpy.clip(numpy.round(ind).astype(int), 0, self.shape - 1)
@ -84,17 +84,17 @@ def pos2ind(self,
""" """
r = numpy.squeeze(r) r = numpy.squeeze(r)
if r.size != 3: if r.size != 3:
raise GridError('r must be 3-element vector: {}'.format(r)) raise GridError(f'r must be 3-element vector: {r}')
if (which_shifts is not None) and (which_shifts >= self.shifts.shape[0]): if (which_shifts is not None) and (which_shifts >= self.shifts.shape[0]):
raise GridError('Invalid which_shifts: {}'.format(which_shifts)) raise GridError(f'Invalid which_shifts: {which_shifts}')
sexyz = self.shifted_exyz(which_shifts) sexyz = self.shifted_exyz(which_shifts)
if check_bounds: if check_bounds:
for a in range(3): for a in range(3):
if self.shape[a] > 1 and (r[a] < sexyz[a][0] or r[a] > sexyz[a][-1]): if self.shape[a] > 1 and (r[a] < sexyz[a][0] or r[a] > sexyz[a][-1]):
raise GridError('Position[{}] outside of grid!'.format(a)) raise GridError(f'Position[{a}] outside of grid!')
grid_pos = numpy.zeros((3,)) grid_pos = numpy.zeros((3,))
for a in range(3): for a in range(3):

Loading…
Cancel
Save