Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Created tests for USGS Spectral Library Version 7 convert function #146

Merged
merged 32 commits into from
May 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d9f451c
splib07
Mar 8, 2018
a9bb2d4
Merge pull request #1 from capstone-coal/master
Mar 15, 2018
840ff4b
spectral 7 converter start
Mar 15, 2018
b5505a6
Splib 07 test one file
Mar 17, 2018
7b10aa9
Finished Spectral Version 7 convert
Mar 21, 2018
0052322
Finish client changes to spectral convert function
Mar 28, 2018
0db1578
Condensed to one script
Mar 28, 2018
ddb47a3
Fix oswalk and other changes
Apr 3, 2018
3f662ad
Remove duplicate spectra
Apr 5, 2018
b8d6826
remove aster files
Apr 5, 2018
a715062
Remove duplicate spectra
Apr 5, 2018
6ef85ba
Merge branch 'master' of https://github.com/bdegley4789/pycoal
Apr 5, 2018
2fede26
Change to unknown
Apr 6, 2018
48a7063
Fix spelling
Apr 6, 2018
efd214c
Move convert function to mineral.py
Apr 12, 2018
ff7154b
Fix band num
Apr 12, 2018
c56ec34
Merge pull request #2 from capstone-coal/master
Apr 13, 2018
06e3df4
Fix reload error travis ci
Apr 13, 2018
8e8b46a
update reload to py3
Apr 13, 2018
73fb86c
remove unused import
Apr 13, 2018
27474dc
fix mineral import
Apr 13, 2018
ae4f4e1
remove sys path import
Apr 18, 2018
c7e4865
removed bad import statements
Apr 19, 2018
72b8b1a
Merge branch 'master' of https://github.com/bdegley4789/pycoal
Apr 19, 2018
c6d4feb
Change spectra names to v7
Apr 20, 2018
2e83470
Worked on testing
Apr 26, 2018
4d9db97
Allow cli to work with spectral v7 and v6
May 3, 2018
1e0ad1b
Fix ftp url
May 3, 2018
c7988a1
Remove ftp calls, fix overwrite error in nosetests
May 8, 2018
11592a3
Remove Spectral 7 library
May 8, 2018
c22132d
Merge pull request #3 from capstone-coal/master
May 8, 2018
7aa86d6
Repush with gitignore updated
May 8, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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