<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FLjbade</id>
	<title>GRASS-Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FLjbade"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FLjbade"/>
	<updated>2026-05-26T04:13:20Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=LANDSAT&amp;diff=16443</id>
		<title>LANDSAT</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=LANDSAT&amp;diff=16443"/>
		<updated>2012-09-11T08:10:23Z</updated>

		<summary type="html">&lt;p&gt;⚠️Ljbade: Fixed bug in python code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== LANDSAT Data Availability==&lt;br /&gt;
&lt;br /&gt;
* data download from [http://landsat.usgs.gov/ USGS LANDSAT archive] and [http://glcfapp.umiacs.umd.edu GLCF] and [http://edcsns17.cr.usgs.gov/NewEarthExplorer/ EarthExplorer] and [http://glovis.usgs.gov USGS GloVis]&lt;br /&gt;
* see also the [[Global datasets]] wiki page&lt;br /&gt;
&lt;br /&gt;
== Modules overview ==&lt;br /&gt;
&lt;br /&gt;
* {{cmd|d.rgb}} - display 3-band data&lt;br /&gt;
* {{cmd|i.landsat.rgb}} - auto-enhance colors&lt;br /&gt;
* {{cmd|i.atcorr}} - correct top of atmosphere to surface reflectance - see also the [[Atmospheric correction]] wiki page&lt;br /&gt;
* {{cmd|i.oif}} - calculate the 3 bands showing the greatest difference (for use as R,G,B bands)&lt;br /&gt;
* {{cmd|r.composite}} - flatten 3-bands of data into a single image (lossy)&lt;br /&gt;
&lt;br /&gt;
* {{AddonCmd|i.landsat.toar}} (addon, included in GRASS 6.5 and 7) - convert DN to top of atmosphere radiance&lt;br /&gt;
* {{cmd|i.landsat.acca}} - cloud identification&lt;br /&gt;
* {{AddonCmd|i.landsat.dehaze}} (addon) - haze removal&lt;br /&gt;
* {{cmd|i.topo.corr}} -used to topographically correct reflectance from imagery files, e.g. obtained with {{cmd|i.landsat.toar}}, using a sun illumination terrain model.&lt;br /&gt;
&lt;br /&gt;
== LANDSAT Pre-Processing ==&lt;br /&gt;
&lt;br /&gt;
=== Import data ===&lt;br /&gt;
&lt;br /&gt;
# Open GRASS GIS, select &amp;quot;Location Wizard&amp;quot; in order to create a new location from georeferenced file&lt;br /&gt;
# Use {{cmd|r.in.gdal}} or the &amp;quot;Import file tool&amp;quot; to import the GeoTIFF files into GRASS GIS. See also &amp;quot;Automated data import&amp;quot; below.&lt;br /&gt;
## Most Landsat scenes are delivered in &amp;quot;north-is-up&amp;quot; orientation, hence import is straightforward&lt;br /&gt;
## If you get &amp;quot;ERROR: Input map is rotated - cannot import.&amp;quot;, the image must be first externally rotated, applying the rotation info stored in the metadata field of the raster image file. For example, the gdalwarp software can be used to transform the map to North-up (note, there are several gdalwarp parameters to select the resampling algorithm):&lt;br /&gt;
  gdalwarp rotated.tif northup.tif&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Automated data import ====&lt;br /&gt;
&lt;br /&gt;
An example of Python script bellow imports raster data into GRASS. For each image creates its own mapset and imports bands as &amp;lt;tt&amp;gt;B&amp;lt;id&amp;gt;&amp;lt;/tt&amp;gt;, e.g. B10, B20, ..., B80. This script also sets up timestamp based on MTL file.&lt;br /&gt;
&lt;br /&gt;
The {{AddonCmd|i.landsat.toar}} and {{AddonCmd|i.landsat.acca}} modules want the maps to be named such as &amp;quot;scenename.1, .2, .3&amp;quot;, etc. for the different bands. GloVis names LANDSAT-7 like _B10, _B20, _B30, etc. Save the following script as &amp;quot;import_landsat.py&amp;quot; file:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=python&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
 &lt;br /&gt;
import os&lt;br /&gt;
import sys&lt;br /&gt;
import glob&lt;br /&gt;
import grass.script as grass&lt;br /&gt;
 &lt;br /&gt;
def get_timestamp(mapset):&lt;br /&gt;
    try:&lt;br /&gt;
        metafile = glob.glob(mapset + '/*MTL.txt')[0]&lt;br /&gt;
    except IndexError:&lt;br /&gt;
        return&lt;br /&gt;
 &lt;br /&gt;
    result = dict()&lt;br /&gt;
    try:&lt;br /&gt;
        fd = open(metafile)&lt;br /&gt;
        for line in fd.readlines():&lt;br /&gt;
            line = line.rstrip('\n')&lt;br /&gt;
            if len(line) == 0:&lt;br /&gt;
                continue&lt;br /&gt;
            if 'ACQUISITION_DATE' in line:&lt;br /&gt;
                result['date'] = line.strip().split('=')[1].strip()&lt;br /&gt;
    finally:&lt;br /&gt;
        fd.close()&lt;br /&gt;
 &lt;br /&gt;
    return result&lt;br /&gt;
 &lt;br /&gt;
def import_tifs(mapset):&lt;br /&gt;
    meta = get_timestamp(mapset)&lt;br /&gt;
    for file in os.listdir(mapset):&lt;br /&gt;
        if os.path.splitext(file)[-1] != '.TIF':&lt;br /&gt;
            continue&lt;br /&gt;
        ffile = os.path.join(mapset, file)&lt;br /&gt;
        name = os.path.splitext(file)[0].split('_')[-1]&lt;br /&gt;
        band = int(name[-1])&lt;br /&gt;
        grass.message('Importing %s -&amp;gt; %s@%s...' % (file, name, mapset))&lt;br /&gt;
        grass.run_command('g.mapset',&lt;br /&gt;
                          flags = 'c',&lt;br /&gt;
                          mapset = mapset,&lt;br /&gt;
                          quiet = True,&lt;br /&gt;
                          stderr = open(os.devnull, 'w'))&lt;br /&gt;
        grass.run_command('r.in.gdal',&lt;br /&gt;
                          input = ffile,&lt;br /&gt;
                          output = name,&lt;br /&gt;
                          quiet = True,&lt;br /&gt;
                          overwrite = True,&lt;br /&gt;
                          title = 'band %d' % band)&lt;br /&gt;
        if meta:&lt;br /&gt;
            year, month, day = meta['date'].split('-')&lt;br /&gt;
            if month == '01':&lt;br /&gt;
                month = 'jan'&lt;br /&gt;
            elif month == '02':&lt;br /&gt;
                month = 'feb'&lt;br /&gt;
            elif month == '03':&lt;br /&gt;
                month = 'mar'&lt;br /&gt;
            elif month == '04':&lt;br /&gt;
                month = 'apr'&lt;br /&gt;
            elif month == '05':&lt;br /&gt;
                month = 'may'&lt;br /&gt;
            elif month == '06':&lt;br /&gt;
                month = 'jun'&lt;br /&gt;
            elif month == '07':&lt;br /&gt;
                month = 'jul'&lt;br /&gt;
            elif month == '08':&lt;br /&gt;
                month = 'aug'&lt;br /&gt;
            elif month == '09':&lt;br /&gt;
                month = 'sep'&lt;br /&gt;
            elif month == '10':&lt;br /&gt;
                month = 'oct'&lt;br /&gt;
            elif month == '11':&lt;br /&gt;
                month = 'nov'&lt;br /&gt;
            elif month == '12':&lt;br /&gt;
                month = 'dec'&lt;br /&gt;
 &lt;br /&gt;
            grass.run_command('r.timestamp',&lt;br /&gt;
                              map = name,&lt;br /&gt;
                              date = ' '.join((day, month, year)))&lt;br /&gt;
 &lt;br /&gt;
def main():&lt;br /&gt;
    if len(sys.argv) == 1:&lt;br /&gt;
        for directory in filter(os.path.isdir, os.listdir(os.getcwd())):&lt;br /&gt;
            import_tifs(directory)&lt;br /&gt;
    else:&lt;br /&gt;
        import_tifs(sys.argv[1])&lt;br /&gt;
 &lt;br /&gt;
if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Example of usage:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;./import_landsat.py&amp;lt;/tt&amp;gt; walk through current directory and import all found satellite images.&lt;br /&gt;
* &amp;lt;tt&amp;gt;./import_landsat.py LM41890261983200FFF03&amp;lt;/tt&amp;gt; imports images only from given directory.&lt;br /&gt;
&lt;br /&gt;
=== Hint: Minimal disk space copies ===&lt;br /&gt;
&lt;br /&gt;
Here's a little trick with {{cmd|r.reclass}} to rename maps without touching the data or wasting disk space:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
BASE=L71074092_09220040924&lt;br /&gt;
&lt;br /&gt;
for BAND in 10 20 30 40 50 61 70 80; do&lt;br /&gt;
  BAND1st=`echo $BAND | sed -e 's/0$//'`&lt;br /&gt;
  r.reclass in=&amp;quot;${BASE}_B$BAND&amp;quot; out=$BASE.$BAND1st &amp;lt;&amp;lt; EOF&lt;br /&gt;
    * = *&lt;br /&gt;
EOF&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Natural color composites ===&lt;br /&gt;
&lt;br /&gt;
Solution A) use {{cmd|i.landsat.rgb}}&lt;br /&gt;
&lt;br /&gt;
Solution B) equalize colors on each R,G,B band with&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
r.colors -e map=band1 color=grey&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Composite: then run {{cmd|r.composite}}&lt;br /&gt;
&lt;br /&gt;
=== Reset color tables ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
BASE=L71074092_09220040924&lt;br /&gt;
&lt;br /&gt;
for map in `g.mlist pat=&amp;quot;$BASE.[0-8]*&amp;quot;` ; do&lt;br /&gt;
  r.colors $map color=grey255&lt;br /&gt;
