<?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%8FAndbal</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%8FAndbal"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FAndbal"/>
	<updated>2026-04-14T17:02:53Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_Community_Sprint_Bonn_2016&amp;diff=22588</id>
		<title>GRASS Community Sprint Bonn 2016</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_Community_Sprint_Bonn_2016&amp;diff=22588"/>
		<updated>2016-02-25T00:42:18Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: corrected host country&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{toc|right}}&lt;br /&gt;
During the [http://2016.foss4g.org/ FOSS4G 2016] , 21-28 August 2016, [http://en.wikipedia.org/wiki/Bonn Bonn], [https://en.wikipedia.org/wiki/Germany Germany], the GRASS GIS project will join the code sprint&lt;br /&gt;
&lt;br /&gt;
'''Important dates:'''&lt;br /&gt;
&lt;br /&gt;
* CodeSprint I: Sun 21.08.2016 12:00 - Tue 23.08.2016 (open end)&lt;br /&gt;
* [http://2016.foss4g.org/#page9 FOSS4G 2016 Schedule]&lt;br /&gt;
* CodeSprint II: Sat 27.08.2016 - Sun 28.08.2016 12:00 a.m&lt;br /&gt;
&lt;br /&gt;
== Purpose ==&lt;br /&gt;
&lt;br /&gt;
Get together of GRASS GIS project members to take decisions and tackle small and larger problems.&lt;br /&gt;
&lt;br /&gt;
For this meeting, we welcome people committed to improving the GRASS GIS project. This includes developers, documenters, bug reporters, translators, and users!&lt;br /&gt;
&lt;br /&gt;
== Sponsors ==&lt;br /&gt;
&lt;br /&gt;
If you are interested to sponsor the GRASS Community Sprint, please read about&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;amp;nbsp;&amp;amp;nbsp;&amp;amp;nbsp; '''sponsoring the GRASS project at [http://grass.osgeo.org/donations/ http://grass.osgeo.org/donations/]'''&amp;lt;br&amp;gt;&lt;br /&gt;
and, if needed, contact [[User:Neteler|Markus Neteler]] &amp;lt;tt&amp;gt;&amp;lt;neteler at osgeo.org&amp;gt;&amp;lt;/tt&amp;gt;. Any surplus at the end of the event will be turned over to the GRASS GIS project.&lt;br /&gt;
&lt;br /&gt;
The GRASS Community Sprint is a great occasion for you to support the development of GRASS. With your contribution you'll enable more developers to meet in Prague. The community sprint is an important opportunity for the GRASS developers to discuss and collaboratively resolve bugs, plan the direction for the project and work on new features. Please see below for the more detailed agenda. The developers and contributors are donating their valuable time, so it would be great if in-kind funding can be made available from within the community to cover out-of-pocket expenses. All of the work that takes place at the community sprint will be directly contributed back into the GRASS project to the benefit of everyone who uses it.&lt;br /&gt;
&lt;br /&gt;
=== Thanks to our sponsors ===&lt;br /&gt;
&lt;br /&gt;
== Venue ==&lt;br /&gt;
&lt;br /&gt;
* Bonn, Germany: http://www.basecamp-bonn.de&lt;br /&gt;
&lt;br /&gt;
== Accommodation and Costs ==&lt;br /&gt;
&lt;br /&gt;
* to be defined&lt;br /&gt;
&lt;br /&gt;
== Weather ==&lt;br /&gt;
&lt;br /&gt;
* https://en.wikipedia.org/wiki/Bonn#Climate&lt;br /&gt;
&lt;br /&gt;
== Agenda - What we plan to do ==&lt;br /&gt;
&lt;br /&gt;
'''Note:''' The program is generally open for your ideas. Please edit this wiki page!&lt;br /&gt;
&lt;br /&gt;
== Participation ==&lt;br /&gt;
&lt;br /&gt;
For organizationals reasons, please '''additionally register''' at: https://wiki.osgeo.org/wiki/FOSS4G_2016_Code_Sprint&lt;br /&gt;
&lt;br /&gt;
=== In person ===&lt;br /&gt;
&lt;br /&gt;
Please add your name here or contact [[User:Lucadelu|Luca Delucchi]] &amp;lt;tt&amp;gt;&amp;lt;lucadeluge at gmail com&amp;gt;&amp;lt;/tt&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
{|class=&amp;quot;wikitable sortable&amp;quot;   border=&amp;quot;2&amp;quot; cellspacing=&amp;quot;0&amp;quot; cellpadding=&amp;quot;4&amp;quot; rules=&amp;quot;all&amp;quot; style=&amp;quot;margin:1em 1em 1em 0; border:solid 1px #AAAAAA; border-collapse:collapse; background-color:#edf9c7; font-size:95%; empty-cells:show;&amp;quot; &lt;br /&gt;
|width=50px|'''No'''&lt;br /&gt;
|width=130px|'''Participant '''&lt;br /&gt;
|width=100px|'''Country'''&lt;br /&gt;
|width=100px|'''Arrival'''&lt;br /&gt;
|width=100px|'''Departure'''&lt;br /&gt;
|'''Topic'''&lt;br /&gt;
|width=75px|'''T-Shirt'''&lt;br /&gt;
|'''Notes'''&lt;br /&gt;
|-&lt;br /&gt;
|1&lt;br /&gt;
|[[User:Lucadelu|Luca Delucchi]]&lt;br /&gt;
|Italy&lt;br /&gt;
| August 21&lt;br /&gt;
| August 28&lt;br /&gt;
| &lt;br /&gt;
| L&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|2&lt;br /&gt;
|[[User:Landa|Martin Landa]]&lt;br /&gt;
|Czech Republic&lt;br /&gt;
| August 21&lt;br /&gt;
| August 28&lt;br /&gt;
| &lt;br /&gt;
| L&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|3&lt;br /&gt;
|[[User:Neteler|Markus Neteler]]&lt;br /&gt;
|Italy&lt;br /&gt;
| August 21&lt;br /&gt;
| August 28&lt;br /&gt;
| &lt;br /&gt;
| M&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|4&lt;br /&gt;
|[[User:Ychemin|Yann Chemin]]&lt;br /&gt;
|France&lt;br /&gt;
| August 21&lt;br /&gt;
| August 28&lt;br /&gt;
| &lt;br /&gt;
| XL&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|5&lt;br /&gt;
|[[User:NikosA|Nikos Alexandris]]&lt;br /&gt;
|Switzerland&lt;br /&gt;
| August 21&lt;br /&gt;
| August 28&lt;br /&gt;
| &lt;br /&gt;
| S or M&lt;br /&gt;
|&lt;br /&gt;
|-&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Via IRC chat ===&lt;br /&gt;
&lt;br /&gt;
== Individual Preparation ==&lt;br /&gt;
&lt;br /&gt;
* Bring your own computer&lt;br /&gt;
* Bring [http://en.wikipedia.org/wiki/Mains_electricity_by_country your power connector adapter] if needed ([https://en.wikipedia.org/wiki/File:Schuko_plug_and_socket.png Germany])&lt;br /&gt;
* Install subversion and the compiler tools, and come with a working GRASS development environment if possible.&lt;br /&gt;
&lt;br /&gt;
== Photos ==&lt;br /&gt;
&lt;br /&gt;
We have to remember to take at least one group photo! :-) &lt;br /&gt;
&lt;br /&gt;
== FAQ ==&lt;br /&gt;
&lt;br /&gt;
* ''Is the GRASS Community Sprint just a coding event?''&lt;br /&gt;
** It is mainly a coding and documentation event. It is a working session for people who are already participants in the GRASS project and/or are committed to improving the GRASS project.&lt;br /&gt;
** On demand we can do some presentations of current working GRASS implementation and new upcoming features to spread the idea of Open Source GIS software&lt;br /&gt;
* ''Is the GRASS Community Sprint for developers only?''&lt;br /&gt;
** No: anybody can help, with testing, checking out bugs and fixes, documentation and more.&lt;br /&gt;
* ''Where can I get help and more information about the community sprint?''&lt;br /&gt;
** Contact [[User:Lucadelu|Luca Delucchi]] &amp;lt;tt&amp;gt;&amp;lt;lucadeluge at gmail com&amp;gt;&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: Code Sprint]]&lt;br /&gt;
[[Category: 2016]]&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=LANDSAT&amp;diff=22480</id>
		<title>LANDSAT</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=LANDSAT&amp;diff=22480"/>
		<updated>2016-02-16T22:19:31Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: added info on haze removal&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Data Availability==&lt;br /&gt;
&lt;br /&gt;
Landsat imagery can be obtained from [http://landsat.usgs.gov/ USGS' LANDSAT archive]:&lt;br /&gt;
&lt;br /&gt;
* [http://glovis.usgs.gov USGS GloVis]&lt;br /&gt;
* [http://earthexplorer.usgs.gov/ EarthExplorer]&lt;br /&gt;
* [http://earthexplorer.usgs.gov/bulk/help Bulk Download Orders] using the [http://earthexplorer.usgs.gov/bulk/ Bulk Download Application]&lt;br /&gt;
* [http://landsatlook.usgs.gov/ LandsatLook Viewer]&lt;br /&gt;
&lt;br /&gt;
See also the [[Global datasets]] wiki page&lt;br /&gt;
&lt;br /&gt;
On 06/12/13, USGS [http://landsat.usgs.gov/about_LU_Vol_7_Issue_4.php announced] the availability of [http://landsat.usgs.gov/landsat8.php LANDSAT 8]. See also [http://landsat.usgs.gov/band_designations_landsat_satellites.php this page].&lt;br /&gt;
&lt;br /&gt;
== Modules overview ==&lt;br /&gt;
&lt;br /&gt;
GRASS GIS features a complete set of native modules and various add-ons for pre- and post-processing Landsat satellite imagery. The following lists offer an overview of related modules and add-ons.&lt;br /&gt;
&lt;br /&gt;
=== Generic modules applicable to Landsat ===&lt;br /&gt;
&lt;br /&gt;
* {{cmd|d.rgb}} → display 3-band data&lt;br /&gt;
* {{cmd|r.composite}} → flatten 3-bands of data into a single image (lossy, maybe used in combination with {{cmd|i.landsat.rgb|version=64}} (GRASS 6.x) | {{cmd|i.colors.enhance|version=70}} (GRASS 7.x)&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.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;
* {{cmd|i.oif}} → calculate the 3 bands showing the greatest difference (for use as R,G,B bands)&lt;br /&gt;
* {{AddonCmd|i.histo.match}} (addon) → histogram matching of two or more raster maps (in grass 7) ''Note, the module works with integer values and does not accept the &amp;quot;.&amp;quot; character as part of the raster map's name!''&lt;br /&gt;
&lt;br /&gt;
=== Landsat specific modules ===&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.landsat.rgb|version=64}} (GRASS 6.x) | {{cmd|i.colors.enhance|version=70}} (GRASS 7.x) → auto-enhance colors&lt;br /&gt;
* {{cmd|i.landsat.toar}} → convert DN to top of atmosphere radiance&lt;br /&gt;
* {{cmd|i.landsat.acca}} → cloud cover assessment&lt;br /&gt;
&lt;br /&gt;
=== Landsat specific GRASS AddOns ===&lt;br /&gt;
&lt;br /&gt;
* {{AddonCmd|i.landsat.trim|version=64}} → trims border fringes for each band separately or with the MASK where coverage exists for all bands&lt;br /&gt;
* {{AddonCmd|i.landsat.dehaze|version=64}} (addon) → haze removal&lt;br /&gt;
&lt;br /&gt;
== Pre-Processing ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
Typically, pre-processing Landsat imagery comprises the following steps:&lt;br /&gt;
&lt;br /&gt;
# '''import''' in the database → {{cmd|r.in.gdal}}&lt;br /&gt;
# geometrically &amp;amp; orthometrically correct imagery&lt;br /&gt;
#* already done for L1T products, read more at [http://landsat.usgs.gov//Landsat_Processing_Details.php USGS' Landsat Information Products] webpage&lt;br /&gt;
# optionally, automatically '''cut-off border fringes''' → {{AddonCmd|i.landsat.trim|version=64}}&lt;br /&gt;
#* of course one can use the official WRS2 Path/Row vector tiles to manually trim border fringes&lt;br /&gt;
# optionally, '''denoise''' for obvious/intensive salt &amp;amp; pepper effects, stripes, etc.&lt;br /&gt;
#* for example by applying Principal Components Analysis as a denoising technique → {{cmd|i.pca}} ''&amp;lt;&amp;lt;&amp;lt; Re-order this step?''&lt;br /&gt;
# '''convert''' the '''Digital Numbers''' (DNs) to '''Top-of-Atmosphere Radiances/Reflectances''' (ToARs) → {{cmd|i.landsat.toar}}&lt;br /&gt;
# optionally, '''correct for atmospheric effects''' → {{cmd|i.atcorr}}&lt;br /&gt;
#* that is, accounting for distorting atmospheric effects and estimating actual reflectances as they would have been measured on the ground&lt;br /&gt;
#* also described as conversion to Top-of-Canopy Reflectances (ToCRs)&lt;br /&gt;
# '''assessing cloud cover''' → {{cmd|i.landsat.acca}}&lt;br /&gt;
#* optionally, detect and remove clouds shadows as well&lt;br /&gt;
# '''topographically normalise''' imagery → {{cmd|i.topo.corr}}&lt;br /&gt;
#* also known as topographic correction, that is, accounting for illumination differences due to the acquisition's geometry&lt;br /&gt;
# '''radiometrically normalise''' → one approach via {{AddonCmd|i.histo.match}} (in '''grass 7''', addon), also known as relative radiometric normalisation -- one approach is the ''histogram matching'' technique of two or more raster maps&lt;br /&gt;
#* '''ToDo/More techniques?'''&lt;br /&gt;
&lt;br /&gt;
See also&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat8-data-in-grass-gis-7/ Processing Landsat 8 data in GRASS GIS 7: Import and visualization]&lt;br /&gt;
&lt;br /&gt;
=== Importing data ===&lt;br /&gt;
&lt;br /&gt;
Importing Landsat spectral bands in GRASS GIS' data base can be done both from the Graphical User Interface or from the command line&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Open GRASS GIS, select ''Location Wizard'' in order to create a new location from georeferenced file&lt;br /&gt;
# Use the ''Import file tool'', or the {{cmd|r.in.gdal}} module, to import the GeoTIFF files into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
See also [http://grasswiki.osgeo.org/wiki/LANDSAT#Automated_data_import Automated data import] below.&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&lt;br /&gt;
# Most Landsat scenes are delivered in ''north-is-up'' orientation, hence the import process is straightforward.&lt;br /&gt;
# If you get &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;ERROR: Input map is rotated - cannot import.&amp;lt;/source&amp;gt;, the image must be first rotated externally, applying the rotation info stored in the metadata field of the raster image file. For example, the &amp;lt;code&amp;gt;gdalwarp&amp;lt;/code&amp;gt; software can be used to transform the map to North-up (note, there are several &amp;lt;code&amp;gt;gdalwarp&amp;lt;/code&amp;gt; parameters to select the resampling algorithm):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  gdalwarp rotated.tif northup.tif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Hint: Minimal disk space copies ====&lt;br /&gt;
&lt;br /&gt;
Here's a little trick using {{cmd|r.reclass}} to rename maps (for example, from ''L71074092_09220040924_B'''10''''' to ''L71074092_09220040924_B'''1''''') 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;
&lt;br /&gt;
&lt;br /&gt;
==== Automated data import ====&lt;br /&gt;
&lt;br /&gt;
The following ''Python'' script imports Landsat imagery into GRASS' data base. Specifically, the script&lt;br /&gt;
&lt;br /&gt;
* creates an independent Mapset for each Landsat scene&lt;br /&gt;
* imports and renames bands of a scene as &amp;lt;tt&amp;gt;B&amp;lt;id&amp;gt;&amp;lt;/tt&amp;gt;, e.g. B10, B20, ..., B80.&lt;br /&gt;
* additionaly sets up the timestamp based on MTL metadata file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note,''' the (newest) official naming pattern for Landsat scenes -- explained in [https://lta.cr.usgs.gov/landsat_dictionary.html USGS' Landsat Data Dictionary] as the [https://lta.cr.usgs.gov/landsat_dictionary.html#entity_id Landsat Scene Identifier] -- and all individual bands that compose a scene -- bands have a suffix which is like _B10, _B20, _B30, etc. -- differ from what some Landsat specific modules expect. For example, the modules {{cmd|i.landsat.toar}} and {{cmd|i.landsat.acca}} expect the bands to follow a naming pattern such as &amp;quot;scenename.1, .2, .3&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To use the script save it as &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;import_landsat.py&amp;lt;/source&amp;gt; file and make sure it is granted the execution permission.&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 any(x in line for x in ('DATE_ACQUIRED', 'ACQUISITION_DATE')):&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;
        if ('VCID') in ffile:&lt;br /&gt;
            name = &amp;quot;&amp;quot;.join((os.path.splitext(file)[0].split('_'))[1::2])&lt;br /&gt;
        else:&lt;br /&gt;
            name = os.path.splitext(file)[0].split('_')[-1]&lt;br /&gt;
        if len(name) == 3 and name[-1] == '0':&lt;br /&gt;
            band = int(name[1:2])&lt;br /&gt;
        elif len(name) == 3 and name[-1] != '0':&lt;br /&gt;
            band = int(name[1:3])&lt;br /&gt;
        else:&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;
&lt;br /&gt;
'''Example of usage'''&lt;br /&gt;
&lt;br /&gt;
After having collected the Landsat scenes of interest in one directory, the script can be used as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;python&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;./import_landsat.py&amp;lt;/source&amp;gt; → the script will walk through a ''pool'' directory that contains unique Landsat scene directories (e.g. three directories named after the official naming pattern: LT51800342011158MOR00  LT51810352009079MTI00  LT51820352009326MTI00) and import all bands of each individual scene in their own Mapset&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;python&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;./import_landsat.py LM41890261983200FFF03&amp;lt;/source&amp;gt; → the scrip will import only bands of the specified Landsat scene directory&lt;br /&gt;
&lt;br /&gt;
== Post-Processing ==&lt;br /&gt;
&lt;br /&gt;
=== Natural color composites ===&lt;br /&gt;
&lt;br /&gt;
Creating natural (also known as true-) color composites, can be done by&lt;br /&gt;
&lt;br /&gt;
a) using {{cmd|i.landsat.rgb|version=64}} (GRASS 6.x) | {{cmd|i.colors.enhance|version=70}} (GRASS 7.x) to automatically balance the colors for the Red, Green and Blue bands&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
b) equalizing the colors on each of the Red, Green and Blue bands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;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;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Composites''' can then be produced with the {{cmd|r.composite}} module.&lt;br /&gt;
&lt;br /&gt;
'''Resetting the color tables''' of all bands back to normal greyscale can be done with a for loop:&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;
See also:&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat-8-data-in-grass-gis-7-rgb-composites-and-pan-sharpening/ Processing Landsat 8 data in GRASS GIS 7: RGB composites and pan sharpening]&lt;br /&gt;
&lt;br /&gt;
=== Create a 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 using the {{cmd|i.landsat.toar}} module. For details, refer to USGS' [http://landsat.usgs.gov/Landsat_Metadata_Changes.php Landsat Filename and Metadata Changes] dedicated page. For Landsat 8, see also [http://landsat.usgs.gov/about_LU_Vol_7_Issue_4.php#3a here].&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 i.landsat.toar input_prefix=$BASE output_prefix=${BASE}_toar metfile=${BASE}_MTL.txt&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, the resulting temperature map is in Kelvin:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&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;
&amp;lt;/source&amp;gt;&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|version=64}}. This addons applies a bandwise haze correction using tasscap4 (haze) and linear regression.&lt;br /&gt;
&lt;br /&gt;
During the 2000s, prior acquired Landsat data were reprocessed to LPGS (Level 1 Product Generation System). Seems that with this level of processing, haze effect in raw data was removed and now is sufficient to apply {{Cmd|i.colors.enhance}} to obtain a good image with high contrast.&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}}:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;i.landsat.acca -f input_prefix=226_62_toar. output=226_62.acca_cloudmask&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mask out the clouds:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;r.mapcalc &amp;quot;MASK = if(isnull($BASE.acca_cloudmask))&amp;quot;&amp;lt;/source&amp;gt;&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:&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&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&amp;lt;/source&amp;gt;&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;
== Time series analysis ==&lt;br /&gt;
&lt;br /&gt;
See [[Time series]]&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
* [http://landsat.usgs.gov/tools_access_all_faqs.php Frequently Asked Questions about the Landsat Missions]&lt;br /&gt;
* [https://landsat8portal.eo.esa.int/portal/ European LANDSAT 8 data in near-realtime]&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat8-data-in-grass-gis-7/ Processing Landsat 8 data in GRASS GIS 7: Import and visualization]&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat-8-data-in-grass-gis-7-rgb-composites-and-pan-sharpening/ Processing Landsat 8 data in GRASS GIS 7: RGB composites and pan sharpening]&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
[[Category: Landsat]]&lt;br /&gt;
[[Category: Image processing]]&lt;br /&gt;
[[Category: Import]]&lt;br /&gt;
[[Category: Digital Numbers]]&lt;br /&gt;
[[Category: Radiance]]&lt;br /&gt;
[[Category: Reflectance]]&lt;br /&gt;
[[Category: Geodata]]&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=GRASS_and_Python&amp;diff=22295</id>
		<title>GRASS and Python</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=GRASS_and_Python&amp;diff=22295"/>
		<updated>2016-01-26T10:33:49Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: update link to trac wiki&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;''This page discusses usage GRASS GIS and Python in a general way if you just want to write a script to run in GRASS GIS go to [[GRASS Python Scripting Library]] wiki page or [http://grass.osgeo.org/grass70/manuals/libpython/ Python API for GRASS GIS 7] documentation.''&lt;br /&gt;
&lt;br /&gt;
==Writing Python scripts in GRASS==&lt;br /&gt;
&lt;br /&gt;
Python is a programming language which is more powerful than shell scripting but easier and more forgiving than C.&lt;br /&gt;
The Python script can contain simple module description definitions which will be processed with {{cmd|g.parser}}, as shown in the example below. In this way with no extra coding a GUI can be built, inputs checked, and a skeleton help page can be generated automatically. In addition it adds links to the GRASS message translation system. The library for &amp;quot;scripting&amp;quot; is &amp;quot;grass.script&amp;quot;, typically used as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The related files are at $GISBASE/etc/python/grass/script/*.py. See below for more details.&lt;br /&gt;
&lt;br /&gt;
''Note: For code which needs access to the power of C, you can access the GRASS C library functions via [[GRASS and Python#Python Ctypes Interface|the Python &amp;quot;ctypes&amp;quot; interface]].''&lt;br /&gt;
&lt;br /&gt;
=== Integrated Python script editor ===&lt;br /&gt;
&lt;br /&gt;
The [[wxGUI]] Layer Manager in GRASS 6.4.3+ comes with a &amp;quot;Python shell&amp;quot; which enables users to type and execute python commands directly in wxGUI environment.&lt;br /&gt;
&lt;br /&gt;
[[Image:wxgui-pyshell.png|center|400px|Embedded interactive Python Shell in wxGUI Layer Manager]]&lt;br /&gt;
&lt;br /&gt;
=== External Python editors (IDE) ===&lt;br /&gt;
&lt;br /&gt;
Besides the wxGUI Python script editor also advanced editors can be used like '''Spyder''' (The Scientific PYthon Development EnviRonment). For details,  see [[Tools for Python programming]]&lt;br /&gt;
&lt;br /&gt;
=== Using the GRASS Python Scripting Library ===&lt;br /&gt;
&lt;br /&gt;
You can run Python scripts easily in a GRASS session.&lt;br /&gt;
&lt;br /&gt;
To write these scripts, &lt;br /&gt;
* check the code in lib/python/ which provides grass.script in order to support GRASS scripts written in Python.&amp;lt;br&amp;gt;&lt;br /&gt;
  See the [[GRASS Python Scripting Library]] for notes and examples.&lt;br /&gt;
* The scripts/ directory of GRASS contains a series of examples actually provided to the end users.&lt;br /&gt;
&lt;br /&gt;
For the desired Python code style, have a look at [https://trac.osgeo.org/grass/wiki/Submitting/Python Submitting Python].&lt;br /&gt;
&lt;br /&gt;
=== Creating Python scripts that call GRASS functionality from outside ===&lt;br /&gt;
&lt;br /&gt;
Note: This is a more advanced use case of using GRASS' functionality from outside via Python. Commonly, a user will run GRASS Python script from inside a GRASS session, i.e. either from the command line or from the Python shell embedded in the wxGUI ([[:File:Wxgui-pyshell.png|screenshot]]).&lt;br /&gt;
&lt;br /&gt;
For calling GRASS functionality from outside, see also [[Working with GRASS without starting it explicitly]].&lt;br /&gt;
&lt;br /&gt;
&amp;lt;font color=&amp;quot;red&amp;quot;&amp;gt;The next two subsections (MS-Windows and Linux) are somewhat outdated, to be improved (see grass-dev archives, 5/2014&amp;lt;/font&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== MS-Windows ====&lt;br /&gt;
&lt;br /&gt;
In order to use GRASS functionality via Python from outside, some environment variables have to be set:&lt;br /&gt;
&lt;br /&gt;
 GISBASE= C:\GRASS-64&lt;br /&gt;
 GISRC= C:\Documents and Settings\user\.grassrc6&lt;br /&gt;
 LD_LIBRARY_PATH= C:\GRASS-64\lib&lt;br /&gt;
 PATH= C:\GRASS-64\etc;C:\GRASS-64\etc\python;C:\GRASS-64\lib;C:\GRASS-64\bin;C:\GRASS-64\extralib;C:\GRASS-64\msys\bin;C:\Python26;&lt;br /&gt;
 PYTHONLIB= C:\Python26&lt;br /&gt;
 PYTHONPATH= C:\GRASS-64\etc\python&lt;br /&gt;
 GRASS_SH= C:\GRASS-64\msys\bin\sh.exe&lt;br /&gt;
&lt;br /&gt;
Some hints:&lt;br /&gt;
&lt;br /&gt;
# The &amp;quot;.grassrc6&amp;quot; file listed above must exist. Run GRASS one time interactively to create it or see below for how to writing it&lt;br /&gt;
# The Python interpreter (python.exe) needs to be in the PATH&lt;br /&gt;
# Python needs to be associated with the .py extension&lt;br /&gt;
# PATHEXT needs to include .py if you want to be able to omit the extension&lt;br /&gt;
# PYTHONPATH needs to be set to %GISBASE%\etc\python&lt;br /&gt;
&lt;br /&gt;
Points 2-4 should be taken care of by the Python installer. 5 needs to be done by the startup (currently, this doesn't appear to be the case on MS-Windows).&lt;br /&gt;
&lt;br /&gt;
Alternatively to run GRASS interactively, you can also create the &amp;quot;.grassrc6&amp;quot; file yourself, e.g. (update to existing directory for &amp;quot;grassdata&amp;quot;):&lt;br /&gt;
&lt;br /&gt;
 GISDBASE: C:\Documents and Settings\user\grassdata&lt;br /&gt;
 LOCATION_NAME: nc_spm_08&lt;br /&gt;
 MAPSET: user1&lt;br /&gt;
 GRASS_DB_ENCODING: ascii&lt;br /&gt;
&lt;br /&gt;
It doesn't matter what the file is called, so long as %GISRC% points to it and it contains the necessary settings.&lt;br /&gt;
&lt;br /&gt;
The normal location for GRASS 6.x on Windows is:&lt;br /&gt;
&lt;br /&gt;
 %APPDATA%\GRASS6\grassrc6&lt;br /&gt;
&lt;br /&gt;
On Windows 7, a typical setting for %APPDATA% is&lt;br /&gt;
&lt;br /&gt;
 C:\Users\&amp;lt;username&amp;gt;\AppData\Roaming&lt;br /&gt;
&lt;br /&gt;
==== Linux ====&lt;br /&gt;
&lt;br /&gt;
In order to use GRASS functionality via Python from outside, some environment variables have to be set:&lt;br /&gt;
&lt;br /&gt;
 export GISBASE=&amp;quot;/usr/local/grass-6.4.svn/&amp;quot;&lt;br /&gt;
 export PATH=&amp;quot;$PATH:$GISBASE/bin:$GISBASE/scripts&amp;quot;&lt;br /&gt;
 export LD_LIBRARY_PATH=&amp;quot;$LD_LIBRARY_PATH:$GISBASE/lib&amp;quot;&lt;br /&gt;
 # for parallel session management, we use process ID (PID) as lock file number:&lt;br /&gt;
 export GIS_LOCK=$$&lt;br /&gt;
 # path to GRASS settings file&lt;br /&gt;
 export GISRC=&amp;quot;$HOME/.grassrc6&amp;quot;&lt;br /&gt;
 export PYTHONPATH=&amp;quot;$PYTHONPATH:$GISBASE/etc/python&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== Executing GRASS Python scripts without starting GRASS explicitly ===&lt;br /&gt;
&lt;br /&gt;
* See [[Working_with_GRASS_without_starting_it_explicitly#Python:_GRASS_GIS_7|Working with GRASS without starting it explicitly]] (examples for GRASS GIS 6 and 7)&lt;br /&gt;
&lt;br /&gt;
=== Running external commands from Python ===&lt;br /&gt;
For information on running external commands from Python, see:&lt;br /&gt;
http://docs.python.org/lib/module-subprocess.html&lt;br /&gt;
&lt;br /&gt;
Avoid using the older os.* functions. Section 17.1.3 lists equivalents&lt;br /&gt;
using the Popen() interface, which is more robust (particularly on&lt;br /&gt;
Windows).&lt;br /&gt;
&lt;br /&gt;
=== Testing and installing Python extensions ===&lt;br /&gt;
&lt;br /&gt;
==== Debugging ====&lt;br /&gt;
&lt;br /&gt;
Make sure the script is executable:&lt;br /&gt;
&lt;br /&gt;
    chmod +x /path/to/my.extension.py&lt;br /&gt;
&lt;br /&gt;
During development, a Python script can be debugged using the Python Debugger (pdb):&lt;br /&gt;
&lt;br /&gt;
    python -m pdb /path/to/my.extension.py input=my_input_layer output=my_output_layer option=value -f&lt;br /&gt;
&lt;br /&gt;
==== Installation ====&lt;br /&gt;
&lt;br /&gt;
Once you're happy with your script, you can put it in the scripts/ folder of your GRASS install. To do so, first create a directory named after your extension, then create a Makefile for it, and a HTML man page:&lt;br /&gt;
&lt;br /&gt;
    cd /path/to/grass_src/&lt;br /&gt;
    cd scripts&lt;br /&gt;
    ls # It is useful to check out the existing scripts and their structure&lt;br /&gt;
    mkdir my.extension&lt;br /&gt;
    cd my.extension&lt;br /&gt;
    cp path/to/my.extension.py .&lt;br /&gt;
    touch my.extension.html&lt;br /&gt;
    touch Makefile&lt;br /&gt;
&lt;br /&gt;
Next step is to edit the Makefile. It is a very simple text file, the only thing to check is to put the right extension name (WITHOUT the .py file extension) after PGM:&lt;br /&gt;
&lt;br /&gt;
    MODULE_TOPDIR = ../..&lt;br /&gt;
    &lt;br /&gt;
    PGM = my.extension&lt;br /&gt;
    &lt;br /&gt;
    include $(MODULE_TOPDIR)/include/Make/Script.make&lt;br /&gt;
    &lt;br /&gt;
    default: script&lt;br /&gt;
&lt;br /&gt;
The HTML file would be generated automatically. If you want to add more precisions in it, you can do it (just make sure you start at DESCRIPTION. See existing scripts.)&lt;br /&gt;
&lt;br /&gt;
You can then run &amp;quot;make&amp;quot; within the my.extension folder. Running &amp;quot;make&amp;quot; in the extension directory places the resulting files in the staging directory (path/to/grass_src/dist.&amp;lt;YOUR_ARCH&amp;gt;/). If you're running GRASS from the staging directory (/path/to/grass_src/bin.&amp;lt;YOUR_ARCH&amp;gt;/grass7), subsequent commands will used the updated files. &lt;br /&gt;
&lt;br /&gt;
    # in your extension directory (/path/to/grass_src/scripts/my.extension/)&lt;br /&gt;
    make&lt;br /&gt;
    # Starting GRASS from the staging directory&lt;br /&gt;
    /path/to/grass_src/bin.&amp;lt;YOUR_ARCH&amp;gt;/grass7&lt;br /&gt;
    my.extension help&lt;br /&gt;
&lt;br /&gt;
You can also run &amp;quot;make install&amp;quot; from the top level directory of your GRASS install (say /usr/local/src/grass_trunk/). Running &amp;quot;make install&amp;quot; from the top level just copies the whole of the dist.&amp;lt;YOUR_ARCH&amp;gt;/ directory to the installation directory (e.g. /usr/local/grass70) and the bin.&amp;lt;YOUR_ARCH&amp;gt;/grass70 bin file to the bin directory (e.g. /usr/local/bin), and fixes any embedded paths in scripts and configuration files.&lt;br /&gt;
&lt;br /&gt;
    cd /path/to/grass_src&lt;br /&gt;
    make install&lt;br /&gt;
    # Starting GRASS as usual would work and show your extension available&lt;br /&gt;
    grass7&lt;br /&gt;
    my.extension help&lt;br /&gt;
&lt;br /&gt;
=== Using the parser ===&lt;br /&gt;
&lt;br /&gt;
Be sure to use the standardized option G_OPT_*_INPUT (e.g. G_OPT_R_INPUT), the definitions can be found here: &lt;br /&gt;
* http://grass.osgeo.org/programming7/parser__standard__options_8c_source.html&lt;br /&gt;
* Overview table of [https://grass.osgeo.org/grass71/manuals/parser_standard_options.html parser standard options]&lt;br /&gt;
&lt;br /&gt;
For more details, see&lt;br /&gt;
* [[Module command line parser]]&lt;br /&gt;
* [[GRASS_Python_Scripting_Library#Parsing_the_options_and_flags]]&lt;br /&gt;
&lt;br /&gt;
=== Using a version of Python different from the default installation ===&lt;br /&gt;
&lt;br /&gt;
Sometimes you don't want to use the default Python version installed on your system. You can control the interpreter used for building by overriding the PYTHON make variable, e.g.&lt;br /&gt;
&lt;br /&gt;
  make PYTHON=/path/to/python ...&lt;br /&gt;
&lt;br /&gt;
For controlling the interpreter used at run time:&lt;br /&gt;
* On Windows, Python scripts are invoked via %GRASS_PYTHON%, so changing that environment variable will change the interpreter.&lt;br /&gt;
* On Unix, GRASS_PYTHON is only used for components which use wxPython, e.g. wxGUI or the parameter dialogs which are displayed when modules are run without arguments.&lt;br /&gt;
&lt;br /&gt;
Scripts rely upon the &amp;quot;#!/usr/bin/env python&amp;quot; line. You can control&lt;br /&gt;
the interpreter used by scripts by creating a directory containing a&lt;br /&gt;
symlink named &amp;quot;python&amp;quot; which refers to your preferred version of the&lt;br /&gt;
interpreter, and placing that directory at the front of $PATH.&lt;br /&gt;
&lt;br /&gt;
==Python extensions in GRASS GIS==&lt;br /&gt;
&lt;br /&gt;
=== Python Scripting Library ===&lt;br /&gt;
&lt;br /&gt;
* See [[GRASS Python Scripting Library]]&lt;br /&gt;
&lt;br /&gt;
=== pygrass Library ===&lt;br /&gt;
&lt;br /&gt;
Pygrass is an object oriented Python Application Programming Interface (API) for GRASS GIS. pygrass wants to improve the integration between GRASS and Python, render the use of Python under GRASS more consistent with the language itself and make the GRASS scripting and programming activity easier and more natural to the final users. Some simple examples below.&lt;br /&gt;
&lt;br /&gt;
For more details, see '''[[Python/pygrass|pygrass]]'''&lt;br /&gt;
&lt;br /&gt;
'''Example 1''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
from grass.pygrass.modules import Module&lt;br /&gt;
&lt;br /&gt;
slope_aspect = Module(&amp;quot;r.slope.aspect&amp;quot;)&lt;br /&gt;
slope_aspect(elevation='elevation', slope='slp',  aspect='asp', &lt;br /&gt;
               format='degrees', overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example 2''', using &amp;quot;shortcuts&amp;quot;:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# simple example for pyGRASS usage: raster processing via modules approach&lt;br /&gt;
&lt;br /&gt;
from grass.pygrass.modules.shortcuts import general as g&lt;br /&gt;
from grass.pygrass.modules.shortcuts import raster as r&lt;br /&gt;
&lt;br /&gt;
g.message(&amp;quot;Filter elevation map by a threshold...&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# set computational region&lt;br /&gt;
input = 'elevation'&lt;br /&gt;
g.region(rast=input)&lt;br /&gt;
&lt;br /&gt;
# hardcoded:&lt;br /&gt;
# r.mapcalc('elev_100m = if(elevation &amp;gt; 100, elevation, null())', overwrite = True)&lt;br /&gt;
# with variables&lt;br /&gt;
&lt;br /&gt;
output = 'elev_100m'&lt;br /&gt;
thresh = 100.0&lt;br /&gt;
r.mapcalc(&amp;quot;%s = if(%s &amp;gt; %d, %s, null())&amp;quot; % (output, input, thresh, input), overwrite = True)&lt;br /&gt;
r.colors(map=output, color=&amp;quot;elevation&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Example 3''', using &amp;quot;shortcuts&amp;quot; and external raster format support:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
# simple example for pyGRASS usage: raster processing via Modules approach&lt;br /&gt;
# Read GeoTIFF directly, write out GeoTIFF directly&lt;br /&gt;
import os&lt;br /&gt;
import tempfile&lt;br /&gt;
from grass.pygrass.modules.shortcuts import general as g&lt;br /&gt;
from grass.pygrass.modules.shortcuts import raster as r&lt;br /&gt;
from grass.pygrass.modules import Module&lt;br /&gt;
&lt;br /&gt;
# use alias name for GRASS GIS commands with more than one dot in name&lt;br /&gt;
r.external_out = Module('r.external.out')&lt;br /&gt;
&lt;br /&gt;
# get the raster elevation map into GRASS without import&lt;br /&gt;
geotiff = 'elevation.tif' # with path&lt;br /&gt;
curr_raster='myraster'&lt;br /&gt;
r.external(input=geotiff, output=curr_raster)&lt;br /&gt;
&lt;br /&gt;
# define output directory for files resulting from GRASS calculation:&lt;br /&gt;
gisdb = os.path.join(tempfile.gettempdir(), 'gisoutput')&lt;br /&gt;
try:&lt;br /&gt;
    os.stat(gisdb)&lt;br /&gt;
except:&lt;br /&gt;
    os.mkdir(gisdb)&lt;br /&gt;
g.message(&amp;quot;Output will be written to %s&amp;quot; % gisdb)&lt;br /&gt;
&lt;br /&gt;
# define where to store the resulting files and format&lt;br /&gt;
r.external_out(directory=gisdb, format='GTiff')&lt;br /&gt;
&lt;br /&gt;
# do the GRASS GIS job&lt;br /&gt;
g.message(&amp;quot;Filter elevation map by a threshold...&amp;quot;)&lt;br /&gt;
# set computational region&lt;br /&gt;
g.region(rast=curr_raster)&lt;br /&gt;
&lt;br /&gt;
# generate GeoTIFF&lt;br /&gt;
output = 'elev_100m.tif'&lt;br /&gt;
thresh = 100.0&lt;br /&gt;
r.mapcalc(&amp;quot;%s = if(%s &amp;gt; %d, %s, null())&amp;quot; % (output, curr_raster, thresh, curr_raster), overwrite = True)&lt;br /&gt;
r.colors(map=output, color=&amp;quot;elevation&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# cease GDAL mode, back to GRASS data writing mode&lt;br /&gt;
r.external_out(flags = 'r')&lt;br /&gt;
# the resulting GeoTIFF file is in the gisdb directory&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Example 4''':&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
 &lt;br /&gt;
# Example for pyGRASS usage - vector API&lt;br /&gt;
&lt;br /&gt;
from grass.pygrass.modules.shortcuts import general as g&lt;br /&gt;
from grass.pygrass.vector import VectorTopo&lt;br /&gt;
from grass.pygrass.modules import Module&lt;br /&gt;
&lt;br /&gt;
vectmap = 'myzipcodes_wake'&lt;br /&gt;
&lt;br /&gt;
g.message(&amp;quot;Importing SHAPE file ...&amp;quot;)&lt;br /&gt;
ogrimport = Module('v.in.ogr')&lt;br /&gt;
ogrimport('/home/neteler/gis_data/zipcodes_wake.shp', output=vectmap)&lt;br /&gt;
&lt;br /&gt;
g.message(&amp;quot;Assessing vector topology...&amp;quot;)&lt;br /&gt;
zipcodes = VectorTopo(vectmap)&lt;br /&gt;
&lt;br /&gt;
# Open the map with topology:&lt;br /&gt;
zipcodes.open()&lt;br /&gt;
&lt;br /&gt;
# query number of topological features&lt;br /&gt;
areas   = zipcodes.number_of(&amp;quot;areas&amp;quot;)&lt;br /&gt;
islands = zipcodes.number_of(&amp;quot;islands&amp;quot;)&lt;br /&gt;
print 'Map: &amp;lt;' + vectmap + '&amp;gt; with %d areas and %d islands' % (areas, islands)&lt;br /&gt;
&lt;br /&gt;
dblink = zipcodes.dblinks[0]&lt;br /&gt;
print 'DB name:'&lt;br /&gt;
print dblink.database&lt;br /&gt;
table = dblink.table()&lt;br /&gt;
print 'Column names:'&lt;br /&gt;
print table.columns.names()&lt;br /&gt;
print 'Column types:'&lt;br /&gt;
print table.columns.types()&lt;br /&gt;
&lt;br /&gt;
zipcodes.close()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* For more examples, see '''[[Python/pygrass|pygrass]]'''&lt;br /&gt;
&lt;br /&gt;
=== Python Ctypes Interface ===&lt;br /&gt;
&lt;br /&gt;
This interface allows calling GRASS library functions from Python scripts. See [[Python Ctypes Examples]] for details.&lt;br /&gt;
&lt;br /&gt;
Examples:&lt;br /&gt;
&lt;br /&gt;
* GRASS 7: [http://trac.osgeo.org/grass/browser/grass/trunk/doc/python/raster_example_ctypes.py raster], [http://trac.osgeo.org/grass/browser/grass/trunk/doc/python/vector_example_ctypes.py vector] example&lt;br /&gt;
&lt;br /&gt;
* Latest and greatest: GRASS 7 Python {{src|scripts}}&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;strike&amp;gt;[[PythonSwigExamples|More complicated examples]]&amp;lt;/strike&amp;gt; &amp;lt;&amp;lt;-- TODO: update to Ctypes&lt;br /&gt;
&lt;br /&gt;
Sample script for GRASS 6 raster access (use within GRASS, Spearfish session):&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
## TODO: update example to Ctypes&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
from grass.lib import grass&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;GISBASE&amp;quot; not in os.environ:&lt;br /&gt;
    print &amp;quot;You must be in GRASS GIS to run this program.&amp;quot;&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv)==2:&lt;br /&gt;
  input = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
  input = raw_input(&amp;quot;Raster Map Name? &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# initialize&lt;br /&gt;
grass.G_gisinit('')&lt;br /&gt;
&lt;br /&gt;
# find map in search path&lt;br /&gt;
mapset = grass.G_find_cell2(input, '')&lt;br /&gt;
&lt;br /&gt;
# determine the inputmap type (CELL/FCELL/DCELL) */&lt;br /&gt;
data_type = grass.G_raster_map_type(input, mapset)&lt;br /&gt;
&lt;br /&gt;
infd = grass.G_open_cell_old(input, mapset)&lt;br /&gt;
inrast = grass.G_allocate_raster_buf(data_type)&lt;br /&gt;
&lt;br /&gt;
rown = 0&lt;br /&gt;
while True:&lt;br /&gt;
    myrow = grass.G_get_raster_row(infd, inrast, rown, data_type)&lt;br /&gt;
    print rown, myrow[0:10]&lt;br /&gt;
    rown += 1&lt;br /&gt;
    if rown == 476:&lt;br /&gt;
        break&lt;br /&gt;
&lt;br /&gt;
grass.G_close_cell(inrast)&lt;br /&gt;
grass.G_free(cell)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Sample script for vector access (use within GRASS, Spearfish session):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/python&lt;br /&gt;
&lt;br /&gt;
# run within GRASS Spearfish session&lt;br /&gt;
# run this before starting python to append module search path:&lt;br /&gt;
#   export PYTHONPATH=/usr/src/grass70/swig/python&lt;br /&gt;
#   check with &amp;quot;import sys; sys.path&amp;quot;&lt;br /&gt;
# or:&lt;br /&gt;
#   sys.path.append(&amp;quot;/usr/src/grass70/swig/python&amp;quot;)&lt;br /&gt;
# FIXME: install the grass bindings in $GISBASE/lib/ ?&lt;br /&gt;
&lt;br /&gt;
import os, sys&lt;br /&gt;
from grass.lib import grass&lt;br /&gt;
from grass.lib import vector as grassvect&lt;br /&gt;
&lt;br /&gt;
if &amp;quot;GISBASE&amp;quot; not in os.environ:&lt;br /&gt;
    print &amp;quot;You must be in GRASS GIS to run this program.&amp;quot;&lt;br /&gt;
    sys.exit(1)&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv)==2:&lt;br /&gt;
  input = sys.argv[1]&lt;br /&gt;
else:&lt;br /&gt;
  input = raw_input(&amp;quot;Vector Map Name? &amp;quot;)&lt;br /&gt;
&lt;br /&gt;
# initialize&lt;br /&gt;
grass.G_gisinit('')&lt;br /&gt;
&lt;br /&gt;
# find map in search path&lt;br /&gt;
mapset = grass.G_find_vector2(input,'')&lt;br /&gt;
&lt;br /&gt;
# define map structure&lt;br /&gt;
map = grassvect.Map_info()&lt;br /&gt;
&lt;br /&gt;
# define open level (level 2: topology)&lt;br /&gt;
grassvect.Vect_set_open_level (2)&lt;br /&gt;
&lt;br /&gt;
# open existing map&lt;br /&gt;
grassvect.Vect_open_old(map, input, mapset)&lt;br /&gt;
&lt;br /&gt;
# query&lt;br /&gt;
print 'Vect map: ', input&lt;br /&gt;
print 'Vect is 3D: ', grassvect.Vect_is_3d (map)&lt;br /&gt;
print 'Vect DB links: ', grassvect.Vect_get_num_dblinks(map)&lt;br /&gt;
print 'Map Scale:  1:', grassvect.Vect_get_scale(map)&lt;br /&gt;
print 'Number of areas:', grassvect.Vect_get_num_areas(map)&lt;br /&gt;
&lt;br /&gt;
# close map&lt;br /&gt;
grassvect.Vect_close(map)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Using ipython ===&lt;br /&gt;
&lt;br /&gt;
Using [http://ipython.org/ ipython] is great due to the TAB completion. Don't remember the function name or curious about what's offered? Hit TAB (maybe twice for a list).&lt;br /&gt;
&lt;br /&gt;
Here an example how to connect to C functions directly from Python:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
grass70&lt;br /&gt;
# ... in the GRASS GIS terminal&lt;br /&gt;
ipython&lt;br /&gt;
In [1]: from grass.lib import gis&lt;br /&gt;
&lt;br /&gt;
In [2]: gis.&amp;lt;TAB&amp;gt;&lt;br /&gt;
Display all 729 possibilities? (y or n)&lt;br /&gt;
gis.ARRAY                                 gis.G_fatal_longjmp                       gis.G_set_key_value&lt;br /&gt;
gis.ArgumentError                         gis.G_file_name                           gis.G_set_keywords&lt;br /&gt;
gis.Array                                 gis.G_file_name_misc                      gis.G_set_ls_exclude_filter&lt;br /&gt;
...&lt;br /&gt;
gis.G_fatal_error                         gis.G_set_gisrc_mode                      gis.wstring_at&lt;br /&gt;
&lt;br /&gt;
In [2]: gis.G_message(&amp;quot;Hello world&amp;quot;)&lt;br /&gt;
Hello world&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
A full ipython workshop is available here: https://github.com/wenzeslaus/python-grass-addon&lt;br /&gt;
&lt;br /&gt;
=== wxPython GUI development ===&lt;br /&gt;
&lt;br /&gt;
* See the [[wxGUI]] wiki page&lt;br /&gt;
&lt;br /&gt;
=== Python-GRASS add-ons ===&lt;br /&gt;
&lt;br /&gt;
Stand-alone addons:&lt;br /&gt;
&lt;br /&gt;
* Jáchym Čepický's PyWPS, GRASS-Web Processing Service (http://pywps.wald.intevation.org)&lt;br /&gt;
&lt;br /&gt;
=== Using GRASS gui.tcl in Python ===&lt;br /&gt;
&lt;br /&gt;
Here is some example code to use the grass automatically generated guis in python code. This could (should) all be bundled up and abstracted away so that the implementation can be replaced later.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import Tkinter&lt;br /&gt;
import os&lt;br /&gt;
&lt;br /&gt;
# Startup (once):&lt;br /&gt;
&lt;br /&gt;
tk = Tkinter.Tk()&lt;br /&gt;
tk.eval (&amp;quot;wm withdraw .&amp;quot;)&lt;br /&gt;
tk.eval (&amp;quot;source $env(GISBASE)/etc/gui.tcl&amp;quot;)&lt;br /&gt;
# Here you could do various things to change what the gui does&lt;br /&gt;
# See gui.tcl and README.GUI&lt;br /&gt;
&lt;br /&gt;
# Make a gui (per dialog)&lt;br /&gt;
# This sets up a window for the command.&lt;br /&gt;
# This can be different to integrate with tkinter:&lt;br /&gt;
tk.eval ('set path &amp;quot;.dialog$dlg&amp;quot;')&lt;br /&gt;
tk.eval ('toplevel .dialog$dlg')&lt;br /&gt;
# Load the code for this command:&lt;br /&gt;
fd = os.popen (&amp;quot;d.vect --tcltk&amp;quot;)&lt;br /&gt;
gui = fd.read()&lt;br /&gt;
# Run it&lt;br /&gt;
tk.eval(gui)&lt;br /&gt;
dlg = tk.eval('set dlg') # This is used later to get and set &lt;br /&gt;
&lt;br /&gt;
# Get the current command in the gui we just made:&lt;br /&gt;
currentcommand = tk.eval (&amp;quot;dialog_get_command &amp;quot; + dlg)&lt;br /&gt;
&lt;br /&gt;
# Set the command in the dialog we just made:&lt;br /&gt;
tk.eval (&amp;quot;dialog_set_command &amp;quot; + dlg + &amp;quot; {d.vect map=roads}&amp;quot;)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== FAQ ==&lt;br /&gt;
&lt;br /&gt;
* '''Q:''' Error message &amp;quot;execl() failed: Permission denied&amp;quot; - what to do?&lt;br /&gt;
: '''A:''' Be sure that the execute bit of the script is set.&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
=== General guides ===&lt;br /&gt;
&lt;br /&gt;
* [http://en.wikibooks.org/wiki/Python_Programming/ Wikibook Python Programming]&lt;br /&gt;
* [http://www.poromenos.org/tutorials/python Quick Python tutorial] for programmers of other languages&lt;br /&gt;
*: [http://wiki.python.org/moin/BeginnersGuide/Programmers More Python tutorials] for programmers&lt;br /&gt;
* [http://www.python.org/dev/peps/pep-0008/ Python programming style guide]&lt;br /&gt;
* [http://wiki.python.org/moin/PythonEditors Python Editors]&lt;br /&gt;
&lt;br /&gt;
=== Programming ===&lt;br /&gt;
&lt;br /&gt;
* Python and GRASS:&lt;br /&gt;
** Library interfaces: [GRASS Python Scripting Library http://grass.osgeo.org/programming7/pythonlib.html]&lt;br /&gt;
** Graphical user interface (GIU): [GRASS wxPython-based GUI http://grass.osgeo.org/programming7/wxpythonlib.html]&lt;br /&gt;
** PyWPS, GRASS-Web Processing Service: [[WPS]]&lt;br /&gt;
&lt;br /&gt;
* Python and OSGeo:&lt;br /&gt;
** [http://wiki.osgeo.org/wiki/OSGeo_Python_Library OSGeo Python Library]&lt;br /&gt;
&lt;br /&gt;
* Python and GDAL/OGR:&lt;br /&gt;
** [http://mapserver.gis.umn.edu/community/conferences/MUM3/workshop/python Open Source Python GIS Hacks Mum'03]&lt;br /&gt;
** http://hobu.biz/software/OSGIS_Hacks - Python OSGIS Hacks '05&lt;br /&gt;
** http://zcologia.com/news/categorylist_html?cat_id=8&lt;br /&gt;
** http://www.perrygeo.net/wordpress/?p=4&lt;br /&gt;
&lt;br /&gt;
* Python bindings to PROJ:&lt;br /&gt;
** http://www.cdc.noaa.gov/people/jeffrey.s.whitaker/python/pyproj.html&lt;br /&gt;
&lt;br /&gt;
* Python and GIS:&lt;br /&gt;
** [http://gispython.org/ Open Source GIS-Python Laboratory]&lt;br /&gt;
&lt;br /&gt;
* Python and Statistics:&lt;br /&gt;
** [http://rpy.sourceforge.net/ RPy] - Python interface to the R-statistics programming language&lt;br /&gt;
&lt;br /&gt;
* Bindings:&lt;br /&gt;
** SIP (C/C++ bindings generator) http://directory.fsf.org/all/Python-SIP.html&lt;br /&gt;
** [http://www.cython.org/ Cython] - C-Extensions for Python (compile where speed is needed)&lt;br /&gt;
&lt;br /&gt;
* Other external projects&lt;br /&gt;
** [http://www.scipy.org Scientific Python]&lt;br /&gt;
** [http://wiki.python.org/moin/NumericAndScientific Numeric and Scientific]&lt;br /&gt;
** [http://w3.pppl.gov/~hammett/comp/python/python.html Info on Python for Scientific Applications]&lt;br /&gt;
&lt;br /&gt;
=== Presentations ===&lt;br /&gt;
&lt;br /&gt;
* http://www.slideshare.net/search/slideshow?q=pygrass&lt;br /&gt;
&lt;br /&gt;
From FOSS4G2006:&lt;br /&gt;
* [http://www.foss4g2006.org/materialDisplay.py?contribId=136&amp;amp;amp;sessionId=48&amp;amp;amp;materialId=slides&amp;amp;amp;confId=1 A Python sweeps in the GRASS] - A. Frigeri 2006&lt;br /&gt;
* [http://www.foss4g2006.org/materialDisplay.py?contribId=67&amp;amp;amp;sessionId=48&amp;amp;amp;materialId=slides&amp;amp;amp;confId=1 GRASS goes web: PyWPS] - J. Cepicky 2006 (see also [[WPS]])&lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
* Zambelli, P., Gebbert, S., Ciolli, M., 2013. ''Pygrass: An Object Oriented Python Application Programming Interface (API) for Geographic Resources Analysis Support System (GRASS) Geographic Information System (GIS)''. ISPRS International Journal of Geo-Information 2, 201–219. ([http://dx.doi.org/10.3390/ijgi2010201 DOI] | [http://www.mdpi.com/2220-9964/2/1/201/pdf PDF])&lt;br /&gt;
&lt;br /&gt;
=== Python SIGs ===&lt;br /&gt;
Python Special Interest Groups are focused collaborative efforts to develop, improve, or maintain specific Python resources. Each SIG has a charter, a coordinator, a mailing list, and a directory on the Python website. SIG membership is informal, defined by subscription to the SIG's mailing list. Anyone can join a SIG, and participate in the development discussions via the SIG's mailing list. Below is the list of currently active Python SIGs, with links to their resources. &lt;br /&gt;
&lt;br /&gt;
See more at http://www.python.org/community/sigs/&lt;br /&gt;
&lt;br /&gt;
{{Python}}&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Atmospheric_correction&amp;diff=22251</id>
		<title>Atmospheric correction</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Atmospheric_correction&amp;diff=22251"/>
		<updated>2016-01-19T11:37:39Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: added grass7.x code&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also the [[LANDSAT]] wiki page.&lt;br /&gt;
&lt;br /&gt;
'''Aim of this tutorial:'''&lt;br /&gt;
&lt;br /&gt;
* Transforming a Landsat ETM+ image from DN values to radiance values&lt;br /&gt;
* Conducting an atmospheric correction of a Landsat image using the {{cmd|i.atcorr}} module in GRASS GIS and convert radiance to reflectance values&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Standard steps for pre-processing satellite images are:&lt;br /&gt;
&lt;br /&gt;
# Converting '''Digital Numbers''' (DN) to '''Top-of-Atmosphere Radiances''' (ToAR)&lt;br /&gt;
#* for Landsat imagery, apply the equation below or use the {{cmd|i.landsat.toar}} module&lt;br /&gt;
#* DNs -- which are actually the pixel values -- are the result of the quantified amount of energy observed and measured at the sensor&lt;br /&gt;
#* the {{cmd|i.landsat.toar}} module supports all Landsat sensors icluding MSS, TM and ETM+&lt;br /&gt;
# Converting '''ToA Radiances''' to '''Top-of-Canopy Reflectances''' (ToCR) → use the {{cmd|i.atcorr}} module&lt;br /&gt;
#* the conversion to ''Reflectances'' attempts to assess for and remove atmospheric effects, a process known as ''atmospheric correction''&lt;br /&gt;
#* the ''atmospheric correction'' step is quite a common topic of discussion in Remote Sensing. However, depending on the quality of the acquisition(s), it can be a complex process that does not always offer a great benefit, in terms of accuracy for subsequent processing steps (e.g. image segmentation and classification).&lt;br /&gt;
&lt;br /&gt;
'''Remember''' to check if water areas are represented by values &amp;lt;code&amp;gt;&amp;gt;0&amp;lt;/code&amp;gt;, since reflectance is always positive. If you encounter negative reflectance values, you have a &amp;quot;cornichon&amp;quot; (pickle in English ;-0). This means that the transformation equations used, do not correspond to the image processed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An overview of options to get &amp;quot;corrected&amp;quot; Spectral Reflectances:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;+------------------------------------------------------------------------------+&lt;br /&gt;
 |                                                                              |&lt;br /&gt;
 | Digital Numbers                                                              |&lt;br /&gt;
 |        |                                                                     |&lt;br /&gt;
 |  +-----v-----+                                                               |&lt;br /&gt;
 |  |  i.*.toar | ---&amp;gt; Reflectance                                              |&lt;br /&gt;
 |  +-----+-----+     (uncorrected)~~~(DOS methods)--+                          |&lt;br /&gt;
 |        |                 +                        |                          |&lt;br /&gt;
 |    (-r flag)         (-r flag)                    +--&amp;gt; &amp;quot;Corrected&amp;quot;           |&lt;br /&gt;
 |        |                 |                        |     Reflectance          |&lt;br /&gt;
 |        v           +-----v----+                   |                          |&lt;br /&gt;
 |     Radiance ------&amp;gt; i.atcorr +-------------------+                          |&lt;br /&gt;
 |                    +----------+                                              |&lt;br /&gt;
 |                                                                              |&lt;br /&gt;
 +------------------------------------------------------------------------------+&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* GRASS 6.4.0 or higher&lt;br /&gt;
* North Carolina sample dataset (location): https://grass.osgeo.org/download/sample-data/&lt;br /&gt;
&lt;br /&gt;
After downloading of the North Carolina dataset, it must be unzipped into your GIS database. When starting GRASS GIS, select this GIS database, open the ‘nc_spm_08’ dataset as LOCATION, and ‘PERMANENT’ as MAPSET. &lt;br /&gt;
&lt;br /&gt;
== Calculating radiance values ==&lt;br /&gt;
&lt;br /&gt;
The NC data set mapset contains, amongst others, a Landsat ETM+ image of 24th of May 2002. Every pixel of this image contains a DN or grey value. In order to be able to make calculations with satellite imagery, or compare values amongst different sensors, these values have to be converted to radiances or reflectances. The formulas to do this conversion are described here for Landsat images (or use {{cmd|i.landsat.toar}}).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The conversion from DN values to top-of-atmosphere radiances is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;L\lambda = \frac{L_{MAX}λ - L_{MIN}λ}{QCAL_{MAX} - QCAL_{MIN}} * (QCAL - QCAL_{MIN}) + L_{MIN}\lambda&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;where:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;Lλ&amp;lt;/math&amp;gt; - spectral Radiance at the sensor's aperture in watts/(meter squared * ster * μm), the apparent radiance as seen by the satellite sensor ;&lt;br /&gt;
* &amp;lt;math&amp;gt;QCAL&amp;lt;/math&amp;gt; - the quantized calibrated pixel value in &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; ;&lt;br /&gt;
* &amp;lt;math&amp;gt;LMINλ&amp;lt;/math&amp;gt; - the spectral radiance that is scaled to &amp;lt;math&amp;gt;QCALMIN&amp;lt;/math&amp;gt; in watts/(meter squared * ster * μm) ;&lt;br /&gt;
* &amp;lt;math&amp;gt;LMAXλ&amp;lt;/math&amp;gt; - the spectral radiance that is scaled to &amp;lt;math&amp;gt;QCALMAX&amp;lt;/math&amp;gt; in watts/(meter squared * ster * μm) ;&lt;br /&gt;
* &amp;lt;math&amp;gt;QCALMINM&amp;lt;/math&amp;gt; - the minimum quantized calibrated pixel value (corresponding to &amp;lt;math&amp;gt;LMINλ&amp;lt;/math&amp;gt;) in &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; ;&lt;br /&gt;
* &amp;lt;math&amp;gt;QCALMAX&amp;lt;/math&amp;gt; - the maximum quantized calibrated pixel value (corresponding to &amp;lt;math&amp;gt;LMAXλ&amp;lt;/math&amp;gt;) in &amp;lt;math&amp;gt;DN=255&amp;lt;/math&amp;gt;.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;LMINλ&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;LMAXλ&amp;lt;/math&amp;gt; are the radiances related to the minimal and maximal &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value, and are reported in the metadata file for each image, or in the table 1. High gain or low gain is also reported in the metadata file of each Landsat image. The minimal &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value (&amp;lt;math&amp;gt;QCALMIN&amp;lt;/math&amp;gt;) is 1 for Landsat ETM+ images (1), and the maximal &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value (&amp;lt;math&amp;gt;QCALMAX&amp;lt;/math&amp;gt;) is 255. &amp;lt;math&amp;gt;QCAL&amp;lt;/math&amp;gt; is the &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value for every separate pixel in the Landsat image.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Accessing the metadata:&lt;br /&gt;
&lt;br /&gt;
 {{cmd|r.info}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;lsat7_2002_xx&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Under ‘comments’, the maximal and minimal radiance (LMAX and LMIN) for each band are given. &lt;br /&gt;
&lt;br /&gt;
Power users may use this for nicely readable output (example for channel 1):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;CHAN=1&amp;lt;/source&amp;gt;&lt;br /&gt;
 {{cmd|r.info}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;lsat7_2002_${CHAN}0 -h | tr '\n' ' '  | sed 's+ ++g' | tr ':' '\n' | grep &amp;quot;LMIN_BAND${CHAN}\|LMAX_BAND${CHAN}&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Conversion to radiance (this calculation is done for band 1, for the other bands, the numbers in italics need to be replaced with their correct values):&lt;br /&gt;
&lt;br /&gt;
 {{cmd|g.region}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;rast=lsat7_2002_10 -p&amp;lt;/source&amp;gt;&lt;br /&gt;
 {{cmd|r.mapcalc}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;&amp;quot;lsat7_2002_10_rad=((''191.6'' - (''-6.2'')) / (255.0 - 1.0)) * (lsat7_2002_10 - 1.0) + (''-6.2'')&amp;quot;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For faster computations, use an integer DEM:&lt;br /&gt;
&lt;br /&gt;
  {{cmd|r.mapcalc}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;&amp;quot;elev_int = round(elevation)&amp;quot;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mean elevation to initialize computations (needed in 'icnd' file below)&lt;br /&gt;
&lt;br /&gt;
 {{cmd|r.univar}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;elev_int&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Estimating the overpass time ==&lt;br /&gt;
This value is needed for the control file. For details, refer to Wikipedia's entry on [http://en.wikipedia.org/wiki/Decimal_time#Scientific_decimal_time Scientific decimal time].&lt;br /&gt;
In case this parameter is not reported in the metadata file, we have two ways to obtain it.&lt;br /&gt;
&lt;br /&gt;
=== From sun position ===&lt;br /&gt;
&lt;br /&gt;
The satellite overpass time can be estimated rather precisely from the sun position reported in metadata using {{cmd|r.sunmask}}.&lt;br /&gt;
The [http://www.grassbook.org/wp-content/uploads/ncexternal/landsat/2002/p016r035_7x20020524.met.gz metadata file] for the following example contains: &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;SUN_AZIMUTH = 120.8810347, SUN_ELEVATION = 64.7730999&amp;lt;/source&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 # iteratively change hour and minutes to obtain a good result, timezone needs to be correct of course&lt;br /&gt;
 {{cmd|r.sunmask}}  &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;-s elev=elevation out=dummy year=2002 month=5 day=24 hour=10 min=42 sec=7 timezone=-5&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above command reports:&lt;br /&gt;
&lt;br /&gt;
 Solar position: sun azimuth: 121.342461, sun angle above horz.(refraction corrected): 65.396652&lt;br /&gt;
&lt;br /&gt;
The resulting overpass local time &amp;lt;code&amp;gt;10:42:07&amp;lt;/code&amp;gt; corresponds to &amp;lt;code&amp;gt;15:42&amp;lt;/code&amp;gt; in GMT which corresponds to &amp;lt;code&amp;gt;15.70&amp;lt;/code&amp;gt; in decimal GMT hours (decimal minutes: &amp;lt;math&amp;gt;42 * 100 / 60&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== From NASA web tool ===&lt;br /&gt;
&lt;br /&gt;
The [http://cloudsgate2.larc.nasa.gov/cgi-bin/predict/predict.cgi NASA LaRC Satellite Overpass Predictor] can compute satellite overpass time from d''ate of acquisition'' and ''scene center coordinates''. The [http://www.grassbook.org/wp-content/uploads/ncexternal/landsat/2002/p016r035_7x20020524.met.gz metadata file] for the following example contains: &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;ACQUISITION_DATE = 2002-05-24, SCENE_CENTER_LAT = +36.0512847, SCENE_CENTER_LON = -79.3280820&amp;lt;/source&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Select the World zone in the bottom-right side of the page and click &amp;lt;code&amp;gt;Go &amp;gt;&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
# Insert Lat/Long coordinates (decimal degrees, without ''plus'' sign but with ''minus'' sign)&lt;br /&gt;
# Select the proper satellite&lt;br /&gt;
# Insert the date of acquisition&lt;br /&gt;
# ''Optional:'' select &amp;quot;Day&amp;quot; or &amp;quot;Night&amp;quot; to restrict computation to (local) day/night overpass of the satellite&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
--- For LANDSAT only ---&lt;br /&gt;
&lt;br /&gt;
USGS provide the [http://landsat.usgs.gov/consumer.php Landsat Bulk Metadata Service] web page where is possible to extract metadata (included overpass time) for all the Landsat missions.&lt;br /&gt;
&lt;br /&gt;
== Atmospheric correction ==&lt;br /&gt;
&lt;br /&gt;
Radiance values can be converted to reflectance values in undergoing an atmospheric correction by applying the &amp;lt;math&amp;gt;6S&amp;lt;/math&amp;gt; algorithm. The algorithm will transform the Top-of-Atmosphere radiance values to Top-of-Canopy reflectance values using predefined information on the aerosol content and atmospheric composition of the time the image was taken. What follows describes the method to use this algorithm in GRASS GIS. Again, only calculations for band 1 are demonstrated here, and the number(s) to be changed for indicating other spectral bands, are &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt;. The &amp;lt;code&amp;gt;icnd_lsat1.txt&amp;lt;/code&amp;gt; control file consists of the following parameters, and is written with a text editor:&lt;br /&gt;
&lt;br /&gt;
 8                          # indicates that it is an ETM+ image&lt;br /&gt;
 05 24 15.67 -78.691 35.749 # image taken on the 24th of May, at 15:42 GMT in decimals; the center of the image lies at 78.691°W and 35.749°N &lt;br /&gt;
 2                          # the midlatitude summer atmospheric model&lt;br /&gt;
 1                          # the continental aerosol model&lt;br /&gt;
 50                         # the visibility for the aerosol model [km]&lt;br /&gt;
 -0.110                     # the terrain lies 110 meters above sea level [km] * -1&lt;br /&gt;
 -1000                      # image taken of a satellite sensor (1000)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;61&amp;lt;/span&amp;gt;                         # spectral band, here 1: blue&lt;br /&gt;
&lt;br /&gt;
Alternatively, in case visibility maps are not available, an Aerosol Optical Depth estimation at 550nm can be used. The control file should be altered accordingly by entering 0 for the visibility and, in a following line, entering the aerosol optical depth. The control file should be structured as follows:&lt;br /&gt;
&lt;br /&gt;
 8                          # indicates that it is an ETM+ image&lt;br /&gt;
 05 24 15.67 -78.691 35.749 # image taken on the 24th of May, at 15:42 GMT in decimals; the center of the image lies at 78.691°W and 35.749°N &lt;br /&gt;
 2                          # the midlatitude summer atmospheric model&lt;br /&gt;
 1                          # the continental aerosol model&lt;br /&gt;
 0                          # set visibility = 0&lt;br /&gt;
 0.112                      # e.g. aerosol optical depth&lt;br /&gt;
 -0.110                     # the terrain lies 110 meters above sea level [km] * -1&lt;br /&gt;
 -1000                      # image taken of a satellite sensor (1000)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;61&amp;lt;/span&amp;gt;                         # spectral band, here 1: blue&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is then used in the {{cmd|i.atcorr}} module:&lt;br /&gt;
&lt;br /&gt;
 {{cmd|i.atcorr}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;-a -o iimg=lsat7_2002_10_rad ialt=elev_int icnd=icdn_lsat1.txt oimg=lsat7_2002_10_atcorr&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
or, using GRASS 7.x:&lt;br /&gt;
&lt;br /&gt;
 {{cmd|i.atcorr}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;-a input=lsat7_2002_10_rad elevation=elev_int parameters=icdn_lsat1.txt output=lsat7_2002_10_atcorr&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''-a'''&amp;lt;/tt&amp;gt;   refers to a Landsat image taken after July 2000&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''-o'''&amp;lt;/tt&amp;gt;   activates the cache acceleration (GRASS 6.x only)&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''iimg/input'''&amp;lt;/tt&amp;gt; is the image to be corrected&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''ialt/elevation'''&amp;lt;/tt&amp;gt; is the altitude map which overrides the initialization value of 110 meters&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''icnd/parameters'''&amp;lt;/tt&amp;gt; is the path to the icnd.txt file&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''oimg/output'''&amp;lt;/tt&amp;gt; is the name of the output image&lt;br /&gt;
&lt;br /&gt;
Detailed information can be found in {{cmd|i.atcorr}}'s manual.&lt;br /&gt;
&lt;br /&gt;
'''Note,''' {{cmd|i.atcorr}} wont complain if the defined elevation model (parameter &amp;lt;code&amp;gt;elevation=&amp;lt;/code&amp;gt;) does not cover the extent of the Landsat scene that is the subject of the process -- it will result in NaN's. ''[Maybe this can be requested as an enhancement?]''&lt;br /&gt;
&lt;br /&gt;
== Sources for aerosol optical depth (AOD) estimations ==&lt;br /&gt;
&lt;br /&gt;
* [http://aeronet.gsfc.nasa.gov AERONET] - provides globally distributed observations of spectral aerosol optical depth (AOD), inversion products, and precipitable water in diverse aerosol regimes.&lt;br /&gt;
* MODIS MOD08 product [http://modis.gsfc.nasa.gov/data/dataprod/dataproducts.php?MOD_NUMBER=08 MOD08 - Gridded Atmospheric Product].&lt;br /&gt;
** Daily MOD08 products can be downloaded directly from NASA's FTP server: [ftp://ladsweb.nascom.nasa.gov/allData/51/MOD08_D3/ '''ftp://ladsweb.nascom.nasa.gov/allData/51/MOD08_D3/'''].&lt;br /&gt;
** File and layer specifications are available, for example, at [http://www.atmos.washington.edu/~robwood/modis/filespecs/MOD08_D3.CDL.fs MODIS HDF File Specification MOD08_D3: MODIS Level 3 Daily Atmosphere Gridded Product]&lt;br /&gt;
** The layer '''Optical_Depth_Land_And_Ocean_Mean''', described as ''Aerosol Optical Thickness at 0.55 microns for both Ocean (best) and Land (corrected): Mean'', can be probably used as an input for {{cmd|i.atcorr}}. '''Note,''' the layer's values have to be scaled by using the scaling factor ''Optical_Depth_Land_And_Ocean_Mean:scale_factor ='' '''0.001d''' as reported in the specifications.&lt;br /&gt;
* [http://www.cesbio.ups-tlse.fr/multitemp/?p=1710 How to estimate Aerosol Optical Thickness]&lt;br /&gt;
&lt;br /&gt;
=== TοDο ===&lt;br /&gt;
* understand if the [http://modis.gsfc.nasa.gov/data/dataprod/dataproducts.php?MOD_NUMBER=04 MODIS Aerosol Product (MOD04)] could be useful to estimate the visibility for the aerosol model.&lt;br /&gt;
* provide an example on using [http://modis.gsfc.nasa.gov/data/dataprod/dataproducts.php?MOD_NUMBER=08 MODIS Gridded Atmospheric Product (MOD08)].&lt;br /&gt;
* explain if it is possible and how to use ''Rayleigh Optical Depths estimated at 0km altitude for six different atmosphere models'' from the paper [http://www.opticsinfobase.org/ao/abstract.cfm?uri=ao-34-15-2765  Rayleigh-scattering calculations for the terrestrial atmosphere] by Anthony Buchholz, table 4, page 2270&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
=== 6S algorithm ===&lt;br /&gt;
&lt;br /&gt;
* [http://6s.ltdri.org 6S Web site]&lt;br /&gt;
* [http://modis-sr.ltdri.org/ Land Surface Reflectance Science Computing Facility website - 6S]&lt;br /&gt;
&lt;br /&gt;
=== Spectral radiance/reflectance ===&lt;br /&gt;
&lt;br /&gt;
* [http://landsat.usgs.gov/how_is_radiance_calculated.php How is radiance calculated?], question on USGS' [http://landsat.usgs.gov/tools_faq.php Landsat Missions - Frequently Asked Questions]&lt;br /&gt;
* (1)  http://landsathandbook.gsfc.nasa.gov/handbook/handbook_htmls/chapter11/chapter11.html&lt;br /&gt;
* (2)  http://landsat.usgs.gov/documents/L5TM_postcal_v11.pdf&lt;br /&gt;
&lt;br /&gt;
=== Whitepapers ===&lt;br /&gt;
&lt;br /&gt;
* Various [http://apollomapping.com/about-us/whitepapers Whitepapers] about conversion and atmospheric correction of High Resolution Satellite Imagery&lt;br /&gt;
*  Song, C., Woodcock, C.E., Seto, K.C., Lenney, M.P., Macomber, S.A., 2001. Classification and Change Detection Using Landsat TM Data: When and How to Correct Atmospheric Effects? Remote Sensing of Environment 75, 230-244. [http://www.unc.edu/courses/2008spring/geog/577/001/www/Song01_RSE.pdf PDF]&lt;br /&gt;
&lt;br /&gt;
=== Related on-line tools ===&lt;br /&gt;
&lt;br /&gt;
* [http://cloudsgate2.larc.nasa.gov/cgi-bin/predict/predict.cgi NASA LaRC Satellite Overpass Predictor]&lt;br /&gt;
* [http://landsat.usgs.gov/consumer.php Landsat Bulk Metadata Service]&lt;br /&gt;
* NASA's [http://atmcorr.gsfc.nasa.gov/ Atmospheric Correction Parameter Calculator]&lt;br /&gt;
&lt;br /&gt;
=== How to add new sensors to i.atcorr ===&lt;br /&gt;
&lt;br /&gt;
How to add new sensors to {{cmd|i.atcorr}}:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* see http://trac.osgeo.org/grass/browser/grass/trunk/imagery/i.atcorr/README&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Image processing]]&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Atmospheric_correction&amp;diff=22140</id>
		<title>Atmospheric correction</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Atmospheric_correction&amp;diff=22140"/>
		<updated>2015-12-11T10:43:17Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: Corrected link and update of overpass time sub-section&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;See also the [[LANDSAT]] wiki page.&lt;br /&gt;
&lt;br /&gt;
'''Aim of this tutorial:'''&lt;br /&gt;
&lt;br /&gt;
* Transforming a Landsat ETM+ image from DN values to radiance values&lt;br /&gt;
* Conducting an atmospheric correction of a Landsat image using the {{cmd|i.atcorr}} module in GRASS GIS and convert radiance to reflectance values&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
&lt;br /&gt;
Standard steps for pre-processing satellite images are:&lt;br /&gt;
&lt;br /&gt;
# Converting '''Digital Numbers''' (DN) to '''Top-of-Atmosphere Radiances''' (ToAR)&lt;br /&gt;
#* for Landsat imagery, apply the equation below or use the {{cmd|i.landsat.toar}} module&lt;br /&gt;
#* DNs -- which are actually the pixel values -- are the result of the quantified amount of energy observed and measured at the sensor&lt;br /&gt;
#* the {{cmd|i.landsat.toar}} module supports all Landsat sensors icluding MSS, TM and ETM+&lt;br /&gt;
# Converting '''ToA Radiances''' to '''Top-of-Canopy Reflectances''' (ToCR) → use the {{cmd|i.atcorr}} module&lt;br /&gt;
#* the conversion to ''Reflectances'' attempts to assess for and remove atmospheric effects, a process known as ''atmospheric correction''&lt;br /&gt;
#* the ''atmospheric correction'' step is quite a common topic of discussion in Remote Sensing. However, depending on the quality of the acquisition(s), it can be a complex process that does not always offer a great benefit, in terms of accuracy for subsequent processing steps (e.g. image segmentation and classification).&lt;br /&gt;
&lt;br /&gt;
'''Remember''' to check if water areas are represented by values &amp;lt;code&amp;gt;&amp;gt;0&amp;lt;/code&amp;gt;, since reflectance is always positive. If you encounter negative reflectance values, you have a &amp;quot;cornichon&amp;quot; (pickle in English ;-0). This means that the transformation equations used, do not correspond to the image processed.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
An overview of options to get &amp;quot;corrected&amp;quot; Spectral Reflectances:&lt;br /&gt;
&lt;br /&gt;
  &amp;lt;nowiki&amp;gt;+------------------------------------------------------------------------------+&lt;br /&gt;
 |                                                                              |&lt;br /&gt;
 | Digital Numbers                                                              |&lt;br /&gt;
 |        |                                                                     |&lt;br /&gt;
 |  +-----v-----+                                                               |&lt;br /&gt;
 |  |  i.*.toar | ---&amp;gt; Reflectance                                              |&lt;br /&gt;
 |  +-----+-----+     (uncorrected)~~~(DOS methods)--+                          |&lt;br /&gt;
 |        |                 +                        |                          |&lt;br /&gt;
 |    (-r flag)         (-r flag)                    +--&amp;gt; &amp;quot;Corrected&amp;quot;           |&lt;br /&gt;
 |        |                 |                        |     Reflectance          |&lt;br /&gt;
 |        v           +-----v----+                   |                          |&lt;br /&gt;
 |     Radiance ------&amp;gt; i.atcorr +-------------------+                          |&lt;br /&gt;
 |                    +----------+                                              |&lt;br /&gt;
 |                                                                              |&lt;br /&gt;
 +------------------------------------------------------------------------------+&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* GRASS 6.4.0 or higher&lt;br /&gt;
* North Carolina sample dataset (location): https://grass.osgeo.org/download/sample-data/&lt;br /&gt;
&lt;br /&gt;
After downloading of the North Carolina dataset, it must be unzipped into your GIS database. When starting GRASS GIS, select this GIS database, open the ‘nc_spm_08’ dataset as LOCATION, and ‘PERMANENT’ as MAPSET. &lt;br /&gt;
&lt;br /&gt;
== Calculating radiance values ==&lt;br /&gt;
&lt;br /&gt;
The NC data set mapset contains, amongst others, a Landsat ETM+ image of 24th of May 2002. Every pixel of this image contains a DN or grey value. In order to be able to make calculations with satellite imagery, or compare values amongst different sensors, these values have to be converted to radiances or reflectances. The formulas to do this conversion are described here for Landsat images (or use {{cmd|i.landsat.toar}}).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The conversion from DN values to top-of-atmosphere radiances is done as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;L\lambda = \frac{L_{MAX}λ - L_{MIN}λ}{QCAL_{MAX} - QCAL_{MIN}} * (QCAL - QCAL_{MIN}) + L_{MIN}\lambda&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;where:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;math&amp;gt;Lλ&amp;lt;/math&amp;gt; - spectral Radiance at the sensor's aperture in watts/(meter squared * ster * μm), the apparent radiance as seen by the satellite sensor ;&lt;br /&gt;
* &amp;lt;math&amp;gt;QCAL&amp;lt;/math&amp;gt; - the quantized calibrated pixel value in &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; ;&lt;br /&gt;
* &amp;lt;math&amp;gt;LMINλ&amp;lt;/math&amp;gt; - the spectral radiance that is scaled to &amp;lt;math&amp;gt;QCALMIN&amp;lt;/math&amp;gt; in watts/(meter squared * ster * μm) ;&lt;br /&gt;
* &amp;lt;math&amp;gt;LMAXλ&amp;lt;/math&amp;gt; - the spectral radiance that is scaled to &amp;lt;math&amp;gt;QCALMAX&amp;lt;/math&amp;gt; in watts/(meter squared * ster * μm) ;&lt;br /&gt;
* &amp;lt;math&amp;gt;QCALMINM&amp;lt;/math&amp;gt; - the minimum quantized calibrated pixel value (corresponding to &amp;lt;math&amp;gt;LMINλ&amp;lt;/math&amp;gt;) in &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; ;&lt;br /&gt;
* &amp;lt;math&amp;gt;QCALMAX&amp;lt;/math&amp;gt; - the maximum quantized calibrated pixel value (corresponding to &amp;lt;math&amp;gt;LMAXλ&amp;lt;/math&amp;gt;) in &amp;lt;math&amp;gt;DN=255&amp;lt;/math&amp;gt;.&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;LMINλ&amp;lt;/math&amp;gt; and &amp;lt;math&amp;gt;LMAXλ&amp;lt;/math&amp;gt; are the radiances related to the minimal and maximal &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value, and are reported in the metadata file for each image, or in the table 1. High gain or low gain is also reported in the metadata file of each Landsat image. The minimal &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value (&amp;lt;math&amp;gt;QCALMIN&amp;lt;/math&amp;gt;) is 1 for Landsat ETM+ images (1), and the maximal &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value (&amp;lt;math&amp;gt;QCALMAX&amp;lt;/math&amp;gt;) is 255. &amp;lt;math&amp;gt;QCAL&amp;lt;/math&amp;gt; is the &amp;lt;math&amp;gt;DN&amp;lt;/math&amp;gt; value for every separate pixel in the Landsat image.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Accessing the metadata:&lt;br /&gt;
&lt;br /&gt;
 {{cmd|r.info}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;lsat7_2002_xx&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Under ‘comments’, the maximal and minimal radiance (LMAX and LMIN) for each band are given. &lt;br /&gt;
&lt;br /&gt;
Power users may use this for nicely readable output (example for channel 1):&lt;br /&gt;
&lt;br /&gt;
 &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;CHAN=1&amp;lt;/source&amp;gt;&lt;br /&gt;
 {{cmd|r.info}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;lsat7_2002_${CHAN}0 -h | tr '\n' ' '  | sed 's+ ++g' | tr ':' '\n' | grep &amp;quot;LMIN_BAND${CHAN}\|LMAX_BAND${CHAN}&amp;quot;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Conversion to radiance (this calculation is done for band 1, for the other bands, the numbers in italics need to be replaced with their correct values):&lt;br /&gt;
&lt;br /&gt;
 {{cmd|g.region}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;rast=lsat7_2002_10 -p&amp;lt;/source&amp;gt;&lt;br /&gt;
 {{cmd|r.mapcalc}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;&amp;quot;lsat7_2002_10_rad=((''191.6'' - (''-6.2'')) / (255.0 - 1.0)) * (lsat7_2002_10 - 1.0) + (''-6.2'')&amp;quot;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For faster computations, use an integer DEM:&lt;br /&gt;
&lt;br /&gt;
  {{cmd|r.mapcalc}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;&amp;quot;elev_int = round(elevation)&amp;quot;&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Find mean elevation to initialize computations (needed in 'icnd' file below)&lt;br /&gt;
&lt;br /&gt;
 {{cmd|r.univar}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;elev_int&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Estimating the overpass time ==&lt;br /&gt;
This value is needed for the control file. For details, refer to Wikipedia's entry on [http://en.wikipedia.org/wiki/Decimal_time#Scientific_decimal_time Scientific decimal time].&lt;br /&gt;
In case this parameter is not reported in the metadata file, we have two ways to obtain it.&lt;br /&gt;
&lt;br /&gt;
=== From sun position ===&lt;br /&gt;
&lt;br /&gt;
The satellite overpass time can be estimated rather precisely from the sun position reported in metadata using {{cmd|r.sunmask}}.&lt;br /&gt;
The [http://www.grassbook.org/wp-content/uploads/ncexternal/landsat/2002/p016r035_7x20020524.met.gz metadata file] for the following example contains: &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;SUN_AZIMUTH = 120.8810347, SUN_ELEVATION = 64.7730999&amp;lt;/source&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 # iteratively change hour and minutes to obtain a good result, timezone needs to be correct of course&lt;br /&gt;
 {{cmd|r.sunmask}}  &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;-s elev=elevation out=dummy year=2002 month=5 day=24 hour=10 min=42 sec=7 timezone=-5&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The above command reports:&lt;br /&gt;
&lt;br /&gt;
 Solar position: sun azimuth: 121.342461, sun angle above horz.(refraction corrected): 65.396652&lt;br /&gt;
&lt;br /&gt;
The resulting overpass local time &amp;lt;code&amp;gt;10:42:07&amp;lt;/code&amp;gt; corresponds to &amp;lt;code&amp;gt;15:42&amp;lt;/code&amp;gt; in GMT which corresponds to &amp;lt;code&amp;gt;15.70&amp;lt;/code&amp;gt; in decimal GMT hours (decimal minutes: &amp;lt;math&amp;gt;42 * 100 / 60&amp;lt;/math&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
=== From NASA web tool ===&lt;br /&gt;
&lt;br /&gt;
The [http://cloudsgate2.larc.nasa.gov/cgi-bin/predict/predict.cgi NASA LaRC Satellite Overpass Predictor] can compute satellite overpass time from d''ate of acquisition'' and ''scene center coordinates''. The [http://www.grassbook.org/wp-content/uploads/ncexternal/landsat/2002/p016r035_7x20020524.met.gz metadata file] for the following example contains: &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;ACQUISITION_DATE = 2002-05-24, SCENE_CENTER_LAT = +36.0512847, SCENE_CENTER_LON = -79.3280820&amp;lt;/source&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
# Select the World zone in the bottom-right side of the page and click &amp;lt;code&amp;gt;Go &amp;gt;&amp;gt;&amp;lt;/code&amp;gt;&lt;br /&gt;
# Insert Lat/Long coordinates (decimal degrees, without ''plus'' sign but with ''minus'' sign)&lt;br /&gt;
# Select the proper satellite&lt;br /&gt;
# Insert the date of acquisition&lt;br /&gt;
# ''Optional:'' select &amp;quot;Day&amp;quot; or &amp;quot;Night&amp;quot; to restrict computation to (local) day/night overpass of the satellite&lt;br /&gt;
&lt;br /&gt;
== Atmospheric correction ==&lt;br /&gt;
&lt;br /&gt;
Radiance values can be converted to reflectance values in undergoing an atmospheric correction by applying the &amp;lt;math&amp;gt;6S&amp;lt;/math&amp;gt; algorithm. The algorithm will transform the Top-of-Atmosphere radiance values to Top-of-Canopy reflectance values using predefined information on the aerosol content and atmospheric composition of the time the image was taken. What follows describes the method to use this algorithm in GRASS GIS. Again, only calculations for band 1 are demonstrated here, and the number(s) to be changed for indicating other spectral bands, are &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;red&amp;lt;/span&amp;gt;. The &amp;lt;code&amp;gt;icnd_lsat1.txt&amp;lt;/code&amp;gt; control file consists of the following parameters, and is written with a text editor:&lt;br /&gt;
&lt;br /&gt;
 8                          # indicates that it is an ETM+ image&lt;br /&gt;
 05 24 15.67 -78.691 35.749 # image taken on the 24th of May, at 15:42 GMT in decimals; the center of the image lies at 78.691°W and 35.749°N &lt;br /&gt;
 2                          # the midlatitude summer atmospheric model&lt;br /&gt;
 1                          # the continental aerosol model&lt;br /&gt;
 50                         # the visibility for the aerosol model [km]&lt;br /&gt;
 -0.110                     # the terrain lies 110 meters above sea level [km] * -1&lt;br /&gt;
 -1000                      # image taken of a satellite sensor (1000)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;61&amp;lt;/span&amp;gt;                         # spectral band, here 1: blue&lt;br /&gt;
&lt;br /&gt;
Alternatively, in case visibility maps are not available, an Aerosol Optical Depth estimation at 550nm can be used. The control file should be altered accordingly by entering 0 for the visibility and, in a following line, entering the aerosol optical depth. The control file should be structured as follows:&lt;br /&gt;
&lt;br /&gt;
 8                          # indicates that it is an ETM+ image&lt;br /&gt;
 05 24 15.67 -78.691 35.749 # image taken on the 24th of May, at 15:42 GMT in decimals; the center of the image lies at 78.691°W and 35.749°N &lt;br /&gt;
 2                          # the midlatitude summer atmospheric model&lt;br /&gt;
 1                          # the continental aerosol model&lt;br /&gt;
 0                          # set visibility = 0&lt;br /&gt;
 0.112                      # e.g. aerosol optical depth&lt;br /&gt;
 -0.110                     # the terrain lies 110 meters above sea level [km] * -1&lt;br /&gt;
 -1000                      # image taken of a satellite sensor (1000)&lt;br /&gt;
 &amp;lt;span style=&amp;quot;color:#FF0000&amp;quot;&amp;gt;61&amp;lt;/span&amp;gt;                         # spectral band, here 1: blue&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
This file is then used in the {{cmd|i.atcorr}} module:&lt;br /&gt;
&lt;br /&gt;
 {{cmd|i.atcorr}} &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=none&amp;gt;-a -o iimg=lsat7_2002_10_rad ialt=elev_int icnd=icdn_lsat1.txt oimg=lsat7_2002_10_atcorr&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''-a'''&amp;lt;/tt&amp;gt;   refers to a Landsat image taken after July 2000&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''-o'''&amp;lt;/tt&amp;gt;   activates the cache acceleration&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''iimg'''&amp;lt;/tt&amp;gt; is the image to be corrected&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''ialt'''&amp;lt;/tt&amp;gt; is the altitude map which overrides the initialization value of 110 meters&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''icnd'''&amp;lt;/tt&amp;gt; is the path to the icnd.txt file&lt;br /&gt;
* &amp;lt;tt&amp;gt;'''oimg'''&amp;lt;/tt&amp;gt; is the name of the output image&lt;br /&gt;
&lt;br /&gt;
Detailed information can be found in {{cmd|i.atcorr}}'s manual.&lt;br /&gt;
&lt;br /&gt;
'''Note,''' {{cmd|i.atcorr}} wont complain if the defined elevation model (parameter &amp;lt;code&amp;gt;elevation=&amp;lt;/code&amp;gt;) does not cover the extent of the Landsat scene that is the subject of the process -- it will result in NaN's. ''[Maybe this can be requested as an enhancement?]''&lt;br /&gt;
&lt;br /&gt;
== Sources for aerosol optical depth (AOD) estimations ==&lt;br /&gt;
&lt;br /&gt;
* [http://aeronet.gsfc.nasa.gov AERONET] - provides globally distributed observations of spectral aerosol optical depth (AOD), inversion products, and precipitable water in diverse aerosol regimes.&lt;br /&gt;
* MODIS MOD08 product [http://modis.gsfc.nasa.gov/data/dataprod/dataproducts.php?MOD_NUMBER=08 MOD08 - Gridded Atmospheric Product].&lt;br /&gt;
** Daily MOD08 products can be downloaded directly from NASA's FTP server: [ftp://ladsweb.nascom.nasa.gov/allData/51/MOD08_D3/ '''ftp://ladsweb.nascom.nasa.gov/allData/51/MOD08_D3/'''].&lt;br /&gt;
** File and layer specifications are available, for example, at [http://www.atmos.washington.edu/~robwood/modis/filespecs/MOD08_D3.CDL.fs MODIS HDF File Specification MOD08_D3: MODIS Level 3 Daily Atmosphere Gridded Product]&lt;br /&gt;
** The layer '''Optical_Depth_Land_And_Ocean_Mean''', described as ''Aerosol Optical Thickness at 0.55 microns for both Ocean (best) and Land (corrected): Mean'', can be probably used as an input for {{cmd|i.atcorr}}. '''Note,''' the layer's values have to be scaled by using the scaling factor ''Optical_Depth_Land_And_Ocean_Mean:scale_factor ='' '''0.001d''' as reported in the specifications.&lt;br /&gt;
* [http://www.cesbio.ups-tlse.fr/multitemp/?p=1710 How to estimate Aerosol Optical Thickness]&lt;br /&gt;
&lt;br /&gt;
=== TοDο ===&lt;br /&gt;
* understand if the [http://modis.gsfc.nasa.gov/data/dataprod/dataproducts.php?MOD_NUMBER=04 MODIS Aerosol Product (MOD04)] could be useful to estimate the visibility for the aerosol model.&lt;br /&gt;
* provide an example on using [http://modis.gsfc.nasa.gov/data/dataprod/dataproducts.php?MOD_NUMBER=08 MODIS Gridded Atmospheric Product (MOD08)].&lt;br /&gt;
* explain if it is possible and how to use ''Rayleigh Optical Depths estimated at 0km altitude for six different atmosphere models'' from the paper [http://www.opticsinfobase.org/ao/abstract.cfm?uri=ao-34-15-2765  Rayleigh-scattering calculations for the terrestrial atmosphere] by Anthony Buchholz, table 4, page 2270&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
=== 6S algorithm ===&lt;br /&gt;
&lt;br /&gt;
* [http://6s.ltdri.org 6S Web site]&lt;br /&gt;
* [http://modis-sr.ltdri.org/ Land Surface Reflectance Science Computing Facility website - 6S]&lt;br /&gt;
&lt;br /&gt;
=== Spectral radiance/reflectance ===&lt;br /&gt;
&lt;br /&gt;
* [http://landsat.usgs.gov/how_is_radiance_calculated.php How is radiance calculated?], question on USGS' [http://landsat.usgs.gov/tools_faq.php Landsat Missions - Frequently Asked Questions]&lt;br /&gt;
* (1)  http://landsathandbook.gsfc.nasa.gov/handbook/handbook_htmls/chapter11/chapter11.html&lt;br /&gt;
* (2)  http://landsat.usgs.gov/documents/L5TM_postcal_v11.pdf&lt;br /&gt;
&lt;br /&gt;
=== Whitepapers ===&lt;br /&gt;
&lt;br /&gt;
* Various [http://apollomapping.com/about-us/whitepapers Whitepapers] about conversion and atmospheric correction of High Resolution Satellite Imagery&lt;br /&gt;
*  Song, C., Woodcock, C.E., Seto, K.C., Lenney, M.P., Macomber, S.A., 2001. Classification and Change Detection Using Landsat TM Data: When and How to Correct Atmospheric Effects? Remote Sensing of Environment 75, 230-244. [http://www.unc.edu/courses/2008spring/geog/577/001/www/Song01_RSE.pdf PDF]&lt;br /&gt;
&lt;br /&gt;
=== Related on-line tools ===&lt;br /&gt;
&lt;br /&gt;
* [http://cloudsgate2.larc.nasa.gov/cgi-bin/predict/predict.cgi NASA LaRC Satellite Overpass Predictor]&lt;br /&gt;
* NASA's [http://atmcorr.gsfc.nasa.gov/ Atmospheric Correction Parameter Calculator]&lt;br /&gt;
&lt;br /&gt;
=== How to add new sensors to i.atcorr ===&lt;br /&gt;
&lt;br /&gt;
How to add new sensors to {{cmd|i.atcorr}}:&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
* see http://trac.osgeo.org/grass/browser/grass/trunk/imagery/i.atcorr/README&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Image processing]]&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=LANDSAT&amp;diff=22139</id>
		<title>LANDSAT</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=LANDSAT&amp;diff=22139"/>
		<updated>2015-12-11T09:21:13Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: Corrected link to manual page and external site&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Data Availability==&lt;br /&gt;
&lt;br /&gt;
Landsat imagery can be obtained from [http://landsat.usgs.gov/ USGS' LANDSAT archive]:&lt;br /&gt;
&lt;br /&gt;
* [http://glovis.usgs.gov USGS GloVis]&lt;br /&gt;
* [http://earthexplorer.usgs.gov/ EarthExplorer]&lt;br /&gt;
* [http://earthexplorer.usgs.gov/bulk/help Bulk Download Orders] using the [http://earthexplorer.usgs.gov/bulk/ Bulk Download Application]&lt;br /&gt;
* [http://landsatlook.usgs.gov/ LandsatLook Viewer]&lt;br /&gt;
&lt;br /&gt;
See also the [[Global datasets]] wiki page&lt;br /&gt;
&lt;br /&gt;
On 06/12/13, USGS [http://landsat.usgs.gov/about_LU_Vol_7_Issue_4.php announced] the availability of [http://landsat.usgs.gov/landsat8.php LANDSAT 8]. See also [http://landsat.usgs.gov/band_designations_landsat_satellites.php this page].&lt;br /&gt;
&lt;br /&gt;
== Modules overview ==&lt;br /&gt;
&lt;br /&gt;
GRASS GIS features a complete set of native modules and various add-ons for pre- and post-processing Landsat satellite imagery. The following lists offer an overview of related modules and add-ons.&lt;br /&gt;
&lt;br /&gt;
=== Generic modules applicable to Landsat ===&lt;br /&gt;
&lt;br /&gt;
* {{cmd|d.rgb}} → display 3-band data&lt;br /&gt;
* {{cmd|r.composite}} → flatten 3-bands of data into a single image (lossy, maybe used in combination with {{cmd|i.landsat.rgb|version=64}} (GRASS 6.x) | {{cmd|i.colors.enhance|version=70}} (GRASS 7.x)&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.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;
* {{cmd|i.oif}} → calculate the 3 bands showing the greatest difference (for use as R,G,B bands)&lt;br /&gt;
* {{AddonCmd|i.histo.match}} (addon) → histogram matching of two or more raster maps (in grass 7) ''Note, the module works with integer values and does not accept the &amp;quot;.&amp;quot; character as part of the raster map's name!''&lt;br /&gt;
&lt;br /&gt;
=== Landsat specific modules ===&lt;br /&gt;
&lt;br /&gt;
* {{cmd|i.landsat.rgb|version=64}} (GRASS 6.x) | {{cmd|i.colors.enhance|version=70}} (GRASS 7.x) → auto-enhance colors&lt;br /&gt;
* {{cmd|i.landsat.toar}} → convert DN to top of atmosphere radiance&lt;br /&gt;
* {{cmd|i.landsat.acca}} → cloud cover assessment&lt;br /&gt;
&lt;br /&gt;
=== Landsat specific GRASS AddOns ===&lt;br /&gt;
&lt;br /&gt;
* {{AddonCmd|i.landsat.trim|version=64}} → trims border fringes for each band separately or with the MASK where coverage exists for all bands&lt;br /&gt;
* {{AddonCmd|i.landsat.dehaze|version=64}} (addon) → haze removal&lt;br /&gt;
&lt;br /&gt;
== Pre-Processing ==&lt;br /&gt;
&lt;br /&gt;
=== Overview ===&lt;br /&gt;
&lt;br /&gt;
Typically, pre-processing Landsat imagery comprises the following steps:&lt;br /&gt;
&lt;br /&gt;
# '''import''' in the database → {{cmd|r.in.gdal}}&lt;br /&gt;
# geometrically &amp;amp; orthometrically correct imagery&lt;br /&gt;
#* already done for L1T products, read more at [http://landsat.usgs.gov//Landsat_Processing_Details.php USGS' Landsat Information Products] webpage&lt;br /&gt;
# optionally, automatically '''cut-off border fringes''' → {{AddonCmd|i.landsat.trim|version=64}}&lt;br /&gt;
#* of course one can use the official WRS2 Path/Row vector tiles to manually trim border fringes&lt;br /&gt;
# optionally, '''denoise''' for obvious/intensive salt &amp;amp; pepper effects, stripes, etc.&lt;br /&gt;
#* for example by applying Principal Components Analysis as a denoising technique → {{cmd|i.pca}} ''&amp;lt;&amp;lt;&amp;lt; Re-order this step?''&lt;br /&gt;
# '''convert''' the '''Digital Numbers''' (DNs) to '''Top-of-Atmosphere Radiances/Reflectances''' (ToARs) → {{cmd|i.landsat.toar}}&lt;br /&gt;
# optionally, '''correct for atmospheric effects''' → {{cmd|i.atcorr}}&lt;br /&gt;
#* that is, accounting for distorting atmospheric effects and estimating actual reflectances as they would have been measured on the ground&lt;br /&gt;
#* also described as conversion to Top-of-Canopy Reflectances (ToCRs)&lt;br /&gt;
# '''assessing cloud cover''' → {{cmd|i.landsat.acca}}&lt;br /&gt;
#* optionally, detect and remove clouds shadows as well&lt;br /&gt;
# '''topographically normalise''' imagery → {{cmd|i.topo.corr}}&lt;br /&gt;
#* also known as topographic correction, that is, accounting for illumination differences due to the acquisition's geometry&lt;br /&gt;
# '''radiometrically normalise''' → one approach via {{AddonCmd|i.histo.match}} (in '''grass 7''', addon), also known as relative radiometric normalisation -- one approach is the ''histogram matching'' technique of two or more raster maps&lt;br /&gt;
#* '''ToDo/More techniques?'''&lt;br /&gt;
&lt;br /&gt;
See also&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat8-data-in-grass-gis-7/ Processing Landsat 8 data in GRASS GIS 7: Import and visualization]&lt;br /&gt;
&lt;br /&gt;
=== Importing data ===&lt;br /&gt;
&lt;br /&gt;
Importing Landsat spectral bands in GRASS GIS' data base can be done both from the Graphical User Interface or from the command line&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Open GRASS GIS, select ''Location Wizard'' in order to create a new location from georeferenced file&lt;br /&gt;
# Use the ''Import file tool'', or the {{cmd|r.in.gdal}} module, to import the GeoTIFF files into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
See also [http://grasswiki.osgeo.org/wiki/LANDSAT#Automated_data_import Automated data import] below.&lt;br /&gt;
&lt;br /&gt;
==== Notes ====&lt;br /&gt;
&lt;br /&gt;
# Most Landsat scenes are delivered in ''north-is-up'' orientation, hence the import process is straightforward.&lt;br /&gt;
# If you get &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;ERROR: Input map is rotated - cannot import.&amp;lt;/source&amp;gt;, the image must be first rotated externally, applying the rotation info stored in the metadata field of the raster image file. For example, the &amp;lt;code&amp;gt;gdalwarp&amp;lt;/code&amp;gt; software can be used to transform the map to North-up (note, there are several &amp;lt;code&amp;gt;gdalwarp&amp;lt;/code&amp;gt; parameters to select the resampling algorithm):&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;gt;&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
  gdalwarp rotated.tif northup.tif&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Hint: Minimal disk space copies ====&lt;br /&gt;
&lt;br /&gt;
Here's a little trick using {{cmd|r.reclass}} to rename maps (for example, from ''L71074092_09220040924_B'''10''''' to ''L71074092_09220040924_B'''1''''') 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;
&lt;br /&gt;
&lt;br /&gt;
==== Automated data import ====&lt;br /&gt;
&lt;br /&gt;
The following ''Python'' script imports Landsat imagery into GRASS' data base. Specifically, the script&lt;br /&gt;
&lt;br /&gt;
* creates an independent Mapset for each Landsat scene&lt;br /&gt;
* imports and renames bands of a scene as &amp;lt;tt&amp;gt;B&amp;lt;id&amp;gt;&amp;lt;/tt&amp;gt;, e.g. B10, B20, ..., B80.&lt;br /&gt;
* additionaly sets up the timestamp based on MTL metadata file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Note,''' the (newest) official naming pattern for Landsat scenes -- explained in [https://lta.cr.usgs.gov/landsat_dictionary.html USGS' Landsat Data Dictionary] as the [https://lta.cr.usgs.gov/landsat_dictionary.html#entity_id Landsat Scene Identifier] -- and all individual bands that compose a scene -- bands have a suffix which is like _B10, _B20, _B30, etc. -- differ from what some Landsat specific modules expect. For example, the modules {{cmd|i.landsat.toar}} and {{cmd|i.landsat.acca}} expect the bands to follow a naming pattern such as &amp;quot;scenename.1, .2, .3&amp;quot;, etc.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
To use the script save it as &amp;lt;source lang=&amp;quot;bash&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;import_landsat.py&amp;lt;/source&amp;gt; file and make sure it is granted the execution permission.&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 any(x in line for x in ('DATE_ACQUIRED', 'ACQUISITION_DATE')):&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;
        if ('VCID') in ffile:&lt;br /&gt;
            name = &amp;quot;&amp;quot;.join((os.path.splitext(file)[0].split('_'))[1::2])&lt;br /&gt;
        else:&lt;br /&gt;
            name = os.path.splitext(file)[0].split('_')[-1]&lt;br /&gt;
        if len(name) == 3 and name[-1] == '0':&lt;br /&gt;
            band = int(name[1:2])&lt;br /&gt;
        elif len(name) == 3 and name[-1] != '0':&lt;br /&gt;
            band = int(name[1:3])&lt;br /&gt;
        else:&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;
&lt;br /&gt;
'''Example of usage'''&lt;br /&gt;
&lt;br /&gt;
After having collected the Landsat scenes of interest in one directory, the script can be used as follows:&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;python&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;./import_landsat.py&amp;lt;/source&amp;gt; → the script will walk through a ''pool'' directory that contains unique Landsat scene directories (e.g. three directories named after the official naming pattern: LT51800342011158MOR00  LT51810352009079MTI00  LT51820352009326MTI00) and import all bands of each individual scene in their own Mapset&lt;br /&gt;
* &amp;lt;source lang=&amp;quot;python&amp;quot; enclose=&amp;quot;none&amp;quot;&amp;gt;./import_landsat.py LM41890261983200FFF03&amp;lt;/source&amp;gt; → the scrip will import only bands of the specified Landsat scene directory&lt;br /&gt;
&lt;br /&gt;
== Post-Processing ==&lt;br /&gt;
&lt;br /&gt;
=== Natural color composites ===&lt;br /&gt;
&lt;br /&gt;
Creating natural (also known as true-) color composites, can be done by&lt;br /&gt;
&lt;br /&gt;
a) using {{cmd|i.landsat.rgb|version=64}} (GRASS 6.x) | {{cmd|i.colors.enhance|version=70}} (GRASS 7.x) to automatically balance the colors for the Red, Green and Blue bands&lt;br /&gt;
&lt;br /&gt;
or&lt;br /&gt;
&lt;br /&gt;
b) equalizing the colors on each of the Red, Green and Blue bands&lt;br /&gt;
&lt;br /&gt;
&amp;lt;ul&amp;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;
&amp;lt;/ul&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''Composites''' can then be produced with the {{cmd|r.composite}} module.&lt;br /&gt;
&lt;br /&gt;
'''Resetting the color tables''' of all bands back to normal greyscale can be done with a for loop:&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;
See also:&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat-8-data-in-grass-gis-7-rgb-composites-and-pan-sharpening/ Processing Landsat 8 data in GRASS GIS 7: RGB composites and pan sharpening]&lt;br /&gt;
&lt;br /&gt;
=== Create a 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 using the {{cmd|i.landsat.toar}} module. For details, refer to USGS' [http://landsat.usgs.gov/Landsat_Metadata_Changes.php Landsat Filename and Metadata Changes] dedicated page. For Landsat 8, see also [http://landsat.usgs.gov/about_LU_Vol_7_Issue_4.php#3a here].&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
 i.landsat.toar input_prefix=$BASE output_prefix=${BASE}_toar metfile=${BASE}_MTL.txt&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note, the resulting temperature map is in Kelvin:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&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;
&amp;lt;/source&amp;gt;&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|version=64}}. 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}}:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;i.landsat.acca -f input_prefix=226_62_toar. output=226_62.acca_cloudmask&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Mask out the clouds:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;r.mapcalc &amp;quot;MASK = if(isnull($BASE.acca_cloudmask))&amp;quot;&amp;lt;/source&amp;gt;&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:&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&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&amp;lt;/source&amp;gt;&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;
== Time series analysis ==&lt;br /&gt;
&lt;br /&gt;
See [[Time series]]&lt;br /&gt;
&lt;br /&gt;
== Sources ==&lt;br /&gt;
&lt;br /&gt;
* [http://landsat.usgs.gov/tools_access_all_faqs.php Frequently Asked Questions about the Landsat Missions]&lt;br /&gt;
* [https://landsat8portal.eo.esa.int/portal/ European LANDSAT 8 data in near-realtime]&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat8-data-in-grass-gis-7/ Processing Landsat 8 data in GRASS GIS 7: Import and visualization]&lt;br /&gt;
* [http://courses.neteler.org/processing-landsat-8-data-in-grass-gis-7-rgb-composites-and-pan-sharpening/ Processing Landsat 8 data in GRASS GIS 7: RGB composites and pan sharpening]&lt;br /&gt;
&lt;br /&gt;
[[Category: Documentation]]&lt;br /&gt;
[[Category: FAQ]]&lt;br /&gt;
[[Category: Landsat]]&lt;br /&gt;
[[Category: Image processing]]&lt;br /&gt;
[[Category: Import]]&lt;br /&gt;
[[Category: Digital Numbers]]&lt;br /&gt;
[[Category: Radiance]]&lt;br /&gt;
[[Category: Reflectance]]&lt;br /&gt;
[[Category: Geodata]]&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Convert_degree&amp;diff=22118</id>
		<title>Convert degree</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Convert_degree&amp;diff=22118"/>
		<updated>2015-12-01T10:39:25Z</updated>

		<summary type="html">&lt;p&gt;⚠️Andbal: restored link to external site&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Converting between sexagesimal and decimal degree notations ==&lt;br /&gt;
&lt;br /&gt;
=== Converting from sexagesimal (DMS) to decimal degree notation ===&lt;br /&gt;
&lt;br /&gt;
To convert from sexagesimal degree to decimal degree notation the degree&lt;br /&gt;
value is kept, the minutes value is divided by 60, the seconds value is divided&lt;br /&gt;
by 3600 and the results are summed. An example of a conversion of 12 degree&lt;br /&gt;
45 min 50 sec north (usually denotes as 12:45:50N):&lt;br /&gt;
&lt;br /&gt;
     12 degree -&amp;gt; 12.00000 degree&lt;br /&gt;
     45 min / 60 -&amp;gt; 0.75000 degree&lt;br /&gt;
     50 sec / 3600 -&amp;gt; 0.01389 degree&lt;br /&gt;
     ---------------- addition of values ----------&lt;br /&gt;
     12.76389 degree (decimal degree notation)&lt;br /&gt;
&lt;br /&gt;
=== Converting from decimal to sexagesimal degree notation ===&lt;br /&gt;
&lt;br /&gt;
To convert from decimal degree to sexagesimal degree notation the calculation is&lt;br /&gt;
done as illustrated by an example for a conversion of 12.7689 degree (decimal&lt;br /&gt;
notation):&lt;br /&gt;
&lt;br /&gt;
     12.76389 -&amp;gt; 12 degree, remainder 0.76389&lt;br /&gt;
     0.76389 * 60 -&amp;gt; 45 minutes, remainder 0.8334&lt;br /&gt;
     0.8334 * 60 -&amp;gt; 50 seconds&lt;br /&gt;
     ----------------------------------------------&lt;br /&gt;
     12:45:50N degree (sexagesimal degree notation)&lt;br /&gt;
&lt;br /&gt;
The N for north has to be added to complete the sexagesimal notation, since&lt;br /&gt;
the value is positive in decimal notation. GRASS supports both notations for&lt;br /&gt;
latitude-longitude coordinate system.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
* https://www.fcc.gov/encyclopedia/degrees-minutes-seconds-tofrom-decimal-degrees&lt;br /&gt;
* [[AddOns#Miscellaneous_Add-ons|utm_which_zone.sh]], a shell script to determine UTM zone from Lat/Lon input&lt;br /&gt;
&lt;br /&gt;
[[Category: FAQ]]&lt;/div&gt;</summary>
		<author><name>⚠️Andbal</name></author>
	</entry>
</feed>