Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from pathlib import Path
- import time
- from threading import Thread
- import datetime as dt
- import numpy as np
- from sklearn.decomposition import PCA
- from sklearn.preprocessing import StandardScaler
- from RSA_API import RSAError
- from keras.models import load_model
- from rsa_config import RSAConfig
- import dpx_data_file_management as dpx_file
- from dpx_graph_data_stream import create_dpx_data_stream
- class FM_Scanner:
- def __init__(self):
- self.fm_list = []
- self.model = load_model('.\MachineLearningScripts\CNN\cnn.h5')
- self.config_cf = 8e7 # centerfrequency starts at 80MHz
- # = RSAConfig(cf=8e7) #8- MHz
- self.stream = create_dpx_data_stream(self.config)
- self.loop_fm_range()
- def loop_fm_range():
- #Open stream
- try:
- self.stream.open()
- except (RSAError, ValueError) as err:
- print("Could not connect to RSA", str(err))
- return
- while (self.config_cf <= 12e7): # while centerfrequency less than 120MHz
- #Grab data
- data = self.stream.get_previous_dpx_data()
- bitmap = np.asarray([data.DPX_bitmap])
- #Data preprocess -> ONLY FOR CNN MODEL!
- sc = StandardScaler()
- tmp = sc.fit_transform(bitmap[0])
- pca = PCA(n_components=32) #TODO: Parametrize?
- = pca.fit_transform(tmp)
- # End of data preprocessing
- #Reshape data to fit the input_shape for the model-> Keep first 3 dimensions the same (batch_size, width, height). The last dimension is the depth (1 = BW, 3 = RGB...)
- arr = []
- arr.append(tmp)
- arr = np.asarray(arr)
- arr = arr.reshape(arr.shape[0],201,32,1)
- prediction = self.model.predict(arr, verbose=0)
- if (prediction[0][0] >= .99):
- self.fm_list.append(self.config_cf)
- #Increase frequency by 0.1 MHz each iteration
- self.config_cfg = self.config_cf + 1e5
- self.stream.set_rsa_config(cf = self.config_cfg)
- self.stream.close()
- print(self.fm_list)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement