-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Created tests for USGS Spectral Library Version 7 convert function (#146
) * 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
Showing
19 changed files
with
15,866 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]> | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.