sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
def roche_misaligned_critical_requiv(q, F, d, s, scale=1.0): """ NOTE: output is in units of scale (so constraints will use SI) NOTE: q should already be flipped (i.e. the output of q_for_component) if necessary NOTE: s should be in roche coordinates at the applicable time/true anomaly """ volume_critical = libphoebe.roche_misaligned_critical_volume(q, F, d, s) logger.debug("libphoebe.roche_misaligned_critical_volume(q={}, F={}, d={}, s={}) => {}".format(q, F, d, s, volume_critical)) requiv_critical = scale * (volume_critical * 3./4 * 1./np.pi)**(1./3) # logger.debug("roche.roche_misaligned_critical_requiv = {}".format(requiv_critical)) return requiv_critical
NOTE: output is in units of scale (so constraints will use SI) NOTE: q should already be flipped (i.e. the output of q_for_component) if necessary NOTE: s should be in roche coordinates at the applicable time/true anomaly
entailment
def rpole_to_pot_aligned(rpole, sma, q, F, d, component=1): """ Transforms polar radius to surface potential """ q = q_for_component(q, component=component) rpole_ = np.array([0, 0, rpole/sma]) logger.debug("libphoebe.roche_Omega(q={}, F={}, d={}, rpole={})".format(q, F, d, rpole_)) pot = libphoebe.roche_Omega(q, F, d, rpole_) return pot_for_component(pot, component, reverse=True)
Transforms polar radius to surface potential
entailment
def pot_to_rpole_aligned(pot, sma, q, F, d, component=1): """ Transforms surface potential to polar radius """ q = q_for_component(q, component=component) Phi = pot_for_component(pot, q, component=component) logger.debug("libphobe.roche_pole(q={}, F={}, d={}, Omega={})".format(q, F, d, pot)) return libphoebe.roche_pole(q, F, d, pot) * sma
Transforms surface potential to polar radius
entailment
def BinaryRoche (r, D, q, F, Omega=0.0): r""" Computes a value of the asynchronous, eccentric Roche potential. If :envvar:`Omega` is passed, it computes the difference. The asynchronous, eccentric Roche potential is given by [Wilson1979]_ .. math:: \Omega = \frac{1}{\sqrt{x^2 + y^2 + z^2}} + q\left(\frac{1}{\sqrt{(x-D)^2+y^2+z^2}} - \frac{x}{D^2}\right) + \frac{1}{2}F^2(1+q)(x^2+y^2) @param r: relative radius vector (3 components) @type r: 3-tuple @param D: instantaneous separation @type D: float @param q: mass ratio @type q: float @param F: synchronicity parameter @type F: float @param Omega: value of the potential @type Omega: float """ return 1.0/sqrt(r[0]*r[0]+r[1]*r[1]+r[2]*r[2]) + q*(1.0/sqrt((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])-r[0]/D/D) + 0.5*F*F*(1+q)*(r[0]*r[0]+r[1]*r[1]) - Omega
r""" Computes a value of the asynchronous, eccentric Roche potential. If :envvar:`Omega` is passed, it computes the difference. The asynchronous, eccentric Roche potential is given by [Wilson1979]_ .. math:: \Omega = \frac{1}{\sqrt{x^2 + y^2 + z^2}} + q\left(\frac{1}{\sqrt{(x-D)^2+y^2+z^2}} - \frac{x}{D^2}\right) + \frac{1}{2}F^2(1+q)(x^2+y^2) @param r: relative radius vector (3 components) @type r: 3-tuple @param D: instantaneous separation @type D: float @param q: mass ratio @type q: float @param F: synchronicity parameter @type F: float @param Omega: value of the potential @type Omega: float
entailment
def dBinaryRochedx (r, D, q, F): """ Computes a derivative of the potential with respect to x. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter """ return -r[0]*(r[0]*r[0]+r[1]*r[1]+r[2]*r[2])**-1.5 -q*(r[0]-D)*((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**-1.5 -q/D/D + F*F*(1+q)*r[0]
Computes a derivative of the potential with respect to x. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter
entailment
def d2BinaryRochedx2(r, D, q, F): """ Computes second derivative of the potential with respect to x. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter """ return (2*r[0]*r[0]-r[1]*r[1]-r[2]*r[2])/(r[0]*r[0]+r[1]*r[1]+r[2]*r[2])**2.5 +\ q*(2*(r[0]-D)*(r[0]-D)-r[1]*r[1]-r[2]*r[2])/((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**2.5 +\ F*F*(1+q)
Computes second derivative of the potential with respect to x. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter
entailment
def dBinaryRochedy (r, D, q, F): """ Computes a derivative of the potential with respect to y. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter """ return -r[1]*(r[0]*r[0]+r[1]*r[1]+r[2]*r[2])**-1.5 -q*r[1]*((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**-1.5 + F*F*(1+q)*r[1]
Computes a derivative of the potential with respect to y. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter
entailment
def dBinaryRochedz(r, D, q, F): """ Computes a derivative of the potential with respect to z. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter """ return -r[2]*(r[0]*r[0]+r[1]*r[1]+r[2]*r[2])**-1.5 -q*r[2]*((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**-1.5
Computes a derivative of the potential with respect to z. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter
entailment
def dBinaryRochedr (r, D, q, F): """ Computes a derivative of the potential with respect to r. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter """ r2 = (r*r).sum() r1 = np.sqrt(r2) return -1./r2 - q*(r1-r[0]/r1*D)/((r[0]-D)*(r[0]-D)+r[1]*r[1]+r[2]*r[2])**1.5 - q*r[0]/r1/D/D + F*F*(1+q)*(1-r[2]*r[2]/r2)*r1
Computes a derivative of the potential with respect to r. @param r: relative radius vector (3 components) @param D: instantaneous separation @param q: mass ratio @param F: synchronicity parameter
entailment
def settings(**kwargs): """ Generally, this will automatically be added to a newly initialized :class:`phoebe.frontend.bundle.Bundle` :parameter **kwargs: defaults for the values of any of the parameters :return: a :class:`phoebe.parameters.parameters.ParameterSet` of all newly created :class:`phoebe.parameters.parameters.Parameter`s """ params = [] params += [StringParameter(qualifier='phoebe_version', value=kwargs.get('phoebe_version', __version__), description='Version of PHOEBE - change with caution')] params += [BoolParameter(qualifier='log_history', value=kwargs.get('log_history', False), description='Whether to log history (undo/redo)')] params += [DictParameter(qualifier='dict_filter', value=kwargs.get('dict_filter', {}), description='Filters to use when using dictionary access')] params += [BoolParameter(qualifier='dict_set_all', value=kwargs.get('dict_set_all', False), description='Whether to set all values for dictionary access that returns more than 1 result')] # params += [ChoiceParameter(qualifier='plotting_backend', value=kwargs.get('plotting_backend', 'mpl'), choices=['mpl', 'mpld3', 'mpl2bokeh', 'bokeh'] if conf.devel else ['mpl'], description='Default backend to use for plotting')] # problem with try_sympy parameter: it can't be used during initialization... so this may need to be a phoebe-level setting # params += [BoolParameter(qualifier='try_sympy', value=kwargs.get('try_sympy', True), description='Whether to use sympy if installed for constraints')] # This could be complicated - because then we'll have to specifically watch to see when its enabled and then run all constraints - not sure if that is worth the time savings # params += [BoolParameter(qualifier='run_constraints', value=kwargs.get('run_constraints', True), description='Whether to run_constraints whenever a parameter changes (warning: turning off will disable constraints until enabled at which point all constraints will be run)')] return ParameterSet(params)
Generally, this will automatically be added to a newly initialized :class:`phoebe.frontend.bundle.Bundle` :parameter **kwargs: defaults for the values of any of the parameters :return: a :class:`phoebe.parameters.parameters.ParameterSet` of all newly created :class:`phoebe.parameters.parameters.Parameter`s
entailment
def send_if_client(fctn): """Intercept and send to the server if bundle is in client mode.""" @functools.wraps(fctn) def _send_if_client(self, *args, **kwargs): fctn_map = {'set_quantity': 'set_value'} b = self._bundle if b is not None and b.is_client: # TODO: self._filter??? # TODO: args??? method = fctn_map.get(fctn.__name__, fctn.__name__) d = self._filter if hasattr(self, '_filter') \ else {'twig': self.twig} d['bundleid'] = b._bundleid for k, v in kwargs.items(): d[k] = v logger.info('emitting to {}({}) to server'.format(method, d)) b._socketio.emit(method, d) if fctn.__name__ in ['run_compute', 'run_fitting']: # then we're expecting a quick response with an added jobparam # let's add that now self._bundle.client_update() else: return fctn(self, *args, **kwargs) return _send_if_client
Intercept and send to the server if bundle is in client mode.
entailment
def update_if_client(fctn): """Intercept and check updates from server if bundle is in client mode.""" @functools.wraps(fctn) def _update_if_client(self, *args, **kwargs): b = self._bundle if b is None or not hasattr(b, 'is_client'): return fctn(self, *args, **kwargs) elif b.is_client and \ (b._last_client_update is None or (datetime.now() - b._last_client_update).seconds > 1): b.client_update() return fctn(self, *args, **kwargs) return _update_if_client
Intercept and check updates from server if bundle is in client mode.
entailment
def _uniqueid(n=30): """Return a unique string with length n. :parameter int N: number of character in the uniqueid :return: the uniqueid :rtype: str """ return ''.join(random.SystemRandom().choice( string.ascii_uppercase + string.ascii_lowercase) for _ in range(n))
Return a unique string with length n. :parameter int N: number of character in the uniqueid :return: the uniqueid :rtype: str
entailment
def parameter_from_json(dictionary, bundle=None): """Load a single parameter from a JSON dictionary. :parameter dict dictionary: the dictionary containing the parameter information :parameter bundle: (optional) :return: instantiated :class:`Parameter` object """ if isinstance(dictionary, str): dictionary = json.loads(dictionary, object_pairs_hook=parse_json) classname = dictionary.pop('Class') if classname not in _parameter_class_that_require_bundle: bundle = None # now let's do some dirty magic and get the actual classitself # from THIS module. __name__ is a string to lookup this module # from the sys.modules dictionary cls = getattr(sys.modules[__name__], classname) return cls._from_json(bundle, **dictionary)
Load a single parameter from a JSON dictionary. :parameter dict dictionary: the dictionary containing the parameter information :parameter bundle: (optional) :return: instantiated :class:`Parameter` object
entailment
def get_meta(self, ignore=['uniqueid']): """Dictionary of all meta-tags, with option to ignore certain tags. See all the meta-tag properties that are shared by ALL Parameters. If a given value is 'None', that means that it is not shared among ALL Parameters. To see the different values among the Parameters, you can access that attribute. :parameter list ignore: list of keys to exclude from the returned dictionary :return: an ordered dictionary of tag properties """ return OrderedDict([(k, getattr(self, k)) for k in _meta_fields_twig if k not in ignore])
Dictionary of all meta-tags, with option to ignore certain tags. See all the meta-tag properties that are shared by ALL Parameters. If a given value is 'None', that means that it is not shared among ALL Parameters. To see the different values among the Parameters, you can access that attribute. :parameter list ignore: list of keys to exclude from the returned dictionary :return: an ordered dictionary of tag properties
entailment
def set_meta(self, **kwargs): """Set the value of tags for all Parameters in this ParameterSet.""" for param in self.to_list(): for k, v in kwargs.items(): # Here we'll set the attributes (_context, _qualifier, etc) if getattr(param, '_{}'.format(k)) is None: setattr(param, '_{}'.format(k), v)
Set the value of tags for all Parameters in this ParameterSet.
entailment
def tags(self): """Returns a dictionary that lists all available tags that can be used for further filtering """ ret = {} for typ in _meta_fields_twig: if typ in ['uniqueid', 'plugin', 'feedback', 'fitting', 'history', 'twig', 'uniquetwig']: continue k = '{}s'.format(typ) ret[k] = getattr(self, k) return ret
Returns a dictionary that lists all available tags that can be used for further filtering
entailment
def common_twig(self): """ The twig that is common between all items in this ParameterSet. This twig gives a single string which can point back to this ParameterSet (but may include other entries as well) see also :meth:`uniquetwig` :return: twig (full) of this Parameter """ return "@".join([getattr(self, k) for k in _meta_fields_twig if self.meta.get(k) is not None])
The twig that is common between all items in this ParameterSet. This twig gives a single string which can point back to this ParameterSet (but may include other entries as well) see also :meth:`uniquetwig` :return: twig (full) of this Parameter
entailment
def _set_meta(self): """ set the meta fields of the ParameterSet as those that are shared by ALL parameters in the ParameterSet. For any fields that are not """ # we want to set meta-fields that are shared by ALL params in the PS for field in _meta_fields_twig: keys_for_this_field = set([getattr(p, field) for p in self.to_list() if getattr(p, field) is not None]) if len(keys_for_this_field)==1: setattr(self, '_'+field, list(keys_for_this_field)[0]) else: setattr(self, '_'+field, None)
set the meta fields of the ParameterSet as those that are shared by ALL parameters in the ParameterSet. For any fields that are not
entailment
def _uniquetwig(self, twig, force_levels=['qualifier']): """ get the least unique twig for the parameter given by twig that will return this single result for THIS PS :parameter str twig: a twig that will return a single Parameter from THIS PS :parameter list force_levels: (optional) a list of "levels" (eg. context) that should be included whether or not they are necessary :return: the unique twig :rtype: str """ for_this_param = self.filter(twig, check_visible=False) metawargs = {} # NOTE: self.contexts is INCREDIBLY expensive # if len(self.contexts) and 'context' not in force_levels: if 'context' not in force_levels: # then let's force context to be included force_levels.append('context') for k in force_levels: metawargs[k] = getattr(for_this_param, k) prev_count = len(self) # just to fake in case no metawargs are passed at all ps_for_this_search = [] for k in _meta_fields_twig: metawargs[k] = getattr(for_this_param, k) if getattr(for_this_param, k) is None: continue ps_for_this_search = self.filter(check_visible=False, **metawargs) if len(ps_for_this_search) < prev_count and k not in force_levels: prev_count = len(ps_for_this_search) elif k not in force_levels: # this didn't help us metawargs[k] = None if len(ps_for_this_search) != 1: # TODO: after fixing regex in twig (t0type vs t0) # change this to raise Error instead of return return twig # now we go in the other direction and try to remove each to make sure # the count goes up for k in _meta_fields_twig: if metawargs[k] is None or k in force_levels: continue ps_for_this_search = self.filter(check_visible=False, **{ki: metawargs[k] for ki in _meta_fields_twig if ki != k}) if len(ps_for_this_search) == 1: # then we didn't need to use this tag metawargs[k] = None # and lastly, we make sure that the tag corresponding to the context # is present context = for_this_param.context if hasattr(for_this_param, context): metawargs[context] = getattr(for_this_param, context) return "@".join([metawargs[k] for k in _meta_fields_twig if metawargs[k] is not None])
get the least unique twig for the parameter given by twig that will return this single result for THIS PS :parameter str twig: a twig that will return a single Parameter from THIS PS :parameter list force_levels: (optional) a list of "levels" (eg. context) that should be included whether or not they are necessary :return: the unique twig :rtype: str
entailment
def _attach_params(self, params, **kwargs): """Attach a list of parameters (or ParameterSet) to this ParameterSet. :parameter list params: list of parameters, or ParameterSet :parameter **kwargs: attributes to set for each parameter (ie tags) """ lst = params.to_list() if isinstance(params, ParameterSet) else params for param in lst: param._bundle = self for k, v in kwargs.items(): # Here we'll set the attributes (_context, _qualifier, etc) if getattr(param, '_{}'.format(k)) is None: setattr(param, '_{}'.format(k), v) self._params.append(param) self._check_copy_for() return
Attach a list of parameters (or ParameterSet) to this ParameterSet. :parameter list params: list of parameters, or ParameterSet :parameter **kwargs: attributes to set for each parameter (ie tags)
entailment
def _check_copy_for(self): """Check the value of copy_for and make appropriate copies.""" if not self._bundle: return # read the following at your own risk - I just wrote it and it still # confuses me and baffles me that it works for param in self.to_list(): if param.copy_for: # copy_for tells us how to filter and what set of attributes # needs a copy of this parameter # # copy_for = {'kind': ['star', 'disk', 'custombody'], 'component': '*'} # means that this should exist for each component (since that has a wildcard) which # has a kind in [star, disk, custombody] # # copy_for = {'kind': ['rv_dep'], 'component': '*', 'dataset': '*'} # means that this should exist for each component/dataset pair with the # rv_dep kind attrs = [k for k,v in param.copy_for.items() if '*' in v] # attrs is a list of the attributes for which we need a copy of # this parameter for any pair ps = self._bundle.filter(check_visible=False, check_default=False, force_ps=True, **param.copy_for) metawargs = {k:v for k,v in ps.meta.items() if v is not None and k in attrs} for k,v in param.meta.items(): if k not in ['twig', 'uniquetwig'] and k not in attrs: metawargs[k] = v # metawargs is a list of the shared tags that will be used to filter for # existing parameters so that we know whether they already exist or # still need to be created # logger.debug("_check_copy_for {}: attrs={}".format(param.twig, attrs)) for attrvalues in itertools.product(*(getattr(ps, '{}s'.format(attr)) for attr in attrs)): # logger.debug("_check_copy_for {}: attrvalues={}".format(param.twig, attrvalues)) # for each attrs[i] (ie component), attrvalues[i] (star01) # we need to look for this parameter, and if it does not exist # then create it by copying param for attr, attrvalue in zip(attrs, attrvalues): #if attrvalue=='_default' and not getattr(param, attr): # print "SKIPPING", attr, attrvalue # continue metawargs[attr] = attrvalue # logger.debug("_check_copy_for {}: metawargs={}".format(param.twig, metawargs)) if not len(self._bundle.filter(check_visible=False, **metawargs)): # then we need to make a new copy logger.debug("copying '{}' parameter for {}".format(param.qualifier, {attr: attrvalue for attr, attrvalue in zip(attrs, attrvalues)})) newparam = param.copy() for attr, attrvalue in zip(attrs, attrvalues): setattr(newparam, '_{}'.format(attr), attrvalue) newparam._copy_for = False if newparam._visible_if and newparam._visible_if.lower() == 'false': newparam._visible_if = None newparam._bundle = self._bundle self._params.append(newparam) # Now we need to handle copying constraints. This can't be # in the previous if statement because the parameters can be # copied before constraints are ever attached. if hasattr(param, 'is_constraint') and param.is_constraint: param_constraint = param.is_constraint copied_param = self._bundle.get_parameter(check_visible=False, check_default=False, **metawargs) if not copied_param.is_constraint: constraint_kwargs = param_constraint.constraint_kwargs.copy() for attr, attrvalue in zip(attrs, attrvalues): if attr in constraint_kwargs.keys(): constraint_kwargs[attr] = attrvalue logger.debug("copying constraint '{}' parameter for {}".format(param_constraint.constraint_func, {attr: attrvalue for attr, attrvalue in zip(attrs, attrvalues)})) self.add_constraint(func=param_constraint.constraint_func, **constraint_kwargs) return
Check the value of copy_for and make appropriate copies.
entailment
def _check_label(self, label): """Check to see if the label is allowed.""" if not isinstance(label, str): label = str(label) if label.lower() in _forbidden_labels: raise ValueError("'{}' is forbidden to be used as a label" .format(label)) if not re.match("^[a-z,A-Z,0-9,_]*$", label): raise ValueError("label '{}' is forbidden - only alphabetic, numeric, and '_' characters are allowed in labels".format(label)) if len(self.filter(twig=label, check_visible=False)): raise ValueError("label '{}' is already in use".format(label)) if label[0] in ['_']: raise ValueError("first character of label is a forbidden character")
Check to see if the label is allowed.
entailment
def open(cls, filename): """ Open a ParameterSet from a JSON-formatted file. This is a constructor so should be called as: >>> b = ParameterSet.open('test.json') :parameter str filename: relative or full path to the file :return: instantiated :class:`ParameterSet` object """ filename = os.path.expanduser(filename) f = open(filename, 'r') if _can_ujson: # NOTE: this will not parse the unicode. Bundle.open always calls # json instead of ujson for this reason. data = ujson.load(f) else: data = json.load(f, object_pairs_hook=parse_json) f.close() return cls(data)
Open a ParameterSet from a JSON-formatted file. This is a constructor so should be called as: >>> b = ParameterSet.open('test.json') :parameter str filename: relative or full path to the file :return: instantiated :class:`ParameterSet` object
entailment
def save(self, filename, incl_uniqueid=False, compact=False): """ Save the ParameterSet to a JSON-formatted ASCII file :parameter str filename: relative or fullpath to the file :parameter bool incl_uniqueid: whether to including uniqueids in the file (only needed if its necessary to maintain the uniqueids when reloading) :parameter bool compact: whether to use compact file-formatting (maybe be quicker to save/load, but not as easily readable) :return: filename :rtype: str """ filename = os.path.expanduser(filename) f = open(filename, 'w') if compact: if _can_ujson: ujson.dump(self.to_json(incl_uniqueid=incl_uniqueid), f, sort_keys=False, indent=0) else: logger.warning("for faster compact saving, install ujson") json.dump(self.to_json(incl_uniqueid=incl_uniqueid), f, sort_keys=False, indent=0) else: json.dump(self.to_json(incl_uniqueid=incl_uniqueid), f, sort_keys=True, indent=0, separators=(',', ': ')) f.close() return filename
Save the ParameterSet to a JSON-formatted ASCII file :parameter str filename: relative or fullpath to the file :parameter bool incl_uniqueid: whether to including uniqueids in the file (only needed if its necessary to maintain the uniqueids when reloading) :parameter bool compact: whether to use compact file-formatting (maybe be quicker to save/load, but not as easily readable) :return: filename :rtype: str
entailment
def ui(self, client='http://localhost:4200', **kwargs): """ [NOT IMPLEMENTED] The bundle must be in client mode in order to open the web-interface. See :meth:`Bundle:as_client` to switch to client mode. :parameter str client: URL of the running client which must be connected to the same server as the bundle :return: URL of the parameterset of this bundle in the client (will also attempt to open webbrowser) :rtype: str """ if self._bundle is None or not self._bundle.is_client: raise ValueError("bundle must be in client mode") if len(kwargs): return self.filter(**kwargs).ui(client=client) querystr = "&".join(["{}={}".format(k, v) for k, v in self._filter.items()]) # print self._filter url = "{}/{}?{}".format(client, self._bundle._bundleid, querystr) logger.info("opening {} in browser".format(url)) webbrowser.open(url) return url
[NOT IMPLEMENTED] The bundle must be in client mode in order to open the web-interface. See :meth:`Bundle:as_client` to switch to client mode. :parameter str client: URL of the running client which must be connected to the same server as the bundle :return: URL of the parameterset of this bundle in the client (will also attempt to open webbrowser) :rtype: str
entailment
def to_list(self, **kwargs): """ Convert the :class:`ParameterSet` to a list of :class:`Parameter`s :return: list of class:`Parameter` objects """ if kwargs: return self.filter(**kwargs).to_list() return self._params
Convert the :class:`ParameterSet` to a list of :class:`Parameter`s :return: list of class:`Parameter` objects
entailment
def to_list_of_dicts(self, **kwargs): """ Convert the :class:`ParameterSet` to a list of the dictionary representation of each :class:`Parameter` :return: list of dicts """ if kwargs: return self.filter(**kwargs).to_list_of_dicts() return [param.to_dict() for param in self._params]
Convert the :class:`ParameterSet` to a list of the dictionary representation of each :class:`Parameter` :return: list of dicts
entailment
def to_flat_dict(self, **kwargs): """ Convert the :class:`ParameterSet` to a flat dictionary, with keys being uniquetwigs to access the parameter and values being the :class:`Parameter` objects themselves. :return: dict of :class:`Parameter`s """ if kwargs: return self.filter(**kwargs).to_flat_dict() return {param.uniquetwig: param for param in self._params}
Convert the :class:`ParameterSet` to a flat dictionary, with keys being uniquetwigs to access the parameter and values being the :class:`Parameter` objects themselves. :return: dict of :class:`Parameter`s
entailment
def to_dict(self, field=None, **kwargs): """ Convert the ParameterSet to a structured (nested) dictionary to allow traversing the structure from the bottom up :parameter str field: (optional) build the dictionary with keys at a given level/field. Can be any of the keys in :func:`meta`. If None, the keys will be the lowest level in which Parameters have different values. :return: dict of :class:`Parameter`s or :class:`ParameterSet`s """ if kwargs: return self.filter(**kwargs).to_dict(field=field) if field is not None: keys_for_this_field = set([getattr(p, field) for p in self.to_list() if getattr(p, field) is not None]) return {k: self.filter(check_visible=False, **{field: k}) for k in keys_for_this_field} # we want to find the first level (from the bottom) in which filtering # further would shorten the list (ie there are more than one unique # item for that field) # so let's go through the fields in reverse (context up to (but not # including) qualifier) for field in reversed(_meta_fields_twig[1:]): # then get the unique keys in this field among the params in this # PS keys_for_this_field = set([getattr(p, field) for p in self.to_list() if getattr(p, field) is not None]) # and if there are more than one, then return a dictionary with # those keys and the ParameterSet of the matching items if len(keys_for_this_field) > 1: self._next_field = field return {k: self.filter(check_visible=False, **{field: k}) for k in keys_for_this_field} # if we've survived, then we're at the bottom and only have times or # qualifier left if self.context in ['hierarchy']: self._next_field = 'qualifier' return {param.qualifier: param for param in self._params} else: self._next_field = 'time' return {param.time: param for param in self._params}
Convert the ParameterSet to a structured (nested) dictionary to allow traversing the structure from the bottom up :parameter str field: (optional) build the dictionary with keys at a given level/field. Can be any of the keys in :func:`meta`. If None, the keys will be the lowest level in which Parameters have different values. :return: dict of :class:`Parameter`s or :class:`ParameterSet`s
entailment
def set(self, key, value, **kwargs): """ Set the value of a Parameter in the ParameterSet. If :func:`get` would retrieve a Parameter, this will set the value of that parameter. Or you can provide 'value@...' or 'default_unit@...', etc to specify what attribute to set. :parameter str key: the twig (called key here to be analagous to a normal dict) :parameter value: value to set :parameter **kwargs: other filter parameters (must result in returning a single :class:`Parameter`) :return: the value of the :class:`Parameter` after setting the new value (including converting units if applicable) """ twig = key method = None twigsplit = re.findall(r"[\w']+", twig) if twigsplit[0] == 'value': twig = '@'.join(twigsplit[1:]) method = 'set_value' elif twigsplit[0] == 'quantity': twig = '@'.join(twigsplit[1:]) method = 'set_quantity' elif twigsplit[0] in ['unit', 'default_unit']: twig = '@'.join(twigsplit[1:]) method = 'set_default_unit' elif twigsplit[0] in ['timederiv']: twig = '@'.join(twigsplit[1:]) method = 'set_timederiv' elif twigsplit[0] in ['description']: raise KeyError("cannot set {} of {}".format(twigsplit[0], '@'.join(twigsplit[1:]))) if self._bundle is not None and self._bundle.get_setting('dict_set_all').get_value() and len(self.filter(twig=twig, **kwargs)) > 1: # then we need to loop through all the returned parameters and call set on them for param in self.filter(twig=twig, **kwargs).to_list(): self.set('{}@{}'.format(method, param.twig) if method is not None else param.twig, value) else: if method is None: return self.set_value(twig=twig, value=value, **kwargs) else: param = self.get_parameter(twig=twig, **kwargs) return getattr(param, method)(value)
Set the value of a Parameter in the ParameterSet. If :func:`get` would retrieve a Parameter, this will set the value of that parameter. Or you can provide 'value@...' or 'default_unit@...', etc to specify what attribute to set. :parameter str key: the twig (called key here to be analagous to a normal dict) :parameter value: value to set :parameter **kwargs: other filter parameters (must result in returning a single :class:`Parameter`) :return: the value of the :class:`Parameter` after setting the new value (including converting units if applicable)
entailment
def to_json(self, incl_uniqueid=False): """ Convert the ParameterSet to a json-compatible dictionary :return: list of dictionaries """ lst = [] for context in _contexts: lst += [v.to_json(incl_uniqueid=incl_uniqueid) for v in self.filter(context=context, check_visible=False, check_default=False).to_list()] return lst
Convert the ParameterSet to a json-compatible dictionary :return: list of dictionaries
entailment
def filter(self, twig=None, check_visible=True, check_default=True, **kwargs): """ Filter the ParameterSet based on the meta-tags of the Parameters and return another ParameterSet. Because another ParameterSet is returned, these filter calls are chainable. >>> b.filter(context='component').filter(component='starA') :parameter str twig: (optional) the search twig - essentially a single string with any delimiter (ie '@') that will be parsed into any of the meta-tags. Example: instead of b.filter(context='component', component='starA'), you could do b.filter('starA@component'). :parameter bool check_visible: whether to hide invisible parameters. These are usually parameters that do not play a role unless the value of another parameter meets some condition. :parameter bool check_default: whether to exclude parameters which have a _default tag (these are parameters which solely exist to provide defaults for when new parameters or datasets are added and the parameter needs to be copied appropriately). Defaults to True. :parameter **kwargs: meta-tags to search (ie. 'context', 'component', 'model', etc). See :func:`meta` for all possible options. :return: the resulting :class:`ParameterSet` """ kwargs['check_visible'] = check_visible kwargs['check_default'] = check_default kwargs['force_ps'] = True return self.filter_or_get(twig=twig, **kwargs)
Filter the ParameterSet based on the meta-tags of the Parameters and return another ParameterSet. Because another ParameterSet is returned, these filter calls are chainable. >>> b.filter(context='component').filter(component='starA') :parameter str twig: (optional) the search twig - essentially a single string with any delimiter (ie '@') that will be parsed into any of the meta-tags. Example: instead of b.filter(context='component', component='starA'), you could do b.filter('starA@component'). :parameter bool check_visible: whether to hide invisible parameters. These are usually parameters that do not play a role unless the value of another parameter meets some condition. :parameter bool check_default: whether to exclude parameters which have a _default tag (these are parameters which solely exist to provide defaults for when new parameters or datasets are added and the parameter needs to be copied appropriately). Defaults to True. :parameter **kwargs: meta-tags to search (ie. 'context', 'component', 'model', etc). See :func:`meta` for all possible options. :return: the resulting :class:`ParameterSet`
entailment
def get(self, twig=None, check_visible=True, check_default=True, **kwargs): """ Get a single parameter from this ParameterSet. This works exactly the same as filter except there must be only a single result, and the Parameter itself is returned instead of a ParameterSet. Also see :meth:`get_parameter` (which is simply an alias of this method) :parameter str twig: (optional) the search twig - essentially a single string with any delimiter (ie '@') that will be parsed into any of the meta-tags. Example: instead of b.filter(context='component', component='starA'), you could do b.filter('starA@component'). :parameter bool check_visible: whether to hide invisible parameters. These are usually parameters that do not play a role unless the value of another parameter meets some condition. :parameter bool check_default: whether to exclude parameters which have a _default tag (these are parameters which solely exist to provide defaults for when new parameters or datasets are added and the parameter needs to be copied appropriately). Defaults to True. :parameter **kwargs: meta-tags to search (ie. 'context', 'component', 'model', etc). See :func:`meta` for all possible options. :return: the resulting :class:`Parameter` :raises ValueError: if either 0 or more than 1 results are found matching the search. """ kwargs['check_visible'] = check_visible kwargs['check_default'] = check_default # print "***", kwargs ps = self.filter(twig=twig, **kwargs) if not len(ps): # TODO: custom exception? raise ValueError("0 results found") elif len(ps) != 1: # TODO: custom exception? raise ValueError("{} results found: {}".format(len(ps), ps.twigs)) else: # then only 1 item, so return the parameter return ps._params[0]
Get a single parameter from this ParameterSet. This works exactly the same as filter except there must be only a single result, and the Parameter itself is returned instead of a ParameterSet. Also see :meth:`get_parameter` (which is simply an alias of this method) :parameter str twig: (optional) the search twig - essentially a single string with any delimiter (ie '@') that will be parsed into any of the meta-tags. Example: instead of b.filter(context='component', component='starA'), you could do b.filter('starA@component'). :parameter bool check_visible: whether to hide invisible parameters. These are usually parameters that do not play a role unless the value of another parameter meets some condition. :parameter bool check_default: whether to exclude parameters which have a _default tag (these are parameters which solely exist to provide defaults for when new parameters or datasets are added and the parameter needs to be copied appropriately). Defaults to True. :parameter **kwargs: meta-tags to search (ie. 'context', 'component', 'model', etc). See :func:`meta` for all possible options. :return: the resulting :class:`Parameter` :raises ValueError: if either 0 or more than 1 results are found matching the search.
entailment
def exclude(self, twig=None, check_visible=True, **kwargs): """ Exclude the results from this filter from the current ParameterSet. See :meth:`filter` for options. """ return self - self.filter(twig=twig, check_visible=check_visible, **kwargs)
Exclude the results from this filter from the current ParameterSet. See :meth:`filter` for options.
entailment
def get_or_create(self, qualifier, new_parameter, **kwargs): """ Get a :class:`Parameter` from the ParameterSet, if it does not exist, create and attach it. Note: running this on a ParameterSet that is NOT a :class:`phoebe.frontend.bundle.Bundle`, will NOT add the Parameter to the bundle, but only the temporary ParameterSet :parameter str qualifier: the qualifier of the :class:`Parameter` (note, not the twig) :parameter new_parameter: the parameter to attach if no result is found :type new_parameter: :class:`Parameter` :parameter **kwargs: meta-tags to search - will also be applied to new_parameter if it is attached. :return: Parameter, created :rtype: :class:`Parameter`, bool :raises ValueError: if more than 1 result was found using the search criteria. """ ps = self.filter_or_get(qualifier=qualifier, **kwargs) if isinstance(ps, Parameter): return ps, False elif len(ps): # TODO: custom exception? raise ValueError("more than 1 result was found") else: self._attach_params(ParameterSet([new_parameter]), **kwargs) logger.debug("creating and attaching new parameter: {}".format(new_parameter.qualifier)) return self.filter_or_get(qualifier=qualifier, **kwargs), True
Get a :class:`Parameter` from the ParameterSet, if it does not exist, create and attach it. Note: running this on a ParameterSet that is NOT a :class:`phoebe.frontend.bundle.Bundle`, will NOT add the Parameter to the bundle, but only the temporary ParameterSet :parameter str qualifier: the qualifier of the :class:`Parameter` (note, not the twig) :parameter new_parameter: the parameter to attach if no result is found :type new_parameter: :class:`Parameter` :parameter **kwargs: meta-tags to search - will also be applied to new_parameter if it is attached. :return: Parameter, created :rtype: :class:`Parameter`, bool :raises ValueError: if more than 1 result was found using the search criteria.
entailment
def _remove_parameter(self, param): """ Remove a Parameter from the ParameterSet :parameter param: the :class:`Parameter` object to be removed :type param: :class:`Parameter` """ # TODO: check to see if protected (required by a current constraint or # by a backend) self._params = [p for p in self._params if p != param]
Remove a Parameter from the ParameterSet :parameter param: the :class:`Parameter` object to be removed :type param: :class:`Parameter`
entailment
def remove_parameter(self, twig=None, **kwargs): """ Remove a :class:`Parameter` from the ParameterSet Note: removing Parameters from a ParameterSet will not remove them from any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter str twig: the twig to search for the parameter :parameter **kwargs: meta-tags to search :raises ValueError: if 0 or more than 1 results are found using the provided search criteria. """ param = self.get(twig=twig, **kwargs) self._remove_parameter(param)
Remove a :class:`Parameter` from the ParameterSet Note: removing Parameters from a ParameterSet will not remove them from any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter str twig: the twig to search for the parameter :parameter **kwargs: meta-tags to search :raises ValueError: if 0 or more than 1 results are found using the provided search criteria.
entailment
def remove_parameters_all(self, twig=None, **kwargs): """ Remove all :class:`Parameter`s that match the search from the ParameterSet. Any Parameter that would be included in the resulting ParameterSet from a :func:`filter` call with the same arguments will be removed from this ParameterSet. Note: removing Parameters from a ParameterSet will not remove them from any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter str twig: the twig to search for the parameter :parameter **kwargs: meta-tags to search """ params = self.filter(twig=twig, check_visible=False, check_default=False, **kwargs) for param in params.to_list(): self._remove_parameter(param)
Remove all :class:`Parameter`s that match the search from the ParameterSet. Any Parameter that would be included in the resulting ParameterSet from a :func:`filter` call with the same arguments will be removed from this ParameterSet. Note: removing Parameters from a ParameterSet will not remove them from any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter str twig: the twig to search for the parameter :parameter **kwargs: meta-tags to search
entailment
def get_quantity(self, twig=None, unit=None, default=None, t=None, **kwargs): """ TODO: add documentation """ # TODO: for time derivatives will need to use t instead of time (time # gets passed to twig filtering) if default is not None is not None: # then we need to do a filter first to see if parameter exists if not len(self.filter(twig=twig, **kwargs)): return default param = self.get_parameter(twig=twig, **kwargs) if param.qualifier in kwargs.keys(): # then we have an "override" value that was passed, and we should # just return that. # Example b.get_value('teff', teff=6000) returns 6000 return kwargs.get(param.qualifier) return param.get_quantity(unit=unit, t=t)
TODO: add documentation
entailment
def set_quantity(self, twig=None, value=None, **kwargs): """ TODO: add documentation """ # TODO: handle twig having parameter key (value@, default_unit@, adjust@, etc) # TODO: does this return anything (update the docstring)? return self.get_parameter(twig=twig, **kwargs).set_quantity(value=value, **kwargs)
TODO: add documentation
entailment
def get_value(self, twig=None, unit=None, default=None, t=None, **kwargs): """ Get the value of a :class:`Parameter` in this ParameterSet :parameter str twig: the twig to search for the parameter :parameter unit: units for the returned result (if applicable). If None or not provided, the value will be returned in that Parameter's default_unit (if applicable) :type unit: str or astropy.units.Unit :parameter default: what to return if the parameter cannot be found. If this is None (default) then an error will be raised instead. Note that the units of default will not be converted. :parameter time: time at which to compute the value (will only affect time-dependent parameters). If provided as a float it is assumed that the units are the same as t0. NOTE: this is not fully supported yet, use with caution. :parameter **kwargs: meta-tags to search :return: value (type depeding on the type of the :class:`Parameter`) """ # TODO: for time derivatives will need to use t instead of time (time # gets passed to twig filtering) if default is not None: # then we need to do a filter first to see if parameter exists if not len(self.filter(twig=twig, **kwargs)): return default param = self.get_parameter(twig=twig, **kwargs) # if hasattr(param, 'default_unit'): # This breaks for constraint parameters if isinstance(param, FloatParameter) or\ isinstance(param,FloatArrayParameter): return param.get_value(unit=unit, t=t, **kwargs) return param.get_value(**kwargs)
Get the value of a :class:`Parameter` in this ParameterSet :parameter str twig: the twig to search for the parameter :parameter unit: units for the returned result (if applicable). If None or not provided, the value will be returned in that Parameter's default_unit (if applicable) :type unit: str or astropy.units.Unit :parameter default: what to return if the parameter cannot be found. If this is None (default) then an error will be raised instead. Note that the units of default will not be converted. :parameter time: time at which to compute the value (will only affect time-dependent parameters). If provided as a float it is assumed that the units are the same as t0. NOTE: this is not fully supported yet, use with caution. :parameter **kwargs: meta-tags to search :return: value (type depeding on the type of the :class:`Parameter`)
entailment
def set_value(self, twig=None, value=None, **kwargs): """ Set the value of a :class:`Parameter` in this ParameterSet Note: setting the value of a Parameter in a ParameterSet WILL change that Parameter across any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter set twig: the twig to search for the parameter :parameter value: the value to set. Provide units, if necessary, by sending a Quantity object (ie 2.4*u.rad) :parameter **kwargs: meta-tags to search :raises ValueError: if 0 or more than 1 results are found matching the search criteria. """ # TODO: handle twig having parameter key (value@, default_unit@, adjust@, etc) # TODO: does this return anything (update the docstring)? if twig is not None and value is None: # then try to support value as the first argument if no matches with twigs if not isinstance(twig, str): value = twig twig = None elif not len(self.filter(twig=twig, check_default=check_default, **kwargs)): value = twig twig = None if "index" in kwargs.keys(): return self.get_parameter(twig=twig, **kwargs).set_index_value(value=value, **kwargs) if "time" in kwargs.keys(): if not len(self.filter(**kwargs)): # then let's try filtering without time and seeing if we get a # FloatArrayParameter so that we can use set_index_value instead time = kwargs.pop("time") param = self.get_parameter(twig=twig, **kwargs) if not isinstance(param, FloatArrayParameter): raise TypeError # TODO: do we need to be more clever about time qualifier for # ETV datasets? TODO: is this robust enough... this won't search # for times outside the existing ParameterSet. We could also # try param.get_parent_ps().get_parameter('time'), but this # won't work when outside the bundle (which is used within # backends.py to set fluxes, etc) print "*** # get_parameter(qualifier='times', **kwargs)", {k:v for k,v in # kwargs.items() if k not in ['qualifier']} time_param = self.get_parameter(qualifier='times', **{k:v for k,v in kwargs.items() if k not in ['qualifier']}) index = np.where(time_param.get_value()==time)[0] return param.set_index_value(value=value, index=index, **kwargs) return self.get_parameter(twig=twig, **kwargs).set_value(value=value, **kwargs)
Set the value of a :class:`Parameter` in this ParameterSet Note: setting the value of a Parameter in a ParameterSet WILL change that Parameter across any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter set twig: the twig to search for the parameter :parameter value: the value to set. Provide units, if necessary, by sending a Quantity object (ie 2.4*u.rad) :parameter **kwargs: meta-tags to search :raises ValueError: if 0 or more than 1 results are found matching the search criteria.
entailment
def set_value_all(self, twig=None, value=None, check_default=False, **kwargs): """ Set the value of all returned :class:`Parameter`s in this ParameterSet. Any :class:`Parameter` that would be included in the resulting ParameterSet from a :func:`filter` call with the same arguments will have their value set. Note: setting the value of a Parameter in a ParameterSet WILL change that Parameter across any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter str twig: the twig to search for the parameter :parameter value: the value to set. Provide units, if necessary, by sending a Quantity object (ie 2.4*u.rad) :parameter bool check_default: whether to exclude any default values. Defaults to False (unlike all filtering). Note that this acts on the current ParameterSet so any filtering done before this call will EXCLUDE defaults by default. :parameter **kwargs: meta-tags to search """ if twig is not None and value is None: # then try to support value as the first argument if no matches with twigs if not isinstance(twig, str): value = twig twig = None elif not len(self.filter(twig=twig, check_default=check_default, **kwargs)): value = twig twig = None params = self.filter(twig=twig, check_default=check_default, **kwargs).to_list() if not kwargs.pop('ignore_none', False) and not len(params): raise ValueError("no parameters found") for param in params: if "index" in kwargs.keys(): return self.get_parameter(twig=twig, **kwargs).set_index_value(value=value, **kwargs) param.set_value(value=value, **kwargs)
Set the value of all returned :class:`Parameter`s in this ParameterSet. Any :class:`Parameter` that would be included in the resulting ParameterSet from a :func:`filter` call with the same arguments will have their value set. Note: setting the value of a Parameter in a ParameterSet WILL change that Parameter across any parent ParameterSets (including the :class:`phoebe.frontend.bundle.Bundle`) :parameter str twig: the twig to search for the parameter :parameter value: the value to set. Provide units, if necessary, by sending a Quantity object (ie 2.4*u.rad) :parameter bool check_default: whether to exclude any default values. Defaults to False (unlike all filtering). Note that this acts on the current ParameterSet so any filtering done before this call will EXCLUDE defaults by default. :parameter **kwargs: meta-tags to search
entailment
def get_default_unit(self, twig=None, **kwargs): """ TODO: add documentation """ return self.get_parameter(twig=twig, **kwargs).get_default_unit()
TODO: add documentation
entailment
def set_default_unit(self, twig=None, unit=None, **kwargs): """ TODO: add documentation """ if twig is not None and unit is None: # then try to support value as the first argument if no matches with twigs if isinstance(unit, u.Unit) or not isinstance(twig, str): unit = twig twig = None elif not len(self.filter(twig=twig, check_default=check_default, **kwargs)): unit = twig twig = None return self.get_parameter(twig=twig, **kwargs).set_default_unit(unit)
TODO: add documentation
entailment
def set_default_unit_all(self, twig=None, unit=None, **kwargs): """ TODO: add documentation """ if twig is not None and unit is None: # then try to support value as the first argument if no matches with twigs if isinstance(unit, u.Unit) or not isinstance(twig, str): unit = twig twig = None elif not len(self.filter(twig=twig, check_default=check_default, **kwargs)): unit = twig twig = None for param in self.filter(twig=twig, **kwargs).to_list(): param.set_default_unit(unit)
TODO: add documentation
entailment
def get_description(self, twig=None, **kwargs): """ TODO: add documentation """ return self.get_parameter(twig=twig, **kwargs).get_description()
TODO: add documentation
entailment
def plot(self, twig=None, **kwargs): """ High-level wrapper around matplotlib (by default, but also has some support for other plotting backends). This function smartly makes one or multiple calls to the plotting backend based on the type of data. Individual lines are each given a label (automatic if not provided), to see these in a legend, pass legend=True (and optionally any keyword arguments to be passed along to plt.legend() as legend_kwargs). :parameter str twig: twig to use for filtering :parameter float time: Current time. For spectra and meshes, time is required to determine at which time to draw. For other types, time will only be used for higlight and uncover (if enabled) :parameter bool highlight: whether to highlight the current time (defaults to True) :parameter str highlight_marker: if highlight==True - what marker-type to use for highlighting the current time (defaults to 'o') :parameter int highlight_ms: if highlight==Ture - what marker-size to use for highlighting the current time :parameter str highlight_color: if highlight==True: what marker-color to use for highlighting the current time :parameter bool uncover: whether to only show data up to the current time (defaults to False) :parameter ax: axes to plot on (defaults to plt.gca()) :type ax: mpl.axes :parameter str x: qualifier or twig of the array to plot on the x-axis (will default based on the kind if not provided). Must be a valid qualifier with the exception of phase. To plot phase along the x-axis set x to 'phases' or 'phases:[component]'. This will use the ephemeris from :meth:`phoebe.frontend.bundle.Bundle.get_ephemeris` if possible. :parameter str y: qualifier or twig of the array to plot on the y-axis (see details for x above) :parameter str z: qualifier or twig of the array to plot on the z-axis if both the backend and ax support 3d plotting (see details for x above) :parameter t0: qualifier or float of the t0 that should be used for phasing, if applicable :type t0: string or float :parameter str xerror: qualifier of the array to plot as x-errors (will default based on x if not provided) :parameter str yerror: qualifier of the array to plot as y-errors (will default based on y if not provided) :parameter str zerror: qualifier of the array to plot as z-errors (will default based on z if not provided) :parameter xunit: unit to plot the x-array (will default based on x if not provided) :type xunit: str or astropy.unit.Unit :parameter yunit: unit to plot the y-array (will default based on y if not provided) :type yunit: str or astropy.unit.Unit :parameter zunit: unit to plot the z-array (will default based on z if not provided) :type zunit: str or astropy.unit.Unit :parameter str xlabel: label for the x-axis (will default based on x if not provided, but will not set if ax already has an xlabel) :parameter str ylabel: label for the y-axis (will default based on y if not provided, but will not set if ax already has an ylabel) :parameter str zlabel: label for the z-axis (will default based on z if not provided, but will not set if ax already has an zlabel) :parameter tuple xlim: limits for the x-axis (will default based on data if not provided) :parameter tuple ylim: limits for the x-axis (will default based on data if not provided) :parameter tuple zlim: limits for the x-axis (will default based on data if not provided) :parameter str label: label to give to ALL lines in this single plotting call (each line with get automatic default labels if not provided) :parameter str c: matplotlib recognized color string or the qualifier/twig of an array to use for color (will apply to facecolor and edgecolor for meshes unless those are provided) :parameter str cmap: matplotlib recognized cmap to use if color is a qualifier pointing to an array (will be ignored otherwise) :parameter bool cbar: whether to display the colorbar (will default to False) :parameter cunit: unit to plot the color-array (will default based on color if not provided) :type cunit: str or astropy.unit.Unit :parameter tuple clim: limit for the colorbar (in same units as cunit) :parameter str clabel: label for the colorbar, if applicable (will default based on color if not provided) :parameter str fc: matplotlib recognized color string or the qualifier/twig of an array to use for facecolor (mesh plots only - takes precedence over color) :parameter str fcmap: matplotlib recognized cmap to use if facecolor is a qualifier pointing to an array (will be ignored otherwise) :parameter fcunit: unit to plot the facecolor-array (will default based on facecolor if not provided) :type fcunit: str or astropy.unit.Unit :parameter tuple fclim: limit for the facecolorbar (in same units as facecolorunit) :parameter str fclabel: label for the facecolorbar, if applicable (will default based on facecolor if not provided) :parameter str ec: matplotlib recognized color string or the qualifier/twig of an array to use for edgecolor (mesh plots only - takes precedence over color) :parameter str ecmap: matplotlib recognized cmap to use if edgecolor is a qualifier pointing to an array (will be ignored otherwise :parameter ecunit: unit to plot the edgecolor-array (will default based on ed if not provided) :type ecunit: str or astropy.unit.Unit :parameter tuple eclim: limit for the edgecolorbar (in same units as ecunit) :parameter str eclabel: label for the edgecolorbar, if applicable (will default based on edgecolor if not provided) :parameter str save: filename of the resulting animation. If provided, the animation will be saved automatically. Either way, the animation object is returned (so you can always call anim.save(fname)). :parameter dict save_kwargs: any additional keyword arguments that need to be sent to the anim.save call (as **save_kwargs, see https://matplotlib.org/2.0.0/api/_as_gen/matplotlib.animation.Animation.save.html#matplotlib.animation.Animation.save) :parameter bool show: whether to automatically show the animation (defaults to False). Either way, the animation object is returned (so you can always call b.show() or plt.show()) :parameter **kwargs: additional kwargs to filter the ParameterSet OR to pass along to the backend plotting call :returns: the matplotlib axes """ if not _use_autofig: if os.getenv('PHOEBE_ENABLE_PLOTTING', 'TRUE').upper() != 'TRUE': raise ImportError("cannot plot because PHOEBE_ENABLE_PLOTTING environment variable is disasbled") else: raise ImportError("autofig not imported, cannot plot") # since we used the args trick above, all other options have to be in kwargs save = kwargs.pop('save', False) show = kwargs.pop('show', False) tight_layout = kwargs.pop('tight_layout', False) draw_sidebars = kwargs.pop('draw_sidebars', False) draw_title = kwargs.pop('draw_title', False) subplot_grid = kwargs.pop('subplot_grid', None) animate = kwargs.pop('animate', False) time = kwargs.get('time', None) # don't pop since time may be used for filtering if twig is not None: kwargs['twig'] = twig plot_kwargss = self._unpack_plotting_kwargs(**kwargs) # this loop handles any of the automatically-generated # multiple plotting calls, passing each on to autofig for plot_kwargs in plot_kwargss: y = plot_kwargs.get('y', []) if (isinstance(y, u.Quantity) and isinstance(y.value, float)) or (hasattr(y, 'value') and isinstance(y.value, float)): pass elif not len(y): # a dataset without observational data, for example continue autofig_method = plot_kwargs.pop('autofig_method', 'plot') # we kept the qualifiers around so we could do some default-logic, # but it isn't necessary to pass them on to autofig. plot_kwargs = {k:v for k,v in plot_kwargs.items() if 'qualifier' not in k} logger.info("calling autofig.{}({})".format(autofig_method, ", ".join(["{}={}".format(k,v if not isinstance(v, np.ndarray) else "<data ({})>".format(v.shape)) for k,v in plot_kwargs.items()]))) func = getattr(self.gcf(), autofig_method) func(**plot_kwargs) if save or show or animate: # NOTE: time, times, will all be included in kwargs try: return self._show_or_save(save, show, animate, draw_sidebars=draw_sidebars, draw_title=draw_title, tight_layout=tight_layout, subplot_grid=subplot_grid, **kwargs) except Exception as err: self.clf() raise err else: afig = self.gcf() fig = None return afig, fig
High-level wrapper around matplotlib (by default, but also has some support for other plotting backends). This function smartly makes one or multiple calls to the plotting backend based on the type of data. Individual lines are each given a label (automatic if not provided), to see these in a legend, pass legend=True (and optionally any keyword arguments to be passed along to plt.legend() as legend_kwargs). :parameter str twig: twig to use for filtering :parameter float time: Current time. For spectra and meshes, time is required to determine at which time to draw. For other types, time will only be used for higlight and uncover (if enabled) :parameter bool highlight: whether to highlight the current time (defaults to True) :parameter str highlight_marker: if highlight==True - what marker-type to use for highlighting the current time (defaults to 'o') :parameter int highlight_ms: if highlight==Ture - what marker-size to use for highlighting the current time :parameter str highlight_color: if highlight==True: what marker-color to use for highlighting the current time :parameter bool uncover: whether to only show data up to the current time (defaults to False) :parameter ax: axes to plot on (defaults to plt.gca()) :type ax: mpl.axes :parameter str x: qualifier or twig of the array to plot on the x-axis (will default based on the kind if not provided). Must be a valid qualifier with the exception of phase. To plot phase along the x-axis set x to 'phases' or 'phases:[component]'. This will use the ephemeris from :meth:`phoebe.frontend.bundle.Bundle.get_ephemeris` if possible. :parameter str y: qualifier or twig of the array to plot on the y-axis (see details for x above) :parameter str z: qualifier or twig of the array to plot on the z-axis if both the backend and ax support 3d plotting (see details for x above) :parameter t0: qualifier or float of the t0 that should be used for phasing, if applicable :type t0: string or float :parameter str xerror: qualifier of the array to plot as x-errors (will default based on x if not provided) :parameter str yerror: qualifier of the array to plot as y-errors (will default based on y if not provided) :parameter str zerror: qualifier of the array to plot as z-errors (will default based on z if not provided) :parameter xunit: unit to plot the x-array (will default based on x if not provided) :type xunit: str or astropy.unit.Unit :parameter yunit: unit to plot the y-array (will default based on y if not provided) :type yunit: str or astropy.unit.Unit :parameter zunit: unit to plot the z-array (will default based on z if not provided) :type zunit: str or astropy.unit.Unit :parameter str xlabel: label for the x-axis (will default based on x if not provided, but will not set if ax already has an xlabel) :parameter str ylabel: label for the y-axis (will default based on y if not provided, but will not set if ax already has an ylabel) :parameter str zlabel: label for the z-axis (will default based on z if not provided, but will not set if ax already has an zlabel) :parameter tuple xlim: limits for the x-axis (will default based on data if not provided) :parameter tuple ylim: limits for the x-axis (will default based on data if not provided) :parameter tuple zlim: limits for the x-axis (will default based on data if not provided) :parameter str label: label to give to ALL lines in this single plotting call (each line with get automatic default labels if not provided) :parameter str c: matplotlib recognized color string or the qualifier/twig of an array to use for color (will apply to facecolor and edgecolor for meshes unless those are provided) :parameter str cmap: matplotlib recognized cmap to use if color is a qualifier pointing to an array (will be ignored otherwise) :parameter bool cbar: whether to display the colorbar (will default to False) :parameter cunit: unit to plot the color-array (will default based on color if not provided) :type cunit: str or astropy.unit.Unit :parameter tuple clim: limit for the colorbar (in same units as cunit) :parameter str clabel: label for the colorbar, if applicable (will default based on color if not provided) :parameter str fc: matplotlib recognized color string or the qualifier/twig of an array to use for facecolor (mesh plots only - takes precedence over color) :parameter str fcmap: matplotlib recognized cmap to use if facecolor is a qualifier pointing to an array (will be ignored otherwise) :parameter fcunit: unit to plot the facecolor-array (will default based on facecolor if not provided) :type fcunit: str or astropy.unit.Unit :parameter tuple fclim: limit for the facecolorbar (in same units as facecolorunit) :parameter str fclabel: label for the facecolorbar, if applicable (will default based on facecolor if not provided) :parameter str ec: matplotlib recognized color string or the qualifier/twig of an array to use for edgecolor (mesh plots only - takes precedence over color) :parameter str ecmap: matplotlib recognized cmap to use if edgecolor is a qualifier pointing to an array (will be ignored otherwise :parameter ecunit: unit to plot the edgecolor-array (will default based on ed if not provided) :type ecunit: str or astropy.unit.Unit :parameter tuple eclim: limit for the edgecolorbar (in same units as ecunit) :parameter str eclabel: label for the edgecolorbar, if applicable (will default based on edgecolor if not provided) :parameter str save: filename of the resulting animation. If provided, the animation will be saved automatically. Either way, the animation object is returned (so you can always call anim.save(fname)). :parameter dict save_kwargs: any additional keyword arguments that need to be sent to the anim.save call (as **save_kwargs, see https://matplotlib.org/2.0.0/api/_as_gen/matplotlib.animation.Animation.save.html#matplotlib.animation.Animation.save) :parameter bool show: whether to automatically show the animation (defaults to False). Either way, the animation object is returned (so you can always call b.show() or plt.show()) :parameter **kwargs: additional kwargs to filter the ParameterSet OR to pass along to the backend plotting call :returns: the matplotlib axes
entailment
def _show_or_save(self, save, show, animate, draw_sidebars=True, draw_title=True, tight_layout=False, subplot_grid=None, **kwargs): """ Draw/animate and show and/or save a autofig plot """ if animate and not show and not save: logger.warning("setting show to True since animate=True and save not provided") show = True if animate: # prefer times over time times = kwargs.get('times', kwargs.get('time', None)) save_kwargs = kwargs.get('save_kwargs', {}) if times is None: # then let's try to get all SYNTHETIC times # it would be nice to only do ENABLED, but then we have to worry about compute # it would also be nice to worry about models... but then you should filter first logger.info("no times were providing, so defaulting to animate over all dataset times") times = [] for dataset in self.datasets: ps = self.filter(dataset=dataset, context='model') if len(ps.times): # for the case of meshes/spectra times += [float(t) for t in ps.times] else: for param in ps.filter(qualifier='times').to_list(): times += list(param.get_value()) times = sorted(list(set(times))) logger.info("calling autofig.animate(i={}, draw_sidebars={}, draw_title={}, tight_layout={}, save={}, show={}, save_kwargs={})".format(times, draw_sidebars, draw_title, tight_layout, save, show, save_kwargs)) mplanim = self.gcf().animate(i=times, draw_sidebars=draw_sidebars, draw_title=draw_title, tight_layout=tight_layout, subplot_grid=subplot_grid, save=save, show=show, save_kwargs=save_kwargs) afig = self.gcf() # clear the autofig figure self.clf() return afig, mplanim else: time = kwargs.get('time', None) if isinstance(time, str): time = self.get_value(time, context=['component', 'system']) logger.info("calling autofig.draw(i={}, draw_sidebars={}, draw_title={}, tight_layout={}, save={}, show={})".format(time, draw_sidebars, draw_title, tight_layout, save, show)) fig = self.gcf().draw(i=time, draw_sidebars=draw_sidebars, draw_title=draw_title, tight_layout=tight_layout, subplot_grid=subplot_grid, save=save, show=show) # clear the figure so next call will start over and future shows will work afig = self.gcf() self.clf() return afig, fig
Draw/animate and show and/or save a autofig plot
entailment
def show(self, **kwargs): """ Draw and show the plot. """ kwargs.setdefault('show', True) kwargs.setdefault('save', False) kwargs.setdefault('animate', False) return self._show_or_save(**kwargs)
Draw and show the plot.
entailment
def savefig(self, filename, **kwargs): """ Draw and save the plot. :parameter str filename: filename to save to. Be careful of extensions here... matplotlib accepts many different image formats while other backends will only export to html. """ filename = os.path.expanduser(filename) kwargs.setdefault('show', False) kwargs.setdefault('save', filename) kwargs.setdefault('animate', False) return self._show_or_save(**kwargs)
Draw and save the plot. :parameter str filename: filename to save to. Be careful of extensions here... matplotlib accepts many different image formats while other backends will only export to html.
entailment
def copy(self): """ Deepcopy the parameter (with a new uniqueid). All other tags will remain the same... so some other tag should be changed before attaching back to a ParameterSet or Bundle. :return: the copied :class:`Parameter` object """ s = self.to_json() cpy = parameter_from_json(s) # TODO: may need to subclass for Parameters that require bundle by using this line instead: # cpy = parameter_from_json(s, bundle=self._bundle) cpy.set_uniqueid(_uniqueid()) return cpy
Deepcopy the parameter (with a new uniqueid). All other tags will remain the same... so some other tag should be changed before attaching back to a ParameterSet or Bundle. :return: the copied :class:`Parameter` object
entailment
def to_string_short(self): """ see also :meth:`to_string` :return: a shorter abreviated string reprentation of the parameter """ if hasattr(self, 'constrained_by') and len(self.constrained_by) > 0: return "* {:>30}: {}".format(self.uniquetwig_trunc, self.get_quantity() if hasattr(self, 'quantity') else self.get_value()) else: return "{:>32}: {}".format(self.uniquetwig_trunc, self.get_quantity() if hasattr(self, 'quantity') else self.get_value())
see also :meth:`to_string` :return: a shorter abreviated string reprentation of the parameter
entailment
def save(self, filename, incl_uniqueid=False): """ Save the Parameter to a JSON-formatted ASCII file :parameter str filename: relative or fullpath to the file :return: filename :rtype: str """ filename = os.path.expanduser(filename) f = open(filename, 'w') json.dump(self.to_json(incl_uniqueid=incl_uniqueid), f, sort_keys=True, indent=0, separators=(',', ': ')) f.close() return filename
Save the Parameter to a JSON-formatted ASCII file :parameter str filename: relative or fullpath to the file :return: filename :rtype: str
entailment
def to_json(self, incl_uniqueid=False): """ :return: a JSON-ready dictionary holding all information for this parameter """ def _parse(k, v): """ """ if k=='value': if isinstance(self._value, nparray.ndarray): if self._value.unit is not None and hasattr(self, 'default_unit'): v = self._value.to(self.default_unit).to_dict() else: v = self._value.to_dict() if isinstance(v, u.Quantity): v = self.get_value() # force to be in default units if isinstance(v, np.ndarray): v = v.tolist() return v elif k=='limits': return [vi.value if hasattr(vi, 'value') else vi for vi in v] elif v is None: return v elif isinstance(v, str): return v elif isinstance(v, dict): return v elif isinstance(v, float) or isinstance(v, int) or isinstance(v, list): return v elif _is_unit(v): return str(v.to_string()) else: try: return str(v) except: raise NotImplementedError("could not parse {} of '{}' to json".format(k, self.uniquetwig)) return {k: _parse(k, v) for k,v in self.to_dict().items() if (v is not None and k not in ['twig', 'uniquetwig', 'quantity'] and (k!='uniqueid' or incl_uniqueid or self.qualifier=='detached_job'))}
:return: a JSON-ready dictionary holding all information for this parameter
entailment
def get_meta(self, ignore=['uniqueid']): """ See all the meta-tag properties for this Parameter :parameter list ignore: list of keys to exclude from the returned dictionary :return: an ordered dictionary of tag properties """ return OrderedDict([(k, getattr(self, k)) for k in _meta_fields_all if k not in ignore])
See all the meta-tag properties for this Parameter :parameter list ignore: list of keys to exclude from the returned dictionary :return: an ordered dictionary of tag properties
entailment
def uniquetwig(self, ps=None): """ see also :meth:`twig` Determine the shortest (more-or-less) twig which will point to this single Parameter in a given parent :class:`ParameterSet` :parameter ps: :class:`ParameterSet` in which the returned uniquetwig will point to this Parameter. If not provided or None this will default to the parent :class:`phoebe.frontend.bundle.Bundle`, if available. :return: uniquetwig :rtype: str """ if ps is None: ps = self._bundle if ps is None: return self.twig return ps._uniquetwig(self.twig)
see also :meth:`twig` Determine the shortest (more-or-less) twig which will point to this single Parameter in a given parent :class:`ParameterSet` :parameter ps: :class:`ParameterSet` in which the returned uniquetwig will point to this Parameter. If not provided or None this will default to the parent :class:`phoebe.frontend.bundle.Bundle`, if available. :return: uniquetwig :rtype: str
entailment
def twig(self): """ The twig of a Parameter is a single string with the individual :meth:`meta` tags separated by '@' symbols. This twig gives a single string which can point back to this Parameter. see also :meth:`uniquetwig` :return: twig (full) of this Parameter """ return "@".join([getattr(self, k) for k in _meta_fields_twig if getattr(self, k) is not None])
The twig of a Parameter is a single string with the individual :meth:`meta` tags separated by '@' symbols. This twig gives a single string which can point back to this Parameter. see also :meth:`uniquetwig` :return: twig (full) of this Parameter
entailment
def is_visible(self): """ see also :meth:`visible_if` :return: whether this parameter is currently visible (and therefore shown in ParameterSets and visible to :meth:`ParameterSet.filter`) :rtype: bool """ def is_visible_single(visible_if): # visible_if syntax: [ignore,these]qualifier:value if visible_if.lower() == 'false': return False # otherwise we need to find the parameter we're referencing and check its value if visible_if[0]=='[': remove_metawargs, visible_if = visible_if[1:].split(']') remove_metawargs = remove_metawargs.split(',') else: remove_metawargs = [] qualifier, value = visible_if.split(':') if 'hierarchy.' in qualifier: # TODO: set specific syntax (hierarchy.get_meshables:2) # then this needs to do some logic on the hierarchy hier = self._bundle.hierarchy if not len(hier.get_value()): # then hierarchy hasn't been set yet, so we can't do any # of these tests return True method = qualifier.split('.')[1] if value in ['true', 'True']: value = True elif value in ['false', 'False']: value = False return getattr(hier, method)(self.component) == value else: # the parameter needs to have all the same meta data except qualifier # TODO: switch this to use self.get_parent_ps ? metawargs = {k:v for k,v in self.get_meta(ignore=['twig', 'uniquetwig', 'uniqueid']+remove_metawargs).items() if v is not None} metawargs['qualifier'] = qualifier # metawargs['twig'] = None # metawargs['uniquetwig'] = None # metawargs['uniqueid'] = None # if metawargs.get('component', None) == '_default': # metawargs['component'] = None try: # this call is quite expensive and bloats every get_parameter(check_visible=True) param = self._bundle.get_parameter(check_visible=False, check_default=False, **metawargs) except ValueError: # let's not let this hold us up - sometimes this can happen when copying # parameters (from copy_for) in order that the visible_if parameter # happens later logger.debug("parameter not found when trying to determine if visible, {}".format(metawargs)) return True #~ print "***", qualifier, param.qualifier, param.get_value(), value if isinstance(param, BoolParameter): if value in ['true', 'True']: value = True elif value in ['false', 'False']: value = False if isinstance(value, str) and value[0] in ['!', '~']: return param.get_value() != value[1:] elif value=='<notempty>': return len(param.get_value()) > 0 else: return param.get_value() == value if self.visible_if is None: return True if not self._bundle: # then we may not be able to do the check, for now let's just return True return True return np.all([is_visible_single(visible_if_i) for visible_if_i in self.visible_if.split(',')])
see also :meth:`visible_if` :return: whether this parameter is currently visible (and therefore shown in ParameterSets and visible to :meth:`ParameterSet.filter`) :rtype: bool
entailment
def get_parent_ps(self): """ Return a :class:`ParameterSet` of all Parameters in the same :class:`phoebe.frontend.bundle.Bundle` which share the same meta-tags (except qualifier, twig, uniquetwig) :return: the parent :class:`ParameterSet` """ if self._bundle is None: return None metawargs = {k:v for k,v in self.meta.items() if k not in ['qualifier', 'twig', 'uniquetwig']} return self._bundle.filter(**metawargs)
Return a :class:`ParameterSet` of all Parameters in the same :class:`phoebe.frontend.bundle.Bundle` which share the same meta-tags (except qualifier, twig, uniquetwig) :return: the parent :class:`ParameterSet`
entailment
def get_value(self, *args, **kwargs): """ This method should be overriden by any subclass of Parameter, and should be decorated with the @update_if_client decorator. Please see the individual classes documentation: * :meth:`FloatParameter.get_value` * :meth:`ArrayParameter.get_value` * :meth:`HierarchyParameter.get_value` * :meth:`IntParameter.get_value` * :meth:`BoolParameter.get_value` * :meth:`ChoiceParameter.get_value` * :meth:`ConstraintParameter.get_value` * :meth:`HistoryParameter.get_value` If subclassing, this method needs to: * cast to the correct type/units, handling defaults :raises NotImplementedError: because this must be subclassed """ if self.qualifier in kwargs.keys(): # then we have an "override" value that was passed, and we should # just return that. # Example teff_param.get_value('teff', teff=6000) returns 6000 return kwargs.get(self.qualifier) return None
This method should be overriden by any subclass of Parameter, and should be decorated with the @update_if_client decorator. Please see the individual classes documentation: * :meth:`FloatParameter.get_value` * :meth:`ArrayParameter.get_value` * :meth:`HierarchyParameter.get_value` * :meth:`IntParameter.get_value` * :meth:`BoolParameter.get_value` * :meth:`ChoiceParameter.get_value` * :meth:`ConstraintParameter.get_value` * :meth:`HistoryParameter.get_value` If subclassing, this method needs to: * cast to the correct type/units, handling defaults :raises NotImplementedError: because this must be subclassed
entailment
def expand_value(self, **kwargs): """ expand the selection to account for wildcards """ selection = [] for v in self.get_value(**kwargs): for choice in self.choices: if v==choice and choice not in selection: selection.append(choice) elif fnmatch(choice, v) and choice not in selection: selection.append(choice) return selection
expand the selection to account for wildcards
entailment
def remove_not_valid_selections(self): """ update the value to remove any that are (no longer) valid """ value = [v for v in self.get_value() if self.valid_selection(v)] self.set_value(value)
update the value to remove any that are (no longer) valid
entailment
def within_limits(self, value): """ check whether a value falls within the set limits :parameter value: float or Quantity to test. If value is a float, it is assumed that it has the same units as default_units """ return (self.limits[0] is None or value >= self.limits[0]) and (self.limits[1] is None or value <= self.limits[1])
check whether a value falls within the set limits :parameter value: float or Quantity to test. If value is a float, it is assumed that it has the same units as default_units
entailment
def within_limits(self, value): """ check whether a value falls within the set limits :parameter value: float or Quantity to test. If value is a float, it is assumed that it has the same units as default_units """ if isinstance(value, int) or isinstance(value, float): value = value * self.default_unit return (self.limits[0] is None or value >= self.limits[0]) and (self.limits[1] is None or value <= self.limits[1])
check whether a value falls within the set limits :parameter value: float or Quantity to test. If value is a float, it is assumed that it has the same units as default_units
entailment
def is_constraint(self): """ returns the expression of the constraint that constrains this parameter """ if self._is_constraint is None: return None return self._bundle.get_parameter(context='constraint', uniqueid=self._is_constraint)
returns the expression of the constraint that constrains this parameter
entailment
def constrained_by(self): """ returns a list of parameters that constrain this parameter """ if self._is_constraint is None: return [] params = [] for var in self.is_constraint._vars: param = var.get_parameter() if param.uniqueid != self.uniqueid: params.append(param) return params
returns a list of parameters that constrain this parameter
entailment
def in_constraints(self): """ returns a list of the expressions in which this parameter constrains another """ expressions = [] for uniqueid in self._in_constraints: expressions.append(self._bundle.get_parameter(context='constraint', uniqueid=uniqueid)) return expressions
returns a list of the expressions in which this parameter constrains another
entailment
def constrains(self): """ returns a list of parameters that are constrained by this parameter """ params = [] for constraint in self.in_constraints: for var in constraint._vars: param = var.get_parameter() if param.component == constraint.component and param.qualifier == constraint.qualifier: if param not in params and param.uniqueid != self.uniqueid: params.append(param) return params
returns a list of parameters that are constrained by this parameter
entailment
def related_to(self): """ returns a list of all parameters that are either constrained by or constrain this parameter """ params = [] constraints = self.in_constraints if self.is_constraint is not None: constraints.append(self.is_constraint) for constraint in constraints: for var in constraint._vars: param = var.get_parameter() if param not in params and param.uniqueid != self.uniqueid: params.append(param) return params
returns a list of all parameters that are either constrained by or constrain this parameter
entailment
def to_string_short(self): """ see also :meth:`to_string` :return: a shorter abreviated string reprentation of the parameter """ opt = np.get_printoptions() np.set_printoptions(threshold=8, edgeitems=3, linewidth=opt['linewidth']-len(self.uniquetwig)-2) str_ = super(FloatArrayParameter, self).to_string_short() np.set_printoptions(**opt) return str_
see also :meth:`to_string` :return: a shorter abreviated string reprentation of the parameter
entailment
def interp_value(self, **kwargs): """ Interpolate to find the value in THIS array given a value from ANOTHER array in the SAME parent :class:`ParameterSet` This currently only supports simple 1d linear interpolation (via numpy.interp) and does no checks to make sure you're interpolating with respect to an independent parameter - so use with caution. >>> print this_param.get_parent_ps().qualifiers >>> 'other_qualifier' in this_param.get_parent_ps().qualifiers True >>> this_param.interp_value(other_qualifier=5) where other_qualifier must be in this_param.get_parent_ps().qualifiers AND must point to another FloatArrayParameter. Example: >>> b['flux@lc01@model'].interp_value(times=10.2) NOTE: Interpolation by phase is not currently supported - but you can use :meth:`phoebe.frontend.bundle.Bundle.to_time` to convert to a valid time first (just make sure its in the bounds of the time array). NOTE: this method does not currently support units. You must provide the interpolating value in its default units and are returned the value in the default units (no support for quantities). :parameter **kwargs: see examples above, must provide a single qualifier-value pair to use for interpolation. In most cases this will probably be time=value or wavelength=value. :raises KeyError: if more than one qualifier is passed :raises KeyError: if no qualifier is passed that belongs to the parent :class:`ParameterSet` :raises KeyError: if the qualifier does not point to another :class:`FloatArrayParameter` """ # TODO: add support for units # TODO: add support for non-linear interpolation (probably would need to use scipy)? # TODO: add support for interpolating in phase_space if len(kwargs.keys()) > 1: raise KeyError("interp_value only takes a single qualifier-value pair") qualifier, qualifier_interp_value = kwargs.items()[0] if isinstance(qualifier_interp_value, str): # then assume its a twig and try to resolve # for example: time='t0_supconj' qualifier_interp_value = self._bundle.get_value(qualifier_interp_value, context=['system', 'component']) parent_ps = self.get_parent_ps() if qualifier not in parent_ps.qualifiers: # TODO: handle plural to singular (having to say # interp_value(times=5) is awkward) raise KeyError("'{}' not valid qualifier (must be one of {})".format(qualifier, parent_ps.qualifiers)) qualifier_parameter = parent_ps.get(qualifier=qualifier) if not isinstance(qualifier_parameter, FloatArrayParameter): raise KeyError("'{}' does not point to a FloatArrayParameter".format(qualifier)) return np.interp(qualifier_interp_value, qualifier_parameter.get_value(), self.get_value())
Interpolate to find the value in THIS array given a value from ANOTHER array in the SAME parent :class:`ParameterSet` This currently only supports simple 1d linear interpolation (via numpy.interp) and does no checks to make sure you're interpolating with respect to an independent parameter - so use with caution. >>> print this_param.get_parent_ps().qualifiers >>> 'other_qualifier' in this_param.get_parent_ps().qualifiers True >>> this_param.interp_value(other_qualifier=5) where other_qualifier must be in this_param.get_parent_ps().qualifiers AND must point to another FloatArrayParameter. Example: >>> b['flux@lc01@model'].interp_value(times=10.2) NOTE: Interpolation by phase is not currently supported - but you can use :meth:`phoebe.frontend.bundle.Bundle.to_time` to convert to a valid time first (just make sure its in the bounds of the time array). NOTE: this method does not currently support units. You must provide the interpolating value in its default units and are returned the value in the default units (no support for quantities). :parameter **kwargs: see examples above, must provide a single qualifier-value pair to use for interpolation. In most cases this will probably be time=value or wavelength=value. :raises KeyError: if more than one qualifier is passed :raises KeyError: if no qualifier is passed that belongs to the parent :class:`ParameterSet` :raises KeyError: if the qualifier does not point to another :class:`FloatArrayParameter`
entailment
def set_property(self, **kwargs): """ set any property of the underlying nparray object """ if not isinstance(self._value, nparray.ndarray): raise ValueError("value is not a nparray object") for property, value in kwargs.items(): setattr(self._value, property, value)
set any property of the underlying nparray object
entailment
def _parse_repr(self): """ turn something like "orbit:outer(orbit:inner(star:starA, star:starB), star:starC)" into ['orbit:outer', ['orbit:inner', ['star:starA', 'star:starB'], 'star:starC']] """ repr_ = self.get_value() repr_str = '["{}"]'.format(repr_.replace(', ', '", "').replace('(', '", ["').replace(')', '"]')).replace(']"', '"]').replace('""', '"').replace(']"', ']') return json.loads(repr_str)
turn something like "orbit:outer(orbit:inner(star:starA, star:starB), star:starC)" into ['orbit:outer', ['orbit:inner', ['star:starA', 'star:starB'], 'star:starC']]
entailment
def _recurse_find_trace(self, structure, item, trace=[]): """ given a nested structure from _parse_repr and find the trace route to get to item """ try: i = structure.index(item) except ValueError: for j,substructure in enumerate(structure): if isinstance(substructure, list): return self._recurse_find_trace(substructure, item, trace+[j]) else: return trace+[i]
given a nested structure from _parse_repr and find the trace route to get to item
entailment
def _get_by_trace(self, structure, trace): """ retrieve an item from the nested structure from _parse_repr given a trace (probably modified from _recurse_find_trace) """ for i in trace: structure = structure[i] return structure
retrieve an item from the nested structure from _parse_repr given a trace (probably modified from _recurse_find_trace)
entailment
def get_stars(self): """ get 'component' of all stars in order primary -> secondary """ l = re.findall(r"[\w']+", self.get_value()) # now search for indices of star and take the next entry from this flat list return [l[i+1] for i,s in enumerate(l) if s=='star']
get 'component' of all stars in order primary -> secondary
entailment
def get_orbits(self): """ get 'component' of all orbits in order primary -> secondary """ #~ l = re.findall(r"[\w']+", self.get_value()) # now search for indices of orbit and take the next entry from this flat list #~ return [l[i+1] for i,s in enumerate(l) if s=='orbit'] orbits = [] for star in self.get_stars(): parent = self.get_parent_of(star) if parent not in orbits and parent!='component' and parent is not None: orbits.append(parent) return orbits
get 'component' of all orbits in order primary -> secondary
entailment
def get_stars_of_sibling_of(self, component): """ same as get_sibling_of except if the sibling is an orbit, this will recursively follow the tree to return a list of all stars under that orbit """ sibling = self.get_sibling_of(component) if sibling in self.get_stars(): return sibling stars = [child for child in self.get_stars_of_children_of(sibling)] # TODO: do we need to make sure there aren't duplicates? # return list(set(stars)) return stars
same as get_sibling_of except if the sibling is an orbit, this will recursively follow the tree to return a list of all stars under that orbit
entailment
def get_children_of(self, component, kind=None): """ get to component labels of the children of a given component """ structure, trace, item = self._get_structure_and_trace(component) item_kind, item_label = item.split(':') if isinstance(kind, str): kind = [kind] if item_kind not in ['orbit']: # return None return [] else: items = self._get_by_trace(structure, trace[:-1]+[trace[-1]+1]) # we want to ignore suborbits #return [str(ch.split(':')[-1]) for ch in items if isinstance(ch, unicode)] return [str(ch.split(':')[-1]) for ch in items if isinstance(ch, unicode) and (kind is None or ch.split(':')[0] in kind)]
get to component labels of the children of a given component
entailment
def get_stars_of_children_of(self, component): """ same as get_children_of except if any of the children are orbits, this will recursively follow the tree to return a list of all children (grandchildren, etc) stars under that orbit """ stars = self.get_stars() orbits = self.get_orbits() stars_children = [] for child in self.get_children_of(component): if child in stars: stars_children.append(child) elif child in orbits: stars_children += self.get_stars_of_children_of(child) else: # maybe an envelope or eventually spot, ring, etc pass return stars_children
same as get_children_of except if any of the children are orbits, this will recursively follow the tree to return a list of all children (grandchildren, etc) stars under that orbit
entailment
def get_child_of(self, component, ind, kind=None): """ get a child (by index) of a given component """ children = self.get_children_of(component, kind=kind) if children is None: return None else: return children[ind]
get a child (by index) of a given component
entailment
def get_primary_or_secondary(self, component, return_ind=False): """ return whether a given component is the 'primary' or 'secondary' component in its parent orbit """ parent = self.get_parent_of(component) if parent is None: # then this is a single component, not in a binary return 'primary' children_of_parent = self.get_children_of(parent) ind = children_of_parent.index(component) if ind > 1: return None if return_ind: return ind + 1 return ['primary', 'secondary'][ind]
return whether a given component is the 'primary' or 'secondary' component in its parent orbit
entailment
def get_meshables(self): """ return a list of components that are meshable (generally stars, but handles the envelope for an contact_binary) """ l = re.findall(r"[\w']+", self.get_value()) # now search for indices of star and take the next entry from this flat list meshables = [l[i+1] for i,s in enumerate(l) if s in ['star', 'envelope']] # now we want to remove any star which has a sibling envelope has_sibling_envelope = [] for item in meshables: if self.get_sibling_of(item, kind='envelope'): has_sibling_envelope.append(item) return [m for m in meshables if m not in has_sibling_envelope]
return a list of components that are meshable (generally stars, but handles the envelope for an contact_binary)
entailment
def is_contact_binary(self, component): """ especially useful for constraints tells whether any component (star, envelope) is part of a contact_binary by checking its siblings for an envelope """ if component not in self._is_contact_binary.keys(): self._update_cache() return self._is_contact_binary.get(component)
especially useful for constraints tells whether any component (star, envelope) is part of a contact_binary by checking its siblings for an envelope
entailment
def is_binary(self, component): """ especially useful for constraints tells whether any component (star, envelope) is part of a binary by checking its parent """ if component not in self._is_binary.keys(): self._update_cache() return self._is_binary.get(component)
especially useful for constraints tells whether any component (star, envelope) is part of a binary by checking its parent
entailment
def vars(self): """ return all the variables in a PS """ # cache _var_params if self._var_params is None: self._var_params = ParameterSet([var.get_parameter() for var in self._vars]) return self._var_params
return all the variables in a PS
entailment
def get_parameter(self, twig=None, **kwargs): """ get a parameter from those that are variables """ kwargs['twig'] = twig kwargs['check_default'] = False kwargs['check_visible'] = False ps = self.vars.filter(**kwargs) if len(ps)==1: return ps.get(check_visible=False, check_default=False) elif len(ps) > 1: # TODO: is this safe? Some constraints may have a parameter listed # twice, so we can do this then, but maybe should check to make sure # all items have the same uniqueid? Maybe check len(ps.uniqueids)? return ps.to_list()[0] else: raise KeyError("no result found")
get a parameter from those that are variables
entailment
def flip_for(self, twig=None, expression=None, **kwargs): """ flip the constraint to solve for for any of the parameters in the expression expression (optional if sympy available, required if not) """ _orig_expression = self.get_value() # try to get the parameter from the bundle kwargs['twig'] = twig newly_constrained_var = self._get_var(**kwargs) newly_constrained_param = self.get_parameter(**kwargs) check_kwargs = {k:v for k,v in newly_constrained_param.meta.items() if k not in ['context', 'twig', 'uniquetwig']} check_kwargs['context'] = 'constraint' if len(self._bundle.filter(**check_kwargs)): raise ValueError("'{}' is already constrained".format(newly_constrained_param.twig)) currently_constrained_var = self._get_var(qualifier=self.qualifier, component=self.component) currently_constrained_param = currently_constrained_var.get_parameter() # or self.constrained_parameter import constraint if self.constraint_func is not None and hasattr(constraint, self.constraint_func): # then let's see if the method is capable of resolving for use # try: if True: # TODO: this is not nearly general enough, each method takes different arguments # and getting solve_for as newly_constrained_param.qualifier lhs, rhs, constraint_kwargs = getattr(constraint, self.constraint_func)(self._bundle, solve_for=newly_constrained_param, **self.constraint_kwargs) # except NotImplementedError: # pass # else: # TODO: this needs to be smarter and match to self._get_var().user_label instead of the current uniquetwig expression = rhs._value # safe expression #~ print "*** flip by recalling method success!", expression # print "***", lhs._value, rhs._value if expression is not None: expression = expression elif _use_sympy: eq_safe = "({}) - {}".format(self._value, currently_constrained_var.safe_label) #~ print "*** solving {} for {}".format(eq_safe, newly_constrained_var.safe_label) expression = sympy.solve(eq_safe, newly_constrained_var.safe_label)[0] #~ print "*** solution: {}".format(expression) else: # TODO: ability for built-in constraints to flip themselves # we could access self.kind and re-call that with a new solve_for option? raise ValueError("must either have sympy installed or provide a new expression") self._qualifier = newly_constrained_param.qualifier self._component = newly_constrained_param.component self._kind = newly_constrained_param.kind self._value = str(expression) # reset the default_unit so that set_default_unit doesn't complain # about incompatible units self._default_unit = None self.set_default_unit(newly_constrained_param.default_unit) self._update_bookkeeping() self._add_history(redo_func='flip_constraint', redo_kwargs={'expression': expression, 'uniqueid': newly_constrained_param.uniqueid}, undo_func='flip_constraint', undo_kwargs={'expression': _orig_expression, 'uniqueid': currently_constrained_param.uniqueid})
flip the constraint to solve for for any of the parameters in the expression expression (optional if sympy available, required if not)
entailment
def get_status(self): """ [NOT IMPLEMENTED] """ if self._value == 'loaded': status = 'loaded' elif not _is_server and self._bundle is not None and self._server_status is not None: if not _can_requests: raise ImportError("requests module required for external jobs") if self._value in ['complete']: # then we have no need to bother checking again status = self._value else: url = self._server_status logger.info("checking job status on server from {}".format(url)) # "{}/{}/parameters/{}".format(server, bundleid, self.uniqueid) r = requests.get(url, timeout=5) try: rjson = r.json() except ValueError: # TODO: better exception here - perhaps look for the status code from the response? status = self._value else: status = rjson['data']['attributes']['value'] else: if self.status_method == 'exists': output_exists = os.path.isfile("_{}.out".format(self.uniqueid)) if output_exists: status = 'complete' else: status = 'unknown' else: raise NotImplementedError # here we'll set the value to be the latest CHECKED status for the sake # of exporting to JSON and updating the status for clients. get_value # will still call status so that it will return the CURRENT value. self._value = status return status
[NOT IMPLEMENTED]
entailment
def get_unbound_form(self): """ Overrides behavior of FormView.get_form_kwargs when method is POST or PUT """ form_kwargs = self.get_form_kwargs() # @@@ remove fields that would cause the form to be bound # when instantiated bound_fields = ["data", "files"] for field in bound_fields: form_kwargs.pop(field, None) return self.get_form_class()(**form_kwargs)
Overrides behavior of FormView.get_form_kwargs when method is POST or PUT
entailment
def get_form_success_data(self, form): """ Allows customization of the JSON data returned when a valid form submission occurs. """ data = { "html": render_to_string( "pinax/teams/_invite_form.html", { "invite_form": self.get_unbound_form(), "team": self.team }, request=self.request ) } membership = self.membership if membership is not None: if membership.state == Membership.STATE_APPLIED: fragment_class = ".applicants" elif membership.state == Membership.STATE_INVITED: fragment_class = ".invitees" elif membership.state in (Membership.STATE_AUTO_JOINED, Membership.STATE_ACCEPTED): fragment_class = { Membership.ROLE_OWNER: ".owners", Membership.ROLE_MANAGER: ".managers", Membership.ROLE_MEMBER: ".members" }[membership.role] data.update({ "append-fragments": { fragment_class: render_to_string( "pinax/teams/_membership.html", { "membership": membership, "team": self.team }, request=self.request ) } }) return data
Allows customization of the JSON data returned when a valid form submission occurs.
entailment
def _value(obj): """ make sure to get a float """ # TODO: this is ugly and makes everything ugly # can we handle this with a clean decorator or just requiring that only floats be passed?? if hasattr(obj, 'value'): return obj.value elif isinstance(obj, np.ndarray): return np.array([o.value for o in obj]) elif hasattr(obj, '__iter__'): return [_value(o) for o in obj] return obj
make sure to get a float
entailment
def _estimate_delta(ntriangles, area): """ estimate the value for delta to send to marching based on the number of requested triangles and the expected surface area of mesh """ return np.sqrt(4./np.sqrt(3) * float(area) / float(ntriangles))
estimate the value for delta to send to marching based on the number of requested triangles and the expected surface area of mesh
entailment
def from_bundle(cls, b, compute=None, datasets=[], **kwargs): """ Build a system from the :class:`phoebe.frontend.bundle.Bundle` and its hierarchy. :parameter b: the :class:`phoebe.frontend.bundle.Bundle` :parameter str compute: name of the computeoptions in the bundle :parameter list datasets: list of names of datasets :parameter **kwargs: temporary overrides for computeoptions :return: an instantiated :class:`System` object, including its children :class:`Body`s """ hier = b.hierarchy if not len(hier.get_value()): raise NotImplementedError("Meshing requires a hierarchy to exist") # now pull general compute options if compute is not None: if isinstance(compute, str): compute_ps = b.get_compute(compute, check_visible=False) else: # then hopefully compute is the parameterset compute_ps = compute eclipse_method = compute_ps.get_value(qualifier='eclipse_method', **kwargs) horizon_method = compute_ps.get_value(qualifier='horizon_method', check_visible=False, **kwargs) dynamics_method = compute_ps.get_value(qualifier='dynamics_method', **kwargs) irrad_method = compute_ps.get_value(qualifier='irrad_method', **kwargs) boosting_method = compute_ps.get_value(qualifier='boosting_method', **kwargs) if conf.devel: mesh_init_phi = compute_ps.get_value(qualifier='mesh_init_phi', unit=u.rad, **kwargs) else: mesh_init_phi = 0.0 else: eclipse_method = 'native' horizon_method = 'boolean' dynamics_method = 'keplerian' irrad_method = 'none' boosting_method = 'none' mesh_init_phi = 0.0 # NOTE: here we use globals()[Classname] because getattr doesn't work in # the current module - now this doesn't really make sense since we only # support stars, but eventually the classname could be Disk, Spot, etc if 'dynamics_method' in kwargs.keys(): # already set as default above _dump = kwargs.pop('dynamics_method') meshables = hier.get_meshables() def get_distortion_method(hier, compute_ps, component, **kwargs): if hier.get_kind_of(component) in ['envelope']: return 'roche' if compute_ps.get_value('mesh_method', component=component, **kwargs)=='wd': return 'roche' return compute_ps.get_value('distortion_method', component=component, **kwargs) bodies_dict = {comp: globals()[_get_classname(hier.get_kind_of(comp), get_distortion_method(hier, compute_ps, comp, **kwargs))].from_bundle(b, comp, compute, dynamics_method=dynamics_method, mesh_init_phi=mesh_init_phi, datasets=datasets, **kwargs) for comp in meshables} # envelopes need to know their relationships with the underlying stars parent_envelope_of = {} for meshable in meshables: if hier.get_kind_of(meshable) == 'envelope': for starref in hier.get_siblings_of(meshable): parent_envelope_of[starref] = meshable return cls(bodies_dict, eclipse_method=eclipse_method, horizon_method=horizon_method, dynamics_method=dynamics_method, irrad_method=irrad_method, boosting_method=boosting_method, parent_envelope_of=parent_envelope_of)
Build a system from the :class:`phoebe.frontend.bundle.Bundle` and its hierarchy. :parameter b: the :class:`phoebe.frontend.bundle.Bundle` :parameter str compute: name of the computeoptions in the bundle :parameter list datasets: list of names of datasets :parameter **kwargs: temporary overrides for computeoptions :return: an instantiated :class:`System` object, including its children :class:`Body`s
entailment
def get_body(self, component): """ TODO: add documentation """ if component in self._bodies.keys(): return self._bodies[component] else: # then hopefully we're a child star of an contact_binary envelope parent_component = self._parent_envelope_of[component] return self._bodies[parent_component].get_half(component)
TODO: add documentation
entailment
def update_positions(self, time, xs, ys, zs, vxs, vys, vzs, ethetas, elongans, eincls, ds=None, Fs=None, ignore_effects=False): """ TODO: add documentation all arrays should be for the current time, but iterable over all bodies """ self.xs = np.array(_value(xs)) self.ys = np.array(_value(ys)) self.zs = np.array(_value(zs)) for starref,body in self.items(): body.update_position(time, xs, ys, zs, vxs, vys, vzs, ethetas, elongans, eincls, ds=ds, Fs=Fs, ignore_effects=ignore_effects)
TODO: add documentation all arrays should be for the current time, but iterable over all bodies
entailment
def populate_observables(self, time, kinds, datasets, ignore_effects=False): """ TODO: add documentation ignore_effects: whether to ignore reflection and features (useful for computing luminosities) """ if self.irrad_method is not 'none' and not ignore_effects: # TODO: only for kinds that require intensities (i.e. not orbit or # dynamical RVs, etc) self.handle_reflection() for kind, dataset in zip(kinds, datasets): for starref, body in self.items(): body.populate_observable(time, kind, dataset)
TODO: add documentation ignore_effects: whether to ignore reflection and features (useful for computing luminosities)
entailment
def handle_eclipses(self, expose_horizon=False, **kwargs): """ Detect the triangles at the horizon and the eclipsed triangles, handling any necessary subdivision. :parameter str eclipse_method: name of the algorithm to use to detect the horizon or eclipses (defaults to the value set by computeoptions) :parameter str subdiv_alg: name of the algorithm to use for subdivision (defaults to the value set by computeoptions) :parameter int subdiv_num: number of subdivision iterations (defaults the value set by computeoptions) """ eclipse_method = kwargs.get('eclipse_method', self.eclipse_method) horizon_method = kwargs.get('horizon_method', self.horizon_method) # Let's first check to see if eclipses are even possible at these # positions. If they are not, then we only have to do horizon # # To do that, we'll take the conservative max_r for each object # and their current positions, and see if the separations are larger # than sum of max_rs possible_eclipse = False if len(self.bodies) == 1: if self.bodies[0].__class__.__name__ == 'Envelope': possible_eclipse = True else: possible_eclipse = False else: logger.debug("system.handle_eclipses: determining if eclipses are possible from instantaneous_maxr") max_rs = [body.instantaneous_maxr for body in self.bodies] # logger.debug("system.handle_eclipses: max_rs={}".format(max_rs)) for i in range(0, len(max_rs)-1): for j in range(i+1, len(max_rs)): proj_sep_sq = sum([(c[i]-c[j])**2 for c in (self.xs,self.ys)]) max_sep_ecl = max_rs[i] + max_rs[j] if proj_sep_sq < (1.05*max_sep_ecl)**2: # then this pair has the potential for eclipsing triangles possible_eclipse = True break if not possible_eclipse and not expose_horizon and horizon_method=='boolean': eclipse_method = 'only_horizon' # meshes is an object which allows us to easily access and update columns # in the meshes *in memory*. That is meshes.update_columns will propogate # back to the current mesh for each body. meshes = self.meshes # Reset all visibilities to be fully visible to start meshes.update_columns('visiblities', 1.0) ecl_func = getattr(eclipse, eclipse_method) if eclipse_method=='native': ecl_kwargs = {'horizon_method': horizon_method} else: ecl_kwargs = {} logger.debug("system.handle_eclipses: possible_eclipse={}, expose_horizon={}, calling {} with kwargs {}".format(possible_eclipse, expose_horizon, eclipse_method, ecl_kwargs)) visibilities, weights, horizon = ecl_func(meshes, self.xs, self.ys, self.zs, expose_horizon=expose_horizon, **ecl_kwargs) # NOTE: analytic horizons are called in backends.py since they don't # actually depend on the mesh at all. # visiblilities here is a dictionary with keys being the component # labels and values being the np arrays of visibilities. We can pass # this dictionary directly and the columns will be applied respectively. meshes.update_columns('visibilities', visibilities) # weights is also a dictionary with keys being the component labels # and values and np array of weights. if weights is not None: meshes.update_columns('weights', weights) return horizon
Detect the triangles at the horizon and the eclipsed triangles, handling any necessary subdivision. :parameter str eclipse_method: name of the algorithm to use to detect the horizon or eclipses (defaults to the value set by computeoptions) :parameter str subdiv_alg: name of the algorithm to use for subdivision (defaults to the value set by computeoptions) :parameter int subdiv_num: number of subdivision iterations (defaults the value set by computeoptions)
entailment