Skip to content
Snippets Groups Projects
AdjustedMatrix.py 1.39 KiB
Newer Older
  • Learn to ignore specific revisions
  • from obspy import UTCDateTime
    
    from pydantic import BaseModel
    
    from typing import Any, List, Optional
    
    from .. import pydantic_utcdatetime
    
    from .Metric import Metric
    
    
    class AdjustedMatrix(BaseModel):
    
        """Attributes pertaining to adjusted(affine) matrices, applied by the AdjustedAlgorithm
    
        Attributes
        ----------
        matrix: affine matrix generated by Affine's calculate method
        pier_correction: pier correction generated by Affine's calculate method
        starttime: beginning of interval that matrix is valid for
        endtime: end of interval that matrix is valid for
        NOTE: valid intervals are only generated when bad data is encountered.
        Matrix is non-constrained otherwise
        """
    
    
        matrix: Any
        pier_correction: float
    
        metrics: Optional[List[Metric]] = None
    
        starttime: Optional[UTCDateTime] = None
        endtime: Optional[UTCDateTime] = None
    
    
        def process(self, values: List[List[float]], outchannels=["X", "Y", "Z", "F"]):
            """ Apply matrix to raw data. Apply pier correction to F when necessary """
            data = np.vstack([values[0:3]] + [np.ones_like(values[0])])
            adjusted = self.matrix @ data
            if "F" in outchannels:
                f = values[-1] + self.pier_correction
                adjusted = np.vstack([adjusted[0 : len(outchannels) - 1]] + [f])
            else:
                adjusted = adjusted[0 : len(outchannels)]
            return adjusted