GRASS and PythonTesting v.transect.py

Download Report

Transcript GRASS and PythonTesting v.transect.py

John Lloyd
MEA582 Fall 2011
Final Project
[email protected]
John Lloyd MEA582 Final Project
1


Introduction
Environment Setup
◦ Linux
◦ Windows
◦ Running Python


v.transects.py
Testing
◦ Methodology
◦ Test Cases
◦ Results

Conclusions
John Lloyd MEA582 Final Project
2

Setup Linux and Windows Environments
◦ Built GRASS from source code

Python script
◦ v.transects.py
◦ Script partitions the shoreline
◦ Written by Eric Hardin

Tested script
◦ Linux
◦ Windows
John Lloyd MEA582 Final Project
3


Introduction
Environment Setup
◦ Linux
◦ Windows


v.transects.py
Testing
◦ Methodology
◦ Test Sets
◦ Results

Conclusions
John Lloyd MEA582 Final Project
4


Linux and Windows
Built GRASS from source code
◦
◦
◦
◦

Latest versions – not dependent on pre-built binaries
Debug problems by following execution in code
Add enhancements
Understand algorithms
GRASS Wiki http://grass.osgeo.org/wiki/Compile_and_Install
John Lloyd MEA582 Final Project
5

CentOS Linux 5.7
◦ Free distribution of Enterprise Linux
◦ Installed groups for software development


Downloaded prerequisite packages for GRASS
Downloaded GRASS source code
◦ (http://grass.osgeo.org/download/software.php

Compiled and Installed
John Lloyd MEA582 Final Project
6


Microsoft Windows7 Professional
OSGeo4W
◦ Installs binaries of open source geospatial software for
Windows

MinGW – Minimalist GNU for Windows
◦ A Unix like environment for Windows



Downloaded prerequisite packages for GRASS
Downloaded GRASS source code
Compiled and Installed
John Lloyd MEA582 Final Project
7


Introduction
Environment Setup
◦ Linux
◦ Windows
◦ Running Python


v.transects.py
Testing
◦ Methodology
◦ Test Sets
◦ Results

Conclusions
John Lloyd MEA582 Final Project
8
script

◦ Open Source
◦ Interpreted
◦ Contains GRASS APIs

Written by Eric Hardin
◦ Graduate Research Assistant at NCSU


Used to partition the shore along Outer Banks
Creates
◦ Lines/transects perpendicular to shore
◦ Or polygons along the shore

Parameters
◦ Distance between transects
◦ Length of transects
John Lloyd MEA582 Final Project
9


Introduction
Environment Setup
◦ Linux
◦ Windows
◦ Running Python


v.transects.py
Testing
◦ Methodology
◦ Test Sets
◦ Results

Conclusions
John Lloyd MEA582 Final Project
10
Start
Run Test
Cases in
Linux
Defects
found?
No
Run Test
Cases in
Windows
Yes
Defects
found?
Yes
Fix Defects
No
Finish
Yes
Layers
the
Same?
John Lloyd MEA582 Final Project
No
Compare
Linux/Windows
Output Layers
11

Parameter Verification Set
◦ Verifies detects and handles incorrect parameters
◦ 10 test cases

Shoreline Dataset Verification Set
◦ Nags Head shoreline in NC State Plane
◦ 9 test cases

Polylines of Various Shapes Set
◦ Polylines not representative of shorelines
◦ 12 test cases

WGS84 Set
◦ Data in the WGS84 projection
◦ 3 test cases
John Lloyd MEA582 Final Project
12

Parameter defects
◦ Before: ValueError: invalid literal for float():
◦ After: ERROR: Invalid transect_spacing value.

xxx
Windows Compatibility Defects
◦ ValueError: close_fds is not supported on Windows platforms
◦ ERROR: Unable to open ASCII file
◦ Transects along network of lines failed in Windows but passed in Linux

Logic defects
◦ Output layer always correct layer if produced
John Lloyd MEA582 Final Project
13
50m Transects along Shore
Transects around circle
50m Polygons along Shore
Transects along in street network
(created in Linux only)
John Lloyd MEA582 Final Project
14
Example 1. Changed Temporary File Creation System Call
####################################
# write transects
def writeTransects( transects, output ):
transects_str = ''
for transect in transects:
transects_str += '\n'.join( [ 'L 2\n'+' '.
join(map(str,end_points[0]))
+'\n'+' '.join(map(str,end_points[1]))+
'\n' for end_points in transect ] )
a = tempfile.NamedTemporaryFile()
a.write( transects_str )
a.seek(0)
grass.run_command('v.in.ascii', flags='n', input=a.name,
output=output, format='standard')
a.close()
####################################
# write transects
def writeTransects( transects, output ):
transects_str = ''
for transect in transects:
transects_str += '\n'.join( [ 'L 2\n'+' '.
join(map(str,end_points[0]))
+'\n'+' '.join(map(str,end_points[1]))+
'\n' for end_points in transect ] )
# JL Rewrote Temporary File Logic for Windows
_, temp_path = tempfile.mkstemp()
a = open(temp_path, 'w')
a.write( transects_str )
a.seek(0)
a.close()
grass.run_command('v.in.ascii', flags='n', input=temp_path,
output=output, format='standard')
Example 2. Added Additional Parameter Validation
transect_spacing = float(options['transect_spacing'])
# JL Handling Invalid transect_spacing parameter
try:
transect_spacing = float(options['transect_spacing'])
except:
grass.fatal(_("Invalid transect_spacing value."))
if transect_spacing == 0.0:
grass.fatal(_("Zero invalid transect_spacing value."))
John Lloyd MEA582 Final Project
15


Introduction
Environment Setup
◦ Linux
◦ Windows
◦ Running Python


v.transects.py
Testing
◦ Methodology
◦ Test Sets
◦ Results

Conclusions
John Lloyd MEA582 Final Project
16

Setting up environment from GRASS source
◦ Problems encountered
 Linux - missing packages
 Windows - environment variables for python
◦ Advantages of build from source not realized

v.transect.py
◦ Previous testing eliminated logic defects
◦ Special testing for Windows needed
◦ Now fit for multiple environment and applications
John Lloyd MEA582 Final Project
17