File size: 1,112 Bytes
1c6540f
a86e7e6
1c6540f
 
 
 
 
d0daecc
1c6540f
 
 
 
 
 
 
 
 
 
 
 
 
 
a86e7e6
 
 
 
1c6540f
 
a86e7e6
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import numpy as np
from hydra.utils import instantiate

from .models import ShimNetWithSCRF, Predictor

class Defaults:
    SCALE = 16.0
    SUFFIX = "_processed"

# functions
def resample_input_spectrum(input_freqs, input_spectrum, Mhz_per_point):
    """resample input spectrum to match the model's frequency range"""
    freqs = np.arange(input_freqs.min(), input_freqs.max(), Mhz_per_point)
    spectrum = np.interp(freqs, input_freqs, input_spectrum)
    return freqs, spectrum

def resample_output_spectrum(input_freqs, freqs, prediction):
    """resample prediction to match the input spectrum's frequency range"""
    prediction = np.interp(input_freqs, freqs, prediction)
    return prediction

def initialize_predictor(config, weights_file):
    if "_target_" in config.model:
        model = instantiate(config.model)
    else:
        model = ShimNetWithSCRF(**config.model.kwargs)
    predictor = Predictor(model, weights_file)
    return predictor

def get_model_ppm_per_point(config):
    return config.data.get("frq_step", config.metadata.get("frq_step")) / config.metadata.spectrometer_frequency