170 likes | 371 Views
GRASS and Python Testing v.transect.py. John Lloyd MEA582 Fall 2011 Final Project jlloyd@ncsu.edu. Presentation Outline. Introduction Environment Setup Linux Windows Running Python v.transects.py Testing Methodology Test Cases Results Conclusions. Introduction.
E N D
GRASS and PythonTesting v.transect.py John Lloyd MEA582 Fall 2011 Final Project jlloyd@ncsu.edu John Lloyd MEA582 Final Project
Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Cases • Results • Conclusions John Lloyd MEA582 Final Project
Introduction • 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
Presentation Outline • Introduction • Environment Setup • Linux • Windows • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project
Environment Setup • 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
Environment Setup - Linux • 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
Environment Setup - Windows • 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
Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project
v.transects.py • 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
Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project
Testing Methodology Defects found? Run Test Cases in Linux Run Test Cases in Windows Start No Yes Defects found? Fix Defects Yes No No Layers the Same? Compare Linux/Windows Output Layers Finish Yes John Lloyd MEA582 Final Project
Test Sets • 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
Test Results • Parameter defects • Before: ValueError: invalid literal for float(): xxx • After: ERROR: Invalid transect_spacing value. • 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
Selection of Inputs and Results 50m Transects along Shore 50m Polygons along Shore Transects around circle Transects along in street network (created in Linux only) John Lloyd MEA582 Final Project
Changes made to v.transects.py 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 # 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.")) transect_spacing = float(options['transect_spacing']) John Lloyd MEA582 Final Project
Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project
Conclusions • 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