_id
stringlengths
2
7
title
stringlengths
1
88
partition
stringclasses
3 values
text
stringlengths
31
13.1k
language
stringclasses
1 value
meta_information
dict
q20100
Pst.less_than_obs_constraints
train
def less_than_obs_constraints(self): """get the names of the observations that are listed as less than inequality constraints. Zero- weighted obs are skipped Returns ------- pandas.Series : obsnme of obseravtions
python
{ "resource": "" }
q20101
Pst.less_than_pi_constraints
train
def less_than_pi_constraints(self): """get the names of the prior information eqs that are listed as less than inequality constraints. Zero- weighted pi are skipped Returns ------- pandas.Series : pilbl of
python
{ "resource": "" }
q20102
Pst.greater_than_obs_constraints
train
def greater_than_obs_constraints(self): """get the names of the observations that are listed as greater than inequality constraints. Zero- weighted obs are skipped Returns ------- pandas.Series : obsnme of obseravtions
python
{ "resource": "" }
q20103
Pst.greater_than_pi_constraints
train
def greater_than_pi_constraints(self): """get the names of the prior information eqs that are listed as greater than inequality constraints. Zero- weighted pi are skipped Returns ------- pandas.Series
python
{ "resource": "" }
q20104
LinearAnalysis.__load_pst
train
def __load_pst(self): """private method set the pst attribute """ if self.pst_arg is None: return None if isinstance(self.pst_arg, Pst): self.__pst = self.pst_arg return self.pst else: try: self.log("loading pst: " + str(self.pst_arg)) self.__pst = Pst(self.pst_arg) self.log("loading pst: " + str(self.pst_arg)) return self.pst
python
{ "resource": "" }
q20105
LinearAnalysis.__load_jco
train
def __load_jco(self): """private method to set the jco attribute from a file or a matrix object """ if self.jco_arg is None: return None #raise Exception("linear_analysis.__load_jco(): jco_arg is None") if isinstance(self.jco_arg, Matrix): self.__jco = self.jco_arg elif isinstance(self.jco_arg, str):
python
{ "resource": "" }
q20106
LinearAnalysis.nnz_obs_names
train
def nnz_obs_names(self): """ wrapper around pyemu.Pst.nnz_obs_names for listing non-zero observation names Returns ------- nnz_obs_names : list pyemu.Pst.nnz_obs_names
python
{ "resource": "" }
q20107
LinearAnalysis.adj_par_names
train
def adj_par_names(self): """ wrapper around pyemu.Pst.adj_par_names for list adjustable parameter names Returns ------- adj_par_names : list pyemu.Pst.adj_par_names
python
{ "resource": "" }
q20108
LinearAnalysis.predictions_iter
train
def predictions_iter(self): """ property decorated prediction iterator Returns ------- iterator : iterator
python
{ "resource": "" }
q20109
LinearAnalysis.pst
train
def pst(self): """ get the pyemu.Pst attribute Returns ------- pst : pyemu.Pst Note ---- returns a references If LinearAnalysis.__pst is None, then the pst attribute is dynamically loaded before returning """ if self.__pst is None and self.pst_arg is None:
python
{ "resource": "" }
q20110
LinearAnalysis.fehalf
train
def fehalf(self): """get the KL parcov scaling matrix attribute. Create the attribute if it has not yet been created Returns ------- fehalf : pyemu.Matrix """ if self.__fehalf != None:
python
{ "resource": "" }
q20111
LinearAnalysis.qhalf
train
def qhalf(self): """get the square root of the cofactor matrix attribute. Create the attribute if it has not yet been created Returns ------- qhalf : pyemu.Matrix """ if self.__qhalf
python
{ "resource": "" }
q20112
LinearAnalysis.qhalfx
train
def qhalfx(self): """get the half normal matrix attribute. Create the attribute if it has not yet been created Returns ------- qhalfx : pyemu.Matrix """ if self.__qhalfx is None:
python
{ "resource": "" }
q20113
LinearAnalysis.xtqx
train
def xtqx(self): """get the normal matrix attribute. Create the attribute if it has not yet been created Returns ------- xtqx : pyemu.Matrix """ if self.__xtqx is None:
python
{ "resource": "" }
q20114
LinearAnalysis.mle_parameter_estimate
train
def mle_parameter_estimate(self): """ get the maximum likelihood parameter estimate. Returns ------- post_expt : pandas.Series the maximum likelihood parameter estimates """ res = self.pst.res assert res is not None # build the prior expectation parameter vector prior_expt = self.pst.parameter_data.loc[:,["parval1"]].copy() islog = self.pst.parameter_data.partrans == "log" prior_expt.loc[islog] = prior_expt.loc[islog].apply(np.log10) prior_expt = Matrix.from_dataframe(prior_expt) prior_expt.col_names = ["prior_expt"] # build the residual vector res_vec = Matrix.from_dataframe(res.loc[:,["residual"]]) # calc posterior expectation
python
{ "resource": "" }
q20115
LinearAnalysis.prior_prediction
train
def prior_prediction(self): """get a dict of prior prediction variances Returns ------- prior_prediction : dict dictionary of prediction name, prior variance pairs """ if self.__prior_prediction is not None: return self.__prior_prediction else: if self.predictions is not None:
python
{ "resource": "" }
q20116
LinearAnalysis.apply_karhunen_loeve_scaling
train
def apply_karhunen_loeve_scaling(self): """apply karhuene-loeve scaling to the jacobian matrix. Note ---- This scaling is not necessary for analyses using Schur's complement, but can be very important for error variance analyses. This operation effectively transfers prior knowledge specified in the parcov to the jacobian and reset parcov
python
{ "resource": "" }
q20117
LinearAnalysis.clean
train
def clean(self): """drop regularization and prior information observation from the jco """ if self.pst_arg is None: self.logger.statement("linear_analysis.clean(): not pst object")
python
{ "resource": "" }
q20118
LinearAnalysis.reset_pst
train
def reset_pst(self,arg): """ reset the LinearAnalysis.pst attribute Parameters ---------- arg : (str or matrix) the value to assign to the pst attribute """
python
{ "resource": "" }
q20119
LinearAnalysis.reset_parcov
train
def reset_parcov(self,arg=None): """reset the parcov attribute to None Parameters ---------- arg : str or pyemu.Matrix the value to assign to the parcov attribute. If None, the private __parcov attribute is cleared but not reset
python
{ "resource": "" }
q20120
LinearAnalysis.reset_obscov
train
def reset_obscov(self,arg=None): """reset the obscov attribute to None Parameters ---------- arg : str or pyemu.Matrix the value to assign to the obscov attribute. If None, the private __obscov attribute is cleared but not reset
python
{ "resource": "" }
q20121
LinearAnalysis.drop_prior_information
train
def drop_prior_information(self): """drop the prior information from the jco and pst attributes """ if self.jco is None: self.logger.statement("can't drop prior info, LinearAnalysis.jco is None") return nprior_str = str(self.pst.nprior) self.log("removing " + nprior_str + " prior info from jco, pst, and " + "obs cov") #pi_names = list(self.pst.prior_information.pilbl.values) pi_names = list(self.pst.prior_names) missing = [name for name in pi_names if name not in self.jco.obs_names] if len(missing) > 0: raise Exception("LinearAnalysis.drop_prior_information(): "+
python
{ "resource": "" }
q20122
LinearAnalysis.adjust_obscov_resfile
train
def adjust_obscov_resfile(self, resfile=None): """reset the elements of obscov by scaling the implied weights based on the phi components in res_file so that the total phi is equal to the number of non-zero weights. Parameters ---------- resfile : str residual file to use. If None, residual file with case name is sought. default is None
python
{ "resource": "" }
q20123
LinearAnalysis.get_par_css_dataframe
train
def get_par_css_dataframe(self): """ get a dataframe of composite scaled sensitivities. Includes both PEST-style and Hill-style. Returns ------- css : pandas.DataFrame """ assert self.jco is not None assert self.pst is not None jco = self.jco.to_dataframe() weights = self.pst.observation_data.loc[jco.index,"weight"].copy().values jco = (jco.T * weights).T dss_sum = jco.apply(np.linalg.norm)
python
{ "resource": "" }
q20124
LinearAnalysis.get_cso_dataframe
train
def get_cso_dataframe(self): """ get a dataframe of composite observation sensitivity, as returned by PEST in the seo file. Note that this formulation deviates slightly from the PEST documentation in that the values are divided by (npar-1) rather than by (npar). The equation is cso_j = ((Q^1/2*J*J^T*Q^1/2)^1/2)_jj/(NPAR-1) Returns: cso : pandas.DataFrame """ assert self.jco is not None assert self.pst is not None weights = self.pst.observation_data.loc[self.jco.to_dataframe().index,"weight"].copy().values
python
{ "resource": "" }
q20125
plot_id_bar
train
def plot_id_bar(id_df, nsv=None, logger=None, **kwargs): """ Plot a stacked bar chart of identifiability based on a identifiability dataframe Parameters ---------- id_df : pandas dataframe of identifiability nsv : number of singular values to consider logger : pyemu.Logger kwargs : dict of keyword arguments Returns ------- ax : matplotlib.Axis Example ------- ``>>> import pyemu`` ``>>> pest_obj = pyemu.Pst(pest_control_file)`` ``>>> ev = pyemu.ErrVar(jco='freyberg_jac.jcb'))`` ``>>> id_df = ev.get_identifiability_dataframe(singular_value=48)`` ``>>> pyemu.plot_id_bar(id_df, nsv=12, figsize=(12,4)`` """ if logger is None: logger=Logger('Default_Loggger.log',echo=False) logger.log("plot id bar") df = id_df.copy() # drop the final `ident` column if 'ident' in df.columns: df.drop('ident', inplace=True, axis=1) if nsv is None or nsv > len(df.columns): nsv = len(df.columns) logger.log('set number of SVs and number in the dataframe') df = df[df.columns[:nsv]] df['ident'] = df.sum(axis=1) df.sort_values(by='ident', inplace=True, ascending=False) df.drop('ident', inplace=True, axis=1) if 'figsize' in kwargs: figsize=kwargs['figsize'] else: figsize = (8, 10.5) if "ax" in kwargs: ax = kwargs["ax"] else: fig = plt.figure(figsize=figsize) ax = plt.subplot(1,1,1) # plto
python
{ "resource": "" }
q20126
res_phi_pie
train
def res_phi_pie(pst,logger=None, **kwargs): """plot current phi components as a pie chart. Parameters ---------- pst : pyemu.Pst logger : pyemu.Logger kwargs : dict accepts 'include_zero' as a flag to include phi groups with only zero-weight obs (not sure why anyone would do this, but whatevs). Returns ------- ax : matplotlib.Axis """ if logger is None: logger=Logger('Default_Loggger.log',echo=False) logger.log("plot res_phi_pie") if "ensemble" in kwargs: try: res=pst_utils.res_from_en(pst,kwargs['ensemble']) except: logger.statement("res_1to1: could not find ensemble file {0}".format(kwargs['ensemble'])) else:
python
{ "resource": "" }
q20127
smp_to_ins
train
def smp_to_ins(smp_filename,ins_filename=None,use_generic_names=False, gwutils_compliant=False, datetime_format=None,prefix=''): """ create an instruction file for an smp file Parameters ---------- smp_filename : str existing smp file ins_filename: str instruction file to create. If None, create an instruction file using the smp filename with the ".ins" suffix use_generic_names : bool flag to force observations names to use a generic int counter instead of trying to use a datetime str gwutils_compliant : bool flag to use instruction set that is compliant with the pest gw utils (fixed format instructions). If false, use free format (with whitespace) instruction set datetime_format : str str to pass to datetime.strptime in the smp_to_dataframe() function prefix : str a prefix to add to the front of the obsnmes. Default is '' Returns ------- df : pandas.DataFrame dataframe instance of the smp file with the observation names and instruction lines as additional columns """ if ins_filename is None: ins_filename = smp_filename+".ins" df = smp_to_dataframe(smp_filename,datetime_format=datetime_format) df.loc[:,"ins_strings"] = None df.loc[:,"observation_names"] = None name_groups = df.groupby("name").groups for name,idxs in name_groups.items(): if not use_generic_names and len(name) <= 11: onames = df.loc[idxs,"datetime"].apply(lambda x: prefix+name+'_'+x.strftime("%d%m%Y")).values else: onames = [prefix+name+"_{0:d}".format(i) for i in range(len(idxs))]
python
{ "resource": "" }
q20128
dataframe_to_smp
train
def dataframe_to_smp(dataframe,smp_filename,name_col="name", datetime_col="datetime",value_col="value", datetime_format="dd/mm/yyyy", value_format="{0:15.6E}", max_name_len=12): """ write a dataframe as an smp file Parameters ---------- dataframe : pandas.DataFrame smp_filename : str smp file to write name_col: str the column in the dataframe the marks the site namne datetime_col: str the column in the dataframe that is a datetime instance value_col: str the column in the dataframe that is the values datetime_format: str either 'dd/mm/yyyy' or 'mm/dd/yyy' value_format: str a python float-compatible format """ formatters = {"name":lambda x:"{0:<20s}".format(str(x)[:max_name_len]),
python
{ "resource": "" }
q20129
date_parser
train
def date_parser(items): """ datetime parser to help load smp files Parameters ---------- items : iterable something or somethings to try to parse into datetimes Returns ------- dt : iterable the cast datetime things """ try: dt = datetime.strptime(items,"%d/%m/%Y %H:%M:%S") except Exception as e:
python
{ "resource": "" }
q20130
MonteCarlo.get_nsing
train
def get_nsing(self,epsilon=1.0e-4): """ get the number of solution space dimensions given a ratio between the largest and smallest singular values Parameters ---------- epsilon: float singular value ratio Returns ------- nsing : float number of singular components above the epsilon ratio threshold Note ----- If nsing == nadj_par, then None is returned
python
{ "resource": "" }
q20131
MonteCarlo.get_null_proj
train
def get_null_proj(self,nsing=None): """ get a null-space projection matrix of XTQX Parameters ---------- nsing: int optional number of singular components to use If Nonte, then nsing is determined from call to MonteCarlo.get_nsing() Returns ------- v2_proj : pyemu.Matrix the null-space projection matrix (V2V2^T) """ if nsing is None: nsing = self.get_nsing() if nsing is None: raise Exception("nsing is
python
{ "resource": "" }
q20132
MonteCarlo.draw
train
def draw(self, num_reals=1, par_file = None, obs=False, enforce_bounds=None, cov=None, how="gaussian"): """draw stochastic realizations of parameters and optionally observations, filling MonteCarlo.parensemble and optionally MonteCarlo.obsensemble. Parameters ---------- num_reals : int number of realization to generate par_file : str parameter file to use as mean values. If None, use MonteCarlo.pst.parameter_data.parval1. Default is None obs : bool add a realization of measurement noise to observation values, forming MonteCarlo.obsensemble.Default is False enforce_bounds : str enforce parameter bounds based on control file information. options are 'reset', 'drop' or None. Default is None how : str type of distribution to draw from. Must be in ["gaussian","uniform"] default is "gaussian". Example ------- ``>>>import pyemu`` ``>>>mc = pyemu.MonteCarlo(pst="pest.pst")`` ``>>>mc.draw(1000)`` """ if par_file is not None: self.pst.parrep(par_file) how = how.lower().strip() assert how in ["gaussian","uniform"] if cov is not None: assert isinstance(cov,Cov) if how == "uniform": raise Exception("MonteCarlo.draw() error: 'how'='uniform'," +\ " 'cov' arg cannot be passed") else: cov = self.parcov self.log("generating {0:d} parameter realizations".format(num_reals)) if how == "gaussian": self.parensemble = ParameterEnsemble.from_gaussian_draw(pst=self.pst,cov=cov, num_reals=num_reals,
python
{ "resource": "" }
q20133
MonteCarlo.project_parensemble
train
def project_parensemble(self,par_file=None,nsing=None, inplace=True,enforce_bounds='reset'): """ perform the null-space projection operations for null-space monte carlo Parameters ---------- par_file: str an optional file of parameter values to use nsing: int number of singular values to in forming null subspace matrix inplace: bool overwrite the existing parameter ensemble with the projected values enforce_bounds: str how to enforce parameter bounds. can be None, 'reset', or 'drop'. Default is None Returns ------- par_en : pyemu.ParameterEnsemble if inplace is False, otherwise None Note ---- to use this method, the MonteCarlo instance must have been constructed with the ``jco`` argument. Example ------- ``>>>import pyemu`` ``>>>mc = pyemu.MonteCarlo(jco="pest.jcb")`` ``>>>mc.draw(1000)`` ``>>>mc.project_parensemble(par_file="final.par",nsing=100)``
python
{ "resource": "" }
q20134
MonteCarlo.write_psts
train
def write_psts(self,prefix,existing_jco=None,noptmax=None): """ write parameter and optionally observation realizations to a series of pest control files Parameters ---------- prefix: str pest control file prefix existing_jco: str filename of an existing jacobian matrix to add to the pest++ options in the control file. This is useful for NSMC since this jco can be used to get the first set of parameter upgrades for free! Needs to be the path the jco file as seen from the location where pest++ will be run noptmax: int value of NOPTMAX to set in new pest control files Example ------- ``>>>import pyemu`` ``>>>mc = pyemu.MonteCarlo(jco="pest.jcb")`` ``>>>mc.draw(1000, obs=True)`` ``>>>mc.write_psts("mc_", existing_jco="pest.jcb", noptmax=1)`` """ self.log("writing realized pest control files") # get a copy of the pest control file pst = self.pst.get(par_names=self.pst.par_names,obs_names=self.pst.obs_names) if noptmax is not None: pst.control_data.noptmax = noptmax pst.control_data.noptmax = noptmax if existing_jco is not None: pst.pestpp_options["BASE_JACOBIAN"] = existing_jco # set the indices pst.parameter_data.index = pst.parameter_data.parnme pst.observation_data.index = pst.observation_data.obsnme if self.parensemble.istransformed:
python
{ "resource": "" }
q20135
ParetoObjFunc.is_nondominated_pathetic
train
def is_nondominated_pathetic(self, obs_df): """identify which candidate solutions are pareto non-dominated - super patheically slow... Parameters ---------- obs_df : pandas.DataFrame dataframe with columns of observation names and rows of realizations Returns ------- is_dominated : pandas.Series series with index of obs_df and bool series """ obj_df = obs_df.loc[:,self.obs_obj_names] is_nondom = [] for i,iidx in enumerate(obj_df.index): ind = True for jidx in obj_df.index: if iidx == jidx: continue # if dominates(jidx,iidx):
python
{ "resource": "" }
q20136
ParetoObjFunc.is_nondominated_continuous
train
def is_nondominated_continuous(self, obs_df): """identify which candidate solutions are pareto non-dominated continuously updated, but still slow Parameters ---------- obs_df : pandas.DataFrame dataframe with columns of observation names and rows of realizations Returns ------- is_dominated : pandas.Series series with index of obs_df and bool series """ obj_df = obs_df.loc[:,self.obs_obj_names] P = list(obj_df.index) PP = set() PP.add(P[0]) #iidx = 1 #while iidx < len(P): for iidx in P: jidx = 0 drop = [] keep = True for jidx in PP: # if dominates(iidx,jidx): # drop.append(jidx) # elif dominates(jidx,iidx):
python
{ "resource": "" }
q20137
ParetoObjFunc.is_nondominated_kung
train
def is_nondominated_kung(self, obs_df): """identify which candidate solutions are pareto non-dominated using Kungs algorithm Parameters ---------- obs_df : pandas.DataFrame dataframe with columns of observation names and rows of realizations Returns ------- is_dominated : pandas.Series series with index of obs_df and bool series """ obj_df = obs_df.loc[:,self.obs_obj_names] obj_names = self.obs_obj_names ascending = False if self.obs_dict[obj_names[0]] == "min": ascending = True obj_df.sort_values(by=obj_names[0],ascending=ascending,inplace=True) P = list(obj_df.index) def front(p): if len(p) == 1: return p p = list(obj_df.loc[p,:].sort_values(by=obj_names[0],ascending=ascending).index) half = int(len(p) / 2) T = front(p[:half]) B = front(p[half:]) M = [] i
python
{ "resource": "" }
q20138
ParetoObjFunc.crowd_distance
train
def crowd_distance(self,obs_df): """determine the crowding distance for each candidate solution Parameters ---------- obs_df : pandas.DataFrame dataframe with columns of observation names and rows of realizations Returns ------- crowd_distance : pandas.Series series with index of obs_df and values of crowd distance """ # initialize the distance container crowd_distance = pd.Series(data=0.0,index=obs_df.index) for name,direction in self.obs_dict.items(): # make a copy - wasteful, but easier obj_df = obs_df.loc[:,name].copy() # sort so that largest values are first
python
{ "resource": "" }
q20139
BaseGlyph._set_unicode
train
def _set_unicode(self, value): """ Assign the primary unicode to the glyph. This will be an integer or None. Subclasses may override this method. """ values = list(self.unicodes) if value
python
{ "resource": "" }
q20140
BaseGlyph.clear
train
def clear(self, contours=True, components=True, anchors=True, guidelines=True, image=True): """ Clear the glyph. >>> glyph.clear() This clears: - contours - components - anchors - guidelines - image It's possible to turn off the clearing of portions of the glyph with the listed arguments.
python
{ "resource": "" }
q20141
BaseGlyph._iterContours
train
def _iterContours(self, **kwargs): """ This must return an iterator that returns wrapped contours. Subclasses may override this method. """ count = len(self) index = 0
python
{ "resource": "" }
q20142
BaseGlyph.appendContour
train
def appendContour(self, contour, offset=None): """ Append a contour containing the same data as ``contour`` to this glyph. >>> contour = glyph.appendContour(contour) This will return a :class:`BaseContour` object representing the new contour in the glyph. ``offset`` indicates the x and
python
{ "resource": "" }
q20143
BaseGlyph._appendContour
train
def _appendContour(self, contour, offset=None, **kwargs): """ contour will be an object with a drawPoints method. offset will be a valid offset (x, y). This must return the new contour. Subclasses may override this method. """
python
{ "resource": "" }
q20144
BaseGlyph.removeContour
train
def removeContour(self, contour): """ Remove ``contour`` from the glyph. >>> glyph.removeContour(contour) ``contour`` may be a :ref:`BaseContour` or an :ref:`type-int` representing a contour index.
python
{ "resource": "" }
q20145
BaseGlyph.appendComponent
train
def appendComponent(self, baseGlyph=None, offset=None, scale=None, component=None): """ Append a component to this glyph. >>> component = glyph.appendComponent("A") This will return a :class:`BaseComponent` object representing the new component in the glyph. ``offset`` indicates the x and y shift values that should be applied to the appended component. It must be a :ref:`type-coordinate` value or ``None``. If ``None`` is given, the offset will be ``(0, 0)``. >>> component = glyph.appendComponent("A", offset=(10, 20)) ``scale`` indicates the x and y scale values that should be applied to the appended component. It must be a :ref:`type-scale` value or ``None``. If ``None`` is given, the scale will be ``(1.0, 1.0)``. >>> component = glyph.appendComponent("A", scale=(1.0, 2.0)) ``component`` may be a :class:`BaseComponent` object from which attribute values will be copied. If ``baseGlyph``, ``offset`` or ``scale`` are specified as arguments, those values will be used instead of the values in the given component object. """ identifier = None sxy = 0 syx = 0 if component is not None: component = normalizers.normalizeComponent(component) if baseGlyph is None: baseGlyph = component.baseGlyph sx, sxy, syx, sy, ox, oy = component.transformation if offset is None: offset = (ox, oy) if scale is None: scale = (sx, sy) if baseGlyph is None: baseGlyph = component.baseGlyph if component.identifier is not None: existing
python
{ "resource": "" }
q20146
BaseGlyph._appendComponent
train
def _appendComponent(self, baseGlyph, transformation=None, identifier=None, **kwargs): """ baseGlyph will be a valid glyph name. The baseGlyph may or may not be in the layer. offset will be a valid offset (x, y). scale will be a valid scale (x, y). identifier will be a valid, nonconflicting identifier.
python
{ "resource": "" }
q20147
BaseGlyph.removeComponent
train
def removeComponent(self, component): """ Remove ``component`` from the glyph. >>> glyph.removeComponent(component) ``component`` may be a :ref:`BaseComponent` or an :ref:`type-int` representing a component index.
python
{ "resource": "" }
q20148
BaseGlyph.appendAnchor
train
def appendAnchor(self, name=None, position=None, color=None, anchor=None): """ Append an anchor to this glyph. >>> anchor = glyph.appendAnchor("top", (10, 20)) This will return a :class:`BaseAnchor` object representing the new anchor in the glyph. ``name`` indicated the name to be assigned to the anchor. It must be a :ref:`type-string` or ``None``. ``position`` indicates the x and y location to be applied to the anchor. It must be a :ref:`type-coordinate` value. ``color`` indicates the color to be applied to the anchor. It must be a :ref:`type-color` or ``None``. >>> anchor = glyph.appendAnchor("top", (10, 20), color=(1, 0, 0, 1)) ``anchor`` may be a :class:`BaseAnchor` object from which attribute values will be copied. If ``name``, ``position`` or ``color`` are specified as arguments, those values will be used instead of the values in the given anchor object. """ identifier = None if anchor is not None: anchor = normalizers.normalizeAnchor(anchor) if name is None: name = anchor.name
python
{ "resource": "" }
q20149
BaseGlyph.removeAnchor
train
def removeAnchor(self, anchor): """ Remove ``anchor`` from the glyph. >>> glyph.removeAnchor(anchor) ``anchor`` may be an :ref:`BaseAnchor` or an :ref:`type-int` representing an anchor index.
python
{ "resource": "" }
q20150
BaseGlyph.removeGuideline
train
def removeGuideline(self, guideline): """ Remove ``guideline`` from the glyph. >>> glyph.removeGuideline(guideline) ``guideline`` may be a :ref:`BaseGuideline` or an :ref:`type-int` representing an guideline index.
python
{ "resource": "" }
q20151
BaseGlyph.interpolate
train
def interpolate(self, factor, minGlyph, maxGlyph, round=True, suppressError=True): """ Interpolate the contents of this glyph at location ``factor`` in a linear interpolation between ``minGlyph`` and ``maxGlyph``. >>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2) ``factor`` may be a :ref:`type-int-float` or a tuple containing two :ref:`type-int-float` values representing x and y factors. >>> glyph.interpolate((0.5, 1.0), otherGlyph1, otherGlyph2) ``minGlyph`` must be a :class:`BaseGlyph` and will be located at 0.0 in the interpolation range. ``maxGlyph`` must be a :class:`BaseGlyph` and will be located at 1.0 in the interpolation range. If ``round`` is ``True``, the contents of the glyph will be rounded to integers after the interpolation is performed. >>> glyph.interpolate(0.5, otherGlyph1, otherGlyph2, round=True) This method assumes that ``minGlyph`` and ``maxGlyph`` are completely compatible with each other for interpolation. If not, any errors encountered will raise a :class:`FontPartsError`. If ``suppressError`` is ``True``, no exception will be raised and errors will be silently ignored. """ factor = normalizers.normalizeInterpolationFactor(factor) if not isinstance(minGlyph, BaseGlyph): raise TypeError(("Interpolation to an
python
{ "resource": "" }
q20152
BaseGlyph.pointInside
train
def pointInside(self, point): """ Determine if ``point`` is in the black or white of the glyph. >>> glyph.pointInside((40, 65)) True ``point`` must be a :ref:`type-coordinate`.
python
{ "resource": "" }
q20153
BaseGlyph._getLayer
train
def _getLayer(self, name, **kwargs): """ name will be a string, but there may not be a layer with a name matching the string. If not, a ``ValueError`` must be raised. Subclasses may override this method. """ for glyph in
python
{ "resource": "" }
q20154
BaseGlyph.newLayer
train
def newLayer(self, name): """ Make a new layer with ``name`` in this glyph. >>> glyphLayer = glyph.newLayer("background") This will return the new :ref:`type-glyph-layer`. If the layer already exists in this glyph, it will be cleared. """ layerName = name glyphName = self.name layerName = normalizers.normalizeLayerName(layerName) for glyph in self.layers: if glyph.layer.name == layerName:
python
{ "resource": "" }
q20155
BaseGlyph.removeLayer
train
def removeLayer(self, layer): """ Remove ``layer`` from this glyph. >>> glyph.removeLayer("background") Layer can be a :ref:`type-glyph-layer` or a :ref:`type-string` representing a layer name. """ if isinstance(layer, BaseGlyph):
python
{ "resource": "" }
q20156
BaseAnchor._get_index
train
def _get_index(self): """ Get the anchor's index. This must return an ``int``. Subclasses may
python
{ "resource": "" }
q20157
BaseLib.asDict
train
def asDict(self): """ Return the Lib as a ``dict``. This is a backwards compatibility method. """
python
{ "resource": "" }
q20158
AutosummaryMethodList.get_items
train
def get_items(self, names): """ Subclass get items to get support for all methods in an given object """ env = self.state.document.settings.env prefixes = get_import_prefixes_from_env(env)
python
{ "resource": "" }
q20159
BaseBPoint.round
train
def round(self): """ Round coordinates. """ x, y = self.anchor self.anchor = (normalizers.normalizeRounding(x), normalizers.normalizeRounding(y)) x, y = self.bcpIn self.bcpIn = (normalizers.normalizeRounding(x),
python
{ "resource": "" }
q20160
_sortValue_isItalic
train
def _sortValue_isItalic(font): """ Returns 0 if the font is italic. Returns 1 if the font is not italic. """ info = font.info styleMapStyleName = info.styleMapStyleName if styleMapStyleName is not None and "italic"
python
{ "resource": "" }
q20161
_sortValue_isMonospace
train
def _sortValue_isMonospace(font): """ Returns 0 if the font is monospace. Returns 1 if the font is not monospace. """ if font.info.postscriptIsFixedPitch: return 0 if not len(font): return 1 testWidth = None
python
{ "resource": "" }
q20162
BaseGuideline._get_index
train
def _get_index(self): """ Get the guideline's index. This must return an ``int``. Subclasses may override this method.
python
{ "resource": "" }
q20163
normalizeFileFormatVersion
train
def normalizeFileFormatVersion(value): """ Normalizes a font's file format version. * **value** must be a :ref:`type-int`. * Returned value will be a
python
{ "resource": "" }
q20164
normalizeLayerOrder
train
def normalizeLayerOrder(value, font): """ Normalizes layer order. ** **value** must be a ``tuple`` or ``list``. * **value** items must normalize as layer names with :func:`normalizeLayerName`. * **value** must contain layers that exist in **font**. * **value** must not contain duplicate layers. * Returned ``tuple`` will be unencoded ``unicode`` strings for each layer name. """ if not isinstance(value, (tuple, list)): raise TypeError("Layer order must be a list, not %s." % type(value).__name__) for v in value: normalizeLayerName(v) fontLayers = [layer.name for layer in font.layers]
python
{ "resource": "" }
q20165
normalizeDefaultLayerName
train
def normalizeDefaultLayerName(value, font): """ Normalizes default layer name. * **value** must normalize as layer name with :func:`normalizeLayerName`. * **value** must be a layer in **font**. * Returned value will be an unencoded ``unicode``
python
{ "resource": "" }
q20166
normalizeGlyphOrder
train
def normalizeGlyphOrder(value): """ Normalizes glyph order. ** **value** must be a ``tuple`` or ``list``. * **value** items must normalize as glyph names with :func:`normalizeGlyphName`. * **value** must not repeat glyph names. * Returned value will be a ``tuple`` of unencoded ``unicode`` strings. """ if not isinstance(value, (tuple, list)): raise TypeError("Glyph order must be a list, not %s." % type(value).__name__) for v in value: normalizeGlyphName(v) duplicates =
python
{ "resource": "" }
q20167
normalizeKerningKey
train
def normalizeKerningKey(value): """ Normalizes kerning key. * **value** must be a ``tuple`` or ``list``. * **value** must contain only two members. * **value** items must be :ref:`type-string`. * **value** items must be at least one character long. * Returned value will be a two member ``tuple`` of unencoded ``unicode`` strings. """ if not isinstance(value, (tuple, list)): raise TypeError("Kerning key must be a tuple instance, not %s." % type(value).__name__) if len(value) != 2: raise ValueError("Kerning key must be a tuple containing two items, " "not %d." % len(value)) for v in value: if not isinstance(v, basestring): raise TypeError("Kerning key items must be strings, not %s." % type(v).__name__) if len(v) < 1: raise ValueError("Kerning key items must be one character long")
python
{ "resource": "" }
q20168
normalizeKerningValue
train
def normalizeKerningValue(value): """ Normalizes kerning value. * **value** must be an :ref:`type-int-float`. * Returned value is the same type as input value. """ if not isinstance(value,
python
{ "resource": "" }
q20169
normalizeGroupValue
train
def normalizeGroupValue(value): """ Normalizes group value. * **value** must be a ``list``. * **value** items must normalize as glyph names with :func:`normalizeGlyphName`. * Returned value will be a ``tuple`` of unencoded ``unicode`` strings. """ if not isinstance(value, (tuple, list)): raise TypeError("Group value must be a
python
{ "resource": "" }
q20170
normalizeFeatureText
train
def normalizeFeatureText(value): """ Normalizes feature text. * **value** must be a :ref:`type-string`. * Returned value will be an unencoded ``unicode`` string. """ if not isinstance(value, basestring):
python
{ "resource": "" }
q20171
normalizeLibValue
train
def normalizeLibValue(value): """ Normalizes lib value. * **value** must not be ``None``. * Returned value is the same type as the input value. """ if value is None: raise ValueError("Lib value must not be None.") if isinstance(value, (list, tuple)): for v in value:
python
{ "resource": "" }
q20172
normalizeGlyphUnicodes
train
def normalizeGlyphUnicodes(value): """ Normalizes glyph unicodes. * **value** must be a ``list``. * **value** items must normalize as glyph unicodes with :func:`normalizeGlyphUnicode`. * **value** must not repeat unicode values. * Returned value will be a ``tuple`` of ints.
python
{ "resource": "" }
q20173
normalizeGlyphUnicode
train
def normalizeGlyphUnicode(value): """ Normalizes glyph unicode. * **value** must be an int or hex (represented as a string). * **value** must be in a unicode range. * Returned value will be an ``int``. """ if not isinstance(value, (int, basestring)) or isinstance(value, bool): raise TypeError("Glyph unicode must be a int or hex string, not %s." % type(value).__name__) if isinstance(value, basestring): try:
python
{ "resource": "" }
q20174
normalizeGlyphWidth
train
def normalizeGlyphWidth(value): """ Normalizes glyph width. * **value** must be a :ref:`type-int-float`. * Returned value is the same type as the input value. """ if not isinstance(value, (int,
python
{ "resource": "" }
q20175
normalizeGlyphLeftMargin
train
def normalizeGlyphLeftMargin(value): """ Normalizes glyph left margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as
python
{ "resource": "" }
q20176
normalizeGlyphRightMargin
train
def normalizeGlyphRightMargin(value): """ Normalizes glyph right margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as
python
{ "resource": "" }
q20177
normalizeGlyphHeight
train
def normalizeGlyphHeight(value): """ Normalizes glyph height. * **value** must be a :ref:`type-int-float`. * Returned value is the same type as the input value. """ if not isinstance(value, (int,
python
{ "resource": "" }
q20178
normalizeGlyphBottomMargin
train
def normalizeGlyphBottomMargin(value): """ Normalizes glyph bottom margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as the input
python
{ "resource": "" }
q20179
normalizeGlyphTopMargin
train
def normalizeGlyphTopMargin(value): """ Normalizes glyph top margin. * **value** must be a :ref:`type-int-float` or `None`. * Returned value is the same type as
python
{ "resource": "" }
q20180
normalizeGlyphFormatVersion
train
def normalizeGlyphFormatVersion(value): """ Normalizes glyph format version for saving to XML string. * **value** must be a :ref:`type-int-float` of either 1 or 2. * Returned value will be an int. """ if not isinstance(value, (int, float)):
python
{ "resource": "" }
q20181
normalizePointType
train
def normalizePointType(value): """ Normalizes point type. * **value** must be an string. * **value** must be one of the following: +----------+ | move | +----------+ | line | +----------+ | offcurve | +----------+ | curve | +----------+ | qcurve | +----------+ * Returned value will be an unencoded ``unicode`` string. """ allowedTypes = ['move',
python
{ "resource": "" }
q20182
normalizePointName
train
def normalizePointName(value): """ Normalizes point name. * **value** must be a :ref:`type-string`. * **value** must be at least one character long. * Returned value will be an unencoded ``unicode`` string. """ if not isinstance(value, basestring): raise TypeError("Point names must be strings, not %s."
python
{ "resource": "" }
q20183
normalizeBPointType
train
def normalizeBPointType(value): """ Normalizes bPoint type. * **value** must be an string. * **value** must be one of the following: +--------+ | corner | +--------+ | curve | +--------+ * Returned value will be an unencoded ``unicode`` string. """ allowedTypes = ['corner', 'curve'] if not isinstance(value, basestring): raise TypeError("bPoint type must
python
{ "resource": "" }
q20184
normalizeInternalObjectType
train
def normalizeInternalObjectType(value, cls, name): """ Normalizes an internal object type. * **value** must be a instance of **cls**. * Returned value is
python
{ "resource": "" }
q20185
normalizeBoolean
train
def normalizeBoolean(value): """ Normalizes a boolean. * **value** must be an ``int`` with value of 0 or 1, or a ``bool``. * Returned value will be a boolean.
python
{ "resource": "" }
q20186
normalizeIndex
train
def normalizeIndex(value): """ Normalizes index. * **value** must be an ``int`` or ``None``. * Returned value is the same type as the input value. """ if value is not None: if not isinstance(value, int):
python
{ "resource": "" }
q20187
normalizeIdentifier
train
def normalizeIdentifier(value): """ Normalizes identifier. * **value** must be an :ref:`type-string` or `None`. * **value** must not be longer than 100 characters. * **value** must not contain a character out the range of 0x20 - 0x7E. * Returned value is an unencoded ``unicode`` string. """ if value is None: return value if not isinstance(value, basestring): raise TypeError("Identifiers must be strings, not %s." % type(value).__name__) if len(value) == 0: raise ValueError("The identifier string is empty.") if len(value) > 100: raise ValueError("The identifier string
python
{ "resource": "" }
q20188
normalizeX
train
def normalizeX(value): """ Normalizes x coordinate. * **value** must be an :ref:`type-int-float`. * Returned value is the same type as the input value.
python
{ "resource": "" }
q20189
normalizeY
train
def normalizeY(value): """ Normalizes y coordinate. * **value** must be an :ref:`type-int-float`. * Returned value is the same type as the input value.
python
{ "resource": "" }
q20190
normalizeCoordinateTuple
train
def normalizeCoordinateTuple(value): """ Normalizes coordinate tuple. * **value** must be a ``tuple`` or ``list``. * **value** must have exactly two items. * **value** items must be an :ref:`type-int-float`. * Returned value is a ``tuple`` of two values of the same type as
python
{ "resource": "" }
q20191
normalizeArea
train
def normalizeArea(value): """ Normalizes area. * **value** must be a positive :ref:`type-int-float`. """ if not isinstance(value, (int, float)): raise TypeError("Area must be an instance of :ref:`type-int-float`, " "not %s." % type(value).__name__)
python
{ "resource": "" }
q20192
normalizeRotationAngle
train
def normalizeRotationAngle(value): """ Normalizes an angle. * Value must be a :ref:`type-int-float`. * Value must be between -360 and 360. * If the value is negative, it is normalized by adding it to 360 * Returned value is a ``float`` between 0 and 360.
python
{ "resource": "" }
q20193
normalizeGlyphNote
train
def normalizeGlyphNote(value): """ Normalizes Glyph Note. * **value** must be a :ref:`type-string`. * Returned value is an unencoded ``unicode`` string """ if not isinstance(value, basestring):
python
{ "resource": "" }
q20194
normalizeFilePath
train
def normalizeFilePath(value): """ Normalizes file path. * **value** must be a :ref:`type-string`. * Returned value is an unencoded ``unicode`` string """ if not isinstance(value, basestring):
python
{ "resource": "" }
q20195
normalizeInterpolationFactor
train
def normalizeInterpolationFactor(value): """ Normalizes interpolation factor. * **value** must be an :ref:`type-int-float`, ``tuple`` or ``list``. * If **value** is a ``tuple`` or ``list``, it must have exactly two items. These items must be instances of :ref:`type-int-float`. * Returned value is a ``tuple`` of two ``float``. """ if not isinstance(value, (int, float, list, tuple)): raise TypeError("Interpolation factor must be an int, float, or tuple " "instances, not %s." % type(value).__name__) if isinstance(value, (int, float)): value = (float(value), float(value)) else: if not len(value) ==
python
{ "resource": "" }
q20196
normalizeRounding
train
def normalizeRounding(value): """ Normalizes rounding. Python 2 and Python 3 handing the rounding of halves (0.5, 1.5, etc) differently. This normalizes rounding to be the same (Python 3 style) in both environments. * **value** must be an :ref:`type-int-float` * Returned value is a ``int`` """
python
{ "resource": "" }
q20197
AskString
train
def AskString(message, value='', title='FontParts'): """ An ask a string dialog, a `message` is required. Optionally a `value` and `title`
python
{ "resource": "" }
q20198
AskYesNoCancel
train
def AskYesNoCancel(message, title='FontParts', default=0, informativeText=""): """ An ask yes, no or cancel dialog, a `message` is required. Optionally a `title`, `default` and `informativeText` can be provided. The `default` option is to indicate which button is the default button. :: from fontParts.ui import AskYesNoCancel
python
{ "resource": "" }
q20199
FindGlyph
train
def FindGlyph(aFont, message="Search for a glyph:", title='FontParts'): """ A dialog to search a glyph for a provided font. Optionally a `message`, `title` and `allFonts` can be provided. from fontParts.ui import FindGlyph from fontParts.world import CurrentFont
python
{ "resource": "" }