This repository has been archived by the owner on May 10, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba6ddfc
commit 20500d4
Showing
4 changed files
with
226 additions
and
17 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
40 changes: 40 additions & 0 deletions
40
lc_classifier/features/extractors/elasticc_metadata_extractor.py
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,40 @@ | ||
import pandas as pd | ||
from typing import Tuple | ||
from functools import lru_cache | ||
from ..core.base import FeatureExtractor | ||
|
||
|
||
class ElasticcMetadataExtractor(FeatureExtractor): | ||
@lru_cache(1) | ||
def get_features_keys(self) -> Tuple[str, ...]: | ||
return 'redshift_helio', 'mwebv' | ||
|
||
@lru_cache(1) | ||
def get_required_keys(self) -> Tuple[str, ...]: | ||
# not very useful | ||
return tuple() | ||
|
||
def _compute_features(self, detections, **kwargs): | ||
return self._compute_features_from_df_groupby( | ||
detections.groupby(level=0), | ||
**kwargs) | ||
|
||
def _compute_features_from_df_groupby( | ||
self, detections, **kwargs) -> pd.DataFrame: | ||
columns = self.get_features_keys() | ||
metadata = kwargs['metadata'] | ||
|
||
def aux_function(oid_detections, **kwargs): | ||
oid = oid_detections.index.values[0] | ||
metadata_lightcurve = metadata.loc[oid] | ||
redshift_helio = metadata_lightcurve['REDSHIFT_HELIO'] | ||
mwebv = metadata_lightcurve['MWEBV'] | ||
|
||
out = pd.Series( | ||
data=[redshift_helio, mwebv], | ||
index=columns) | ||
return out | ||
|
||
features = detections.apply(aux_function) | ||
features.index.name = 'oid' | ||
return features |