Skip to content

Commit

Permalink
Created tests for USGS Spectral Library Version 7 convert function (#146
Browse files Browse the repository at this point in the history
)

* splib07

* spectral 7 converter start

* Splib 07 test one file

* Finished Spectral Version 7 convert

* Finish client changes to spectral convert function

* Condensed to one script

* Fix oswalk and other changes

* Remove duplicate spectra

* remove aster files

* Remove duplicate spectra

* Change to unknown

* Fix spelling

* Move convert function to mineral.py

* Fix band num

* Fix reload error travis ci

* update reload to py3

* remove unused import

* fix mineral import

* remove sys path import

* removed bad import statements

* Change spectra names to v7

* Worked on testing

* Allow cli to work with spectral v7 and v6

* Fix ftp url

* Remove ftp calls, fix overwrite error in nosetests

* Remove Spectral 7 library

* Repush with gitignore updated
  • Loading branch information
bdegley4789 authored and lewismc committed May 8, 2018
1 parent 2e9c882 commit 2c59bac
Show file tree
Hide file tree
Showing 19 changed files with 15,866 additions and 32 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# Floor, Boston, MA 02110-1301, USA.

# Use an official Python runtime as a base image (host debian:jessie)
FROM python:3-slim
FROM python:3.6-slim

MAINTAINER COAL Developers <[email protected]>

Expand Down
164 changes: 164 additions & 0 deletions examples/example07_mineral.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# Copyright (C) 2017-2018 COAL Developers
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
# encoding: utf-8

'''
example_mineral -- an example script which demonstrates COAL mineral classification
example_mineral provides a CLI which demonstrates how the COAL Mineral Classification
API provides methods for generating visible-light and mineral classified images.
Mineral classification can take hours to days depending on the size of the spectral
library and the available computing resources, so running a script in the background
is recommended. More reading an this example can be seen at
https://capstone-coal.github.io/docs#usage
@author: COAL Developers
@copyright: Copyright (C) 2017-2018 COAL Developers
@license: GNU General Public License version 2
@contact: [email protected]
'''

import sys
import os
from sys import path
from os import getcwd
import inspect

from argparse import ArgumentParser
from argparse import RawDescriptionHelpFormatter

import logging

import sys
import os
import pycoal
sys.path.insert(0, '../pycoal')
import mineral
import mining
import environment

__all__ = []

DEBUG = 1
TESTRUN = 0
PROFILE = 0


input_filename = 'avng.jpl.nasa.gov/AVNG_2015_data_distribution/L2/ang20150420t182050_rfl_v1e/ang20150420t182050_corr_v1e_img.hdr'
library_filename='../pycoal/tests/s07_AV95_envi.hdr'

def run_mineral(input_filename, library_filename):
'''
...
'''
logging.info("Starting mineral classification with input file '%s' and spectral library '%s'." %(input_filename, library_filename))
# path to save RGB image
rgb_filename = "ang20150420t182050_corr_v1e_img_rgb.hdr"

# path to save mineral classified image
classified_filename = "ang20150420t182050_corr_v1e_img_class.hdr"

# create a new mineral classification instance
mineral_classification = mineral.MineralClassification(library_filename)

# generate a georeferenced visible-light image
mineral_classification.to_rgb(input_filename, rgb_filename)

# generate a mineral classified image
mineral_classification.classify_image(input_filename, classified_filename)

def main(argv=None):
'''Command line options.'''
logging.basicConfig(filename='pycoal.log',level=logging.INFO, format='%(asctime)s %(message)s')
if argv is None:
argv = sys.argv
else:
sys.argv.extend(argv)

program_name = os.path.basename(sys.argv[0])
program_shortdesc = __import__('__main__').__doc__.split("\n")[1]
program_license = '''%s
VERSION %s
Copyright (C) 2017-2018 COAL Developers
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; version 2.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty
of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free
Software Foundation, Inc., 51 Franklin Street, Fifth
Floor, Boston, MA 02110-1301, USA.
USAGE
''' % (program_shortdesc, pycoal.version)

try:
# Setup argument parser
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-i", "--image", dest="image", default=input_filename, help="Input file to be processed [default: ang20150420t182050_corr_v1e_img.hdr]")
parser.add_argument("-s", "--slib", dest="slib", default=library_filename, help="Spectral Library filename [default: s07_AV95_envi.hdr]")

# Process arguments
args = parser.parse_args(['-i', input_filename, '-s', library_filename])
#args = parser.parse_args()

image = args.image
slib = args.slib

run_mineral(image, slib)

except KeyboardInterrupt:
### handle keyboard interrupt ###
return 0
except Exception as e:
if DEBUG or TESTRUN:
raise e
indent = len(program_name) * " "
sys.stderr.write(program_name + ": " + repr(e) + "\n")
sys.stderr.write(indent + " for help use --help")
return 2

