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

ISSUE #134 Support ECOStress Spectral Library #153

Closed
wants to merge 14 commits into from
18 changes: 9 additions & 9 deletions docs/source/mineral.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@
#
# 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
# 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.
# 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
# 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.

Mineral Classification API
*********************************
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add the following

.. autoclass:: pycoal.mineral.SpectalToAsterFileFormat
   :special-members:
   :members:

.. autoclass:: pycoal.mineral.FullSpectralLibrary7Convert
   :special-members:
   :members:


Expand Down
70 changes: 70 additions & 0 deletions examples/example_ecostress.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#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_ecostress.py -- a script which will generate envi .sli and .hdr convolved library
files of `ECOStress Spectral Library <https://speclib.jpl.nasa.gov/>`_

Dependencies
`ECOStress Spectral Library <https://speclib.jpl.nasa.gov/>`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should be more descriptive here.
The downloads page includes the following artifacts

All Lunar (17 files)
All Man-made (72 files)
All Meteorites (59 files)
All Minerals (3104 files)
All Non-Photosynthetic Vegetation (62 files)
All Rock (647 files)
All Soil (120 files)
All Vegetation (1031 files)
All Water (9 files)

Or

ALL Spectra (5104 files)

Which of the above do we download?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALL Spectra, I have now made a comment in the code to specify

must be downloaded to the examples directory

All files generated will be located in the examples directory


@author: COAL Developers

@copyright: 2018 COAL Developers. All rights reserved.

@license: GNU General Public License version 2

@contact: [email protected]
'''

#!/usr/bin/python

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

#Path to EcoStress Spectral Library
if (len(sys.argv) == 1):
raise Exception('Must pass in location of EcoStress Spectral Library')
library_filename = sys.argv[1]
#Loop through and edit all .spectrum.txt files
for root, dir, files in os.walk(library_filename):
dir[:] = [d for d in dir]
for items in fnmatch.filter(files, "*spectrum.txt"):
#Remove vegation files because their format causes errors in the Spectral class
if "vegetation" in items:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remind me again why we are not using the vegetation indexes?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On lines 4 & 5 Vegetation Spectra has Genus and Species instead of Subclass and Particle Size entries like other Spectra.
The ASTER conversion function throws an error when it reads lines 4 & 5 so I just removed the vegetation files.
If we wanted to read Vegetation files then we would need to change lines 4 & 5 to give them a subclass and particle size with a default value like I did with Spectral 7 conversion function. I know you said you prefer if we not plug in default values. Let me know if you want me to change this, it wouldn't be very hard

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manmade.concrete.constructionconcrete.solid.all.0598uuucnc.jhu.becknic.spectrum.txt

Name: Construction Concrete
Type: manmade
Class: Concrete
Subclass: Construction Concrete
Particle Size: Solid
Sample No.: 0598UUUCNC

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nonphotosyntheticvegetation.bark.abies.concolor.all.vh311.ucsb.asdnicolet.spectrum.txt

Name: Abies concolor bark
Type: non photosynthetic vegetation
Class: bark
Genus: Abies
Species: concolor
Sample No.: VH311

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, ideally we want to be able to use every spectra from the entire ECOSTRESS library. If you could implement the suggested workaround for including the vegetation files it would be appreciated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lewismc Ok, I fixed it so it works with Vegetation files. I added the Subclass and Particle Size and removed the Genus and Species. It can now convert the entire EcoStress library

os.remove(library_filename + '/' + items);
else:
input_file = open(library_filename + '/' + items, "r", encoding="utf8", errors='ignore')
contents = input_file.readlines()
input_file.close()
#Add 5 '\n' after description
contents.insert(11, '\n\n\n\n\n')
input_file = open(library_filename + '/' + items, "w", encoding="utf8", errors='ignore')
contents = "".join(contents)
input_file.write(contents)
input_file.close()

ecoStress = mineral.AsterConversion()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change ecoStress to ecostress, thanks

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you address this then we can think about ripping this code out of the example and embedding it in conversion.py under a new Class the same as the other conversion functions.

ecoStress.convert(library_filename,'dataEcoStress.db','ECO_01_SPLIB.envi')