Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ ignore = E501, W605, W503, E203, F401
#,E402, E203,E722
#F841, E402, E722
#ignore = E203, E266, E501, W503, F403, F401
max-line-length = 88
max-line-length = 79
max-complexity = 18
select = B,C,E,F,W,T4,B9
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/ambv/black
rev: 21.7b0
rev: stable
hooks:
- id: black
language_version: python3.6
- repo: https://gitlab.com/pycqa/flake8
rev: 3.9.2
rev: 3.7.9
hooks:
- id: flake8
11 changes: 4 additions & 7 deletions aurora/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
BANDS_256_FILE = BAND_SETUP_PATH.joinpath("bs_256.cfg")



from .metadata import (
Window,
Station,
Window,
Station,
Channel,
Run,
Stations,
Band,
Decimation,
Decimation,
Regression,
Estimator,
DecimationLevel,
Expand All @@ -31,6 +30,4 @@
"Estimator",
"DecimationLevel",
"Processing",
]


]
43 changes: 23 additions & 20 deletions aurora/config/config_creator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,52 @@


class ConfigCreator:

def __init__(self, **kwargs):
default_config_path = Path("config")
self.config_path = kwargs.get("config_path", default_config_path)




def create_run_processing_object(
self, station_id=None, run_id=None, mth5_path=None, sample_rate=1,
input_channels=["hx", "hy"], output_channels=["hz", "ex", "ey"],
estimator=None,
emtf_band_file=BANDS_DEFAULT_FILE, **kwargs):
self,
station_id=None,
run_id=None,
mth5_path=None,
sample_rate=1,
input_channels=["hx", "hy"],
output_channels=["hz", "ex", "ey"],
estimator=None,
emtf_band_file=BANDS_DEFAULT_FILE,
**kwargs,
):
"""
Create a default processing object

:return: DESCRIPTION
:rtype: TYPE

"""
processing_id = f"{station_id}-{run_id}"
processing_obj = Processing(id=processing_id, **kwargs)

if not isinstance(run_id, list):
run_id = [run_id]

runs = []
for run in run_id:
run_obj = Run(
id=run_id,
input_channels=input_channels,
output_channels=output_channels,
sample_rate=sample_rate)
sample_rate=sample_rate,
)
runs.append(run_obj)

station_obj = Station(id=station_id, mth5_path=mth5_path)
station_obj.runs = runs

processing_obj.stations.local = station_obj
if emtf_band_file is not None:
processing_obj.read_emtf_bands(emtf_band_file)

for key in sorted(processing_obj.decimations_dict.keys()):
if key in [0, "0"]:
d = 1
Expand All @@ -66,18 +70,18 @@ def create_run_processing_object(
decimation_obj.decimation.sample_rate = sr
decimation_obj.input_channels = input_channels
decimation_obj.output_channels = output_channels
#set estimator if provided as kwarg
# set estimator if provided as kwarg
if estimator:
try:
decimation_obj.estimator.engine = estimator["engine"]
except KeyError:
pass
return processing_obj

def to_json(self, processing_obj, path=None, nested=True, required=False):
"""
Write a processing object to path

:param path: DESCRIPTION
:type path: TYPE
:param processing_obj: DESCRIPTION
Expand All @@ -86,10 +90,9 @@ def to_json(self, processing_obj, path=None, nested=True, required=False):
:rtype: TYPE

"""
json_fn = processing_obj.json_fn()#config_id + "_run_config.json"
if path is None:
json_fn = processing_obj.json_fn()#config_id + "_run_config.json"
json_fn = processing_obj.json_fn() # config_id + "_run_config.json"
self.config_path.mkdir(exist_ok=True)
path = self.config_path.joinpath(json_fn)
with open(path, "w") as fid:
fid.write(processing_obj.to_json(nested=nested, required=required))
fid.write(processing_obj.to_json(nested=nested, required=required))
2 changes: 1 addition & 1 deletion aurora/config/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@
"Estimator",
"DecimationLevel",
"Processing",
]
]
5 changes: 2 additions & 3 deletions aurora/config/metadata/band.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ class Band(Base):
__doc__ = write_lines(attr_dict)