done&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Create an MASK to only show data where coverage exists for all bands ===&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
BASE=L71074092_09220040924&lt;br /&gt;
&lt;br /&gt;
g.region rast=$BASE.1&lt;br /&gt;
r.series in=`g.mlist pat=&amp;quot;$BASE.[0-8]*&amp;quot; sep=,` -n out=$BASE.thresh method=threshold thresh=1&lt;br /&gt;
r.mapcalc &amp;quot;$BASE.mask = if(isnull($BASE.thresh))&amp;quot;&lt;br /&gt;
g.remove $BASE.thresh&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Calculate top-of-atmosphere reflectance and band-6 temperature ===&lt;br /&gt;
&lt;br /&gt;
Calculate top-of-atmosphere reflectance and band-6 temperature (-t only if MTL, not MET file) with {{AddonCmd|i.landsat.toar}}:&lt;br /&gt;
 i.landsat.toar input_prefix=$BASE output_prefix=${BASE}_toar sensor=tm7 metfile=${BASE}_MTL.txt -t&lt;br /&gt;
&lt;br /&gt;
Note: the resulting temperature map is in Kelvin:&lt;br /&gt;
 # convert to degree Celsius&lt;br /&gt;
 r.mapcalc &amp;quot;$BASE.temp_celsius = ${BASE}_toar.6 - 273.15&amp;quot;&lt;br /&gt;
 r.info -r $BASE.temp_celsius&lt;br /&gt;
