|
1
|
|
|
import pandas as pd |
|
|
|
|
|
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
class DataAnalysisBin(object): |
|
|
|
|
|
|
5
|
|
|
|
|
6
|
|
|
def __init__(self, name, observation_hpx_map, background_hpx_map, active_pixels_ids, n_transits, scheme='RING'): |
|
|
|
|
|
|
7
|
|
|
|
|
8
|
|
|
# Get nside |
|
9
|
|
|
self._nside = observation_hpx_map.nside |
|
10
|
|
|
|
|
11
|
|
|
nside_bkg = background_hpx_map.nside |
|
12
|
|
|
|
|
13
|
|
|
assert self._nside == nside_bkg, "Observation and background maps have " \ |
|
14
|
|
|
"different nside (%i vs %i)" % (self._nside, nside_bkg) |
|
15
|
|
|
|
|
16
|
|
|
self._npix = observation_hpx_map.npix |
|
17
|
|
|
|
|
18
|
|
|
# Store healpix maps |
|
19
|
|
|
self._observation_hpx_map = observation_hpx_map |
|
20
|
|
|
|
|
21
|
|
|
self._background_hpx_map = background_hpx_map |
|
22
|
|
|
|
|
23
|
|
|
# Store the active pixels (i.e., the pixels that are within the selected ROI) |
|
24
|
|
|
self._active_pixels_ids = active_pixels_ids |
|
25
|
|
|
|
|
26
|
|
|
# Store name and scheme |
|
27
|
|
|
self._name = str(name) |
|
28
|
|
|
|
|
29
|
|
|
assert scheme in ['RING', 'NEST'], "Scheme must be either RING or NEST" |
|
30
|
|
|
|
|
31
|
|
|
self._scheme = scheme |
|
32
|
|
|
|
|
33
|
|
|
self._n_transits = n_transits |
|
34
|
|
|
|
|
35
|
|
|
def to_pandas(self): |
|
|
|
|
|
|
36
|
|
|
|
|
37
|
|
|
# Make a dataframe |
|
38
|
|
|
df = pd.DataFrame.from_dict({'observation': self._observation_hpx_map.to_pandas(), |
|
|
|
|
|
|
39
|
|
|
'background': self._background_hpx_map.to_pandas()}) |
|
40
|
|
|
|
|
41
|
|
|
if self._active_pixels_ids is not None: |
|
42
|
|
|
# We are saving only a subset |
|
43
|
|
|
df.set_index(self._active_pixels_ids, inplace=True) |
|
44
|
|
|
|
|
45
|
|
|
# Some metadata |
|
46
|
|
|
meta = {'scheme': 0 if self._scheme == 'RING' else 1, |
|
47
|
|
|
'n_transits': self._n_transits, |
|
48
|
|
|
'nside': self._nside} |
|
49
|
|
|
|
|
50
|
|
|
return df, meta |
|
51
|
|
|
|
|
52
|
|
|
@property |
|
53
|
|
|
def name(self): |
|
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
return self._name |
|
56
|
|
|
|
|
57
|
|
|
@property |
|
58
|
|
|
def n_transits(self): |
|
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
return self._n_transits |
|
61
|
|
|
|
|
62
|
|
|
@property |
|
63
|
|
|
def scheme(self): |
|
|
|
|
|
|
64
|
|
|
|
|
65
|
|
|
return self._scheme |
|
66
|
|
|
|
|
67
|
|
|
@property |
|
68
|
|
|
def nside(self): |
|
|
|
|
|
|
69
|
|
|
|
|
70
|
|
|
return self._nside |
|
71
|
|
|
|
|
72
|
|
|
@property |
|
73
|
|
|
def npix(self): |
|
|
|
|
|
|
74
|
|
|
return self._npix |
|
75
|
|
|
|
|
76
|
|
|
@property |
|
77
|
|
|
def observation_map(self): |
|
|
|
|
|
|
78
|
|
|
|
|
79
|
|
|
return self._observation_hpx_map |
|
80
|
|
|
|
|
81
|
|
|
@property |
|
82
|
|
|
def background_map(self): |
|
|
|
|
|
|
83
|
|
|
|
|
84
|
|
|
return self._background_hpx_map |
|
85
|
|
|
|
The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:
If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.