Skip to content
Snippets Groups Projects
IRISSNCL.py 2.4 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 IRISSNCL(SNCL):
        @classmethod
        def get_sncl(
            cls,
            data_type: DataType,
            element: str,
            interval: DataInterval,
            station: str,
            network: str = "NT",
            location: Optional[str] = None,
        ) -> "IRISSNCL":
    
            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)
            return IRISSNCL(
                station=station,
                network=network,
                channel=get_iris_channel(
                    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_iris_element(channel=self.channel)
            return super().element
    
    
    def _get_iris_element(channel: str) -> str:
        channel_end = channel[1:]
        if channel_end == "F1":
            return "U"
        elif channel_end == "F2":
            return "V"
        elif channel_end == "FZ":
            return "W"
        raise ValueError(f"Unsupported channel: {channel}")
    
    
    def get_iris_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 "F1"
        elif element in ["E", "V"]:
            return "F2"
        elif element in ["Z", "W"]:
            return "FZ"
        elif element[0:2] == "LF":  # predefined element
            return element[1:]
        raise ValueError(f"Unsupported element: {element}")