&lt;br /&gt;
=== Haze removal ===&lt;br /&gt;
&lt;br /&gt;
Simple haze removal can be done with {{AddonCmd|i.landsat.dehaze}}. i.landsat.dehaze applies a bandwise haze correction using tasscap4 (haze) and linear regression.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Atmospheric correction ===&lt;br /&gt;
&lt;br /&gt;
See [[Atmospheric correction]]&lt;br /&gt;
&lt;br /&gt;
=== Cloud identification ===&lt;br /&gt;
&lt;br /&gt;
Identify clouds in the image with {{cmd|i.landsat.acca|version=65}}:&lt;br /&gt;
 i.landsat.acca -f input_prefix=226_62_toar. output=226_62.acca_cloudmask&lt;br /&gt;
&lt;br /&gt;
Mask out the clouds:&lt;br /&gt;
 r.mapcalc &amp;quot;MASK = if(isnull($BASE.acca_cloudmask))&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== Download sample data ==&lt;br /&gt;
&lt;br /&gt;
=== Preprocessed Landsat-7 data for North Carolina ===&lt;br /&gt;
&lt;br /&gt;
The [[Sample_datasets|North Carolina 2008 sample dataset]] comes with 3 different Landsat scenes:&lt;br /&gt;
: (''Wake County -- path: 16  row: 35 for various dates'')&lt;br /&gt;
&lt;br /&gt;
The above import efforts are not needed since the data are already in a GRASS location.&lt;br /&gt;
&lt;br /&gt;
=== Landsat-5: Oct 14, 1987 ===&lt;br /&gt;
&lt;br /&gt;
;Glovis download: LT50160351987287XXX08&lt;br /&gt;
: http://edcsns17.cr.usgs.gov/cgi-bin/EarthExplorer/run-phtml/results/download.phtml?node=GV&amp;amp;ordered=LT50160351987287XXX08&amp;amp;dataset_name=LANDSAT_TM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ??? or ETP016R35_5T19871014 --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provided metadata:&lt;br /&gt;
 IMAGE_ID=P016R35_5T871014&lt;br /&gt;
 PATH=16&lt;br /&gt;
 ROW=35&lt;br /&gt;
 DATE=10/14/87&lt;br /&gt;
 PLATFORM=LANDSAT5&lt;br /&gt;
