def _percentile(axis, pctl=50, unit='um', suffix='', _dir='', **kwargs): fname = './data2/{3}/{0}_{1}.hdf5'.format(axis, pctl, suffix, _dir) model = kwargs.pop('model', None) _asd = FrequencySeries.read(fname)**0.5 if model == '120QA': amp = 10**(30.0 / 20.0) elif model == 'compact': amp = 10**(45.0 / 20.0) seis = Trillium(model) v2vel = seis.v2vel c2v = 20.0 / 2**15 _asd = v2vel(_asd) * c2v / amp * 1e6 if unit == 'um': asd = _asd / (2.0 * np.pi * _asd.frequencies.value) #asd.write('./LongTerm_{0}_{1}_DISP.txt'.format(axis,pctl),format='txt') elif unit == 'm': asd = _asd / (2.0 * np.pi * _asd.frequencies.value) * 1e-6 asd.write('./{0}_{1}_DISP.txt'.format(axis, pctl), format='txt') elif unit == 'um/sec': asd = _asd asd.write('./{0}_{1}_VELO.txt'.format(axis, pctl), format='txt') elif unit == 'um/sec/sec': asd = _asd * (2.0 * np.pi * _asd.frequencies.value) #asd.write('./LongTerm_{0}_{1}_ACC.txt'.format(axis,pctl),format='txt') elif unit == 'm/sec/sec': asd = _asd * (2.0 * np.pi * _asd.frequencies.value) * 1e-6 else: raise ValueError('!!1', unit) return asd
bw = exv0.df # Calcrate several noises if True: ref = exv0 _adcnoise = 2e-6 * u.V * np.ones(len(ref)) # [V/rtHz] _adcnoise2 = np.sqrt((10 / 2**15)**2 / 12 / (214 / 2)) * u.V * np.ones(len(ref)) # [V/rtHz] _ampnoise = 6e-7 * u.V * np.ones(len(ref)) # [V/rtHz] _aanoise = 7e-8 * u.V * np.ones(len(ref)) # [V/rtHz] _adcnoise = FrequencySeries(_adcnoise, frequencies=ref.frequencies) _adcnoise2 = FrequencySeries(_adcnoise2, frequencies=ref.frequencies) _ampnoise = FrequencySeries(_ampnoise, frequencies=ref.frequencies) _aanoise = FrequencySeries(_aanoise, frequencies=ref.frequencies) amp = 10**(30 / 20.) tr120q = Trillium('120QA') tr240 = Trillium('240') v2vel = tr120q.v2vel v2vel = tr240.v2vel adcnoise = v2vel(_adcnoise) / amp ampnoise = v2vel(_ampnoise) / amp # aanoise = v2vel(_aanoise) / amp selfnoise_120q = tr120q.selfnoise() selfnoise_240 = tr240.selfnoise() # Plot if True: from gwpy.plot import Plot plot = Plot() ax = plot.gca(xscale='log', xlim=(1e-3, 10),
import numpy as np import matplotlib.pyplot as plt from gwpy.frequencyseries import FrequencySeries from gwpy.spectrogram import Spectrogram from miyopy.utils.trillium import Trillium from obspy.signal.spectral_estimation import get_nhnm, get_nlnm from gwpy.types.array2d import Array2D from gwpy.timeseries import TimeSeries import astropy.units as u amp = 10**(30.0/20.0) c2v = 20.0/2**15 tr120 = Trillium('120QA') v2vel = tr120.v2vel lt, ldb = get_nlnm() ht, hdb = get_nhnm() lfreq, lacc = 1./lt, 10**(ldb/20)*1e6 hfreq, hacc = 1./ht, 10**(hdb/20)*1e6 lfreq, lvel = lfreq, lacc/(2.0*np.pi*lfreq) hfreq, hvel = hfreq, hacc/(2.0*np.pi*hfreq) lfreq, ldisp = lfreq, lvel/(2.0*np.pi*lfreq) hfreq, hdisp = hfreq, hvel/(2.0*np.pi*hfreq) def _plot_band_histgram(blrms,blrms2,blrms3,scale=0.9,loc=0): blrms.override_unit('m/s') blrms = blrms/amp*c2v/1000*1e6
def main(chnames, start, end, check_timeseries=False, check_velocity=False, check_reduction_rate=True): # ---------------------------------------- # TimeSeries Data from nds # ---------------------------------------- datadict = TimeSeriesDict.fetch(chnames, start, end, host='10.68.10.121', verbose=True, port=8088) try: ts_eyv = datadict['K1:PEM-SEIS_EYV_GND_EW_IN1_DQ'] ts_exv = datadict['K1:PEM-SEIS_EXV_GND_EW_IN1_DQ'] ts_ixv = datadict['K1:PEM-SEIS_IXV_GND_EW_IN1_DQ'] ts_bs = datadict['K1:PEM-SEIS_BS_GND_EW_IN1_DQ'] ts_mcf = datadict['K1:PEM-SEIS_MCF_GND_EW_IN1_DQ'] except KeyError as e: print( '''KeyError: Channel name not found, {0}. Please check this channel name.''' .format(e)) exit() except Exception as e: print('Unexpected Error!!') print(e) exit() if check_timeseries: for data in datadict.values(): plot = data.rms().plot() plot.savefig('./{0}/img_TimeSeries_RMS_{1}.png'.format( segname, data.name)) print('./{0}/img_TimeSeries_RMS_{1}.png'.format( segname, data.name)) plot.close() # ---------------------------------------- # Coherence # ---------------------------------------- fftlength = 2**7 csd3000 = ts_exv.csd(ts_ixv, fftlength=fftlength, overlap=fftlength / 2.0) # CSD csd30 = ts_mcf.csd(ts_bs, fftlength=fftlength, overlap=fftlength / 2.0) # CSD csd60 = ts_mcf.csd(ts_ixv, fftlength=fftlength, overlap=fftlength / 2.0) # CSD exv = ts_exv.asd(fftlength=fftlength, overlap=fftlength / 2.0) # ASD ixv = ts_ixv.asd(fftlength=fftlength, overlap=fftlength / 2.0) # ASD mcf = ts_mcf.asd(fftlength=fftlength, overlap=fftlength / 2.0) # ASD bs = ts_bs.asd(fftlength=fftlength, overlap=fftlength / 2.0) # ASD coh3000 = np.real(csd3000) / exv / ixv # Re[coh] coh30 = np.real(csd30) / mcf / bs # Re[coh] coh60 = np.real(csd60) / mcf / ixv # Re[coh] # ---------------------------------------- # SPAC model # ---------------------------------------- freq = np.logspace(-3, 2, 1e4) w = 2.0 * np.pi * freq L_ixv2exv = 3000.0 L_mcf2bs = 22.0 L_mcf2ixc = 62.0 L_mcf2ixv = 62.0 # guess L_mcf2mce = 22.0 #cp = 5500.0 # m/sec #cr = 2910 # m/sec L_KAGRA = 3000.0 L_Virgo = 4000.0 cr_virgo = lambda f: 150.0 + 1000.0 * np.exp(-f / 1.5 ) # from M. Beker PhD thesis. cr_kagra = lambda f: 800.0 + 3000.0 * np.exp(-f / 1.5) # by eye cr_kagra_x = lambda f: 2200.0 + 3000.0 * np.exp(-f / 1.5) # by eye cp_kagra_x = lambda f: 5400.0 * np.ones(len(f)) spac = lambda f, c, L: np.real(jv(0, L * 2.0 * np.pi * f / c)) spac_kagra = lambda f, L: spac(f, cr_kagra(f), L) spac_kagra_p = lambda f, L: spac(f, cp_kagra_x(f), L) spac_kagra_r = lambda f, L: spac(f, cr_kagra_x(f), L) reduction = lambda f, c, L: 1.0 - np.real(jv(0, L * 2.0 * np.pi * f / c)) # ---------------------------------------- # ASD # ---------------------------------------- from miyopy.utils.trillium import Trillium tr120q = Trillium('120QA') trcpt = Trillium('compact') v2vel_120 = tr120q.v2vel v2vel_cpt = trcpt.v2vel c2v = 20.0 / 2**15 print c2v amp = 10**(30.0 / 20.0) #ixv = v2vel_120(ixv*c2v)/amp #exv = v2vel_120(exv*c2v)/amp #mcf = v2vel_cpt(mcf*c2v)/amp #bs = v2vel_cpt(bs*c2v)/amp if True: fig, ax = plt.subplots(1, 1, figsize=(8, 6)) if 'UD' in ts_ixv.name: plt.title(segname.replace('_', '\_') + ', ASD' + ', Z') elif 'EW' in ts_ixv.name: plt.title(segname.replace('_', '\_') + ', ASD' + ', X') ax.loglog(ixv, label='ixv') ax.loglog(exv, label='exv') ax.loglog(mcf, label='mcf') ax.loglog(bs, label='bs') ax.set_xlim(0.01, 100) ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Count') ax.legend() if 'UD' in ts_ixv.name: plt.savefig('./{0}/img_ASD_Z.png'.format(segname)) print('saved ./{0}/img_ASD_Z.png'.format(segname)) elif 'EW' in ts_ixv.name: plt.savefig('./{0}/img_ASD_X.png'.format(segname)) print('saved ./{0}/img_ASD_X.png'.format(segname)) plt.close() # ------------------------------------------ # Spatial autocorrection (SPAC) # ------------------------------------------ if 'UD' in ts_ixv.name: fig, ax = plt.subplots(1, 1, figsize=(8, 6)) plt.title(segname.replace('_', '\_') + ', SPAC') ax.axvspan(0.01, 0.1, alpha=0.2, color='gray') ax.axvspan(2, 100, alpha=0.2, color='gray') ax.semilogx(coh3000, 'r', label='3000 m ') ax.semilogx(freq, spac_kagra(freq, 3000.0), 'k--', label='3000 m model') ax.semilogx(coh30, 'b', label='22 m') ax.semilogx(freq, spac_kagra(freq, 22.0), 'k--', label='3000 m model') #ax.semilogx(coh60,'g',label='60 m ') #ax.semilogx(freq,spac_kagra(freq,62.0),'k--',label='60 m model') ax.set_ylim(-1.1, 1.1) ax.set_xlim(0.01, 20) ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Coherence') ax.set_yticks(np.arange(-1.0, 1.1, 0.5)) ax.text(110, -1.1, 'START : {0}'.format(start), rotation=90, ha='left', va='bottom') ax.legend() plt.savefig('./{0}/img_SPAC.png'.format(segname)) print('saved ./{0}/img_SPAC.png'.format(segname)) plt.close() # ------------------------------------------ # Spatial autocorrection (SPAC) X # ------------------------------------------ if 'EW' in ts_ixv.name: fig, ax = plt.subplots(1, 1, figsize=(8, 6)) plt.title(segname.replace('_', '\_') + ', X') ax.axvspan(0.01, 0.1, alpha=0.2, color='gray') ax.axvspan(1.5, 100, alpha=0.2, color='gray') ax.semilogx(coh3000, 'r', label='3000 m ') ax.semilogx(freq, spac_kagra_r(freq, 3000.0), 'k--', label='3000 m model') ax.semilogx(freq, spac_kagra_p(freq, 3000.0), 'g--', label='3000 m model (p)') ax.semilogx(coh30, 'b', label='22 m') ax.semilogx(freq, spac_kagra_r(freq, 22.0), 'k--', label='22 m model') ax.semilogx(freq, spac_kagra_p(freq, 22.0), 'g--', label='22 m model (p)') #ax.semilogx(coh60,'g',label='60 m ') #ax.semilogx(freq,spac_kagra_x(freq,62.0),'k--',label='60 m model') ax.set_ylim(-1.1, 1.1) ax.set_xlim(0.01, 20) ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Coherence') ax.set_yticks(np.arange(-1.0, 1.1, 0.5)) ax.text(110, -1.1, 'START : {0}'.format(start), rotation=90, ha='left', va='bottom') ax.legend() plt.savefig('./{0}/img_SPAC_X.png'.format(segname)) print('saved ./{0}/img_SPAC_X.png'.format(segname)) plt.close() # ------------------------------------------ # Reyleigh wave velocity in KAGRA and Virgo # ------------------------------------------ if check_velocity: fig, ax = plt.subplots(1, 1, figsize=(7, 6)) plt.title('Phase Velocity of Rayleigh Wave', fontsize=25) ax.loglog(freq, cr_virgo(freq), 'k', label='Virgo') ax.loglog(freq, cr_kagra(freq), 'r', label='KAGRA (Vertical)') ax.loglog(freq, cr_kagra_x(freq), 'r--', label='KAGRA (Horizontal)??') ax.loglog(freq, cp_kagra_x(freq), 'r:', label='ref. KAGRA P-wave') ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Velocity [m/s]') ax.set_ylim(100, 10e3) ax.set_xlim(1e-3, 100) ax.legend(fontsize=15) plt.savefig('./{0}/img_RwaveVelocity.png'.format(segname)) print('saved ./{0}/img_RwaveVelocity.png'.format(segname)) plt.close() # ---------------------------------- # Reduction Rate of arm displacement in KAGRA and Virgo # ---------------------------------- if check_reduction_rate: fig, ax = plt.subplots(1, 1, figsize=(7, 6)) plt.title('Displacement Reduction of the Bedrock', fontsize=25) ax.loglog(freq, reduction(freq, cr_virgo(freq), L_Virgo), 'k', label='Virgo (Z velo.)') ax.loglog(freq, reduction(freq, cr_kagra_x(freq), L_KAGRA), 'r', label='KAGRA (X velo.)') ax.set_xlim(0.01, 20) ax.set_ylim(1e-3, 2) ax.legend(fontsize=15) ax.set_xlabel('Frequency [Hz]') ax.set_ylabel('Reduction Rate') plt.savefig('./{0}/img_ReductionRate.png'.format(segname)) print('saved ./{0}/img_ReductionRate.png'.format(segname)) plt.close()
def percentile(axis, **kwargs): if axis == 'H': x = _percentile('X', **kwargs) y = _percentile('Y', **kwargs) return (x**2 + y**2)**0.5 elif axis in ['X', 'Y', 'Z']: return _percentile(axis, **kwargs) else: raise ValueError('!!!') if __name__ == '__main__': unit = 'um' # tr120 = Trillium('120QA') v2vel = tr120.v2vel # h50 = percentile('H', pctl=50, unit=unit) h10 = percentile('H', pctl=10, unit=unit) h90 = percentile('H', pctl=90, unit=unit) z50 = percentile('Z', pctl=50, unit=unit) z10 = percentile('Z', pctl=10, unit=unit) z90 = percentile('Z', pctl=90, unit=unit) nlnm, nhnm = peterson_noise_model(unit=unit) selfnoise = tr120.selfnoise(unit=unit.replace('um', 'm')) * 1e6 # fig, ax = plt.subplots(1, 1, figsize=(9, 7)) ax.plot_mmm(h50, h10, h90,
def hoge(fname=None, unit='m', **kwargs): # kwargs['unit'] = unit plot_selfnoise = kwargs.pop('plot_selfnoise', True) peterson = kwargs.pop('peterson', True) prefix, suffix = fname.split('_compare_') path = prefix.split('_') dof, suffix = suffix[:-4].split('_with_') dof = dof.split('_vs_') option = suffix.split('_') dof = list(set(dof)) #print(path) if not len(set(dof) & set(['X', 'Y', 'Z', 'H', 'V'])): path = [path[0] + '_' + _dof for _dof in dof] dof = list(filter(lambda x: x in ['X', 'Y', 'Z', 'H', 'V'], option)) option = list(set(option) ^ set(dof)) data = [] for _path in path: for _dof in dof: if 'V' in _path: model = '120QA' else: model = 'compact' data += [huge(_dof, _dir=_path, model=model, **kwargs)] # Plot fig, ax = plt.subplots(1, 1, figsize=(8, 7)) colors = ['blue', 'red', 'green', 'magenta'] label = ['{0}_{1}'.format(_path, _dof) for _dof in dof for _path in path] if len(data) != len(label): raise ValueError('plot error.') for _data, _color, _label in zip(data, colors, label): asd01, asd10, asd50, asd90, asd99, asdmean = _data ax.loglog(asdmean.frequencies.value, asdmean.value, color='k') if '_V' in _label: _color = 'red' if '90' in option: ax.plot_mmm(asd50, asd10, asd90, color=_color, alpha=0.3, label=_label) if '99' in option: ax.plot_mmm(asd50, asd01, asd99, color=_color, zorder=0, alpha=0.1) if plot_selfnoise: if 'V' in path[0]: model = '120QA' else: model = 'compact' seis = Trillium(model) if 'um' in unit: selfnoise = seis.selfnoise(unit=unit.replace('um', 'm')) * 1e6 else: selfnoise = seis.selfnoise(unit=unit) ax.loglog(selfnoise, 'g--', label='Selfnoise of Trillium 120Q seismometer', alpha=1.0) if peterson: nlnm, nhnm = peterson_noise_model(unit=unit) ax.loglog(nlnm[0], nlnm[1], '--', color='black') ax.loglog(nhnm[0], nhnm[1], '--', label='Peterson Low and High Noise Models', color='black') ax.set_xscale('log') ax.set_yscale('log') ax.set_xlabel('Frequency [Hz]', fontsize=20) ax.set_xlim(1e-3, 100) if unit == 'um/sec/sec': ax.set_ylim(1e-4, 1e3) ax.set_ylabel('Acceleration [um/sec/sec/rtHz]', fontsize=20) elif unit == 'm/sec/sec': ax.set_ylim(1e-10, 1e-3) ax.set_ylabel('ASD [$\mathrm{m}/\mathrm{s}^2/ \sqrt{\mathrm{Hz}}$]', fontsize=20) if unit == 'um/sec': ax.set_ylim(1e-5, 10) ax.set_ylabel('Velocity [um/sec/rtHz]', fontsize=20) elif unit == 'um': ax.set_ylim(1e-6, 1e2) ax.set_yticks(np.logspace(-6, 2, 9)) ax.set_ylabel('Displacement [um/rtHz, or um]', fontsize=20) elif unit == 'm': ax.set_ylim(1e-13, 1e-4) ax.set_yticks(np.logspace(-13, -4, 10)) ax.set_ylabel('Displacement [m/rtHz', fontsize=20) ax.legend(fontsize=14) #,loc='lower left') ax.grid(b=True, which='major', axis='both', linestyle='-') ax.grid(b=True, which='minor', axis='both', linestyle='--') #plt.suptitle(fname[:-4],fontsize=20) print('./results/' + fname) plt.tight_layout() plt.savefig('./results/' + fname) plt.close()
import numpy as np import matplotlib.pyplot as plt from gwpy.plot import Plot from gwpy.timeseries import TimeSeriesDict, TimeSeries from gwpy.time import tconvert from glue import lal import sys sys.path.insert(0, '../../miyopy') from miyopy.utils.trillium import Trillium from gwpy.frequencyseries import FrequencySeries from astropy import units as u from lalframe.utils import frtools amp = 10**(30 / 20.) _v2vel = 1 / 1202.5 * u.m / u.s / u.V tr120q = Trillium('120QA') v2vel = tr120q.v2vel # -------------------- # Utils # -------------------- def asd(ts, fftlength=2**10, percentile=50): sg = ts.spectrogram2(fftlength=fftlength, overlap=fftlength / 2.0)**(1 / 2.) return sg.percentile(percentile) def csd(ts1, ts2, fftlength=2**10): csd = ts1.csd(ts2, fftlength=fftlength) return csd
'X1500_TR240posEW', format='gwf.lalframe') strain = TimeSeries.read(gwf_fmt.format(sensor='strain'), 'CALC_STRAIN', format='gwf.lalframe') print('read') # calc asd x1500_x.name = 'x1500' strain.name = 'strain' median_x1500, low_x1500, high_x1500 = calc_asd(x1500_x) median_strain, low_strain, high_strain = calc_asd(strain) print('calc asd') # calib tr240 = Trillium('240') median_x1500 = tr240.v2vel(median_x1500) / 2.0 low_x1500 = tr240.v2vel(low_x1500) / 2.0 high_x1500 = tr240.v2vel(high_x1500) / 2.0 median_strain = median_strain low_strain = low_strain high_strain = high_strain # save as hdf5 hdf5_fmt = './{dataname}/Xaxis_{sensor}_{pct}.hdf5'.replace( "{dataname}", dataname) x1500_fmt = hdf5_fmt.replace("{sensor}", 'x1500') save(median_x1500, fname=x1500_fmt.format(pct='50pct')) save(low_x1500, fname=x1500_fmt.format(pct='5pct')) save(high_x1500, fname=x1500_fmt.format(pct='95pct')) strain_fmt = hdf5_fmt.replace("{sensor}", 'strain')