2022年6月13日 星期一

類別屬性檢查


class test:
def __init__(self):
self._score = 60

@property
def score(self):
return self._score

@score.setter
def score(self, value):
if value < 0:
self._score = 0
if value > 100:
self._score = 100


x = test()
print(x.score)
x.score = 110
print(x.score)
x.score = -10
print(x.score)

 








2022年5月16日 星期一

傅立葉轉換

時域訊號經過傅立葉轉換到頻域,再轉回時域做比較

import numpy as np

tstop = 10
tstep = 0.01

fstart = -1 / tstep / 2
fstop = 1 / tstep / 2
fstep = 1 / tstop

t = np.arange(0, tstop, tstep)
y0 = np.sin(20 * t)

import matplotlib.pyplot as plt

scale = np.sqrt(2 * np.pi * len(t))
plt.plot(t, y0)
plt.show()
y1 = []
f = np.arange(fstart, fstop, fstep)
for w in f:
y1.append(np.sum(np.exp(-1j * w * t) * y0) / scale)

plt.plot(f, np.abs(y1))
plt.show()

y2 = []
for t0 in t:
y2.append(np.sum(np.exp(1j * t0 * f) * y1) / scale)

plt.plot(t, np.real(y2))
plt.show()

plt.plot(t, y0)
plt.plot(t, y2, c='r', linewidth=1)
plt.show()




2022年4月21日 星期四

在Spyder當中修改padstack definition某一層的屬性

在Spyder當中修改padstack definition某一層的屬性

import clr, os, sys, System
from distutils.dir_util import copy_tree

AnsysEM_Path = 'C:/Program Files/AnsysEM/v221/Win64/'
sys.path.append(AnsysEM_Path)
os.environ['PATH'] += ';' + AnsysEM_Path

clr.AddReference('Ansys.Ansoft.Edb')
clr.AddReference('Ansys.Ansoft.SimSetupData')
import Ansys.Ansoft.Edb as edb

edb.Database.SetRunAsStandAlone(True)

aedb_path = "D:\demo2\Galileo_G87173_20431_12.aedb"
cell_name = 'Galileo_G87173_204'
layer_name = 'UNNAMED_004'
up_height = '10mil'
low_height = '12mil'

# %%----------------------------------------------------------------------------
n = 1
while True:
new_aedb_path = aedb_path.replace('.aedb', '_{}.aedb'.format(n))
if not os.path.isdir(new_aedb_path):
break
n += 1
copy_tree(aedb_path, new_aedb_path)

middle_layer_name = layer_name + '_1'
low_layer_name = layer_name + '_2'

DB = edb.Database.Open(new_aedb_path, False)

try:
cells = [i for i in DB.CircuitCells]
for cell in cells:
if cell.GetName() == cell_name:
break

layout = cell.GetLayout()
padstack_instances = [i for i in layout.PadstackInstances]
padstack_def = {}
for i in padstack_instances:
if i.GetPadstackDef().GetName() not in padstack_def:
padstack_def[i.GetPadstackDef().GetName()] = i.GetPadstackDef()

dimension = System.Collections.Generic.List[edb.Utility.Value]()
dimension.Add(edb.Utility.Value(0))

for i, d in padstack_def.items():
new_data = edb.Definition.PadstackDefData(d.GetData())

new_data.SetPadParameters('Default',
edb.Definition.PadType.RegularPad,
edb.Definition.PadGeometryType.NoGeometry,
dimension,
edb.Utility.Value(0),
edb.Utility.Value(0),
edb.Utility.Value(0))
new_data.SetPadParameters('Default',
edb.Definition.PadType.AntiPad,
edb.Definition.PadGeometryType.NoGeometry,
dimension,
edb.Utility.Value(0),
edb.Utility.Value(0),
edb.Utility.Value(0))
d.SetData(new_data)
DB.Save()
except:
raise
finally:
DB.Close()



2022年4月18日 星期一

在Spyder當中用EDB在stackup當中插入新的layers

 注意需要將layer複製,才能修改屬性。

import clr, os, sys, System
from distutils.dir_util import copy_tree

AnsysEM_Path = 'C:/Program Files/AnsysEM/v221/Win64/'
sys.path.append(AnsysEM_Path)
os.environ['PATH'] += ';' + AnsysEM_Path

clr.AddReference('Ansys.Ansoft.Edb')
clr.AddReference('Ansys.Ansoft.SimSetupData')
import Ansys.Ansoft.Edb as edb

edb.Database.SetRunAsStandAlone(True)

aedb_path = "D:\demo2\Galileo_G87173_20431.aedb"
cell_name = 'Galileo_G87173_204'
layer_name = 'UNNAMED_004'
up_height = '10mil'
low_height = '12mil'

# %%----------------------------------------------------------------------------
n = 1
while True:
new_aedb_path = aedb_path.replace('.aedb', '_{}.aedb'.format(n))
if not os.path.isdir(new_aedb_path):
break
n += 1
copy_tree(aedb_path, new_aedb_path)

middle_layer_name = layer_name + '_1'
low_layer_name = layer_name + '_2'

DB = edb.Database.Open(new_aedb_path, False)

try:
cells = [i for i in DB.CircuitCells]
for cell in cells:
if cell.GetName() == cell_name:
break

layout = cell.GetLayout()
raw_layercollection = layout.GetLayerCollection()
new_layercollection = edb.Cell.LayerCollection(raw_layercollection)

all_layers = raw_layercollection.Layers(edb.Cell.LayerTypeSet.AllLayerSet)

for layer in all_layers:
if layer.GetName() == layer_name:
layer_material = layer.GetMaterial()
layer2 = edb.Cell.StackupLayer(middle_layer_name, edb.Cell.LayerType.SignalLayer, edb.Utility.Value('0'),
edb.Utility.Value(0), "COPPER")
layer3 = edb.Cell.StackupLayer(low_layer_name, edb.Cell.LayerType.DielectricLayer,
edb.Utility.Value(low_height), edb.Utility.Value(0), layer_material)
new_layercollection.AddLayerBelow(layer2, layer_name)
new_layercollection.AddLayerBelow(layer3, middle_layer_name)

empty_layercollection = edb.Cell.LayerCollection()
for layer in new_layercollection.Layers(edb.Cell.LayerTypeSet.AllLayerSet):
if layer.GetName() == layer_name:
layer = layer.Clone()
layer.SetThickness(edb.Utility.Value(up_height))
empty_layercollection.AddLayerBottom(layer)
else:
empty_layercollection.AddLayerBottom(layer)

layout.SetLayerCollection(empty_layercollection)

DB.Save()
except:
raise
finally:
DB.Close()


2022年3月16日 星期三

如何在AEDT Console執行Script

 可以使用execfile()指令如下,搭配input()可做為一個簡單互動的UI。



利用批次檔執行AEDT Classical API Script

 test.bat

PATH="C:\Program Files\AnsysEM\v221\Win64\common\IronPython";%PATH%

ipy64 .\test.py
pause

test.py

import sys
sys.path.append(r'C:\Program Files\AnsysEM\v221\Win64\PythonFiles\DesktopPlugin')
sys.path.append(r'C:\Program Files\AnsysEM\v221\Win64')

import ScriptEnv
ScriptEnv.Initialize("Ansoft.ElectronicsDesktop")
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()

2022年2月25日 星期五

如何在編輯器環境編寫Classical AEDT API腳本

Spyder當中直接編輯Classical AEDT  API代碼,pip install pypiwin32

from win32com import client

oApp = client.Dispatch("Ansoft.ElectronicsDesktop.2022.1")
oDesktop = oApp.GetAppDesktop()
oDesktop.RestoreWindow()
oProject = oDesktop.NewProject()
oDesign = oProject.InsertDesign("HFSS", "HFSSDesign1", "HFSS Terminal Network", "")
oEditor = oDesign.SetActiveEditor("3D Modeler")
oEditor.CreateCylinder(
[
"NAME:CylinderParameters",
"XCenter:=" , "0mm",
"YCenter:=" , "-0.3mm",
"ZCenter:=" , "0mm",
"Radius:=" , "0.282842712474619mm",
"Height:=" , "0.8mm",
"WhichAxis:=" , "Z",
"NumSides:=" , "0"
],
[
"NAME:Attributes",
"Name:=" , "Cylinder1",
"Flags:=" , "",
"Color:=" , "(143 175 143)",
"Transparency:=" , 0,
"PartCoordinateSystem:=", "Global",
"UDMId:=" , "",
"MaterialValue:=" , "\"vacuum\"",
"SurfaceMaterialValue:=", "\"\"",
"SolveInside:=" , True,
"ShellElement:=" , False,
"ShellElementThickness:=", "0mm",
"IsMaterialEditable:=" , True,
"UseMaterialAppearance:=", False,
"IsLightweight:=" , False
])
#oDesktop.QuitApplication()