&lt;br /&gt;
=== Landsat-7: Mar 31, 2000 ===&lt;br /&gt;
&lt;br /&gt;
;Glovis download: LE70160352000091EDC00&lt;br /&gt;
: http://edcsns17.cr.usgs.gov/cgi-bin/EarthExplorer/run-phtml/results/download.phtml?node=GV&amp;amp;ordered=LE70160352000091EDC00&amp;amp;dataset_name=LANDSAT_ETM&lt;br /&gt;
&lt;br /&gt;
Values in the metadata below indicate that the version provided with the NC 2008 dataset's production date was after July 1, 2000, and that the channel gains were &amp;lt;tt&amp;gt;HHHLHLHHL&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Convert DNs to radiance/temperatures:&lt;br /&gt;
 GRASS&amp;gt; i.landsat.toar -v band=lsat7_2000 sensor=7 date=2000-03-31 \&lt;br /&gt;
    product_date=2000-07-02 solar_elevation=51.5246529 gain=HHHLHLHHL&lt;br /&gt;
&lt;br /&gt;
Provided metadata:&lt;br /&gt;
 SPACECRAFT_ID=Landsat7&lt;br /&gt;
 SENSOR_ID=ETM+&lt;br /&gt;
 '''ACQUISITION_DATE=2000-03-31'''&lt;br /&gt;
 WRS_PATH=16&lt;br /&gt;
 CPF_FILE_NAME=L7CPF20000101_20000331_12&lt;br /&gt;
 SUN_AZIMUTH=139.6033279&lt;br /&gt;
 '''SUN_ELEVATION=51.5246529'''&lt;br /&gt;
 LMAX_BAND1=191.600&lt;br /&gt;
 LMIN_BAND1=-6.200&lt;br /&gt;
 LMAX_BAND2=196.500&lt;br /&gt;
 LMIN_BAND2=-6.400&lt;br /&gt;
 LMAX_BAND3=152.900&lt;br /&gt;
 LMIN_BAND3=-5.000&lt;br /&gt;
 LMAX_BAND4=241.100&lt;br /&gt;
 LMIN_BAND4=-5.100&lt;br /&gt;
 LMAX_BAND5=31.060&lt;br /&gt;
 LMIN_BAND5=-1.000&lt;br /&gt;
 LMAX_BAND61=17.040&lt;br /&gt;
 LMIN_BAND61=0.000&lt;br /&gt;
 LMAX_BAND62=12.650&lt;br /&gt;
 LMIN_BAND62=3.200&lt;br /&gt;
 LMAX_BAND7=10.800&lt;br /&gt;
 LMIN_BAND7=-0.350&lt;br /&gt;
 LMAX_BAND8=243.100&lt;br /&gt;
 LMIN_BAND8=-4.700&lt;br /&gt;
 QCALMAX_BAND1=255.0&lt;br /&gt;
 QCALMIN_BAND1=1.0&lt;br /&gt;
 QCALMAX_BAND2=255.0&lt;br /&gt;
 QCALMIN_BAND2=1.0&lt;br /&gt;
 QCALMAX_BAND3=255.0&lt;br /&gt;
 QCALMIN_BAND3=1.0&lt;br /&gt;
 QCALMAX_BAND4=255.0&lt;br /&gt;
 QCALMIN_BAND4=1.0&lt;br /&gt;
 QCALMAX_BAND5=255.0&lt;br /&gt;
 QCALMIN_BAND5=1.0&lt;br /&gt;
 QCALMAX_BAND61=255.0&lt;br /&gt;
 QCALMIN_BAND61=1.0&lt;br /&gt;
 QCALMAX_BAND62=255.0&lt;br /&gt;
 QCALMIN_BAND62=1.0&lt;br /&gt;
 QCALMAX_BAND7=255.0&lt;br /&gt;
 QCALMIN_BAND7=1.0&lt;br /&gt;
 QCALMAX_BAND8=255.0&lt;br /&gt;
 QCALMIN_BAND8=1.0&lt;br /&gt;
