{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Mock power dataset" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import pandas as pd\n", "import numpy as np" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import os\n", "import sys\n", "from radiocalibrationtoolkit import *" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This ensures Plotly output works in multiple places:\n", "# plotly_mimetype: VS Code notebook UI\n", "# notebook: \"Jupyter: Export to HTML\" command in VS Code\n", "# See https://plotly.com/python/renderers/#multiple-renderers\n", "import plotly.io as pio\n", "pio.renderers.default = \"plotly_mimetype+notebook\"" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "piko = 1e-12" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# read HW response\n", "hw_file_path = \"./antenna_setup_files/HardwareProfileList_realistic.xml\"\n", "# hw_file_path = \"./antenna_setup_files/HardwareProfileList_flat.xml\"\n", "\n", "hw_dict = read_hw_file(hw_file_path, interp_args={\"fill_value\": \"extrapolate\"})\n", "\n", "hw_reponse_1 = hw_dict[\"RResponse\"][\"LNA\"]\n", "hw_reponse_2 = hw_dict[\"RResponse\"][\"digitizer\"]\n", "hw_reponse_3 = hw_dict[\"RResponse\"][\"cable_fromLNA2digitizer\"]\n", "hw_reponse_4 = hw_dict[\"RResponse\"][\"impedance_matching_EW\"]\n", "\n", "# merge all hw responses to one function\n", "def hw_response_func(x):\n", " return dB2PowerAmp(\n", " hw_reponse_1(x) + hw_reponse_2(x) + hw_reponse_3(x) + hw_reponse_4(x)\n", " )\n", "\n", "\n", "# impedance function\n", "impedance_func = hw_dict[\"IImpedance\"][\n", " \"antenna_EW\"\n", "]\n", "\n", "# read sidereal voltage square spectral density\n", "sidereal_voltage2_density_DF = pd.read_csv(\n", " \"./voltage2_density/voltage2_density_Salla_EW_GSM16.csv\",\n", " # \"./voltage2_density/voltage2_density_isoAnt_GSM16.csv\",\n", " index_col=0,\n", ")\n", "sidereal_voltage2_density_DF.columns = sidereal_voltage2_density_DF.columns.astype(\n", " float\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "def hw_response_func(x):\n", " return dB2PowerAmp(\n", " hw_reponse_1(x) + hw_reponse_2(x) + hw_reponse_3(x) + hw_reponse_4(x)\n", " )" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mock_trace_generator = Mock_trace_generator(\n", " sidereal_voltage2_density_DF=sidereal_voltage2_density_DF,\n", " hw_response_func=hw_response_func,\n", " impedance_func=impedance_func,\n", " voltage2ADC=2048,\n", " time_trace_size=2048,\n", " sampling_frequency_MHz=250,\n", ")\n", "freq_MHz_bins = mock_trace_generator.get_frequency_bins()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "additional_noise = 5e-4*piko\n", "number_of_traces = 5000\n", "mock_traces_DF = mock_trace_generator.generate_mock_trace(\n", " number_of_traces,\n", " # temp_celsius=30,\n", " additional_noise=additional_noise,\n", " # nbi={\"67.25\": 1},\n", " # nbi_err=0.3,\n", " rounding=True\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# system parameters\n", "sampling_frequency_MHz = 250\n", "N = mock_traces_DF.columns[2:].size\n", "ADC2Volts = 1/2048\n", "trace_time_length_sec = N/(sampling_frequency_MHz*1e+6)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# FFT to spectra\n", "spectra_df = time_trace_df_2_spectra_df(mock_traces_DF, DSC=2, sampling_frequency_MHz=250)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The power $P_s$ within band from $f$ to $f+\\delta f$ is calculated using the following formula:\n", "\n", " \\begin{equation}\n", "P_s = 2\\frac{1}{T} \\sum_{k=f}^{f+\\delta f} \\frac{|X(k)|^2}{R(f)} \\Delta f\n", "\\end{equation}\n", "\n", "where\n", "$\\Delta t$ is the sampling time, $T$ is the time trace length, $N$ number of samples, $f_s$ sampling frequency and $R$ the impedance,\n", "\n", "and $X(k)$ is defined as\n", "\n", "\\begin{equation}\n", "X(k) = X(k)_{DFT} \\Delta t = \\frac{X(k)_{DFT}}{fs}\n", "\\end{equation}\n", "\n", "meaning that $X(k)_{DFT}$ is direct output using discrete Fourier transform on the time trace. \n", "Furthermore, this relations hold:\n", "\n", "\\begin{equation}\n", "\\Delta f = \\frac{fs}{N} = \\frac{1}{N\\Delta t} = \\frac{1}{T}\n", "\\end{equation}\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# use the formula, create the integrand first\n", "integrand_df = ((spectra_df* ADC2Volts / (sampling_frequency_MHz*1e+6))**2).divide(\n", " impedance_func(spectra_df.columns.values)\n", ")\n", "\n", "# integrate\n", "mock_power_unbinned_DF = (2 / trace_time_length_sec) *integrate_spectral_density(\n", " integrand_df,\n", " # integrated_MHz_bands=np.linspace(0, 125, 126),\n", " integrated_MHz_bands=np.linspace(30, 81, 52),\n", " integrating_method='on_discontinuous_function',\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mock_power_unbinned_DF = pd.concat((mock_traces_DF.iloc[:,:2], mock_power_unbinned_DF), axis=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "mock_power_DF = bin_df_rows(mock_power_unbinned_DF, binning_column='lst', bins=list(range(25)))\n", "mock_power_DF.index.name = 'lst'\n", "mock_power_DF = mock_power_DF.drop(['temp_c', 'lst'], axis=1)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fig = px.imshow(\n", " mock_power_DF.T * 1e12, width=600, aspect=\"cube\", color_continuous_scale=\"jet\"\n", ")\n", "fig.update_layout(\n", " title='Mock power dataset: {} mock traces'.format(number_of_traces),\n", " xaxis=dict(title=\"LST\", tickprefix=\"\", ticksuffix=\"\", dtick=2),\n", " yaxis=dict(\n", " title=\"frequency [MHz]\",\n", " tickprefix=\"\",\n", " ticksuffix=\"\",\n", " range=(30, 80),\n", " tick0=0,\n", " dtick=10,\n", " autorange=False,\n", " ),\n", " coloraxis=dict(\n", " colorbar=dict(\n", " title=dict(\n", " text=\"power [pW]\",\n", " side=\"right\",\n", " ),\n", " tickprefix=\"\",\n", " ticksuffix=\"\",\n", " ),\n", " ),\n", " font=dict(\n", " # family=font,\n", " size=20,\n", " color=\"black\",\n", " ),\n", ")\n", "fig.update_layout(\n", " coloraxis=dict(colorbar=dict(title=dict(text=\"Power [pW]\", side=\"right\"))\n", " ,cmin=0, cmax=20))\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# mock_power_DF.to_csv('./mock_power_dataset-{}.csv'.format(number_of_traces))\n", "# mock_power_DF.to_csv('./mock_power_dataset-{}_fixed_temp_30C_norounding_flathwgain_isoant.csv'.format(number_of_traces))\n", "# mock_power_DF.to_csv('./mock_power_dataset-{}_fixed_temp_30C_norounding_flathwgain_isoant_extranoise.csv'.format(number_of_traces))\n", "# mock_power_DF.to_csv('./mock_power_dataset-{}_fixed_temp_30C_rounded_flathwgain_isoant.csv'.format(number_of_traces))\n", "\n", "# mock_power_DF.to_csv('./mock_power_dataset-{}_fixed_temp_30C_norounding_realhwgain_realant.csv'.format(number_of_traces))\n", "# mock_power_DF.to_csv('./mock_power_dataset-{}_fixed_temp_30C_rounded_realhwgain_realant.csv'.format(number_of_traces))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.6" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }