Skip to content

Commit

Permalink
Repackaging
Browse files Browse the repository at this point in the history
  • Loading branch information
u.zanovello committed Feb 9, 2022
1 parent bc8052e commit 9fc755f
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 10 deletions.
6 changes: 6 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build-system]
requires = [
"setuptools>=42",
"wheel"
]
build-backend = "setuptools.build_meta"
27 changes: 27 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[metadata]
name = cosimpy
version = 3.0.0.2
author = Umberto Zanovello
author_email = umbertozanovello@hotmail.com
description = Python electromagnetic co-simulation library
long_description = file: README.md
long_description_content_type = text/markdown
url = https://umbertozanovello.github.io/CoSimPy/
classifiers =
Programming Language :: Python :: 3
License :: OSI Approved :: MIT License
Operating System :: OS Independent

[options]
package_dir =
= src
packages = find:
python_requires = >=3.5
install_requires =
numpy >=1.15.2
matplotlib >=3.0.0
h5py >=2.8.0
scipy >=1.1.0

[options.packages.find]
where = src
6 changes: 0 additions & 6 deletions setup.py

This file was deleted.

6 changes: 3 additions & 3 deletions cosimpy/EM_Field.py → src/cosimpy/EM_Field.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ def importFields_cst(cls, directory, freqs, nPorts, nPoints=None, Pinc_ref=1, b_
print("Importing %s MHz fields\n"%f)

for port in range(nPorts):
print("\tImporting port%d fields\n\n"%(port+1))
print("\r\tImporting port%d fields"%(port+1), end='', flush=True)
if col_ascii_order == 0:
re_cols = (3,4,5)
im_cols = (6,7,8)
Expand All @@ -531,7 +531,7 @@ def importFields_cst(cls, directory, freqs, nPorts, nPoints=None, Pinc_ref=1, b_
print("Importing %s MHz fields\n"%f)

for port in range(nPorts):
print("\tImporting port%d fields\n\n"%(port+1))
print("\r\tImporting port%d fields"%(port+1), end='', flush=True)
if imp_efield:

filename = "/efield_%s_port%d.h5"%(f,port+1)
Expand Down Expand Up @@ -593,7 +593,7 @@ def importFields_s4l(cls, directory, freqs, nPorts, Pinc_ref=1, b_multCoeff=1, p

for port in range(nPorts):

print("\tImporting port%d fields\n\n"%(port+1))
print("\rImporting port%d fields"%(port+1), end='', flush=True)

if imp_efield:

Expand Down
38 changes: 37 additions & 1 deletion cosimpy/RF_Coil.py → src/cosimpy/RF_Coil.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,10 @@ def flattenCompArray(compArray):
if filename.split(".")[-1] != "cspy":
filename += ".cspy"

description = " ".join(description.split("\n"))
if description:
description = " ".join(description.split("\n"))
else:
description = "N/D"

# Extraction of S_Matrix nested instances (Up to now only level 0 (final S matrix) and 1 (original S matrix) will be present)
s_matrix = self.s_matrix
Expand All @@ -254,6 +257,10 @@ def flattenCompArray(compArray):
n_ports_list.append(s_matrix.nPorts)

with open(filename, 'wb') as f:

#Saving status
print("\nSaving: header...", end='', flush=True)

#File version and header lines
f.write(struct.pack('<h', file_version))
f.write(struct.pack('<h', header_lines))
Expand All @@ -271,6 +278,9 @@ def flattenCompArray(compArray):
f.write(b"EM_PROP: %s\n"%(b"N/D" if (self.em_field is None or self.em_field.properties == {}) else b", ".join(bytes(x, encoding="utf-8") for x in self.em_field.properties.keys())))
f.write(b"### HEADER END ###\n")

#Saving status
print("\rSaving: S_Matrix...", end='', flush=True)

#s_matrix_frequencies
for freq in self.s_matrix.frequencies:
f.write(struct.pack('<f',freq))
Expand All @@ -289,24 +299,35 @@ def flattenCompArray(compArray):
phaseM_flat = s_matrix_instance._phaseM.flatten()
for ph in phaseM_flat:
f.write(struct.pack('<f', ph))

#em_field
if self.em_field is not None:

em_field_prop_names = self.em_field.properties.keys()
#EM frequencies
for freq in self.em_field.frequencies:
f.write(struct.pack('<f', freq))
#E field
if self.em_field.e_field is not None:
#Saving status
print("\rSaving: EM_Field.e_field...", end='', flush=True)

e_field_flat = flattenCompArray(self.em_field.e_field)
for e in e_field_flat:
f.write(struct.pack('<f', e))
#B field
if self.em_field.b_field is not None:
#Saving status
print("\rSaving: EM_Field.b_field...", end='', flush=True)

b_field_flat = flattenCompArray(self.em_field.b_field)
for b in b_field_flat:
f.write(struct.pack('<f', b))
# properties
for prop_name in em_field_prop_names:
#Saving status
print("\rSaving: EM_Field.properties...", end='', flush=True)

for pr in self.em_field.properties[prop_name]:
f.write(struct.pack('<f', pr))

Expand All @@ -320,6 +341,9 @@ def loadRFCoil(cls, filename, **kwarg):
file_version, = struct.unpack('<h', f.read(2)) #When higher version will be implemented, a check can be performed over this variable
header_lines, = struct.unpack('<h', f.read(2))

#Loading status
print("\nLoading: header...", end='', flush=True)

#Reading header
header = {}
f.readline() #HEADER BEGIN
Expand All @@ -329,6 +353,9 @@ def loadRFCoil(cls, filename, **kwarg):
header[line[0]] = line[1]
line = f.readline() #HEADER END

#Loading status
print("\rLoading: S_Matrix...", end='', flush=True)

#s_matrix_frequencies
s_frequencies = np.zeros(int(header['S_NFREQ']))
for i in range(int(header['S_NFREQ'])):
Expand Down Expand Up @@ -373,12 +400,18 @@ def loadRFCoil(cls, filename, **kwarg):
for i in range(int(header['EMNFREQ'])):
em_frequencies[i] = struct.unpack('<f', f.read(4))[0]
if header["E_FIELD"] == 'TRUE':
#Loading status
print("\rLoading: EM_Field.e_field...", end='', flush=True)

e_field = np.zeros(int(header['EMNFREQ'])*n_ports[0]*3*n_points, dtype=np.complex)
for i in range((int(header['EMNFREQ'])*n_ports[0]*3*n_points)):
e_field[i] = struct.unpack('<f', f.read(4))[0]
e_field[i] += 1j*struct.unpack('<f', f.read(4))[0]
e_field = e_field.reshape([int(header['EMNFREQ']),n_ports[0],3,n_points])
if header["B_FIELD"] == 'TRUE':
#Loading status
print("\rLoading: EM_Field.b_field...", end='', flush=True)

b_field = np.zeros(int(header['EMNFREQ'])*n_ports[0]*3*n_points, dtype=np.complex)
for i in range((int(header['EMNFREQ'])*n_ports[0]*3*n_points)):
b_field[i] = struct.unpack('<f', f.read(4))[0]
Expand All @@ -387,6 +420,9 @@ def loadRFCoil(cls, filename, **kwarg):
em_properties = {}
prop_names = header["EM_PROP"].split(", ")
if prop_names[0] != 'N/D':
#Loading status
print("\rLoading: EM_Field.properties...", end='', flush=True)

for prop_name in prop_names:
em_property = np.zeros([n_points], dtype=np.float)
for i in range(n_points):
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit 9fc755f

Please sign in to comment.