本文整理汇总了Python中astropy.utils.OrderedDict.items方法的典型用法代码示例。如果您正苦于以下问题:Python OrderedDict.items方法的具体用法?Python OrderedDict.items怎么用?Python OrderedDict.items使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类astropy.utils.OrderedDict
的用法示例。
在下文中一共展示了OrderedDict.items方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _args_to_payload
# 需要导入模块: from astropy.utils import OrderedDict [as 别名]
# 或者: from astropy.utils.OrderedDict import items [as 别名]
def _args_to_payload(self, *args, **kwargs):
"""
accepts the arguments for different query functions and
builds a script suitable for the Vizier votable CGI.
"""
body = OrderedDict()
center = kwargs.get('center')
# process: catalog
catalog = kwargs.get('catalog')
if catalog is None:
catalog = self.catalog
if catalog is not None:
if isinstance(catalog, basestring):
body['-source'] = catalog
elif isinstance(catalog, list):
body['-source'] = ",".join(catalog)
else:
raise TypeError("Catalog must be specified as list or string")
# process: columns
columns = kwargs.get('columns')
if columns is None:
columns = self.columns
else:
columns = self.columns + columns
# process: columns - always request computed positions in degrees
if "_RAJ2000" not in columns:
columns += ["_RAJ2000"]
if "_DEJ2000" not in columns:
columns += ["_DEJ2000"]
# process: columns - identify sorting requests
columns_out = []
sorts_out = []
for column in columns:
if column[0] == '+':
columns_out += [column[1:]]
sorts_out += [column[1:]]
elif column[0] == '-':
columns_out += [column[1:]]
sorts_out += [column]
else:
columns_out += [column]
body['-out'] = ','.join(columns_out)
if len(sorts_out)>0:
body['-sort'] = ','.join(sorts_out)
# process: maximum rows returned
if self.ROW_LIMIT < 0:
body["-out.max"] = 'unlimited'
else:
body["-out.max"] = self.ROW_LIMIT
# process: column filters
column_filters = self.column_filters.copy()
column_filters.update(kwargs.get('column_filters', {}))
for (key, value) in column_filters.items():
body[key] = value
# process: center
if center is not None:
for (key, value) in center.items():
body[key] = value
# add column metadata: name, unit, UCD1+, and description
body["-out.meta"] = "huUD"
# computed position should always be in decimal degrees
body["-oc.form"] = "d"
# create final script
script = "\n".join(["{key}={val}".format(key=key, val=val)
for key, val in body.items()])
# add keywords
if not isinstance(self.keywords, property) and self.keywords is not None:
script += "\n" + str(self.keywords)
return script
示例2: _args_to_payload
# 需要导入模块: from astropy.utils import OrderedDict [as 别名]
# 或者: from astropy.utils.OrderedDict import items [as 别名]
def _args_to_payload(self, *args, **kwargs):
"""
accepts the arguments for different query functions and
builds a script suitable for the Vizier votable CGI.
"""
body = OrderedDict()
center = kwargs.get('center')
# process: catalog
catalog = kwargs.get('catalog')
if catalog is None:
catalog = self.catalog
if catalog is not None:
if isinstance(catalog, six.string_types):
body['-source'] = catalog
elif isinstance(catalog, list):
body['-source'] = ",".join(catalog)
else:
raise TypeError("Catalog must be specified as list or string")
# process: columns
columns = kwargs.get('columns')
if columns is None:
columns = copy.copy(self.columns)
else:
columns = self.columns + columns
# keyword names that can mean 'all' need to be treated separately
alls = ['all','*']
if any(x in columns for x in alls):
for x in alls:
if x in columns:
columns.remove(x)
body['-out.all'] = 2
# process: columns - always request computed positions in degrees
if "_RAJ2000" not in columns:
columns += ["_RAJ2000"]
if "_DEJ2000" not in columns:
columns += ["_DEJ2000"]
# process: columns - identify sorting requests
columns_out = []
sorts_out = []
for column in columns:
if column[0] == '+':
columns_out += [column[1:]]
sorts_out += [column[1:]]
elif column[0] == '-':
columns_out += [column[1:]]
sorts_out += [column]
else:
columns_out += [column]
body['-out.add'] = ','.join(columns_out)
body['-out'] = columns_out
if len(sorts_out) > 0:
body['-sort'] = ','.join(sorts_out)
# process: maximum rows returned
row_limit = kwargs.get('row_limit') or self.ROW_LIMIT
if row_limit < 0:
body["-out.max"] = 'unlimited'
else:
body["-out.max"] = row_limit
# process: column filters
column_filters = self.column_filters.copy()
column_filters.update(kwargs.get('column_filters', {}))
for (key, value) in column_filters.items():
body[key] = value
# process: center
if center is not None:
for (key, value) in center.items():
body[key] = value
# add column metadata: name, unit, UCD1+, and description
body["-out.meta"] = "huUD"
# merge tables when a list is queried against a single catalog
body["-out.form"] = "mini"
# computed position should always be in decimal degrees
body["-oc.form"] = "d"
ucd = kwargs.get('ucd', "") + self.ucd
if ucd:
body['-ucd'] = ucd
# create final script
script = "\n".join(["{key}={val}".format(key=key, val=val)
for key, val in body.items()])
# add keywords
if not isinstance(self.keywords, property) and self.keywords is not None:
script += "\n" + str(self.keywords)
return script
示例3: _args_to_payload
# 需要导入模块: from astropy.utils import OrderedDict [as 别名]
# 或者: from astropy.utils.OrderedDict import items [as 别名]
def _args_to_payload(self, *args, **kwargs):
"""
accepts the arguments for different query functions and
builds a script suitable for the Vizier votable CGI.
"""
body = OrderedDict()
caller = kwargs['caller']
del kwargs['caller']
catalog = kwargs.get('catalog')
if catalog is not None:
if isinstance(catalog, basestring):
body['-source'] = catalog
elif isinstance(catalog, list):
body['-source'] = ",".join(catalog)
else:
raise TypeError("Catalog must be specified as list or string")
if caller == 'query_object_async':
body["-c"] = args[0]
elif caller == 'query_region_async':
c = commons.parse_coordinates(args[0])
ra = str(c.icrs.ra.degree)
dec = str(c.icrs.dec.degree)
if dec[0] not in ['+', '-']:
dec = '+' + dec
body["-c"] = "".join([ra, dec])
# decide whether box or radius
if kwargs.get('radius') is not None:
radius = kwargs['radius']
unit, value = _parse_dimension(radius)
switch = "-c.r" + unit
body[switch] = value
elif kwargs.get('width') is not None:
width = kwargs['width']
w_unit, w_value = _parse_dimension(width)
switch = "-c.b" + w_unit
height = kwargs.get('height')
# is box a rectangle or square?
if height is not None:
h_unit, h_value = _parse_dimension(height)
if h_unit != w_unit:
warnings.warn(
"Converting height to same unit as width")
h_value = u.Quantity(h_value, u.Unit
(_str_to_unit(h_unit))).to(u.Unit(_str_to_unit(w_unit)))
body[switch] = "x".join([str(w_value), str(h_value)])
else:
body[switch] = "x".join([str(w_value)] * 2)
elif kwargs.get('height'):
warnings.warn(
"No width given - shape interpreted as square (height x height)")
height = kwargs['height']
h_unit, h_value = _parse_dimension(height)
switch = "-c.b" + h_unit
body[switch] = h_value
else:
raise Exception(
"At least one of radius, width/height must be specified")
# set output parameters
if not isinstance(self.columns, property) and self.columns is not None:
if "all" in self.columns:
body["-out"] = "**"
else:
out_cols = ",".join([col for col in self.columns])
# if default then return default cols and listed cols
if "default" in self.columns:
body["-out.add"] = out_cols
# else return only the listed cols
else:
body["-out"] = out_cols
# otherwise ask to return default columns
else:
body["-out"] = "*"
# set the maximum rows returned
body["-out.max"] = Vizier.ROW_LIMIT
script = "\n".join(["{key}={val}".format(key=key, val=val)
for key, val in body.items()])
# add keywords
if not isinstance(self.keywords, property) and self.keywords is not None:
script += "\n" + str(self.keywords)
# add column filters
if not isinstance(self.column_filters, property) and self.column_filters is not None:
filter_str = "\n".join(["{key}={constraint}".format(key=key, constraint=constraint) for key, constraint in
self.column_filters.items()])
script += "\n" + filter_str
return script