1 / 17

GRASS and Python Testing v.transect.py

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.

molimo
Download Presentation

GRASS and Python Testing v.transect.py

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. GRASS and PythonTesting v.transect.py John Lloyd MEA582 Fall 2011 Final Project jlloyd@ncsu.edu John Lloyd MEA582 Final Project

  2. Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Cases • Results • Conclusions John Lloyd MEA582 Final Project

  3. 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

  4. Presentation Outline • Introduction • Environment Setup • Linux • Windows • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project

  5. 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

  6. 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

  7. 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

  8. Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project

  9. 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

  10. Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project

  11. 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

  12. 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

  13. 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

  14. 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

  15. 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

  16. Presentation Outline • Introduction • Environment Setup • Linux • Windows • Running Python • v.transects.py • Testing • Methodology • Test Sets • Results • Conclusions John Lloyd MEA582 Final Project

  17. 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

More Related