Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What is the easiest way to read and plot coordinates from an airfoil coordinates file?

I have downloaded an airfoil from Airfoil Tools. I want to load it into Python to plot it and make some calculations from the geometry.

Edit: example file

To read the file I’ve tried using this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

with open(filename) as file:
    lines = [line.rstrip() for line in file]

However I encountered many problems because the data is a string so I have to manually convert types and delete columns and such. Is there an easier way to do this? What I want is flexibility to access and manipulate the data.

>Solution :

You should really embrace Python libraries to perform certain tasks for which code is already tested and neatly packaged into a library. For your purposes (importing data, array manipulation and operations and plotting) libraries such as Pandas, Numpy and Matplotlib are very common and powerful, there are a bunch of resources on it’s capabilities. I really recommend you to check out their websites:

On Airfoil tools you can directly download a .dat file which you can import directly using pandas. Then using simple parameters declared when calling your function will correctly parse the data and return it in the appropriate data type (float instead of str).

Code Sample:

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt


filename = 'airfoil.dat' #enter your file path here
data = pd.read_table(filename,delim_whitespace=True,skiprows=[0],names=['x','y'],index_col=False)

#Plot
plt.plot(data.x, data.y, 'r',marker='.',markeredgecolor='black', markersize=3)
plt.plot(0.5*data.x+0.3,0.5*data.y) #Scale & translate the datapoints

#Plot settings
plt.axis('equal')
plt.xlim((-0.05, 1.05))
plt.legend(['GOE 383 AIRFOIL','SCALED AIRFOIL'])

Airfoil Plots

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading