Differences between revisions 1 and 2
Revision 1 as of 2020-03-18 15:03:37
Size: 2642
Comment:
Revision 2 as of 2020-03-18 16:33:13
Size: 3978
Comment:
Deletions are marked like this. Additions are marked like this.
Line 42: Line 42:

時刻を指定してファイル一覧を取得するには、以下をコピペして使えば柏でも神岡でも使える。
GPS時刻でも、''sources = get_sources('Mar 9 2020 14:00:00', 'Mar 9 2020 14:05:00')''みたいにUTC時刻でもイケる。
{{{#!python
import os
import numpy as np
from gwpy.timeseries import TimeSeriesDict
from gwpy.time import to_gps
                                                                                  
def get_sources(start, end):
    if os.path.isdir('/frame0'): path = '/frame0/full/'
    elif os.path.isdir('/data/full'): path = '/data/full/'
    else: return

    if type(start) in (int, float):
        ts = int(start)
        te = int(end)
    else:
        ts = int(to_gps(start))
        te = int(to_gps(end))

    t0 = ts - ts%32
    td = te + (32 - te%32) - ts
    N = int(td/32) +1
    sources = []
    for i in range(N):
        dname = path + str(int(t0 + i*32)//100000)
        fname = '/K-K1_C-' + str(int(t0 + i*32)) + '-32.gwf'
        source = dname +fname
        if os.path.isfile(source): sources.append(source)

    return sources
}}}
もしくは、[[https://github.com/gw-detchar/Kozapy/blob/master/samples/mylib/mylib.py|Kozapyのmylib]]にある'' GetFilelist(gpsstart,gpsend)''を使うのも良い。

データの読み書き

時系列データを読む場合は、基本的にgwpy.timeseriesのTimeSeries もしくはTimeSeriesDictを用いる。 単一ファイルの単一チャンネルを読むだけなら前者で十分だが、結局のところ後者の方が上位互換なので、常にそちらを使う方がおススメ。 (gwpy1.0.0では、バグにより単一チャンネルであってもTimeSeriesで複数ファイルをまとめ読みできないとの報告がある。)

frame fileを読む

柏のKAGRAメインサーバー(以下 柏サーバー)では/data 、神岡サーバーでは /frame0 もしくは /frame1 以下にファイルが置いてある。 ディレクトリ構造の詳細はJGW-G1911052を参照。 GPS時刻を調べるには、GPS Time Converterなどを使うのが手っ取り早い。

例えば、2020/3/9 14:00 UTCあたりの干渉計信号(strain)とREFL定盤の加速度計の信号を読むには、

   1 from gwpy.timeseries import TimeSeriesDict
   2 from gwpy.timeseries import TimeSeriesDict
   3 import numpy as np
   4 sources = ['/data/full/12677/K-K1_C-1267797600-32.gwf', '/data/full/12677/K-K1_C-1267797632-32.gwf', '/data/full/12677/K-K1_C-1267797664-32.gwf']
   5 channels = ['K1:CAL-CS_PROC_C00_STRAIN_DBL_DQ', 'K1:PEM-ACC_MCF_TABLE_REFL_Z_OUT_DQ']
   6 data = TimeSeriesDict.read(sources, channels, format='gwf.lalframe', pad=np.nan, nproc=4)
   7 print(data[channels[0]])
   8 print(data[channels[1]])

TimeSeries([ -2.13041590e-12,  -2.12980671e-12,  -2.12920164e-12,
            ...,   3.02297020e-13,   3.03052655e-13,
              3.03810103e-13]
           unit: dimensionless,
           t0: 1267797600.0 s,
           dt: 6.103515625e-05 s,
           name: K1:CAL-CS_PROC_C00_STRAIN_DBL_DQ,
           channel: K1:CAL-CS_PROC_C00_STRAIN_DBL_DQ)
TimeSeries([-0.00049336,  0.00021882, -0.00037257, ...,
             0.0007291 , -0.00051094,  0.00017448]
           unit: dimensionless,
           t0: 1267797600.0 s,
           dt: 0.00048828125 s,
           name: K1:PEM-ACC_MCF_TABLE_REFL_Z_OUT_DQ,
           channel: K1:PEM-ACC_MCF_TABLE_REFL_Z_OUT_DQ)

時刻を指定してファイル一覧を取得するには、以下をコピペして使えば柏でも神岡でも使える。 GPS時刻でも、sources = get_sources('Mar 9 2020 14:00:00', 'Mar 9 2020 14:05:00')みたいにUTC時刻でもイケる。

   1 import os
   2 import numpy as np
   3 from gwpy.timeseries import TimeSeriesDict
   4 from gwpy.time import to_gps
   5                                                                                   
   6 def get_sources(start, end):
   7     if os.path.isdir('/frame0'):        path = '/frame0/full/'
   8     elif os.path.isdir('/data/full'):   path = '/data/full/'
   9     else:        return
  10 
  11     if type(start) in (int, float):
  12         ts = int(start)
  13         te = int(end)
  14     else:
  15         ts = int(to_gps(start))
  16         te = int(to_gps(end))
  17 
  18     t0 = ts - ts%32
  19     td = te + (32 - te%32) - ts
  20     N  = int(td/32) +1
  21     sources = []
  22     for i in range(N):
  23         dname = path + str(int(t0 + i*32)//100000)
  24         fname = '/K-K1_C-' + str(int(t0 + i*32)) + '-32.gwf'
  25         source = dname +fname
  26         if os.path.isfile(source):   sources.append(source)
  27 
  28     return sources

もしくは、Kozapyのmylibにある GetFilelist(gpsstart,gpsend)を使うのも良い。

KAGRA/Subgroups/PEM/PythonMemoJP/ReadFile (last edited 2024-03-11 20:31:28 by tatsuki.washimi)