pythonnumpy

How to read/extract climate model data in .asc file format by using Python?


I have downloaded some global climate model data from an opensource website. But, these data are in .asc file format. How could I read/extract these data using Python? Anything in Numpy?


Solution

  • .asc means you likely chose the ASCII Grid download option from CCAFS. These are simple text files with a 6 line header containing the geographic information.

    If you just want to load the data into a numpy array you can use the loadtxt function. You just have to skip the first 6 rows which contain the header.

    import numpy as np
    ascii_grid = np.loadtxt("bio_1.asc", skiprows=6)
    

    If you want to preserve the geographic information in the ASCII Grid while working in Python there is a tutorial by Joel Lawhead over at Geospatial Python.