#%matplotlib inline
#%matplotlib nbagg
%matplotlib notebook
import sys
import os
try:
hostname = os.environ['HOSTNAME']
except KeyError:
hostname = 'juno'
print('HOSTNAME:', hostname)
#os.path.exists('/home/chust/tch')
if hostname == 'juno' and not '/home/chust/tch' in sys.path:
sys.path.append('/home/chust/tch')
print('sys.path:', sys.path, '\n')
import matplotlib.pyplot as plt
import numpy as np
import glob
from datetime import datetime, timedelta
from lib_lfr.load_routines import (get_lfr_decom_l1_swf, get_lfr_decom_l1_cwf, get_lfr_decom_l1_asm,
get_lfr_decom_l1_bp2, get_lfr_decom_l1_bp1)
from lib_lfr.time_routines import v_sec_to_datetime
from lib_lfr.calib_routines import sm_from_swf, sm_from_cwf
from lib_plot.spectral_routines import fig_spectrograms
dir_root = '/WIN/Users/chust/DD CHUST' if hostname == 'PC-CHUST2.lpp.polytechnnique.fr' else \
'/home/chust/DD pc-p-chust' if hostname == 'pc-p-chust' else \
'/home/thomas/Labo' if hostname == 'pc-tango2' else 'ERROR!'
dir_DATA = '/DATA1' if hostname == 'PC-CHUST2.lpp.polytechnnique.fr' else \
'/home/chust/DATA' if hostname in ['pc-p-chust', 'juno'] else \
'/home/thomas/Labo/DATA' if hostname == 'pc-tango2' else 'ERROR!'
dir_plots = '/home/thomas/Labo/Plots' if hostname == 'pc-tango2' else '/home/chust/Plots'
dir_storage = '/home/thomas/Labo/Storage' if hostname == 'pc-tango2' else '/home/chust/Storage'
print('dir_root:', dir_root)
print('dir_DATA:', dir_DATA)
HOSTNAME: PC-CHUST2.lpp.polytechnnique.fr sys.path: ['/WIN/Users/chust/DD CHUST/Missions/Solar Orbiter/LFR/Python/Alexis', '/WIN/Users/chust/DD CHUST/Missions/Solar Orbiter/LFR/Python/tch', '/usr/lib64/python39.zip', '/usr/lib64/python3.9', '/usr/lib64/python3.9/lib-dynload', '', '/home/lab-lpp.local/chust/venv_py3/lib64/python3.9/site-packages', '/home/lab-lpp.local/chust/venv_py3/lib/python3.9/site-packages', '/usr/lib64/python3.9/site-packages', '/usr/lib/python3.9/site-packages', '/home/lab-lpp.local/chust/venv_py3/lib/python3.9/site-packages/IPython/extensions', '/home/lab-lpp.local/chust/.ipython'] dir_root: /WIN/Users/chust/DD CHUST dir_DATA: /DATA1
/home/lab-lpp.local/chust/venv_py3/lib64/python3.9/site-packages/spacepy/time.py:2294: UserWarning: Leapseconds may be out of date. Use spacepy.toolbox.update(leapsecs=True) warnings.warn('Leapseconds may be out of date.'
Le problème
Bruno's decom
Thomas
files=glob.glob(dir_DATA + '/SO/Tests/Test Charge 3.2.0.24/decom/*f1*')
files.sort()
for file in files:
print(os.path.basename(file))
bp1_l1_file = files[0]
bp1_l1_bname = os.path.basename(bp1_l1_file)[:-4]
bp2_l1_file = files[1]
bp2_l1_bname = os.path.basename(bp2_l1_file)[:-4]
asm_l1_file = files[2]
asm_l1_bname = os.path.basename(asm_l1_file)[:-4]
swf_l1_file = files[3]
swf_l1_bname = os.path.basename(swf_l1_file)[:-4]
2019_03_06_12_05_38_packet_record_NORMAL.1f1 2019_03_06_12_05_38_packet_record_NORMAL.2f1 2019_03_06_12_05_38_packet_record_NORMAL.af1 2019_03_06_12_05_38_packet_record_NORMAL.sf1 2019_03_06_12_05_38_packet_record_SBM1.cf1 2019_03_06_12_05_38_packet_record_SBM2.1f1 2019_03_06_12_05_38_packet_record_SBM2.2f1
bp2_l1_n_data = 3*[None]
bp2_l1_n_freq = 3*[None]
bp2_l1_n_second = 3*[None]
bp2_l1_n_datetime = 3*[None]
bp2_l1 = get_lfr_decom_l1_bp2(bp2_l1_file)
F = 1
bp2_l1_n_data[F] = bp2_l1['bp2_idl']
bp2_l1_n_freq[F] = np.array(bp2_l1['freq'])
bp2_l1_n_second[F] = np.array(bp2_l1['relative_time'])
bp2_l1_n_datetime[F] = np.array(v_sec_to_datetime(bp2_l1_n_second[F], tref=datetime(2019, 3, 6, 0, 0, 0)))
psd_bp2_l1 = True
bgd_bp2_l1 = False
corr_bp2_l1 = 2.*8./3 if bgd_bp2_l1 else 4.
nfreq_ave_n = 8
bp2_l1_n_data[F] *= corr_bp2_l1*nfreq_ave_n/(bp2_l1_n_freq[F][1]-bp2_l1_n_freq[F][0]) \
if psd_bp2_l1 else corr_bp2_l1
bp2_l1_n_data[F].shape
(1010, 13, 5, 5)
ampl_rg_B_F0F1 = [[[0.003, 1], [0.003, 1], [0.003, 1], [0.001, 1], [0.001, 1]],
[[0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1]]]
ampl_rg_N_F0F1F2 = [[[0.003, 1], [0.003, 1], [0.003, 1], [0.001, 1], [0.001, 1]],
[[0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1]],
[[1, 10], [1, 10], [1,10], [1, 10], [1, 10]]]
ampl_range = [[0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1]]
#ampl_range = None
#date_fmt = '%Y-%m-%d %H:%M:%S'
date_fmt = '%H:%M'
fig_spectrograms([bp2_l1_n_data[F][:,:,0,0].real, bp2_l1_n_data[F][:,:,1,1].real,
bp2_l1_n_data[F][:,:,2,2].real, bp2_l1_n_data[F][:,:,3,3].real,
bp2_l1_n_data[F][:,:,4,4].real],
bp2_l1_n_datetime[F], bp2_l1_n_freq[F],
fname=dir_plots+'/'+bp2_l1_bname+'_BP2_F%s_spectrogram5-corr=%d.png'%(F, corr_bp2_l1),
cmap=plt.cm.jet, figsize=(10,16), hspace=0.05, cbar_aspect=20, cbar_pad=0.02,
fontsize=(15,14), fs_name=14, fs_title=13, ticklabel_fs=(13,12), cbar_ticklabel_fs=11,
ylabel='freq. (Hz)', xlabel=True, xtl_rot=0., xtl_ha='center', dt_i1i2=0,
date_fmt=date_fmt, ampl_range=ampl_range, freq_range=None,
log=5*[True], psd=5*[True], nop=5*[False],
units=5*['count'], time_gap=True, gap_echo=True,
names=['B1B1*', 'B2B2*', 'B3B3*','E1E1*','E2E2*'],
comment=' {} @F{:d} '.format('BP2', F) + bp2_l1_bname)
gap insertion here: 2019-03-06 00:59:59.974411 2019-03-06 01:29:49.961578 2019-03-06 02:29:49.937317 2019-03-06 02:59:49.925720 2019-03-06 03:59:49.902344 2019-03-06 04:29:49.890671 2019-03-06 04:59:49.877975 2019-03-06 05:30:29.864944 gap interval: 0:00:29.999786 0:00:39.999710 0:00:39.999756 0:00:39.999741 0:00:39.999786 0:00:39.999710 0:00:39.999711 0:00:29.999787
asm_l1_data = 3*[None]
asm_l1_freq = 3*[None]
asm_l1_second = 3*[None]
asm_l1_datetime = 3*[None]
asm_l1 = get_lfr_decom_l1_asm(asm_l1_file)
F = 1
asm_l1_data[F] = asm_l1['asm_idl']
asm_l1_freq[F] = np.array(asm_l1['freq'])
asm_l1_second[F] = np.array(asm_l1['relative_time'])
asm_l1_datetime[F] = np.array(v_sec_to_datetime(asm_l1_second[F], tref=datetime(2019, 3, 6, 0, 0, 0)))
psd_asm_l1 = True
bgd_asm_l1 = False
corr_asm_l1 = 2.*8./3 if bgd_asm_l1 else 4.
asm_l1_data[F] *= corr_asm_l1/(asm_l1_freq[F][1]-asm_l1_freq[F][0]) if psd_asm_l1 else corr_asm_l1
asm_l1_data[F].shape
(5082, 104, 5, 5)
ampl_rg_F0F1F2 = [[[0.003, 1], [0.003, 1], [0.003, 1], [0.001, 1], [0.001, 1]],
[[0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1]],
[[1, 10], [1, 10], [1,10], [1, 10], [1, 10]]]
ampl_range = [[0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1], [0.03, 1]]
#ampl_range = None
#date_fmt = '%Y-%m-%d %H:%M:%S'
date_fmt = '%H:%M'
fig_spectrograms([asm_l1_data[F][:,:,0,0].real, asm_l1_data[F][:,:,1,1].real,
asm_l1_data[F][:,:,2,2].real, asm_l1_data[F][:,:,3,3].real,
asm_l1_data[F][:,:,4,4].real],
asm_l1_datetime[F], asm_l1_freq[F],
fname=dir_plots+'/'+asm_l1_bname+'_ASM_F%s_spectrogram5-corr=%d.png'%(F, corr_asm_l1),
cmap=plt.cm.jet, figsize=(10,16), hspace=0.05, cbar_aspect=20, cbar_pad=0.02,
fontsize=(15,14), fs_name=14, fs_title=13, ticklabel_fs=(13,12), cbar_ticklabel_fs=11,
ylabel='freq. (Hz)', xlabel=True, xtl_rot=0., xtl_ha='center', dt_i1i2=0,
date_fmt=date_fmt, ampl_range=ampl_range, freq_range=None,
log=5*[True], psd=5*[True], nop=5*[False],
units=5*['count'], time_gap=True, gap_echo=True,
names=['B1B1*', 'B2B2*', 'B3B3*','E1E1*','E2E2*'],
comment=' {} @F{:d} '.format('ASM', F) + asm_l1_bname)
gap insertion here: 2019-03-06 01:00:23.974228 2019-03-06 01:30:21.961334 2019-03-06 02:30:21.937103 2019-03-06 03:00:21.925507 2019-03-06 04:00:21.902145 2019-03-06 04:30:21.890427 2019-03-06 05:00:21.877731 2019-03-06 05:30:53.864761 gap interval: 0:00:05.999954 0:00:07.999939 0:00:07.999939 0:00:07.999939 0:00:07.999955 0:00:07.999939 0:00:07.999955 0:00:05.999955
/WIN/Users/chust/DD CHUST/Missions/Solar Orbiter/LFR/Python/tch/lib_plot/spectral_routines.py:207: RuntimeWarning: divide by zero encountered in log10 z = np.log10(spectrogram_list2[i]) if log[i] else spectrogram_list2[i]
swf_l1_data = 3*[None]
swf_l1_second = 3*[None]
#swf_l1_datetime = 3*[None]
sm_l1_swf_data = 3*[None]
sm_l1_swf_second = 3*[None]
sm_l1_swf_datetime = 3*[None]
sm_l1_swf_freq = 3*[None]
swf_l1 = get_lfr_decom_l1_swf(swf_l1_file)
F = 1
swf_l1_data[F] = swf_l1['data_block'] # v, e1, e2, b1, b2, b3 ...
swf_l1_second[F] = np.array(swf_l1['relative_time'])
#swf_l1_datetime[F] = np.array(v_sec_to_datetime(swf_l1_second[F], tref=datetime(2019, 3, 6, 0, 0, 0)))
psd_swf_l1 = True
bgd_swf_l1 = False
unit_l1 = 'count^2/Hz' if psd_swf_l1 else 'count^2'
win_l1 = 'hanning_idl'
if win_l1 in ['hanning', 'hanning_idl']:
corr_swf_l1 = 2.*8./3 if bgd_swf_l1 else 4.
else:
corr_swf_l1 = 1.
na_swf_l1 = 4
psd_swf_l1 = True
bgd_swf_l1 = False
(sm_l1_swf_data[F], sm_l1_swf_second[F], sm_l1_swf_freq[F]) = \
sm_from_swf(swf_l1_data[F][:,3:], swf_l1_data[F][:,1:3], swf_l1_data[F][:,0:1],
swf_l1_second[F], F=F, nw=int(2048/na_swf_l1), na=na_swf_l1, echo=False,
win=win_l1, unit=unit_l1, background=bgd_swf_l1, DC=False)
sm_l1_swf_datetime[F] = np.array(v_sec_to_datetime(sm_l1_swf_second[F], tref=datetime(2019, 3, 6, 0, 0, 0)))
sm_l1_swf_data[F].shape
(924, 255, 6, 6)
ampl_rg_F0F1F2 = [[[1e-4, 3], [1e-4, 3], [1e-4, 3], [1e-5, 1], [1e-5, 1], [1e-5, 1]],
[[1e-3, 20], [1e-3, 20], [1e-3, 20], [1e-4, 10], [1e-4, 10], [1e-4, 1]],
[[3e-3, 100], [3e-3, 100], [3e-3,100], [5e-4, 100], [5e-4, 100], [1e-4, 10]]]
ampl_range = 6*[[1e-3, 1]]
#ampl_range = None
#date_fmt = '%Y-%m-%d %H:%M:%S'
date_fmt = '%H:%M'
fig_spectrograms([sm_l1_swf_data[F][:,:,0,0].real, sm_l1_swf_data[F][:,:,1,1].real,
sm_l1_swf_data[F][:,:,2,2].real, sm_l1_swf_data[F][:,:,3,3].real,
sm_l1_swf_data[F][:,:,4,4].real, sm_l1_swf_data[F][:,:,5,5].real],
sm_l1_swf_datetime[F], sm_l1_swf_freq[F],
fname=dir_plots+'/'+swf_l1_bname+'_SWF_F%s_spectrogram5-corr=%d.png'%(F, corr_asm_l1),
cmap=plt.cm.jet, figsize=(10,16), hspace=0.05, cbar_aspect=20, cbar_pad=0.02,
fontsize=(15,14), fs_name=14, fs_title=13, ticklabel_fs=(13,12), cbar_ticklabel_fs=11,
ylabel='freq. (Hz)', xlabel=True, xtl_rot=0., xtl_ha='center', dt_i1i2=0,
date_fmt=date_fmt, ampl_range=ampl_range, freq_range=None,
log=6*[True], psd=6*[True], nop=6*[False],
units=6*['count'], time_gap=True, gap_echo=True,
names=['B1B1*', 'B2B2*', 'B3B3*','E1E1*','E2E2*', 'VV*'],
comment=' {} @F{:d} '.format('SWF', F) + asm_l1_bname)
gap insertion here: gap interval: