简体   繁体   English

使用Abaqus / Python脚本从多个Excel工作表中读取XY坐标

[英]Read XY Coordinates from Multiple Excel Sheets Using Abaqus/Python Script

I have a stack of CT-scan images. 我有一堆CT扫描图像。 After processing (one image from those stack) CT-scan image using Matlab, I saved XY coordinates for each different boundary region in different Excel sheets as follows: 使用Matlab处理(这些堆栈中的一幅图像)CT扫描图像后,我将每个不同边界区域的XY坐标保存在不同的Excel工作表中,如下所示:

I = imread('myCTscan.jpeg');
BW = im2bw(I);
[coords, labeledImg] = bwboundaries(BW, 4, 'holes'); 
sheet = 1;
for n=1:length(coords);
    xlswrite('fig.xlsx',coords{n,1},sheet,'A1');
    sheet = sheet+1;
end

The next step is then to import this set of coordinates and plot it into Abaqus CAE Sketch for finite element analysis. 然后,下一步是导入这组坐标并将其绘制到Abaqus CAE Sketch中以进行有限元分析。 I figure out that my workflow is something like this: 我发现我的工作流程是这样的:

  1. Import Excel workbook 导入Excel工作簿
  2. For each sheet in workbook: 对于工作簿中的每个工作表:
    2.1. 2.1。 For each row: read both column to get xy coordinates (each row has two column, x and y coordinate) 对于每一行:读取两列以获取xy坐标(每行都有两列x和y坐标)
    2.2. 2.2。 Put each xy coordinates inside a list 将每个xy坐标放入列表中
    2.3. 2.3。 From list, sketch using spline method 从列表中,使用样条法绘制草图
  3. Repeat step 2 for other sheets within the workbook 对工作簿中的其他工作表重复步骤2

I searched for a while and found something like this: 我搜索了一会儿,发现是这样的:

from abaqus import *
lines= open('fig.xlsx', 'r').readlines()
pointList= []
for line in lines:
    pointList.append(eval('(%s)' %line.strip()))
s1= mdb.models['Model-1'].ConstrainedSketch(name='mySketch', sheetSize=500.0)
s1.Spline(points= pointList)

But this only read XY coordinates from only one sheet and I'm stuck at step 3 above. 但这只能从一张纸上读取XY坐标,而我在上面的第3步中遇到了麻烦。 Thus my problem is that how to read these coordinates in different sheets using Abaqus/Python (Abaqus 6.14, Python 2.7) script? 因此,我的问题是如何使用Abaqus / Python(Abaqus 6.14,Python 2.7)脚本在不同的工作表中读取这些坐标?

I'm new to Python programming, I can read and understand the syntax but can't write very well (I'm still struggling on how to import Python module in Abaqus). 我是Python编程的新手,我可以阅读和理解语法,但是写得不太好(我仍在努力如何在Abaqus中导入Python模块)。 Manually type each coordinates (like in Abaqus' modelAExample.py tutorial) is practically impossible since each of my CT-scan image can have 100++ of boundary regions and 10k++ points. 几乎不可能手动键入每个坐标(例如在Abaqus的modelAExample.py教程中),因为我的每个CT扫描图像都可以具有100 ++的边界区域和10k ++的点。

I'm using: 我正在使用:
Windows 7 x64 Windows 7 x64
Abaqus 6.14 (with built in Python 2.7) Abaqus 6.14(内置Python 2.7)
Excel 2013 Excel 2013
Matlab 2016a with Image Processing Toolbox 具有图像处理工具箱的Matlab 2016a

You are attempting to read excel files as comma separated files. 您正在尝试将excel文件读取为逗号分隔的文件。 CSV files by definition can not have more than one tab. 根据定义,CSV文件不能包含多个标签。 Your read command is interpreting the file as a csv and not allowing you to iterate over the tabs in your file (though it begs the question how your file is opening properly in the first place as you are saving an xlsx and reading a csv). 您的读取命令会将文件解释为csv,并且不允许您迭代文件中的选项卡(尽管这样会产生一个问题,即您在保存xlsx和读取csv时首先如何正确打开文件)。

There are numerous python libraries that will parse and process XLS/XLSX files. 有许多Python库可解析和处理XLS / XLSX文件。

Take a look at pyxl and use it to read your file in. You would likely use something like 看看pyxl并用它来读入文件。您可能会使用类似

from openpyxl import Workbook
(some commands to open the workbook)

listofnames=wb.sheetnames
for k in listofnames:
    ws=wb.worksheets(k)

and then input your remaining commands. 然后输入您剩余的命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM