Most of my work currently revolves around raster processing of one kind or another. Being able to take advantage of the extensive libraries within Python (e.g. Numpy) is extremely helpful when carrying out such tasks. This blog really got me onto this.
Before trying to make use of the below functions, make sure you have access to the osgeo libraries - if you don’t, see here.
Below is a Python function that you can take that will get any given ENVI type binary file (so long as it has a .hdr file) into a numpy array.
There is a lot more you can return from the above function as you can see - adjust to taste. To import files of different types, have a look here
and alter the line:
Once you have your numpy array and you’ve done some processing or whatever, it is then useful to be able to pull the array back out, exporting it
back as an ENVI (or other) binary. A “post” input is required in case you’ve resampled the original imported binary through your processing. If you haven’t
resampled just pass in the original post as returned by the first function.