Skip to content

Commit bba4ea9

Browse files
committed
add get_spec
1 parent f53d8a7 commit bba4ea9

File tree

4 files changed

+63
-20
lines changed

4 files changed

+63
-20
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,37 @@ Install the latest version of *stelspec* from [PyPI](https://pypi.org/project/st
1313

1414
Requirements are *requests*, *numpy* and *pandas*.
1515

16+
## Quick start
17+
18+
Let's start by creating an Elodie instance by passing an object name:
19+
20+
```python
21+
import stelspec as sp
22+
23+
el = Elodie('HD217014')
24+
```
25+
26+
You can access two tables, ccf and Spectra, as pandas DataFrame.
27+
28+
```python
29+
# table: Cross-Correlation Functions
30+
df_ccf = el.ccf()
31+
32+
# table: Spectra
33+
df_spc = el.spec()
34+
```
35+
36+
You can also download spectra as FITS file, whether in *s1d* or *s2d* format:
37+
38+
```python
39+
# download spectrum FITS file in s1d format
40+
el.get_spec(dataset=19960831, imanum='0017', path='data/', s1d=True)
41+
42+
# download spectrum FITS file in s2d format
43+
el.get_spec(dataset=19960831, imanum='0017', path='data/', s1d=Flase)
44+
```
45+
46+
The same process can be done for Sophie, except that instead of *dataset* and
47+
*imanum*, you should pass the *seq* number.
48+
49+
For a brief help the structure of FITS files, see [ELODIE](http://atlas.obs-hp.fr/elodie/500/download.html) and [SOPHIE](http://atlas.obs-hp.fr/sophie/spec_help.html).

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="stelspec",
8-
version="0.0.3",
8+
version="0.0.4",
99
author="Behrouz Safari",
1010
author_email="behrouz.safari@gmail.com",
1111
description="A python package for retrieving and analysing stellar spectra (ELODIE-SOPHIE Archive)",

stelspec/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
from .core import Elodie, Sophie
22
from .columns import desc_el_ccf, desc_el_spec, desc_so_ccf, desc_so_spec
33

4-
__version__ = "0.0.3"
4+
__version__ = "0.0.4"

stelspec/core.py

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
11
"""
2-
Module catalogues
3-
=================
4-
This module retrieves data from ELODIE/SOPHIE archive.
2+
Module core
3+
===========
4+
This module retrieves data from ELODIE/SOPHIE archive. It has two classes,
5+
Elodie and Sophie, both could be constructed by passing an object name.
6+
7+
Help on Elodie FITS files:
8+
http://atlas.obs-hp.fr/elodie/500/download.html
9+
10+
Help on Sophie FITS files:
11+
http://atlas.obs-hp.fr/sophie/spec_help.html
512
"""
613

714
import numpy as np
@@ -10,8 +17,8 @@
1017
from urllib.request import urlretrieve
1118
from .columns import desc_el_ccf, desc_el_spec, desc_so_ccf, desc_so_spec
1219

13-
def _get_df(base, col_dc, int_cols, float_cols):
14-
url = base + str(list(col_dc.keys())).replace("'", "").replace(" ", "")[1:-1]
20+
def _get_df(url_, col_dc, int_cols, float_cols):
21+
url = url_ + str(list(col_dc.keys())).replace("'", "").replace(" ", "")[1:-1]
1522
req = requests.request('GET', url)
1623
r = req.content.decode('utf-8')
1724
lines = r.splitlines()
@@ -41,30 +48,31 @@ def __init__(self, obj):
4148
spect : Spectra table
4249
"""
4350
self.obj = obj
51+
self.BASE = 'http://atlas.obs-hp.fr/elodie/fE.cgi?'
4452

4553
def ccf(self):
4654
"""
4755
Elodie Cross-Correlation Functions table
4856
"""
49-
BASE = f'http://atlas.obs-hp.fr/elodie/fE.cgi?n=e501&o={self.obj}&ob=jdb&a=csv&&d='
57+
url_ = self.BASE + f'n=e501&o={self.obj}&ob=jdb&a=csv&&d='
5058
int_cols = ['datenuit']
5159
float_cols = ['jdb','exptim','sn','vfit','sigfit','ampfit','ctefit']
52-
url, df = _get_df(BASE, desc_el_ccf, int_cols, float_cols)
60+
url, df = _get_df(url_, desc_el_ccf, int_cols, float_cols)
5361
print(url.replace('a=csv', 'a=htab'))
5462
return df
5563

5664
def spec(self):
5765
"""
5866
Elodie Spectra table
5967
"""
60-
BASE = f'http://atlas.obs-hp.fr/elodie/fE.cgi?o={self.obj}&a=csv&d='
68+
url_ = self.BASE + f'o={self.obj}&a=csv&d='
6169
int_cols = ['dataset']
6270
float_cols = ['exptime','sn','vfit','sigfit','ampfit']
63-
url, df = _get_df(BASE, desc_el_spec, int_cols, float_cols)
71+
url, df = _get_df(url_, desc_el_spec, int_cols, float_cols)
6472
print(url.replace('a=csv', 'a=htab'))
6573
return df
6674

67-
def get_spec(dataset, imanum, s1d=True, path=None):
75+
def get_spec(self, dataset, imanum, path=None, s1d=True):
6876
BASE = 'http://atlas.obs-hp.fr/elodie/E.cgi?'
6977
s1 = '&z=s1d' if s1d else ''
7078
PAR1 = f'&c=i&o=elodie:{dataset}/{imanum}'
@@ -90,32 +98,33 @@ def __init__(self, obj):
9098
spect : Spectra table
9199
"""
92100
self.obj = obj
101+
self.BASE = 'http://atlas.obs-hp.fr/sophie/sophie.cgi?'
93102

94103
def ccf(self):
95104
"""
96105
Sophie Cross-Correlation Functions table
97106
"""
98-
BASE = f'http://atlas.obs-hp.fr/sophie/sophie.cgi?n=sophiecc&ob=bjd&a=csv&o={self.obj}&d='
107+
url_ = self.BASE + f'n=sophiecc&ob=bjd&a=csv&o={self.obj}&d='
99108
int_cols = ['seq','sseq','slen','nexp','expno','ccf_offline','maxcpp','lines']
100109
float_cols = ['bjd','rv','err','dvrms','fwhm','span','contrast','sn26']
101-
url, df = _get_df(BASE, desc_so_ccf, int_cols, float_cols)
110+
url, df = _get_df(url_, desc_so_ccf, int_cols, float_cols)
102111
print(url.replace('a=csv', 'a=htab'))
103112
return df
104113

105114
def spec(self):
106115
"""
107116
Sophie Spectra table
108117
"""
109-
BASE = f'http://atlas.obs-hp.fr/sophie/sophie.cgi?n=sophie&a=csv&ob=bjd&c=o&o={self.obj}&d='
118+
url_ = self.BASE + f'n=sophie&a=csv&ob=bjd&c=o&o={self.obj}&d='
110119
int_cols = ['seq','sseq','slen','nexp','expno']
111120
float_cols = ['bjd','sn26','exptime']
112-
url, df = _get_df(BASE, desc_so_spec, int_cols, float_cols)
121+
url, df = _get_df(url_, desc_so_spec, int_cols, float_cols)
113122
print(url.replace('a=csv', 'a=htab'))
114123
return df
115124

116-
def get_spec(seq, path=None):
117-
url = f'http://atlas.obs-hp.fr/sophie/sophie.cgi?c=i&a=mime:application/fits&o=sophie:[s1d,{seq}]'
118-
filename = f'sophie_[s1d,{seq}].fits'
125+
def get_spec(self, seq, path=None, s1d=True):
126+
s1d = 's1d' if s1d==True else 'e2ds'
127+
url = self.BASE + f'c=i&a=mime:application/fits&o=sophie:[{s1d},{seq}]'
128+
filename = f'sophie_[{s1d},{seq}].fits'
119129
path = '' if path is None else path
120130
urlretrieve(url, path+filename)
121-

0 commit comments

Comments
 (0)