Skip to content

Commit e45e844

Browse files
authored
Merge pull request #6 from fermiPy/dmcat-dev
Documentation formatting for readthedocs.
2 parents dfd18ee + 07c4941 commit e45e844

10 files changed

Lines changed: 478 additions & 116 deletions

File tree

dmsky/density.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#!/usr/bin/env python
22

33
"""
4+
45
Density profiles need to be set by:
6+
57
1) rhos and rs
68
2) Integrated J-factor at a given radius and scale radius
79
3) Ingegrated J-factor only (need to approximate scale radius)
@@ -24,7 +26,12 @@
2426

2527

2628
class DensityProfile(Model):
27-
"""A DM density profile"""
29+
"""Am abstract base class for DM density profiles
30+
31+
At a minimum sub-classes need to implement the self._rho(r) method
32+
to compute the density as a function of radius from the center of the halo
33+
34+
"""
2835
_params = odict([
2936
('rs', Parameter(default=1.0)),
3037
('rhos', Parameter(default=1.0)),

dmsky/file_io/table.py

Lines changed: 174 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
"""
3-
Module file IO using astropy.table class.
3+
Module that handles file IO using `astropy.table.Table` class.
44
"""
55

66
from astropy import table
@@ -12,7 +12,24 @@
1212

1313

1414
def get_column_kwargs(name, prop):
15-
"""Get keyword arguments needed to build a column for a `Property` object
15+
"""Get keyword arguments needed to build a column for a `dmsky.Property` object
16+
17+
Parameters
18+
----------
19+
20+
name : str
21+
Name of the Column we will build
22+
23+
prop : `dmsky.Property`
24+
Property object we are building the column for
25+
26+
27+
Returns
28+
-------
29+
30+
opt_keys : dict
31+
A dictionary we can use to constuct a `astropy.table.Column`
32+
1633
"""
1734
opt_keys = ['data', 'unit', 'shape', 'length']
1835
d = dict(data=None,
@@ -36,6 +53,23 @@ def get_column_kwargs(name, prop):
3653

3754
def get_row_values(model, keys):
3855
"""Get the values needed to fill a row in the table
56+
57+
Parameters
58+
----------
59+
60+
model : `dmsky.Model`
61+
Model that we are getting the data from
62+
63+
keys : list
64+
Names of the properties we are reading
65+
66+
67+
Returns
68+
-------
69+
70+
vals : dict
71+
A dictionary we can use to fill an `astropy.table.Column` row
72+
3973
"""
4074
d = {}
4175
for k in keys:
@@ -44,14 +78,50 @@ def get_row_values(model, keys):
4478

4579

4680
def columns_from_property(name, prop):
47-
"""Build a set of `Columns` objects for a `Property` object
81+
"""Build some of `astropy.table.Column` objects for a `dmsky.Property` object
82+
83+
In this case we only build a single column
84+
85+
Parameters
86+
----------
87+
88+
name : str
89+
Name of the Column we will build
90+
91+
prop : `dmsky.Property`
92+
Property object we are building the column for
93+
94+
Returns
95+
-------
96+
97+
cols : list
98+
A list of `astropy.table.Column`
99+
48100
"""
49101
d = get_column_kwargs(name, prop)
50102
return [table.Column(**d)]
51103

52104

53105
def columns_from_parameter(name, prop):
54-
"""Build a set of `Column` objects for a `Parameter` object
106+
"""Build a set of `astropy.table.Column` objects for a `dmsky.Parameter` object
107+
108+
In this case we build a several columns
109+
110+
Parameters
111+
----------
112+
113+
name : str
114+
Base of the names of the Column we will build
115+
116+
prop : `dmsky.Property`
117+
Property object we are building the column for
118+
119+
Returns
120+
-------
121+
122+
cols : list
123+
A list of `astropy.table.Column`
124+
55125
"""
56126
d = get_column_kwargs(name, prop)
57127
c_val = table.Column(**d)
@@ -66,14 +136,48 @@ def columns_from_parameter(name, prop):
66136

67137
def columns_from_derived(name, prop):
68138
"""Build a set of `Column` objects for a `Derived` object
139+
140+
In this case we only build a single column
141+
142+
Parameters
143+
----------
144+
145+
name : str
146+
Name of the Column we will build
147+
148+
prop : `dmsky.Property`
149+
Property object we are building the column for
150+
151+
Returns
152+
-------
153+
154+
cols : list
155+
A list of `astropy.table.Column`
156+
69157
"""
70158
d = get_column_kwargs(name, prop)
71159
return [table.Column(**d)]
72160

73161

74162
def make_columns_for_prop(name, prop):
75-
"""Generic function to make a set of `Column` objects
76-
for any `Property` sub-class
163+
"""Generic function to make a set of `astropy.table.Column` objects
164+
for any `dmsky.Property` sub-class
165+
166+
Parameters
167+
----------
168+
169+
name : str
170+
Name of the Column we will build
171+
172+
prop : `dmsky.Property`
173+
Property object we are building the column for
174+
175+
Returns
176+
-------
177+
178+
cols : list
179+
A list of `astropy.table.Column`
180+
77181
"""
78182
if isinstance(prop, Derived):
79183
return columns_from_derived(name, prop)
@@ -89,6 +193,23 @@ def make_columns_for_prop(name, prop):
89193
def make_columns_for_model(names, model):
90194
"""Make a set of `Column` objects needed to
91195
describe a `Model` object.
196+
197+
Parameters
198+
----------
199+
200+
names : list
201+
List of the names of the properties to convert
202+
203+
model : `dmsky.Model`
204+
Model that we are getting the data from
205+
206+
207+
Returns
208+
-------
209+
210+
clist : list
211+
A list of `astropy.table.Column`
212+
92213
"""
93214
clist = []
94215
for n in names:
@@ -98,16 +219,43 @@ def make_columns_for_model(names, model):
98219

99220

100221
def fill_table_from_targetlist(tab, targetList):
101-
"""Fill a table for a set of `Target` objects
222+
"""Fill a table for a set of `dmsky.Target` objects
223+
224+
Parameters
225+
----------
226+
227+
tab : `astropy.table.Table`
228+
The table we are filling
229+
230+
targetList : list
231+
List of 'dmsky.Target' object used to fill the table
232+
102233
"""
103234
cnames = tab.colnames
104235
for t in targetList:
105236
tab.add_row(get_row_values(t, cnames))
106-
return
237+
107238

108239

109240
def make_table_for_targetlist(colNames, targetList):
110241
"""Build a table for a set of `Target` objects
242+
243+
Parameters
244+
----------
245+
246+
colNames : list
247+
The names of the properties to include in the table
248+
249+
targetList : list
250+
List of 'dmsky.Target' object used to fill the table
251+
252+
253+
Returns
254+
-------
255+
256+
table : `astropy.table.Table`
257+
A table with the data from those targets
258+
111259
"""
112260
clist = make_columns_for_model(colNames, NullTarget)
113261
tab = table.Table(data=clist)
@@ -117,6 +265,24 @@ def make_table_for_targetlist(colNames, targetList):
117265

118266
def make_table_for_roster(colNames, roster):
119267
"""Make a table for a `Roster` object
268+
269+
Parameters
270+
----------
271+
272+
colNames : list
273+
The names of the properties to include in the table
274+
275+
roster : `dmsky.Roster`
276+
Roster used to fill the table
277+
278+
279+
Returns
280+
-------
281+
282+
table : `astropy.table.Table`
283+
A table with the data from that Roster
284+
285+
120286
"""
121287
clist = make_columns_for_model(colNames, NullTarget)
122288
tab = table.Table(data=clist)

dmsky/utils/coords.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ def angsep(lon1, lat1, lon2, lat2):
9292
Angular separation (deg) between two sky coordinates.
9393
Faster than creating astropy coordinate objects.
9494
95+
Parameters
96+
----------
97+
lon1 : `numpy.array`
98+
lat1 : `numpy.array`
99+
lon2 : `numpy.array`
100+
lat2 : `numpy.array`
101+
Coordinates (in degrees)
102+
103+
Returns
104+
-------
105+
dist : `numpy.array`
106+
Angular seperations (in degrees)
107+
95108
Notes
96109
-----
97110
The angular separation is calculated using the Vincenty formula [1],

dmsky/utils/speed.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,3 @@ def speedtest(func, *args, **kwargs):
1616
end = time.time()
1717
return (end - start) / n
1818

19-
if __name__ == "__main__":
20-
from optparse import OptionParser
21-
usage = "Usage: %prog [options] input"
22-
description = "python script"
23-
parser = OptionParser(usage=usage, description=description)
24-
(opts, args) = parser.parse_args()

dmsky/utils/units.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,3 @@ def convert_from(value, key):
109109
if conv is None:
110110
return value
111111
return value * conv
112-
113-
114-
if __name__ == "__main__":
115-
import argparse
116-
description = __doc__
117-
parser = argparse.ArgumentParser(description=description)
118-
args = parser.parse_args()

dmsky/utils/wcs.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,3 @@ def write_image_hdu(filename, data, wcs, name=None, clobber=False):
101101
"""
102102
hdu = create_image_hdu(data, wcs, name)
103103
hdu.writeto(filename, clobber=clobber)
104-
105-
106-
if __name__ == "__main__":
107-
import argparse
108-
parser = argparse.ArgumentParser(description=__doc__)
109-
args = parser.parse_args()

0 commit comments

Comments
 (0)