I have been creating .asc raster files by saving a numpy array with numpy.savetxt and the following header: header = "ncols %s\n" % ncols header += "nrows %s\n" % nrows header += "xllcorner %s\n" % xll header += "yllcorner %s\n" % yll header += "cellsize %s\n" % cellsize header += "NODATA_value -99999"

After producing the .asc files I load them into QGIS and they are by default given a style with min: nan, and max: nan. If I go into the Style dialog, set to Stretch to min/max, and change the min and max to match the appropriate range for the source file (eg 0 to 40), the preview thumbnail shows a pixelated mess and the raster shows as completely black.

Sometimes the raster shows up fine if I just hit apply, but then reverts to all black once I hit OK. If I am zoomed very far in (well within the limits of the raster), then sometimes the raster shows up fine and sometimes it doesn't.

Source and generated .asc files here: https://github.com/mrlmautner/PrecipRasters


1 Answer 1


In the GeneratedRaster.asc header, you specify:

ncols        98
nrows        70

But there are are only 69 rows. Change to:

ncols        98
nrows        69

And gdal can read the raster correctly, so I presume QGIS will be able to as well.

  • Thanks! You were correct, I found a resampling definition error in my Python code. Commented Mar 14, 2018 at 22:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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