<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import initExample
import os
from lase.core import KClient, HTTPInterface
from lase.drivers import Spectrum

# Modules to import
import numpy as np
import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import pyplot as plt
import time

# Load the spectrum instrument
host = os.getenv('HOST','192.168.1.100')
password = os.getenv('PASSWORD','<PASSWORD>')
ssh = ZynqSSH(host, password)
ssh.unzip_app()
ssh.install_instrument('spectrum')

client = KClient(host)
driver = Spectrum(client)

# Enable laser
driver.start_laser()

# Set laser current
current = 30  # mA
driver.set_laser_current(current)

# Plot parameters
fig = plt.figure()
ax = fig.add_subplot(111)
x = 1e-6 * np.fft.fftshift(driver.sampling.f_fft)
y = 10*np.log10(np.fft.fftshift(driver.spectrum))
li, = ax.plot(x, y)
fig.canvas.draw()
ax.set_xlim((x[0],x[-1]))
ax.set_ylim((100,250))
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('Power spectral density (dB)')

while True:
    try:
        driver.get_spectrum()
        li.set_ydata(10*np.log10(np.fft.fftshift(driver.spectrum)))
        fig.canvas.draw()
        plt.pause(0.001)
    except KeyboardInterrupt:
        # Save last spectrum in a csv file
        np.savetxt("psd.csv", driver.spectrum, delimiter=",")
        driver.stop_laser()
        driver.close()
        break
<commit_msg>Update spectrum_analyzer.py<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-

import initExample
import os
from lase.core import KClient, ZynqSSH
from lase.drivers import Spectrum

# Modules to import
import numpy as np
import matplotlib
matplotlib.use('GTKAgg')
from matplotlib import pyplot as plt
import time

# Load the spectrum instrument
host = os.getenv('HOST','192.168.1.100')
password = os.getenv('PASSWORD','<PASSWORD>')
ssh = ZynqSSH(host, password)
ssh.unzip_app()
ssh.install_instrument('spectrum')

client = KClient(host)
driver = Spectrum(client)

# Enable laser
driver.start_laser()

# Set laser current
current = 30  # mA
driver.set_laser_current(current)

# Plot parameters
fig = plt.figure()
ax = fig.add_subplot(111)
x = 1e-6 * np.fft.fftshift(driver.sampling.f_fft)
y = 10*np.log10(np.fft.fftshift(driver.spectrum))
li, = ax.plot(x, y)
fig.canvas.draw()
ax.set_xlim((x[0],x[-1]))
ax.set_ylim((100,250))
ax.set_xlabel('Frequency (MHz)')
ax.set_ylabel('Power spectral density (dB)')

while True:
    try:
        driver.get_spectrum()
        li.set_ydata(10*np.log10(np.fft.fftshift(driver.spectrum)))
        fig.canvas.draw()
        plt.pause(0.001)
    except KeyboardInterrupt:
        # Save last spectrum in a csv file
        np.savetxt("psd.csv", driver.spectrum, delimiter=",")
        driver.stop_laser()
        driver.close()
        break

{'fraction_non_alphanumeric': 0.14031907179115302, 'fraction_numerical': 0.02755620014503263, 'mean_word_length': 4.043875685557587, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4413840', 'n_tokens_mistral': 1078, 'n_tokens_neox': 999, 'n_words': 215}