I have a .asc climate data file at hand and want to explore it to extract some information.

Based on searching, some general read methods have been tried as, import it as python pandas or numpy structure to see its contents.

Here the result:

if read in using pandas:

df = pd.read_table(path + "\max1951_1.asc")
                  NCOLS   1068
0                 NROWS    510
1    XLLCORNER  -141.0000
2    YLLCORNER   41.00000
3    CELLSIZE   0.83333330E-01
4      NODATA_VALUE  -999.00
5                      -999.00
6                      -999.00

Using numpy:

ascii_grid = np.loadtxt(path + "\max1951_1.asc", skiprows=6)
array([[-999., -999., -999., ..., -999., -999., -999.],
       [-999., -999., -999., ..., -999., -999., -999.],
       [-999., -999., -999., ..., -999., -999., -999.],
       [-999., -999., -999., ..., -999., -999., -999.],
       [-999., -999., -999., ..., -999., -999., -999.],
       [-999., -999., -999., ..., -999., -999., -999.]])

I still doubt what is the best solution or packet working with this kind of ESRI ASCII Raster format, not sure if the above print already shows all the file's content or not. Besides, my question is, if I want to extract any specific gridded cell's lat and lon information, How can I do that?

  1. if asc file naturally contain those information so I can simply use certain existed packet to extract that?

  2. Or the only method is use coordinate to calculate and convert base on the CELLSIZE and X,YLLCORNER.

  • Your question is a bit vague about what (precisely) you're trying to achieve. You could open in QGIS to explore the file... To get value coordinates I'd use GDAL, get the GeoTransform object and then translate row, col to georeferenced coordinate by origin and cell size. If you're not keen on scripting then convert the raster to points and interrogate each point for its X and Y coordinate. – Michael Stimson Jan 16 '18 at 23:42
  • 1
    Careful not to mix ascii text files (usually xyz files) that pandas can read easily and ESRI arc ASCII grids, which is yours and not appropriate. what exactly do you want to extract ? Every pixel has lat/long info... are you trying to get this asc as a xyz files ? Instead of pandas, have a look at geopandas : geopandas.org/io.html – gisnside Jan 16 '18 at 23:44
  • 1
    Option 2 is your answer. – FelixIP Jan 17 '18 at 0:29
  • @gisnside yes, I do want to extract lat lon information from the file, that's what I currently need... I think you are right - pandas is bit simple to handle those data, I have thought about geopandas, but find geopandas also cannot open ASC file(don't know why..), maybe like above says GDAL is a good option. – wflwo Jan 18 '18 at 17:44

You've tagged your question with ESRI-ASCII, why not use ESRI tools?

You can get properties of a raster or individual cell values. If you want to call these tools in python simply scroll to the bottom of these pages to see how to call them?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.