def __init__(self, **kwargs):

super().__init__(attr_dict=attr_dict, **kwargs)

# should add properties to calculate index from frequency and vise-versa

# should add properties to calculate index from frequency and vise-versa
4 changes: 0 additions & 4 deletions aurora/config/metadata/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,3 @@ class Channel(Base):

def __init__(self, **kwargs):
super().__init__(attr_dict=attr_dict, **kwargs)




10 changes: 2 additions & 8 deletions aurora/config/metadata/decimation.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,9 @@ class Decimation(Base):
__doc__ = write_lines(attr_dict)

def __init__(self, **kwargs):

super().__init__(attr_dict=attr_dict, **kwargs)

@property
def decimated_sample_rate(self):
return self.sample_rate / self.factor






65 changes: 27 additions & 38 deletions aurora/config/metadata/decimation_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ class DecimationLevel(Base):
__doc__ = write_lines(attr_dict)

def __init__(self, **kwargs):

self.window = Window()
self.decimation = Decimation()
self.regression = Regression()
self.estimator = Estimator()

self._bands = []

super().__init__(attr_dict=attr_dict, **kwargs)

@property
def bands(self):
"""
get bands, something weird is going on with appending.

"""
return_list = []
for band in self._bands:
Expand All @@ -53,88 +53,86 @@ def bands(self):
b = band
return_list.append(b)
return return_list

@bands.setter
def bands(self, value):
"""
Set bands make sure they are a band object

:param value: list of bands
:type value: list, Band

"""

if isinstance(value, Band):
self._bands = [value]

elif isinstance(value, list):
self._bands = []
for obj in value:
if not isinstance(obj, (Band, dict)):
raise TypeError(
f"List entry must be a Band object not {type(obj)}"
)
raise TypeError(f"List entry must be a Band object not {type(obj)}")
if isinstance(obj, dict):
band = Band()
band.from_dict(obj)

else:
band = obj

self._bands.append(band)
else:
raise TypeError(f"Not sure what to do with {type(value)}")

def add_band(self, band):
"""
add a band
"""

if not isinstance(band, (Band, dict)):
raise TypeError(
f"List entry must be a Band object not {type(band)}"
)
raise TypeError(f"List entry must be a Band object not {type(band)}")
if isinstance(band, dict):
obj = Band()
obj.from_dict(band)

else:
obj = band

self._bands.append(obj)



@property
def lower_bounds(self):
"""
get lower bounds index values into an array.
"""

return np.array(sorted([band.index_min for band in self.bands]))

@property
def upper_bounds(self):
"""
get upper bounds index values into an array.
"""

return np.array(sorted([band.index_max for band in self.bands]))

def frequency_bands_obj(self):
from aurora.time_series.frequency_band_helpers import df_from_bands
from aurora.time_series.frequency_band import FrequencyBands

emtf_band_df = df_from_bands(self.bands)
frequency_bands = FrequencyBands()
frequency_bands.from_emtf_band_df(emtf_band_df,
self.decimation.level,
self.decimation.sample_rate,
self.window.num_samples)
frequency_bands.from_emtf_band_df(
emtf_band_df,
self.decimation.level,
self.decimation.sample_rate,
self.window.num_samples,
)
return frequency_bands


@property
def windowing_scheme(self):
from aurora.time_series.windowing_scheme import WindowingScheme

windowing_scheme = WindowingScheme(
taper_family=self.window.type,
num_samples_window=self.window.num_samples,
Expand Down Expand Up @@ -166,12 +164,3 @@ def windowing_scheme(self):
# output["prewhitening_type"] = self.prewhitening_type
# output["extra_pre_fft_detrend_type"] = self.extra_pre_fft_detrend_type
# return output









2 changes: 1 addition & 1 deletion aurora/config/metadata/estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class Estimator(Base):
__doc__ = write_lines(attr_dict)

def __init__(self, **kwargs):

super().__init__(attr_dict=attr_dict, **kwargs)
Loading