Getting Airfoil Coordinates

Develop an airfoil plotter.

You need to use the Requests and Matplotlib libraries:

import requests
import matplotlib.pyplot as plt

Organizing the program

First, you will define a get_airfoil_coordinates() function that will:

  • accept an airfoil name as an argument
  • scrape the UIUC website
  • get the results and clean the data
  • return the x coordinates, the y coordinates, and the airfoil name as elements of a tuple

To build this function, you will use the NACA 2412 airfoil to ensure that the program works.

Understanding airfoil coordinates

The URL of each airfoil’s coordinates in the UIUC airfoil database follows the same format: https://m-selig.ae.illinois.edu/ads/coord/{airfoil_name}.dat. Each time you query the database, you will replace {airfoil_name} with the airfoil argument in the function. The NACA 2412 file is formatted as follows:

NACA 2412
1.0000     0.0013
0.9500     0.0114
0.9000     0.0208
......
0.9500     -0.0048
1.0000     -0.0013

Interestingly, it is not a CSV file; rather, it is a raw text (txt) file. The first line of the file is the airfoil name, and the subsequent lines are normalized coordinates in the x and y direction, respectively. The URL also returns a Not Found page if any of the airfoil letters are uppercase. You will need to make sure any URL query uses airfoils with all lowercase letters.

Next, to figure out what character was separating the two coordinates, you can copy the first line of coordinates and try to see what characters would properly split the str. The tab character is represented as \t in Python; similarly, the new line character (otherwise known as hitting Enter or Return) is represented as \n.

Get hands-on with 1200+ tech skills courses.