-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add configuration file rather than constant scattered in code base
- Loading branch information
1 parent
7f120bb
commit b5a8141
Showing
16 changed files
with
6,251 additions
and
1,110 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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Spectrai Configuration | ||
|
||
# ~/data_spectrai/ | ||
# |__ raw/ | ||
# | |__ astorga_arg_2018/ | ||
# | |__ spectra/ | ||
# | |__ measurements/2015-xrf-results-mean-and-errors.xls | ||
# | |__ schmitter_vnm_2010/ | ||
# | |__ mir-models/ | ||
# |__ 20090215-soil-database-mirs.xls | ||
# | |__ vietnam-petra/ | ||
# |__ kssl/ | ||
# |__ normalized/ | ||
# |__ spectra/ | ||
|
||
[DATA_ASTORGA_ARG] | ||
SPECTRA = "~/data_spectrai/raw/astorga_arg_2018/spectra" | ||
MEASUREMENTS = "~/data_spectrai/raw/astorga_arg_2018/measurements/2015-xrf-results-mean-and-errors.xls" | ||
|
||
[DATA_SCHMITTER_VNM] | ||
SPECTRA = "~/data_spectrai/raw/schmitter_vnm_2010/mir-models" | ||
SPECTRA_REP = "~/data_spectrai/raw/schmitter_vnm_2010/vietnam_petra" | ||
MEASUREMENTS = "~/data_spectrai/raw/schmitter_vnm_2010/mir-models/20090215-soil-database-mirs.xls" | ||
|
||
[DATA_KSSL] | ||
HOME = "~/data_spectrai/kssl" | ||
NORM = "~/data_spectrai/kssl/normalized" | ||
SPECTRA = "~/data_spectrai/kssl/spectra" | ||
DB_NAME = "All_Spectra_Access_Portable 2-20-20.accdb" |
2,685 changes: 2,685 additions & 0 deletions
2,685
examples/_legacy/.ipynb_checkpoints/kssl-predictions-playgound-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
2,823 changes: 2,823 additions & 0 deletions
2,823
examples/_legacy/kssl-predictions-playgound.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
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
802 changes: 282 additions & 520 deletions
802
examples/data_loading/.ipynb_checkpoints/0-importing-data-checkpoint.ipynb
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
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,43 @@ | ||
from pathlib import Path | ||
import toml | ||
|
||
|
||
# | ||
# Config | ||
# | ||
def load_config(path=None): | ||
"""Loads as dictionary from configuration file.""" | ||
default_path = Path('~/.spectrai_config/config.toml').expanduser() | ||
if not path and default_path.is_file(): | ||
path = default_path | ||
assert path, 'Either path argument or ~/.spectrai_config/config.toml is required.' | ||
|
||
config = toml.load(path) | ||
assert config, "Unable to parse config file" | ||
|
||
return config | ||
|
||
|
||
def get_astorga_config(): | ||
config = load_config()['DATA_ASTORGA_ARG'] | ||
config = path_expand(config) | ||
return (config['SPECTRA'], config['MEASUREMENTS']) | ||
|
||
|
||
def get_schmitter_config(): | ||
config = load_config()['DATA_SCHMITTER_VNM'] | ||
config = path_expand(config) | ||
return (config['SPECTRA'], config['SPECTRA_REP'], config['MEASUREMENTS']) | ||
|
||
|
||
def get_kssl_config(): | ||
config = load_config()['DATA_KSSL'] | ||
config = path_expand(config, exclude = ['DB_NAME']) | ||
return (config['HOME'], config['NORM'], config['SPECTRA'], config['DB_NAME']) | ||
|
||
|
||
def path_expand(config, exclude=[]): | ||
for k, v in config.items(): | ||
if k not in exclude: | ||
config[k] = Path(v).expanduser() | ||
return config |
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
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
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 was deleted.
Oops, something went wrong.
Empty file.
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,11 @@ | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
|
||
|
||
def plot_spectra(X, X_names, figsize=(18, 5), sample=20): | ||
with plt.style.context(('ggplot')): | ||
fig, ax = plt.subplots(figsize=figsize) | ||
idx = np.random.randint(X.shape[0], size=sample) | ||
ax.set_xlim(np.max(X_names), np.min(X_names)) | ||
plt.xlabel('Wavenumber') | ||
_ = ax.plot(X_names, X[idx, :].T) |