text
stringlengths 0
828
|
---|
query = {""output"": ""json"", ""user_credentials"": self.api_key}
|
resp = requests.get(
|
""%sdownload/%s"" % (self._url, download_key),
|
params=query,
|
timeout=self._timeout,
|
)
|
if raise_exception_on_failure and resp.status_code != 200:
|
raise DocumentDownloadFailure(resp.content, resp.status_code)
|
return resp"
|
243,"def merge_INIConf(a, b):
|
""""""用 b 的内容覆盖 a 的内容(若重名),并返回 a
|
""""""
|
for sname in b.sections():
|
if a.has_section(sname):
|
for oname in b.options(sname):
|
a[sname][oname] = b[sname][oname]
|
else:
|
a[sname] = b[sname]
|
return a"
|
244,"def copy_from_dict(self, adict, parent=None):
|
""""""从一个已经存在的 dict 中复制所有的值。
|
:param adict: 被复制的 dict。
|
:type adict: dict
|
:param parent: 复制到哪个父对象。
|
若为 None 则复制到 self 。
|
:type parent: rookout.PYConf
|
""""""
|
if not parent:
|
parent = self
|
for k,v in adict.items():
|
if isinstance(v, dict):
|
vDict = PYConf(v)
|
self.copy_from_dict(v, vDict)
|
parent[k] = vDict
|
else:
|
parent[k] = v"
|
245,"def dump(self, human=False):
|
""""""将自身内容打印成字符串
|
:param bool human: 若值为 True ,则打印成易读格式。
|
""""""
|
txt = str(self)
|
if human:
|
txt = txt.replace("", '"", "",\n'"")
|
txt = txt.replace(""{"", ""{\n"")
|
txt = txt.replace(""}"", ""\n}"")
|
txt = txt.replace(""["", ""[\n"")
|
txt = txt.replace(""]"", ""\n]"")
|
return txt"
|
246,"def save_to_file(self, path, human=True):
|
""""""将自身内容保存到文件。
|
:param str path: 保存的文件路径。
|
:param bool human: 参见 :func:`dump()`
|
""""""
|
write_file(path, self.dump(human))
|
slog.info(""Save %a done."", path)"
|
247,"def read_from_file(self, path):
|
""""""从一个文本文件中读入信息。
|
假设该文本文件的格式与 :func:`dump()` 相同。
|
:param str path: 待读入的文件路径。
|
""""""
|
if not os.path.exists(path):
|
slog.warning(""The file %s is not exist."", path)
|
return False
|
txt = read_file(path)
|
dic = eval(txt)
|
self.copy_from_dict(dic)
|
return True"
|
248,"def _set_parameters(self, parameters):
|
""""""Sort out the various possible parameter inputs and return a config
|
object (dict)
|
We have multiple input formats:
|
1) a list, tuple, or numpy.ndarray, containing the linear parameters
|
in the following order:
|
* for single term: rho0, m1, tau1, c1
|
* for multiple termss: rho0, m1, m2, ..., tau1, tau2, ..., c1, c2, ...
|
2) a dictionary with the entries ""rho0"", ""m"", ""tau"", ""c""
|
2b) if the dictionary entries for ""m"", ""tau"", and ""c"" are lists, the
|
entries correspond to mulitple polarisazion terms
|
""""""
|
nr_f = self.f.size
|
# sort out parameters
|
rho0, m, tau, c = self._sort_parameters(parameters)
|
newsize = (nr_f, len(m))
|
# rho0_resized = np.resize(rho0, newsize)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.