def test_copyDefaultConfig() -> None: """Test copying of default config""" from datapaths import path_config_copy from resistics.config.defaults import copyDefaultConfig from resistics.config.io import loadConfig copyDefaultConfig(path_config_copy) # load in this file config = loadConfig(str(path_config_copy)) assert config["name"] == "global copy" defaultConfig = loadConfig() for key in config.keys(): if key == "name": continue assert config[key] == defaultConfig[key]
def __init__( self, sampleFreq: float, winSamples: int, config: Union[Dict, None] = None ) -> None: """Initialise Parameters ---------- sampleFreq : float Sampling frequency of time data winSamples : int Number of samples in a window """ self.sampleFreq: float = sampleFreq self.numSamples: int = winSamples if config is None: config = loadConfig() self.detrend: bool = True self.applywindow: bool = config["Spectra"]["applywindow"] self.window: str = config["Spectra"]["windowfunc"] self.windowFunc: np.ndarray = signal.get_window( config["Spectra"]["windowfunc"], winSamples ) # create an pyfftw plan self.dataArray: np.ndarray = pyfftw.empty_aligned( self.numSamples, dtype="float64" ) self.fftObj: pyfftw.FFTW = pyfftw.builders.rfft(self.dataArray)
def __init__(self, refTime: datetime, timeData: TimeData, winSize: int, winOlap: int) -> None: """Initialise the windower Parameters ---------- refTime : datetime The reference time timeData : TimeData The time series data to window winSize : int The window size in samples winOlap : int The overlap size between windows in samples """ self.timeData: TimeData = timeData self.numSamples: int = timeData.numSamples self.sampleFreq: float = timeData.sampleFreq self.winSize: int = winSize self.winDuration: float = (winSize - 1) / timeData.sampleFreq self.winOlap: int = winOlap self.chans: List[str] = timeData.chans # refTime and dataTime are already datetime objects self.refTime: datetime = refTime self.dataTime: datetime = timeData.startTime # min window warning setting config = loadConfig() self.minWindows: int = config["Window"]["minwindows"] # initialise self.initialiseWindows() self.calcWindowTimes()
def getDefaultParameter(param: str) -> Any: """Get the default global configuration option Parameters ---------- param : str The config parameter """ from resistics.config.io import loadConfig config = loadConfig() return config[param]
def __init__(self, configFile: str = "") -> None: """Initialise with default configuration options Parameters ---------- configFile : str Path to the configuration file """ self.configFile: str = configFile self.configParams = loadConfig(self.configFile) # options dictionary self.flags: Dict[str, bool] = {} self.configure()
def __init__(self, decParams: DecimationParameters) -> None: """Initialise with decParams and default window parameters Parameters ---------- decParams : int Decimation level """ self.decParams = decParams config = loadConfig() self.minSize = config["Window"]["minwindowsize"] self.minOlap = config["Window"]["minoverlapsize"] self.windowFactor = config["Window"]["windowfactor"] self.overlapFraction = config["Window"]["overlapfraction"] self.calcParameters(self.windowFactor, self.overlapFraction)
def test_loadConfig() -> None: """Test loading config""" from resistics.config.io import loadConfig config = loadConfig() assert config["name"] == "default" assert config["ncores"] == -1 assert config["Calibration"]["extend"] == True assert config["Calibration"]["usetheoretical"] == False assert config["Decimation"]["numlevels"] == 7 assert config["Decimation"]["minsamples"] == 100 assert config["Frequencies"]["frequencies"] == [] assert config["Frequencies"]["perlevel"] == 7 assert config["Window"]["minwindows"] == 5 assert config["Window"]["windowfactor"] == 2.0 assert config["Window"]["minwindowsize"] == 512 assert config["Window"]["minoverlapsize"] == 128 assert config["Window"]["overlapfraction"] == 0.25 assert config["Window"]["windowsizes"] == [] assert config["Window"]["overlapsizes"] == [] assert config["Spectra"]["ncores"] == -1 assert config["Spectra"]["specdir"] == "spectra" assert config["Spectra"]["applywindow"] == True assert config["Spectra"]["windowfunc"] == "hann" assert config["Statistics"]["ncores"] == -1 assert config["Statistics"]["stats"] == ["coherence", "transferFunction"] assert config["Statistics"]["remotestats"] == [ "RR_coherence", "RR_transferFunction" ] assert config["Solver"]["ncores"] == -1 assert config["Solver"]["method"] == "cm" assert config["Solver"]["intercept"] == False assert config["Solver"]["smoothfunc"] == "hann" assert config["Solver"]["smoothlen"] == 9 assert config["Solver"]["OLS"] == {} assert config["Solver"]["MM"]["weightfnc1"] == "huber" assert config["Solver"]["MM"]["weightfnc2"] == "bisquare" assert config["Solver"]["CM"] == {}
def test_config_data() -> None: """Test ConfigData initialiser""" from resistics.config.io import loadConfig # load default config config = ConfigData() assert config.configFile == "" configParams = config.configParams flags = config.flags defaultConfig = loadConfig() for key in defaultConfig.keys(): assert configParams[key] == defaultConfig[key] assert flags["customfrequencies"] is False assert flags["customwindows"] is False assert config.getSpectraCores() == 0 assert config.getStatisticCores() == 0 assert config.getSolverCores() == 0 assert config.getConfigComment() == "Using default configuration"
def __init__(self, calDirectory: str) -> None: """Set the calibration directory and initialise Calibrator will automatically find calibration files in the provided directory Parameters ---------- calDirectory : str Path of directory containing calibration files """ self.calExt, self.calFormats = getKnownCalibrationFormats() self.calFiles: List[str] = [] self.numCalFiles = 0 self.calDir: str = calDirectory self.findCalFiles() # set whether to use theoretical calibration functions conf = loadConfig() self.extend: bool = conf["Calibration"]["extend"] self.useTheoretical: bool = conf["Calibration"]["usetheoretical"]
def __init__(self, timeData: TimeData, decParams: DecimationParameters) -> None: """Initialise with timeData and decimation parameters Parameters ---------- timeData : TimeData The time data to decimate decParams : DecimationParams Decimation parameters for performing the decimation """ self.timeData: TimeData = timeData self.sampleFreq: float = timeData.sampleFreq * 1.0 self.chans: List = timeData.chans self.numSamples: int = timeData.numSamples self.decParams: DecimationParameters = decParams config = loadConfig() self.minSamples: int = config["Decimation"]["minsamples"] self.level: int = -1 self.maxDownsampleFactor: int = 8
def __init__(self, sampleFreq: float): """Initialise decimation parameters with sampling frequency Calculates decimation factors and evaluation frequencies based on defaults Parameters ---------- sampleFreq : float Sampling frequency """ self.sampleFreq = sampleFreq config = loadConfig() self.divFactor: int = 2 self.numLevels: int = config["Decimation"]["numlevels"] self.freqPerLevel: int = config["Frequencies"]["perlevel"] self.decFactors: Union[np.ndarray, None] = None self.decFrequencies: Union[np.ndarray, None] = None self.evalFreq: Union[np.ndarray, None] = None self.evalFreqPerLevel: Union[np.ndarray, None] = None # calculate some initial values decimation parameters based on defaults self.calcFrequencyParams(self.numLevels, self.freqPerLevel)