Skip to content

Commit

Permalink
adding in how features are accessed and organized
Browse files Browse the repository at this point in the history
  • Loading branch information
kujaku11 committed Jan 31, 2025
1 parent 929d36c commit 9283c87
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 50 deletions.
13 changes: 13 additions & 0 deletions mth5/groups/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Import all Group objects
"""

## !!! DO NOT CHANGE ORDER !!!
from .base import BaseGroup
from .reports import ReportsGroup
Expand All @@ -17,6 +18,13 @@
AuxiliaryDataset,
)
from .run import RunGroup
from .features import (
MasterFeaturesGroup,
FeatureGroup,
FeatureTSRunGroup,
FeatureFCRunGroup,
FeatureDecimationGroup,
)
from .station import MasterStationGroup, StationGroup
from .survey import MasterSurveyGroup, SurveyGroup
from .experiment import ExperimentGroup
Expand All @@ -41,6 +49,11 @@
"SurveyGroup",
"ReportsGroup",
"StandardsGroup",
"MasterFeaturesGroup",
"FeatureGroup",
"FeatureTSRunGroup",
"FeatureFCRunGroup",
"FeatureDecimationGroup",
"StationGroup",
"MasterStationGroup",
"MasterSurveyGroup",
Expand Down
2 changes: 2 additions & 0 deletions mth5/groups/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
Channel,
FC,
)
from mt_metadata.features import Feature
from mt_metadata.base import Base

from mth5.helpers import get_tree, validate_name
Expand All @@ -41,6 +42,7 @@
meta_classes["FCDecimation"] = Decimation
meta_classes["FCChannel"] = Channel
meta_classes["FC"] = FC
meta_classes["Feature"] = Feature


# =============================================================================
Expand Down
98 changes: 48 additions & 50 deletions mth5/groups/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,7 @@
import pandas as pd
import h5py

from mth5.groups import BaseGroup, FeatureChannelDataset, RunGroup

# from mth5.groups import FCGroup
from mth5.groups import BaseGroup, FCChannelDataset, RunGroup

from mth5.helpers import validate_name
from mth5.utils.exceptions import MTH5Error
Expand All @@ -31,7 +29,7 @@
"""feature -> FeatureMasterGroup -> FeatureGroup -> DecimationLevelGroup -> ChannelGroup -> FeatureChannelDataset"""


class MasterFeatureGroup(BaseGroup):
class MasterFeaturesGroup(BaseGroup):
"""
Master group to hold various features associated with either Fourier
Coefficients or time series.
Expand Down Expand Up @@ -407,52 +405,52 @@ def update_metadata(self):
)
self.write_metadata()

def supports_aurora_processing_config(
self, processing_config, remote
) -> bool:
"""
An "all-or-nothing" check: Return True if every (valid) decimation needed to satisfy the processing_config
is available in the FCGroup (self) otherwise return False (and we will build all FCs).
Logic:
1. Get a list of all fc groups in the FCGroup (self)
2. Loop the processing_config decimations, checking if there is a corresponding, already built FCDecimation
in the FCGroup.
Parameters
----------
processing_config: aurora.config.metadata.processing.Processing
remote: bool
Returns
-------
"""
pre_existing_fc_decimation_ids_to_check = self.groups_list
levels_present = np.full(processing_config.num_decimation_levels, False)
for i, dec_level in enumerate(processing_config.decimations):

# Quit checking if dec_level wasn't there
if i > 0:
if not levels_present[i - 1]:
return False

# iterate over existing decimations
for fc_decimation_id in pre_existing_fc_decimation_ids_to_check:
fc_dec_group = self.get_decimation_level(fc_decimation_id)
fc_decimation = fc_dec_group.metadata
levels_present[i] = fc_decimation.has_fcs_for_aurora_processing(
dec_level, remote
)

if levels_present[i]:
pre_existing_fc_decimation_ids_to_check.remove(
fc_decimation_id
) # no need to check this one again
break # break inner for-loop over decimations

return levels_present.all()
# def supports_aurora_processing_config(
# self, processing_config, remote
# ) -> bool:
# """

# An "all-or-nothing" check: Return True if every (valid) decimation needed to satisfy the processing_config
# is available in the FCGroup (self) otherwise return False (and we will build all FCs).

# Logic:
# 1. Get a list of all fc groups in the FCGroup (self)
# 2. Loop the processing_config decimations, checking if there is a corresponding, already built FCDecimation
# in the FCGroup.

# Parameters
# ----------
# processing_config: aurora.config.metadata.processing.Processing
# remote: bool

# Returns
# -------

# """
# pre_existing_fc_decimation_ids_to_check = self.groups_list
# levels_present = np.full(processing_config.num_decimation_levels, False)
# for i, dec_level in enumerate(processing_config.decimations):

# # Quit checking if dec_level wasn't there
# if i > 0:
# if not levels_present[i - 1]:
# return False

# # iterate over existing decimations
# for fc_decimation_id in pre_existing_fc_decimation_ids_to_check:
# fc_dec_group = self.get_decimation_level(fc_decimation_id)
# fc_decimation = fc_dec_group.metadata
# levels_present[i] = fc_decimation.has_fcs_for_aurora_processing(
# dec_level, remote
# )

# if levels_present[i]:
# pre_existing_fc_decimation_ids_to_check.remove(
# fc_decimation_id
# ) # no need to check this one again
# break # break inner for-loop over decimations

# return levels_present.all()


class FeatureDecimationGroup(BaseGroup):
Expand Down
9 changes: 9 additions & 0 deletions mth5/groups/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
RunGroup,
TransferFunctionsGroup,
MasterFCGroup,
MasterFeaturesGroup,
)
from mth5.helpers import from_numpy_type
from mth5.utils.exceptions import MTH5Error
Expand Down Expand Up @@ -477,6 +478,7 @@ def __init__(self, group, station_metadata=None, **kwargs):
self._default_subgroup_names = [
"Transfer_Functions",
"Fourier_Coefficients",
"Features",
]
super().__init__(group, group_metadata=station_metadata, **kwargs)

Expand Down Expand Up @@ -521,6 +523,13 @@ def fourier_coefficients_group(self):
self.hdf5_group["Fourier_Coefficients"], **self.dataset_options
)

@property
def features_group(self):
"""Convinience method for /Station/Features"""
return MasterFeaturesGroup(
self.hdf5_group["Features"], **self.dataset_options
)

@property
def survey_metadata(self):
"""survey metadata"""
Expand Down
23 changes: 23 additions & 0 deletions tests/version_2/test_features.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
"""
Created on Fri Jan 31 13:31:22 2025
@author: jpeacock
"""

# =============================================================================
# Imports
# =============================================================================
from pathlib import Path
import unittest
from mth5.mth5 import MTH5

# =============================================================================


m = MTH5(file_version="0.2.0")
m.open_mth5(Path(__file__).parent.joinpath("test_feature.h5"))

survey_group = m.add_survey("top_survey")
station_group = m.add_station("mt01", survey="top_survey")
features_group = station_group.features_group

0 comments on commit 9283c87

Please sign in to comment.