Skip to content
Snippets Groups Projects
FDSNSNCL.py 2.91 KiB
Newer Older
  • Learn to ignore specific revisions
  • from typing import Optional
    
    from ..geomag_types import DataInterval, DataType
    from .SNCL import SNCL, get_channel, get_location, _get_channel_start
    
    
    class FDSNSNCL(SNCL):
        @classmethod
        def get_sncl(
            cls,
            data_type: DataType,
            element: str,
            interval: DataInterval,
            station: str,
            network: str = "NT",
            location: Optional[str] = None,
        ) -> "FDSNSNCL":
            if (
                network == "IU"
                and location == "40"
                and data_type not in ["40", "variation"]  # ASL only supports variation data
            ):
                raise ValueError(f"Unsupported data type: {data_type}")
            location = location or get_location(element=element, data_type=data_type)
    
                    element=element,
                    data_type=data_type,
                    interval=interval,
                    network=network,
                    location=location,
                ),
                location=location,
            )
    
        @property
        def data_type(self) -> str:
            if self.location == "40" and self.network == "IU":
                return "variation"
            return super().data_type
    
        @property
        def element(self) -> str:
            if self.location == "40" and self.network == "IU":
    
                return _get_FDSN_element(channel=self.channel)
    
        @property
        def interval(self) -> str:
            """Translates beginning of channel to interval"""
            channel_start = self.channel[0]
            if channel_start == "B":
                return "tenhertz"
            elif channel_start == "L":
                return "second"
            elif channel_start == "U":
                return "minute"
            elif channel_start == "R":
                return "hour"
            elif channel_start == "P":
                return "day"
            raise ValueError(f"Unexcepted interval code: {channel_start}")
    
        channel_end = channel[1:]
        if channel_end == "F1":
            return "V"
        elif channel_end == "F2":
            return "U"
        elif channel_end == "FZ":
            return "W"
        raise ValueError(f"Unsupported channel: {channel}")
    
    
    
        element: str,
        data_type: DataType,
        interval: DataInterval,
        network: Optional[str] = None,
        location: Optional[str] = None,
    ) -> str:
        if location == "40" and network == "IU":
            return _get_channel_start(interval=interval) + _get_channel_end(element=element)
        return get_channel(element=element, interval=interval, data_type=data_type)
    
    
    def _get_channel_end(element: str) -> str:
        if element in ["H", "U"]:
            return "F2"
        elif element in ["E", "V"]:
            return "F1"
        elif element in ["Z", "W"]:
            return "FZ"
        elif element[0:2] == "LF":  # predefined element
            return element[1:]
        raise ValueError(f"Unsupported element: {element}")