if __name__ == "__main__":
if DEBUG:
sys.argv.append("-h")
sys.argv.append("-v")
sys.argv.append("-r")
if TESTRUN:
import doctest
doctest.testmod()
if PROFILE:
import cProfile
import pstats
profile_filename = 'example_mineral_profile.txt'
cProfile.run('main()', profile_filename)
statsfile = open("profile_stats.txt", "wb")
p = pstats.Stats(profile_filename, stream=statsfile)
stats = p.strip_dirs().sort_stats('cumulative')
stats.print_stats()
statsfile.close()
sys.exit(0)
sys.exit(main())
15 changes: 10 additions & 5 deletions examples/example_mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
TESTRUN = 0
PROFILE = 0

def run_mining(mineral_filename="ang20150420t182050_corr_v1e_img_class.hdr", mining_filename="ang20150420t182050_corr_v1e_img_class_mining.hdr"):
def run_mining(mineral_filename="ang20150420t182050_corr_v1e_img_class.hdr", mining_filename="ang20150420t182050_corr_v1e_img_class_mining.hdr",spectral_version="6"):
'''
...
'''
Expand All @@ -61,12 +61,15 @@ def run_mining(mineral_filename="ang20150420t182050_corr_v1e_img_class.hdr", min

# path to save mining classified image
mining_filename = "ang20150420t182050_corr_v1e_img_class_mining.hdr"

#Spectral Library Verison Number, Change to 7 if you want to use USGS Spectral Library Version 7
spectral_version = "6"

# create a new mining classification instance
mining_classification = mining.MiningClassification()

# generate a mining classified image
mining_classification.classify_image(mineral_filename, mining_filename)
mining_classification.classify_image(mineral_filename, mining_filename,spectral_version)

def main(argv=None): # IGNORE:C0111
'''Command line options.'''
Expand Down Expand Up @@ -106,15 +109,17 @@ def main(argv=None): # IGNORE:C0111
parser = ArgumentParser(description=program_license, formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-mi", "--mineral_input", dest="input", default='ang20150420t182050_corr_v1e_img_class.hdr', help="Input classified mineral file to be processed [default: ang20150420t182050_corr_v1e_img_class.hdr]")
parser.add_argument("-mo", "--mining_output", dest="output", default='ang20150420t182050_corr_v1e_img_class_mining.hdr', help="Output mining classified image filename [default: ang20150420t182050_corr_v1e_img_class_mining.hdr]")
parser.add_argument("-v", "--spectral_version", dest="spectral_version", default='6', help="USGS Spectral Library Version Number")

# Process arguments
args = parser.parse_args(['-mi', 'ang20150420t182050_corr_v1e_img_class.hdr', '-mo', 'ang20150420t182050_corr_v1e_img_class_mining.hdr'])
args = parser.parse_args(['-mi', 'ang20150420t182050_corr_v1e_img_class.hdr', '-mo', 'ang20150420t182050_corr_v1e_img_class_mining.hdr', '-v', '6'])
#args = parser.parse_args()

mineral_filename = args.input
mining_filename = args.output
spectral_version = args.spectral_version

run_mining(mineral_filename, mining_filename)
run_mining(mineral_filename, mining_filename, spectral_version)
except KeyboardInterrupt:
### handle keyboard interrupt ###
return 0
Expand Down Expand Up @@ -145,4 +150,4 @@ def main(argv=None): # IGNORE:C0111
stats.print_stats()
statsfile.close()
sys.exit(0)
sys.exit(main())
sys.exit(main())
46 changes: 46 additions & 0 deletions examples/example_spectral07.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/python
#Copyright (C) 2017-2018 COAL Developers
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty
# of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 51 Franklin Street, Fifth
# Floor, Boston, MA 02110-1301, USA.
# encoding: utf-8

'''
example_spectral07.py -- a script which will generate envi .sli and .hdr convolved library
files of `USGS Spectral Library Version 7 <https://speclab.cr.usgs.gov/spectral-lib.html>`_
Dependencies
`USGS Spectral Library Version 7 <https://speclab.cr.usgs.gov/spectral-lib.html>`_
must be downloaded and unzipped to the examples directory
All files generated will be located in the examples directory
@author: COAL Developers
@copyright: 2017-2018 COAL Developers. All rights reserved.
@license: GNU General Public License version 2
@contact: [email protected]
'''

import os
import sys
import pycoal
sys.path.insert(0, '../pycoal')
import mineral

usgs_convolved = mineral.FullSpectralLibrary7Convert()
usgs_convolved.convert('usgs_splib07')
4 changes: 3 additions & 1 deletion pycoal/cli/mining.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,20 @@ def main(argv=None): # IGNORE:C0111
parser = ArgumentParser(description=program_description,formatter_class=RawDescriptionHelpFormatter)
parser.add_argument("-mi", "--mineral_input", dest="input", help="Input classified mineral file to be processed")
parser.add_argument("-mo", "--mining_output", dest="output", help="Output mining classified image filename")
parser.add_argument("-v", "--spectral_version", dest="spectral_version", help="USGS Spectral Library Version Number (6 or 7)")

# Process arguments
args = parser.parse_args()

mineral_filename = args.input
mining_filename = args.output
spectral_version = args.spectral_version

# create a new mining classification instance
mining_classification = MiningClassification()

# generate a mining classified image
mining_classification.classify_image(mineral_filename, mining_filename)
mining_classification.classify_image(mineral_filename, mining_filename, spectral_version)


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 2c59bac

Please sign in to comment.