pull_slitorie.py 817 Bytes
Newer Older
Carl Schaffer's avatar
Carl Schaffer committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env python3

import sys
from pathlib import Path

import pandas as pd

from kis_tools.util.util import gris_run_number, date_from_fn

fn = sys.argv[1]
assert Path(fn).exists(), f'Invalid input file {fn} not found!'

from scipy.io.idl import readsav

data = readsav(fn)
# rotation angle of the slit with respect to the solar equator
angle = data['slit_angle']

run = gris_run_number(fn)
date = date_from_fn(fn)

ser = pd.Series({'slit_angle': angle})
df = pd.DataFrame()
df[f'gris_{date.strftime("%Y%m%d")}_{run:03d}'] = ser
df = df.T
df.index.name = 'obs_name'

from sqlalchemy import create_engine

outfile = Path(__file__).parent / 'gris_coords.db'
db_name = 'sqlite:///' + str(outfile)
engine = create_engine(str(db_name))
df.to_sql('slit_angle', con=engine, if_exists='append', index_label='obs_name')