Skip to content

Commit

Permalink
fixed syntax warning: invalid escape sequence in re
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtanner committed Nov 20, 2024
1 parent 8d20857 commit 54ad6dd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions src/femagtools/me.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"""
__author__ = 'dapu zhang'

import re
import numpy as np
import re
import numpy as np
import matplotlib.pyplot as plt
import logging

Expand All @@ -16,33 +16,33 @@ def get_eigenvectors(filelist, psfiles):
eigenvecs = {}
eigenfreq = []
ps_data = []
temp = []
temp = []
temp_arr = []
read_fig = False

if len(psfiles) > 0: read_fig = True
if len(filelist) == 0: return []
for k, kk in zip(filelist, range(len(filelist))):

for k, kk in zip(filelist, range(len(filelist))):
# read ps file
if read_fig: ps_data.append(plt.imread(psfiles[kk]))
eigenvecs[str(kk)] = {}
with open(k, 'r') as f:
with open(k, 'r') as f:
data = f.read().split('\n')
eigenval = float(re.split('\s+', data[0].strip())[2])
eigenval = float(re.split(r'\s+', data[0].strip())[2])
eigenfreq.append(eigenval/2/np.pi)
for i in range(len(data[1:-1])):
for j in data[2+i].strip().split(' '):

for i in range(len(data[1:-1])):
for j in data[2+i].strip().split(' '):
if j != '':
temp.append(float(j))

temp_arr = np.array(temp).reshape(-1, 5)
idx_collect = []
# remove the index, at which the dof equals zero
for c in range(temp_arr.shape[0]):
for c in range(temp_arr.shape[0]):
if np.abs(temp_arr[c, 1]) < 1e-15 and \
np.abs(temp_arr[c, 2]) < 1e-15:
np.abs(temp_arr[c, 2]) < 1e-15:
idx_collect.append(c)
# prepare the data from the further calculation
temp_arr = np.delete(temp_arr, np.array(idx_collect), axis=0)
Expand All @@ -52,4 +52,4 @@ def get_eigenvectors(filelist, psfiles):
# return node position
if kk == 0: eigenvecs.update({'node_pos': temp_arr[:, 4::]})

return [ps_data, eigenfreq, eigenvecs]
return [ps_data, eigenfreq, eigenvecs]
2 changes: 1 addition & 1 deletion src/femagtools/plot/fieldlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import numpy as np
import matplotlib.lines as mpl

rgbpat = re.compile('rgb\((\d+),(\d+),(\d+)\)')
rgbpat = re.compile(r'rgb\((\d+),(\d+),(\d+)\)')

def fieldlines(svgfilename, ax=0):
"""plot fieldlines from svg file"""
Expand Down

0 comments on commit 54ad6dd

Please sign in to comment.