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
66from astropy import table
1212
1313
1414def 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
3754def 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
4680def 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
53105def 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
67137def 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
74162def 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):
89193def 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
100221def 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
109240def 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
118266def 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 )
0 commit comments