&lt;br /&gt;
=== Landsat-7: May 24, 2002 ===&lt;br /&gt;
&lt;br /&gt;
;Glovis download: LE70160352002144EDC00&lt;br /&gt;
: http://edcsns17.cr.usgs.gov/cgi-bin/EarthExplorer/run-phtml/results/download.phtml?node=GV&amp;amp;ordered=LE70160352002144EDC00&amp;amp;dataset_name=LANDSAT_ETM&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- ???&lt;br /&gt;
or ELP016R035_7T20020524&lt;br /&gt;
: http://edcsns17.cr.usgs.gov/helpdocs/download.cgi?file=lsatortho/etm/16/35/elp016r035_7t20020524.tar.gz&lt;br /&gt;
---&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Provided metadata: (`p016r035_7x20020524.met`)&lt;br /&gt;
 SPACECRAFT_ID=Landsat7&lt;br /&gt;
 SENSOR_ID=ETM+&lt;br /&gt;
 '''ACQUISITION_DATE=2002-05-24'''&lt;br /&gt;
 WRS_PATH=016&lt;br /&gt;
 WRS_ROW=035&lt;br /&gt;
 SUN_AZIMUTH=120.8810347&lt;br /&gt;
 '''SUN_ELEVATION=64.7730999'''&lt;br /&gt;
 QA_PERCENT_MISSING_DATA=0&lt;br /&gt;
 CLOUD_COVER=0&lt;br /&gt;
 CPF_FILE_NAME=L7CPF20020401_20020630_03&lt;br /&gt;
 LMAX_BAND1=191.600&lt;br /&gt;
 LMIN_BAND1=-6.200&lt;br /&gt;
 LMAX_BAND2=196.500&lt;br /&gt;
 LMIN_BAND2=-6.400&lt;br /&gt;
 LMAX_BAND3=152.900&lt;br /&gt;
 LMIN_BAND3=-5.000&lt;br /&gt;
 LMAX_BAND4=241.100&lt;br /&gt;
 LMIN_BAND4=-5.100&lt;br /&gt;
 LMAX_BAND5=31.060&lt;br /&gt;
 LMIN_BAND5=-1.000&lt;br /&gt;
 LMAX_BAND61=17.040&lt;br /&gt;
 LMIN_BAND61=0.000&lt;br /&gt;
 LMAX_BAND62=12.650&lt;br /&gt;
 LMIN_BAND62=3.200&lt;br /&gt;
 LMAX_BAND7=10.800&lt;br /&gt;
 LMIN_BAND7=-0.350&lt;br /&gt;
 LMAX_BAND8=243.100&lt;br /&gt;
 LMIN_BAND8=-4.700&lt;br /&gt;
 QCALMAX_BAND1=255.0&lt;br /&gt;
 QCALMIN_BAND1=1.0&lt;br /&gt;
 QCALMAX_BAND2=255.0&lt;br /&gt;
 QCALMIN_BAND2=1.0&lt;br /&gt;
 QCALMAX_BAND3=255.0&lt;br /&gt;
 QCALMIN_BAND3=1.0&lt;br /&gt;
 QCALMAX_BAND4=255.0&lt;br /&gt;
 QCALMIN_BAND4=1.0&lt;br /&gt;
 QCALMAX_BAND5=255.0&lt;br /&gt;
 QCALMIN_BAND5=1.0&lt;br /&gt;
 QCALMAX_BAND61=255.0&lt;br /&gt;
 QCALMIN_BAND61=1.0&lt;br /&gt;
 QCALMAX_BAND62=255.0&lt;br /&gt;
 QCALMIN_BAND62=1.0&lt;br /&gt;
 QCALMAX_BAND7=255.0&lt;br /&gt;
 QCALMIN_BAND7=1.0&lt;br /&gt;
 QCALMAX_BAND8=255.0&lt;br /&gt;
 QCALMIN_BAND8=1.0&lt;br /&gt;
&lt;br /&gt;
== LANDSAT Image classification ==&lt;br /&gt;
&lt;br /&gt;
See [[Image classification]]&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;br /&gt;
[[Category:FAQ]]&lt;br /&gt;
[[Category:Image processing]]&lt;/div&gt;</summary>
		<author><name>⚠️Ljbade</name></author>
	</entry>
</feed>