-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use c.to("km/s") for speed of light and re-standardize astropy constants imports. * Lazy load configuration using _config.py and testing. * fix version in __init__ and __all__ * Remove starfish test config ad fix config tests. * Test lazy load. xfail as not working correctly. * Fix cache location config. * Lint
- Loading branch information
1 parent
fbef82e
commit eeff318
Showing
25 changed files
with
199 additions
and
112 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,32 @@ | ||
__version__ = "0.6-beta" | ||
__all__ = [ | ||
"atmosphere", | ||
"io_module", | ||
"Qcalculator", | ||
"resample", | ||
"snr_normalization", | ||
"utilities", | ||
] | ||
|
||
# Read the users config.yaml file. | ||
# If it doesn't exist, print a useful help message | ||
__version__ = "1.0rc1" | ||
|
||
import os | ||
import warnings | ||
|
||
import yaml | ||
|
||
try: | ||
with open("config.yaml") as f: | ||
config = yaml.safe_load(f) | ||
except FileNotFoundError as e: | ||
default = __file__[:-11] + "config.yaml" | ||
import warnings | ||
from ._config import Config | ||
|
||
if os.path.exists("config.yaml"): | ||
config = Config("config.yaml") | ||
else: | ||
base_dir = os.path.dirname(__file__) | ||
default = os.path.join(base_dir, "config.yaml") | ||
warnings.warn( | ||
"Using the default config.yaml file located at {0}. " | ||
"This is likely NOT what you want. Please create a similar " | ||
"'config.yaml' file in your current working directory.".format(default), | ||
UserWarning, | ||
) | ||
with open(default) as f: | ||
config = yaml.safe_load(f) | ||
config = Config(default) | ||
|
||
# Read the YAML variables into package-level dictionaries to be used by the other programs. | ||
name = config["name"] | ||
paths = config["paths"] | ||
bands = config["bands"] | ||
custom_bands = config["custom_bands"] | ||
atmmodel = config["atmmodel"] | ||
cache = config["cache"] | ||
|
||
# Turn list into path | ||
for key, value in paths.items(): | ||
if isinstance(value, list): | ||
paths[key] = os.path.join(*value) | ||
|
||
if (cache["location"] is None) or (cache["location"] == "None"): | ||
cache["location"] = None # Disables caching | ||
else: | ||
cache["location"] = os.path.join(*cache["location"]) | ||
__all__ = [ | ||
"atmosphere", | ||
"broaden", | ||
"config", | ||
"corrections", | ||
"legacy", | ||
"io_module", | ||
"Qcalculator", | ||
"resample", | ||
"snr_normalization", | ||
"utilities", | ||
] |
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,48 @@ | ||
import yaml | ||
import os | ||
|
||
|
||
class Config: | ||
""" | ||
This is a class to allow lazy-loading of config files. This means that the atributes are only read from the file | ||
when accessed in the code, allowing for changes in the file without having to restart the python instance | ||
""" | ||
|
||
def __init__(self, filename): | ||
self.filename = filename | ||
# Format string for saving/reading orders | ||
self.specfmt = "s{}_o{}" | ||
|
||
def __getitem__(self, item): | ||
with open(self.filename) as f: | ||
base = yaml.safe_load(f) | ||
return base[item] | ||
|
||
def __getattribute__(self, item): | ||
# Short circuit on filename or else infinite recursion | ||
if item == 'filename': | ||
return super().__getattribute__(item) | ||
with open(self.filename) as f: | ||
base = yaml.safe_load(f) | ||
if item == 'paths': | ||
paths = base['paths'] | ||
for key, value in paths.items(): | ||
if isinstance(value, list): | ||
paths[key] = os.path.join(*value) | ||
return paths | ||
elif item == 'bands': | ||
return base['bands'] | ||
elif item == 'custom_bands': | ||
return base['custom_bands'] | ||
elif item == 'atmmodel': | ||
return base['atmmodel'] | ||
elif item == 'cache': | ||
cache = base['cache'] | ||
if (cache["location"] is None) or (cache["location"] == "None"): | ||
cache["location"] = None # Disables caching | ||
else: | ||
if isinstance(cache["location"], list): | ||
cache["location"] = os.path.join(*cache["location"]) | ||
return cache | ||
else: | ||
return super().__getattribute__(item) |
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 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
Oops, something went wrong.