repo
stringlengths
7
55
path
stringlengths
4
223
func_name
stringlengths
1
134
original_string
stringlengths
75
104k
language
stringclasses
1 value
code
stringlengths
75
104k
code_tokens
listlengths
19
28.4k
docstring
stringlengths
1
46.9k
docstring_tokens
listlengths
1
1.97k
sha
stringlengths
40
40
url
stringlengths
87
315
partition
stringclasses
3 values
summary
stringlengths
4
350
JoseAntFer/pyny3d
pyny3d/geoms.py
Space.mirror
def mirror(self, axes='x', inplace=False): """ Generates a symmetry of the Space respect global axes. :param axes: 'x', 'y', 'z', 'xy', 'xz', 'yz'... :type axes: str :param inplace: If True, the new ``pyny.Space`` is copied and added to the current ``...
python
def mirror(self, axes='x', inplace=False): """ Generates a symmetry of the Space respect global axes. :param axes: 'x', 'y', 'z', 'xy', 'xz', 'yz'... :type axes: str :param inplace: If True, the new ``pyny.Space`` is copied and added to the current ``...
[ "def", "mirror", "(", "self", ",", "axes", "=", "'x'", ",", "inplace", "=", "False", ")", ":", "state", "=", "Polygon", ".", "verify", "Polygon", ".", "verify", "=", "False", "mirror", "=", "np", ".", "ones", "(", "3", ")", "if", "'x'", "in", "ax...
Generates a symmetry of the Space respect global axes. :param axes: 'x', 'y', 'z', 'xy', 'xz', 'yz'... :type axes: str :param inplace: If True, the new ``pyny.Space`` is copied and added to the current ``pyny.Space``. If False, it returns the new ``pyny.S...
[ "Generates", "a", "symmetry", "of", "the", "Space", "respect", "global", "axes", ".", ":", "param", "axes", ":", "x", "y", "z", "xy", "xz", "yz", "...", ":", "type", "axes", ":", "str", ":", "param", "inplace", ":", "If", "True", "the", "new", "pyn...
fb81684935a24f7e50c975cb4383c81a63ab56df
https://github.com/JoseAntFer/pyny3d/blob/fb81684935a24f7e50c975cb4383c81a63ab56df/pyny3d/geoms.py#L2296-L2326
train
Returns a new pyny. Space with the same coordinates and the same size.
JoseAntFer/pyny3d
pyny3d/geoms.py
Space.photo
def photo(self, azimuth_zenit, plot=False): """ Computes a change of the reference system for the whole ``pyny.Space`` to align the `y` axis with a given direction. Returns its elements (polygons, holes, points) extracted in a list. In its conception, th...
python
def photo(self, azimuth_zenit, plot=False): """ Computes a change of the reference system for the whole ``pyny.Space`` to align the `y` axis with a given direction. Returns its elements (polygons, holes, points) extracted in a list. In its conception, th...
[ "def", "photo", "(", "self", ",", "azimuth_zenit", ",", "plot", "=", "False", ")", ":", "self", ".", "lock", "(", ")", "a", ",", "z", "=", "azimuth_zenit", "R", "=", "np", ".", "array", "(", "[", "[", "np", ".", "cos", "(", "a", ")", ",", "-"...
Computes a change of the reference system for the whole ``pyny.Space`` to align the `y` axis with a given direction. Returns its elements (polygons, holes, points) extracted in a list. In its conception, this method was created as a tool for the shadows computat...
[ "Computes", "a", "change", "of", "the", "reference", "system", "for", "the", "whole", "pyny", ".", "Space", "to", "align", "the", "y", "axis", "with", "a", "given", "direction", ".", "Returns", "its", "elements", "(", "polygons", "holes", "points", ")", ...
fb81684935a24f7e50c975cb4383c81a63ab56df
https://github.com/JoseAntFer/pyny3d/blob/fb81684935a24f7e50c975cb4383c81a63ab56df/pyny3d/geoms.py#L2328-L2388
train
Returns the elements of the same type of reference system as the original photo.
JoseAntFer/pyny3d
pyny3d/geoms.py
Space.iplot
def iplot(self, places=-1, c_poly='default', c_holes='default', c_sop='r', s_sop=25, extra_height=0, ret=False, ax=None): """ Improved plot that allows to visualize the Places in the Space selectively. It also allows to plot polygons and holes in different colors and ...
python
def iplot(self, places=-1, c_poly='default', c_holes='default', c_sop='r', s_sop=25, extra_height=0, ret=False, ax=None): """ Improved plot that allows to visualize the Places in the Space selectively. It also allows to plot polygons and holes in different colors and ...
[ "def", "iplot", "(", "self", ",", "places", "=", "-", "1", ",", "c_poly", "=", "'default'", ",", "c_holes", "=", "'default'", ",", "c_sop", "=", "'r'", ",", "s_sop", "=", "25", ",", "extra_height", "=", "0", ",", "ret", "=", "False", ",", "ax", "...
Improved plot that allows to visualize the Places in the Space selectively. It also allows to plot polygons and holes in different colors and to change the size and the color of the set of points. The points can be plotted accordingly to a ndarray colormap. ...
[ "Improved", "plot", "that", "allows", "to", "visualize", "the", "Places", "in", "the", "Space", "selectively", ".", "It", "also", "allows", "to", "plot", "polygons", "and", "holes", "in", "different", "colors", "and", "to", "change", "the", "size", "and", ...
fb81684935a24f7e50c975cb4383c81a63ab56df
https://github.com/JoseAntFer/pyny3d/blob/fb81684935a24f7e50c975cb4383c81a63ab56df/pyny3d/geoms.py#L2390-L2435
train
Returns a 3D figure showing the maximum number of polygons and holes in the given places.
JoseAntFer/pyny3d
pyny3d/geoms.py
Space.shadows
def shadows(self, data=None, t=None, dt=None, latitude=None, init='empty', resolution='mid'): ''' Initializes a ShadowManager object for this ``pyny.Space`` instance. The 'empty' initialization accepts ``data`` and ``t`` and ``dt`` but the Shadows...
python
def shadows(self, data=None, t=None, dt=None, latitude=None, init='empty', resolution='mid'): ''' Initializes a ShadowManager object for this ``pyny.Space`` instance. The 'empty' initialization accepts ``data`` and ``t`` and ``dt`` but the Shadows...
[ "def", "shadows", "(", "self", ",", "data", "=", "None", ",", "t", "=", "None", ",", "dt", "=", "None", ",", "latitude", "=", "None", ",", "init", "=", "'empty'", ",", "resolution", "=", "'mid'", ")", ":", "from", "pyny3d", ".", "shadows", "import"...
Initializes a ShadowManager object for this ``pyny.Space`` instance. The 'empty' initialization accepts ``data`` and ``t`` and ``dt`` but the ShadowsManager will not start the calculations. It will wait the user to manually insert the rest of the parameters. Call ...
[ "Initializes", "a", "ShadowManager", "object", "for", "this", "pyny", ".", "Space", "instance", ".", "The", "empty", "initialization", "accepts", "data", "and", "t", "and", "dt", "but", "the", "ShadowsManager", "will", "not", "start", "the", "calculations", "....
fb81684935a24f7e50c975cb4383c81a63ab56df
https://github.com/JoseAntFer/pyny3d/blob/fb81684935a24f7e50c975cb4383c81a63ab56df/pyny3d/geoms.py#L2437-L2503
train
Returns a new object containing all the required parameters and values for the given time vector.
xflr6/bitsets
bitsets/series.py
Series.frommembers
def frommembers(cls, members): """Series from iterable of member iterables.""" return cls.frombitsets(map(cls.BitSet.frommembers, members))
python
def frommembers(cls, members): """Series from iterable of member iterables.""" return cls.frombitsets(map(cls.BitSet.frommembers, members))
[ "def", "frommembers", "(", "cls", ",", "members", ")", ":", "return", "cls", ".", "frombitsets", "(", "map", "(", "cls", ".", "BitSet", ".", "frommembers", ",", "members", ")", ")" ]
Series from iterable of member iterables.
[ "Series", "from", "iterable", "of", "member", "iterables", "." ]
ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf
https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/series.py#L18-L20
train
Series from iterable of member iterables.
xflr6/bitsets
bitsets/series.py
Series.frombools
def frombools(cls, bools): """Series from iterable of boolean evaluable iterables.""" return cls.frombitsets(map(cls.BitSet.frombools, bools))
python
def frombools(cls, bools): """Series from iterable of boolean evaluable iterables.""" return cls.frombitsets(map(cls.BitSet.frombools, bools))
[ "def", "frombools", "(", "cls", ",", "bools", ")", ":", "return", "cls", ".", "frombitsets", "(", "map", "(", "cls", ".", "BitSet", ".", "frombools", ",", "bools", ")", ")" ]
Series from iterable of boolean evaluable iterables.
[ "Series", "from", "iterable", "of", "boolean", "evaluable", "iterables", "." ]
ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf
https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/series.py#L23-L25
train
Series from iterable of boolean evaluable iterables.
xflr6/bitsets
bitsets/series.py
Series.frombits
def frombits(cls, bits): """Series from binary string arguments.""" return cls.frombitsets(map(cls.BitSet.frombits, bits))
python
def frombits(cls, bits): """Series from binary string arguments.""" return cls.frombitsets(map(cls.BitSet.frombits, bits))
[ "def", "frombits", "(", "cls", ",", "bits", ")", ":", "return", "cls", ".", "frombitsets", "(", "map", "(", "cls", ".", "BitSet", ".", "frombits", ",", "bits", ")", ")" ]
Series from binary string arguments.
[ "Series", "from", "binary", "string", "arguments", "." ]
ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf
https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/series.py#L28-L30
train
Series from binary string arguments.
xflr6/bitsets
bitsets/series.py
Series.fromints
def fromints(cls, ints): """Series from integer rank arguments.""" return cls.frombitsets(map(cls.BitSet.fromint, ints))
python
def fromints(cls, ints): """Series from integer rank arguments.""" return cls.frombitsets(map(cls.BitSet.fromint, ints))
[ "def", "fromints", "(", "cls", ",", "ints", ")", ":", "return", "cls", ".", "frombitsets", "(", "map", "(", "cls", ".", "BitSet", ".", "fromint", ",", "ints", ")", ")" ]
Series from integer rank arguments.
[ "Series", "from", "integer", "rank", "arguments", "." ]
ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf
https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/series.py#L33-L35
train
Series from integer rank arguments.
xflr6/bitsets
bitsets/series.py
Series.index_sets
def index_sets(self, as_set=False): """Return the series as list of index set tuples.""" indexes = frozenset if as_set else tuple return [indexes(b.iter_set()) for b in self]
python
def index_sets(self, as_set=False): """Return the series as list of index set tuples.""" indexes = frozenset if as_set else tuple return [indexes(b.iter_set()) for b in self]
[ "def", "index_sets", "(", "self", ",", "as_set", "=", "False", ")", ":", "indexes", "=", "frozenset", "if", "as_set", "else", "tuple", "return", "[", "indexes", "(", "b", ".", "iter_set", "(", ")", ")", "for", "b", "in", "self", "]" ]
Return the series as list of index set tuples.
[ "Return", "the", "series", "as", "list", "of", "index", "set", "tuples", "." ]
ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf
https://github.com/xflr6/bitsets/blob/ddcfe17e7c7a11f71f1c6764b2cecf7db05d9cdf/bitsets/series.py#L57-L60
train
Return the series as list of index set tuples.
arkottke/pysra
pysra/output.py
append_arrays
def append_arrays(many, single): """Append an array to another padding with NaNs for constant length. Parameters ---------- many : array_like of rank (j, k) values appended to a copy of this array. This may be a 1-D or 2-D array. single : array_like of rank l values to appen...
python
def append_arrays(many, single): """Append an array to another padding with NaNs for constant length. Parameters ---------- many : array_like of rank (j, k) values appended to a copy of this array. This may be a 1-D or 2-D array. single : array_like of rank l values to appen...
[ "def", "append_arrays", "(", "many", ",", "single", ")", ":", "assert", "np", ".", "ndim", "(", "single", ")", "==", "1", "# Check if the values need to be padded to for equal length", "diff", "=", "single", ".", "shape", "[", "0", "]", "-", "many", ".", "sh...
Append an array to another padding with NaNs for constant length. Parameters ---------- many : array_like of rank (j, k) values appended to a copy of this array. This may be a 1-D or 2-D array. single : array_like of rank l values to append. This should be a 1-D array. Retu...
[ "Append", "an", "array", "to", "another", "padding", "with", "NaNs", "for", "constant", "length", "." ]
c72fd389d6c15203c0c00728ac00f101bae6369d
https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/output.py#L46-L74
train
Append an array to another array of rank k with NaNs for constant length.
arkottke/pysra
pysra/output.py
RatioBasedOutput._get_locations
def _get_locations(self, calc): """Locate locations within the profile.""" return (self._location_in(calc.profile), self._location_out(calc.profile))
python
def _get_locations(self, calc): """Locate locations within the profile.""" return (self._location_in(calc.profile), self._location_out(calc.profile))
[ "def", "_get_locations", "(", "self", ",", "calc", ")", ":", "return", "(", "self", ".", "_location_in", "(", "calc", ".", "profile", ")", ",", "self", ".", "_location_out", "(", "calc", ".", "profile", ")", ")" ]
Locate locations within the profile.
[ "Locate", "locations", "within", "the", "profile", "." ]
c72fd389d6c15203c0c00728ac00f101bae6369d
https://github.com/arkottke/pysra/blob/c72fd389d6c15203c0c00728ac00f101bae6369d/pysra/output.py#L363-L366
train
Locate locations within the profile.
guaix-ucm/numina
numina/array/wavecalib/fix_pix_borders.py
find_pix_borders
def find_pix_borders(sp, sought_value): """Find useful region of a given spectrum Detemine the useful region of a given spectrum by skipping the initial (final) pixels with values equal to 'sought_value'. Parameters ---------- sp : 1D numpy array Input spectrum. sought_value : int,...
python
def find_pix_borders(sp, sought_value): """Find useful region of a given spectrum Detemine the useful region of a given spectrum by skipping the initial (final) pixels with values equal to 'sought_value'. Parameters ---------- sp : 1D numpy array Input spectrum. sought_value : int,...
[ "def", "find_pix_borders", "(", "sp", ",", "sought_value", ")", ":", "if", "sp", ".", "ndim", "!=", "1", ":", "raise", "ValueError", "(", "'Unexpected number of dimensions:'", ",", "sp", ".", "ndim", ")", "naxis1", "=", "len", "(", "sp", ")", "jborder_min"...
Find useful region of a given spectrum Detemine the useful region of a given spectrum by skipping the initial (final) pixels with values equal to 'sought_value'. Parameters ---------- sp : 1D numpy array Input spectrum. sought_value : int, float, bool Pixel value that indicate ...
[ "Find", "useful", "region", "of", "a", "given", "spectrum" ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/wavecalib/fix_pix_borders.py#L16-L59
train
Find the possible region of a given spectrum by skipping the initial pixels with values equal to sought_value.
guaix-ucm/numina
numina/array/wavecalib/fix_pix_borders.py
fix_pix_borders
def fix_pix_borders(image2d, nreplace, sought_value, replacement_value): """Replace a few pixels at the borders of each spectrum. Set to 'replacement_value' 'nreplace' pixels at the beginning (at the end) of each spectrum just after (before) the spectrum value changes from (to) 'sought_value', as seen ...
python
def fix_pix_borders(image2d, nreplace, sought_value, replacement_value): """Replace a few pixels at the borders of each spectrum. Set to 'replacement_value' 'nreplace' pixels at the beginning (at the end) of each spectrum just after (before) the spectrum value changes from (to) 'sought_value', as seen ...
[ "def", "fix_pix_borders", "(", "image2d", ",", "nreplace", ",", "sought_value", ",", "replacement_value", ")", ":", "# input image size", "naxis2", ",", "naxis1", "=", "image2d", ".", "shape", "for", "i", "in", "range", "(", "naxis2", ")", ":", "# only spectra...
Replace a few pixels at the borders of each spectrum. Set to 'replacement_value' 'nreplace' pixels at the beginning (at the end) of each spectrum just after (before) the spectrum value changes from (to) 'sought_value', as seen from the image borders. Parameters ---------- image2d : numpy array...
[ "Replace", "a", "few", "pixels", "at", "the", "borders", "of", "each", "spectrum", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/wavecalib/fix_pix_borders.py#L62-L108
train
Replace a few pixels at the borders of each spectrum.
guaix-ucm/numina
numina/array/wavecalib/fix_pix_borders.py
define_mask_borders
def define_mask_borders(image2d, sought_value, nadditional=0): """Generate mask avoiding undesired values at the borders. Set to True image borders with values equal to 'sought_value' Parameters ---------- image2d : numpy array Initial 2D image. sought_value : int, float, bool ...
python
def define_mask_borders(image2d, sought_value, nadditional=0): """Generate mask avoiding undesired values at the borders. Set to True image borders with values equal to 'sought_value' Parameters ---------- image2d : numpy array Initial 2D image. sought_value : int, float, bool ...
[ "def", "define_mask_borders", "(", "image2d", ",", "sought_value", ",", "nadditional", "=", "0", ")", ":", "# input image size", "naxis2", ",", "naxis1", "=", "image2d", ".", "shape", "# initialize mask", "mask2d", "=", "np", ".", "zeros", "(", "(", "naxis2", ...
Generate mask avoiding undesired values at the borders. Set to True image borders with values equal to 'sought_value' Parameters ---------- image2d : numpy array Initial 2D image. sought_value : int, float, bool Pixel value that indicates missing data in the spectrum. naddition...
[ "Generate", "mask", "avoiding", "undesired", "values", "at", "the", "borders", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/wavecalib/fix_pix_borders.py#L111-L161
train
Generate 2D mask of undesired pixels at the borders.
guaix-ucm/numina
numina/array/wavecalib/solutionarc.py
SolutionArcCalibration.update_features
def update_features(self, poly): """Evaluate wavelength at xpos using the provided polynomial.""" for feature in self.features: feature.wavelength = poly(feature.xpos)
python
def update_features(self, poly): """Evaluate wavelength at xpos using the provided polynomial.""" for feature in self.features: feature.wavelength = poly(feature.xpos)
[ "def", "update_features", "(", "self", ",", "poly", ")", ":", "for", "feature", "in", "self", ".", "features", ":", "feature", ".", "wavelength", "=", "poly", "(", "feature", ".", "xpos", ")" ]
Evaluate wavelength at xpos using the provided polynomial.
[ "Evaluate", "wavelength", "at", "xpos", "using", "the", "provided", "polynomial", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/wavecalib/solutionarc.py#L203-L207
train
Evaluate wavelength at xpos using the provided polynomial.
guaix-ucm/numina
numina/core/oresult.py
dataframe_from_list
def dataframe_from_list(values): """Build a DataFrame object from a list.""" if(isinstance(values, six.string_types)): return DataFrame(filename=values) elif(isinstance(values, fits.HDUList)): return DataFrame(frame=values) else: return None
python
def dataframe_from_list(values): """Build a DataFrame object from a list.""" if(isinstance(values, six.string_types)): return DataFrame(filename=values) elif(isinstance(values, fits.HDUList)): return DataFrame(frame=values) else: return None
[ "def", "dataframe_from_list", "(", "values", ")", ":", "if", "(", "isinstance", "(", "values", ",", "six", ".", "string_types", ")", ")", ":", "return", "DataFrame", "(", "filename", "=", "values", ")", "elif", "(", "isinstance", "(", "values", ",", "fit...
Build a DataFrame object from a list.
[ "Build", "a", "DataFrame", "object", "from", "a", "list", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/oresult.py#L86-L93
train
Build a DataFrame object from a list.
guaix-ucm/numina
numina/core/oresult.py
obsres_from_dict
def obsres_from_dict(values): """Build a ObservationResult object from a dictionary.""" obsres = ObservationResult() ikey = 'frames' # Workaround if 'images' in values: ikey = 'images' obsres.id = values.get('id', 1) obsres.mode = values['mode'] obsres.instrument = values['ins...
python
def obsres_from_dict(values): """Build a ObservationResult object from a dictionary.""" obsres = ObservationResult() ikey = 'frames' # Workaround if 'images' in values: ikey = 'images' obsres.id = values.get('id', 1) obsres.mode = values['mode'] obsres.instrument = values['ins...
[ "def", "obsres_from_dict", "(", "values", ")", ":", "obsres", "=", "ObservationResult", "(", ")", "ikey", "=", "'frames'", "# Workaround", "if", "'images'", "in", "values", ":", "ikey", "=", "'images'", "obsres", ".", "id", "=", "values", ".", "get", "(", ...
Build a ObservationResult object from a dictionary.
[ "Build", "a", "ObservationResult", "object", "from", "a", "dictionary", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/oresult.py#L96-L120
train
Build a ObservationResult object from a dictionary.
guaix-ucm/numina
numina/core/oresult.py
ObservationResult.get_sample_frame
def get_sample_frame(self): """Return first available image in observation result""" for frame in self.frames: return frame.open() for res in self.results.values(): return res.open() return None
python
def get_sample_frame(self): """Return first available image in observation result""" for frame in self.frames: return frame.open() for res in self.results.values(): return res.open() return None
[ "def", "get_sample_frame", "(", "self", ")", ":", "for", "frame", "in", "self", ".", "frames", ":", "return", "frame", ".", "open", "(", ")", "for", "res", "in", "self", ".", "results", ".", "values", "(", ")", ":", "return", "res", ".", "open", "(...
Return first available image in observation result
[ "Return", "first", "available", "image", "in", "observation", "result" ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/core/oresult.py#L75-L83
train
Return first available image in observation result
guaix-ucm/numina
numina/array/nirproc.py
fowler_array
def fowler_array(fowlerdata, ti=0.0, ts=0.0, gain=1.0, ron=1.0, badpixels=None, dtype='float64', saturation=65631, blank=0, normalize=False): """Loop over the first axis applying Fowler processing. *fowlerdata* is assumed to be a 3D numpy.ndarray containing the result of a...
python
def fowler_array(fowlerdata, ti=0.0, ts=0.0, gain=1.0, ron=1.0, badpixels=None, dtype='float64', saturation=65631, blank=0, normalize=False): """Loop over the first axis applying Fowler processing. *fowlerdata* is assumed to be a 3D numpy.ndarray containing the result of a...
[ "def", "fowler_array", "(", "fowlerdata", ",", "ti", "=", "0.0", ",", "ts", "=", "0.0", ",", "gain", "=", "1.0", ",", "ron", "=", "1.0", ",", "badpixels", "=", "None", ",", "dtype", "=", "'float64'", ",", "saturation", "=", "65631", ",", "blank", "...
Loop over the first axis applying Fowler processing. *fowlerdata* is assumed to be a 3D numpy.ndarray containing the result of a nIR observation in Fowler mode (Fowler and Gatley 1991). The shape of the array must be of the form 2N_p x M x N, with N_p being the number of pairs in Fowler mode. The ...
[ "Loop", "over", "the", "first", "axis", "applying", "Fowler", "processing", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/nirproc.py#L18-L132
train
This function takes a 3D numpy array containing the nIR observation Fowler data and returns the nIR observation Fowler data.
guaix-ucm/numina
numina/array/nirproc.py
ramp_array
def ramp_array(rampdata, ti, gain=1.0, ron=1.0, badpixels=None, dtype='float64', saturation=65631, blank=0, nsig=None, normalize=False): """Loop over the first axis applying ramp processing. *rampdata* is assumed to be a 3D numpy.ndarray containing the result of a nIR observat...
python
def ramp_array(rampdata, ti, gain=1.0, ron=1.0, badpixels=None, dtype='float64', saturation=65631, blank=0, nsig=None, normalize=False): """Loop over the first axis applying ramp processing. *rampdata* is assumed to be a 3D numpy.ndarray containing the result of a nIR observat...
[ "def", "ramp_array", "(", "rampdata", ",", "ti", ",", "gain", "=", "1.0", ",", "ron", "=", "1.0", ",", "badpixels", "=", "None", ",", "dtype", "=", "'float64'", ",", "saturation", "=", "65631", ",", "blank", "=", "0", ",", "nsig", "=", "None", ",",...
Loop over the first axis applying ramp processing. *rampdata* is assumed to be a 3D numpy.ndarray containing the result of a nIR observation in folow-up-the-ramp mode. The shape of the array must be of the form N_s x M x N, with N_s being the number of samples. :param fowlerdata: Convertible to a ...
[ "Loop", "over", "the", "first", "axis", "applying", "ramp", "processing", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/nirproc.py#L135-L202
train
Loop over the first axis applying ramp processing.
ponty/eagexp
eagexp/cmd.py
accept_freeware_license
def accept_freeware_license(): '''different Eagle versions need differnt TAB count. 6.5 -> 2 6.6 -> 3 7.4 -> 2 ''' ntab = 3 if version().startswith('6.6.') else 2 for _ in range(ntab): EasyProcess('xdotool key KP_Tab').call() time.sleep(0.5) EasyProcess('xdotool key KP...
python
def accept_freeware_license(): '''different Eagle versions need differnt TAB count. 6.5 -> 2 6.6 -> 3 7.4 -> 2 ''' ntab = 3 if version().startswith('6.6.') else 2 for _ in range(ntab): EasyProcess('xdotool key KP_Tab').call() time.sleep(0.5) EasyProcess('xdotool key KP...
[ "def", "accept_freeware_license", "(", ")", ":", "ntab", "=", "3", "if", "version", "(", ")", ".", "startswith", "(", "'6.6.'", ")", "else", "2", "for", "_", "in", "range", "(", "ntab", ")", ":", "EasyProcess", "(", "'xdotool key KP_Tab'", ")", ".", "c...
different Eagle versions need differnt TAB count. 6.5 -> 2 6.6 -> 3 7.4 -> 2
[ "different", "Eagle", "versions", "need", "differnt", "TAB", "count", ".", "6", ".", "5", "-", ">", "2", "6", ".", "6", "-", ">", "3", "7", ".", "4", "-", ">", "2" ]
1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2
https://github.com/ponty/eagexp/blob/1dd5108c1d8112cc87d1bda64fa6c2784ccf0ff2/eagexp/cmd.py#L20-L35
train
accepts freeware license
guaix-ucm/numina
numina/util/fqn.py
fully_qualified_name
def fully_qualified_name(obj, sep='.'): """Return fully qualified name from object""" if inspect.isclass(obj): return obj.__module__ + sep + obj.__name__ else: return obj.__module__ + sep + obj.__class__.__name__
python
def fully_qualified_name(obj, sep='.'): """Return fully qualified name from object""" if inspect.isclass(obj): return obj.__module__ + sep + obj.__name__ else: return obj.__module__ + sep + obj.__class__.__name__
[ "def", "fully_qualified_name", "(", "obj", ",", "sep", "=", "'.'", ")", ":", "if", "inspect", ".", "isclass", "(", "obj", ")", ":", "return", "obj", ".", "__module__", "+", "sep", "+", "obj", ".", "__name__", "else", ":", "return", "obj", ".", "__mod...
Return fully qualified name from object
[ "Return", "fully", "qualified", "name", "from", "object" ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/util/fqn.py#L16-L21
train
Return fully qualified name from object
guaix-ucm/numina
numina/array/numsplines.py
fun_residuals
def fun_residuals(params, xnor, ynor, w, bbox, k, ext): """Compute fit residuals""" spl = LSQUnivariateSpline( x=xnor, y=ynor, t=[item.value for item in params.values()], w=w, bbox=bbox, k=k, ext=ext, check_finite=False ) return spl.get_re...
python
def fun_residuals(params, xnor, ynor, w, bbox, k, ext): """Compute fit residuals""" spl = LSQUnivariateSpline( x=xnor, y=ynor, t=[item.value for item in params.values()], w=w, bbox=bbox, k=k, ext=ext, check_finite=False ) return spl.get_re...
[ "def", "fun_residuals", "(", "params", ",", "xnor", ",", "ynor", ",", "w", ",", "bbox", ",", "k", ",", "ext", ")", ":", "spl", "=", "LSQUnivariateSpline", "(", "x", "=", "xnor", ",", "y", "=", "ynor", ",", "t", "=", "[", "item", ".", "value", "...
Compute fit residuals
[ "Compute", "fit", "residuals" ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/numsplines.py#L17-L30
train
Compute fit residuals
guaix-ucm/numina
numina/user/clirundal.py
mode_run_common_obs
def mode_run_common_obs(args, extra_args): """Observing mode processing mode of numina.""" # Loading observation result if exists loaded_obs = [] sessions = [] if args.session: for obfile in args.obsresult: _logger.info("session file from %r", obfile) with open(obfi...
python
def mode_run_common_obs(args, extra_args): """Observing mode processing mode of numina.""" # Loading observation result if exists loaded_obs = [] sessions = [] if args.session: for obfile in args.obsresult: _logger.info("session file from %r", obfile) with open(obfi...
[ "def", "mode_run_common_obs", "(", "args", ",", "extra_args", ")", ":", "# Loading observation result if exists", "loaded_obs", "=", "[", "]", "sessions", "=", "[", "]", "if", "args", ".", "session", ":", "for", "obfile", "in", "args", ".", "obsresult", ":", ...
Observing mode processing mode of numina.
[ "Observing", "mode", "processing", "mode", "of", "numina", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/user/clirundal.py#L72-L242
train
Common observation processing mode of numina.
guaix-ucm/numina
numina/user/clirundal.py
parse_as_yaml
def parse_as_yaml(strdict): """Parse a dictionary of strings as if yaml reads it""" interm = "" for key, val in strdict.items(): interm = "%s: %s, %s" % (key, val, interm) fin = '{%s}' % interm return yaml.load(fin)
python
def parse_as_yaml(strdict): """Parse a dictionary of strings as if yaml reads it""" interm = "" for key, val in strdict.items(): interm = "%s: %s, %s" % (key, val, interm) fin = '{%s}' % interm return yaml.load(fin)
[ "def", "parse_as_yaml", "(", "strdict", ")", ":", "interm", "=", "\"\"", "for", "key", ",", "val", "in", "strdict", ".", "items", "(", ")", ":", "interm", "=", "\"%s: %s, %s\"", "%", "(", "key", ",", "val", ",", "interm", ")", "fin", "=", "'{%s}'", ...
Parse a dictionary of strings as if yaml reads it
[ "Parse", "a", "dictionary", "of", "strings", "as", "if", "yaml", "reads", "it" ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/user/clirundal.py#L245-L252
train
Parse a dictionary of strings as if yaml reads it
SUNCAT-Center/CatHub
cathub/cli.py
ase
def ase(dbuser, dbpassword, args, gui): """Connection to atomic structures on the Catalysis-Hub server with ase db cli. Arguments to the the ase db cli client must be enclosed in one string. For example: <cathub ase 'formula=Ag6In6H -s energy -L 200'>. To see possible ase db arguments ru...
python
def ase(dbuser, dbpassword, args, gui): """Connection to atomic structures on the Catalysis-Hub server with ase db cli. Arguments to the the ase db cli client must be enclosed in one string. For example: <cathub ase 'formula=Ag6In6H -s energy -L 200'>. To see possible ase db arguments ru...
[ "def", "ase", "(", "dbuser", ",", "dbpassword", ",", "args", ",", "gui", ")", ":", "if", "dbuser", "==", "'upload'", ":", "dbpassword", "=", "'cHyuuQH0'", "db", "=", "CathubPostgreSQL", "(", "user", "=", "dbuser", ",", "password", "=", "dbpassword", ")",...
Connection to atomic structures on the Catalysis-Hub server with ase db cli. Arguments to the the ase db cli client must be enclosed in one string. For example: <cathub ase 'formula=Ag6In6H -s energy -L 200'>. To see possible ase db arguments run <ase db --help>
[ "Connection", "to", "atomic", "structures", "on", "the", "Catalysis", "-", "Hub", "server", "with", "ase", "db", "cli", ".", "Arguments", "to", "the", "the", "ase", "db", "cli", "client", "must", "be", "enclosed", "in", "one", "string", ".", "For", "exam...
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L44-L60
train
A function that connects to the Catalysis - Hub with ase db cli.
SUNCAT-Center/CatHub
cathub/cli.py
folder2db
def folder2db(folder_name, debug, energy_limit, skip_folders, goto_reaction): """Read folder and collect data in local sqlite3 database""" folder_name = folder_name.rstrip('/') skip = [] for s in skip_folders.split(', '): for sk in s.split(','): skip.append(sk) pub...
python
def folder2db(folder_name, debug, energy_limit, skip_folders, goto_reaction): """Read folder and collect data in local sqlite3 database""" folder_name = folder_name.rstrip('/') skip = [] for s in skip_folders.split(', '): for sk in s.split(','): skip.append(sk) pub...
[ "def", "folder2db", "(", "folder_name", ",", "debug", ",", "energy_limit", ",", "skip_folders", ",", "goto_reaction", ")", ":", "folder_name", "=", "folder_name", ".", "rstrip", "(", "'/'", ")", "skip", "=", "[", "]", "for", "s", "in", "skip_folders", ".",...
Read folder and collect data in local sqlite3 database
[ "Read", "folder", "and", "collect", "data", "in", "local", "sqlite3", "database" ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L82-L99
train
Read folder and collect data in local sqlite3 database
SUNCAT-Center/CatHub
cathub/cli.py
db2server
def db2server(dbfile, block_size, dbuser, dbpassword): """Transfer data from local database to Catalysis Hub server""" _db2server.main(dbfile, write_reaction=True, write_ase=True, write_publication=True, write_reaction_system=True,...
python
def db2server(dbfile, block_size, dbuser, dbpassword): """Transfer data from local database to Catalysis Hub server""" _db2server.main(dbfile, write_reaction=True, write_ase=True, write_publication=True, write_reaction_system=True,...
[ "def", "db2server", "(", "dbfile", ",", "block_size", ",", "dbuser", ",", "dbpassword", ")", ":", "_db2server", ".", "main", "(", "dbfile", ",", "write_reaction", "=", "True", ",", "write_ase", "=", "True", ",", "write_publication", "=", "True", ",", "writ...
Transfer data from local database to Catalysis Hub server
[ "Transfer", "data", "from", "local", "database", "to", "Catalysis", "Hub", "server" ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L109-L120
train
Transfer data from local database to Catalysis Hub server
SUNCAT-Center/CatHub
cathub/cli.py
reactions
def reactions(columns, n_results, write_db, queries): """Search for reactions""" if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dic...
python
def reactions(columns, n_results, write_db, queries): """Search for reactions""" if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dic...
[ "def", "reactions", "(", "columns", ",", "n_results", ",", "write_db", ",", "queries", ")", ":", "if", "not", "isinstance", "(", "queries", ",", "dict", ")", ":", "query_dict", "=", "{", "}", "for", "q", "in", "queries", ":", "key", ",", "value", "="...
Search for reactions
[ "Search", "for", "reactions" ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L171-L204
train
Search for reactions in the database
SUNCAT-Center/CatHub
cathub/cli.py
publications
def publications(columns, n_results, queries): """Search for publications""" if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dict.up...
python
def publications(columns, n_results, queries): """Search for publications""" if not isinstance(queries, dict): query_dict = {} for q in queries: key, value = q.split('=') if key == 'distinct': if value in ['True', 'true']: query_dict.up...
[ "def", "publications", "(", "columns", ",", "n_results", ",", "queries", ")", ":", "if", "not", "isinstance", "(", "queries", ",", "dict", ")", ":", "query_dict", "=", "{", "}", "for", "q", "in", "queries", ":", "key", ",", "value", "=", "q", ".", ...
Search for publications
[ "Search", "for", "publications" ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L223-L266
train
Search for publications in the database
SUNCAT-Center/CatHub
cathub/cli.py
make_folders
def make_folders(template, custom_base): """Create a basic folder tree for dumping DFT calculcations for reaction energies. Dear all Use this command make the right structure for your folders for submitting data for Catalysis Hub's Surface Reactions. Start by creating a template file by calling: ...
python
def make_folders(template, custom_base): """Create a basic folder tree for dumping DFT calculcations for reaction energies. Dear all Use this command make the right structure for your folders for submitting data for Catalysis Hub's Surface Reactions. Start by creating a template file by calling: ...
[ "def", "make_folders", "(", "template", ",", "custom_base", ")", ":", "def", "dict_representer", "(", "dumper", ",", "data", ")", ":", "return", "dumper", ".", "represent_dict", "(", "data", ".", "items", "(", ")", ")", "Dumper", ".", "add_representer", "(...
Create a basic folder tree for dumping DFT calculcations for reaction energies. Dear all Use this command make the right structure for your folders for submitting data for Catalysis Hub's Surface Reactions. Start by creating a template file by calling: $ cathub make_folders <template_name> ...
[ "Create", "a", "basic", "folder", "tree", "for", "dumping", "DFT", "calculcations", "for", "reaction", "energies", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L274-L408
train
Create a basic folder tree for dumping DFT calculcations for reaction energies.
SUNCAT-Center/CatHub
cathub/cli.py
organize
def organize(**kwargs): """Read reactions from non-organized folder""" # do argument wrangling before turning it into an obect # since namedtuples are immutable if len(kwargs['adsorbates']) == 0: print("""Warning: no adsorbates specified, can't pick up reaction reaction energies.""") ...
python
def organize(**kwargs): """Read reactions from non-organized folder""" # do argument wrangling before turning it into an obect # since namedtuples are immutable if len(kwargs['adsorbates']) == 0: print("""Warning: no adsorbates specified, can't pick up reaction reaction energies.""") ...
[ "def", "organize", "(", "*", "*", "kwargs", ")", ":", "# do argument wrangling before turning it into an obect", "# since namedtuples are immutable", "if", "len", "(", "kwargs", "[", "'adsorbates'", "]", ")", "==", "0", ":", "print", "(", "\"\"\"Warning: no adsorbates ...
Read reactions from non-organized folder
[ "Read", "reactions", "from", "non", "-", "organized", "folder" ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/cli.py#L551-L576
train
Read reactions from non - organized folder
iiSeymour/game-of-life
conway/gol.py
gol.initCurses
def initCurses(self): """ Set up screen properties """ curses.noecho() curses.cbreak() curses.curs_set(0) curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, -1) curses.init_pair(2, curses.COLOR_YELLOW, ...
python
def initCurses(self): """ Set up screen properties """ curses.noecho() curses.cbreak() curses.curs_set(0) curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, -1) curses.init_pair(2, curses.COLOR_YELLOW, ...
[ "def", "initCurses", "(", "self", ")", ":", "curses", ".", "noecho", "(", ")", "curses", ".", "cbreak", "(", ")", "curses", ".", "curs_set", "(", "0", ")", "curses", ".", "start_color", "(", ")", "curses", ".", "use_default_colors", "(", ")", "curses",...
Set up screen properties
[ "Set", "up", "screen", "properties" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L81-L96
train
Initialize the curses system
iiSeymour/game-of-life
conway/gol.py
gol.patchCurses
def patchCurses(self): """ Fix curses addch function for python 3.4.0 """ if (sys.version_info)[:3] == (3, 4, 0): self.addchar = lambda y, x, *args: self.win.addch(x, y, *args) else: self.addchar = self.win.addch
python
def patchCurses(self): """ Fix curses addch function for python 3.4.0 """ if (sys.version_info)[:3] == (3, 4, 0): self.addchar = lambda y, x, *args: self.win.addch(x, y, *args) else: self.addchar = self.win.addch
[ "def", "patchCurses", "(", "self", ")", ":", "if", "(", "sys", ".", "version_info", ")", "[", ":", "3", "]", "==", "(", "3", ",", "4", ",", "0", ")", ":", "self", ".", "addchar", "=", "lambda", "y", ",", "x", ",", "*", "args", ":", "self", ...
Fix curses addch function for python 3.4.0
[ "Fix", "curses", "addch", "function", "for", "python", "3", ".", "4", ".", "0" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L98-L105
train
Patches curses addch function for python 3. 4. 0
iiSeymour/game-of-life
conway/gol.py
gol.splash
def splash(self): """ Draw splash screen """ dirname = os.path.split(os.path.abspath(__file__))[0] try: splash = open(os.path.join(dirname, "splash"), "r").readlines() except IOError: return width = len(max(splash, key=len)) y = in...
python
def splash(self): """ Draw splash screen """ dirname = os.path.split(os.path.abspath(__file__))[0] try: splash = open(os.path.join(dirname, "splash"), "r").readlines() except IOError: return width = len(max(splash, key=len)) y = in...
[ "def", "splash", "(", "self", ")", ":", "dirname", "=", "os", ".", "path", ".", "split", "(", "os", ".", "path", ".", "abspath", "(", "__file__", ")", ")", "[", "0", "]", "try", ":", "splash", "=", "open", "(", "os", ".", "path", ".", "join", ...
Draw splash screen
[ "Draw", "splash", "screen" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L110-L126
train
Draw the splash screen
iiSeymour/game-of-life
conway/gol.py
gol.drawHUD
def drawHUD(self): """ Draw information on population size and current generation """ self.win.move(self.height - 2, self.x_pad) self.win.clrtoeol() self.win.box() self.addstr(2, self.x_pad + 1, "Population: %i" % len(self.grid)) self.addstr(3, self.x_pad ...
python
def drawHUD(self): """ Draw information on population size and current generation """ self.win.move(self.height - 2, self.x_pad) self.win.clrtoeol() self.win.box() self.addstr(2, self.x_pad + 1, "Population: %i" % len(self.grid)) self.addstr(3, self.x_pad ...
[ "def", "drawHUD", "(", "self", ")", ":", "self", ".", "win", ".", "move", "(", "self", ".", "height", "-", "2", ",", "self", ".", "x_pad", ")", "self", ".", "win", ".", "clrtoeol", "(", ")", "self", ".", "win", ".", "box", "(", ")", "self", "...
Draw information on population size and current generation
[ "Draw", "information", "on", "population", "size", "and", "current", "generation" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L128-L138
train
Draw information on population size and current generation
iiSeymour/game-of-life
conway/gol.py
gol.drawGrid
def drawGrid(self): """ Redraw the grid with the new generation """ for cell in self.grid: y, x = cell y += self.y_pad x += self.x_pad if self.traditional: sprite = '.' color = curses.color_pair(4) ...
python
def drawGrid(self): """ Redraw the grid with the new generation """ for cell in self.grid: y, x = cell y += self.y_pad x += self.x_pad if self.traditional: sprite = '.' color = curses.color_pair(4) ...
[ "def", "drawGrid", "(", "self", ")", ":", "for", "cell", "in", "self", ".", "grid", ":", "y", ",", "x", "=", "cell", "y", "+=", "self", ".", "y_pad", "x", "+=", "self", ".", "x_pad", "if", "self", ".", "traditional", ":", "sprite", "=", "'.'", ...
Redraw the grid with the new generation
[ "Redraw", "the", "grid", "with", "the", "new", "generation" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L140-L158
train
Redraw the grid with the new generation
iiSeymour/game-of-life
conway/gol.py
gol.nextGen
def nextGen(self): """ Decide the fate of the cells """ self.current_gen += 1 self.change_gen[self.current_gen % 3] = copy.copy(self.grid) grid_cp = copy.copy(self.grid) for cell in self.grid: y, x = cell y1 = (y - 1) % self.y_grid ...
python
def nextGen(self): """ Decide the fate of the cells """ self.current_gen += 1 self.change_gen[self.current_gen % 3] = copy.copy(self.grid) grid_cp = copy.copy(self.grid) for cell in self.grid: y, x = cell y1 = (y - 1) % self.y_grid ...
[ "def", "nextGen", "(", "self", ")", ":", "self", ".", "current_gen", "+=", "1", "self", ".", "change_gen", "[", "self", ".", "current_gen", "%", "3", "]", "=", "copy", ".", "copy", "(", "self", ".", "grid", ")", "grid_cp", "=", "copy", ".", "copy",...
Decide the fate of the cells
[ "Decide", "the", "fate", "of", "the", "cells" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L160-L191
train
Decide the fate of the cells
iiSeymour/game-of-life
conway/gol.py
gol.countNeighbours
def countNeighbours(self, cell): """ Return the number active neighbours within one positions away from cell """ count = 0 y, x = cell y = y % self.y_grid x = x % self.x_grid y1 = (y - 1) % self.y_grid y2 = (y + 1) % self.y_grid x1 = (x - 1...
python
def countNeighbours(self, cell): """ Return the number active neighbours within one positions away from cell """ count = 0 y, x = cell y = y % self.y_grid x = x % self.x_grid y1 = (y - 1) % self.y_grid y2 = (y + 1) % self.y_grid x1 = (x - 1...
[ "def", "countNeighbours", "(", "self", ",", "cell", ")", ":", "count", "=", "0", "y", ",", "x", "=", "cell", "y", "=", "y", "%", "self", ".", "y_grid", "x", "=", "x", "%", "self", ".", "x_grid", "y1", "=", "(", "y", "-", "1", ")", "%", "sel...
Return the number active neighbours within one positions away from cell
[ "Return", "the", "number", "active", "neighbours", "within", "one", "positions", "away", "from", "cell" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L193-L210
train
Return the number of active neighbours within one positions away from cell
iiSeymour/game-of-life
conway/gol.py
gol.initGrid
def initGrid(self): """ Initialise the game grid """ blinker = [(4, 4), (4, 5), (4, 6)] toad = [(9, 5), (9, 6), (9, 7), (10, 4), (10, 5), (10, 6)] glider = [(4, 11), (5, 12), (6, 10), (6, 11), (6, 12)] r_pentomino = [(10, 60), (9, 61), (10, 61), (11, 61), (9, 62)]...
python
def initGrid(self): """ Initialise the game grid """ blinker = [(4, 4), (4, 5), (4, 6)] toad = [(9, 5), (9, 6), (9, 7), (10, 4), (10, 5), (10, 6)] glider = [(4, 11), (5, 12), (6, 10), (6, 11), (6, 12)] r_pentomino = [(10, 60), (9, 61), (10, 61), (11, 61), (9, 62)]...
[ "def", "initGrid", "(", "self", ")", ":", "blinker", "=", "[", "(", "4", ",", "4", ")", ",", "(", "4", ",", "5", ")", ",", "(", "4", ",", "6", ")", "]", "toad", "=", "[", "(", "9", ",", "5", ")", ",", "(", "9", ",", "6", ")", ",", "...
Initialise the game grid
[ "Initialise", "the", "game", "grid" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L212-L230
train
Initialise the game grid
iiSeymour/game-of-life
conway/gol.py
gol.start
def start(self): """ Game logic """ self.initGrid() self.win.clear() self.state = 'running' while self.state == 'running': if self.hud: self.drawHUD() self.drawGrid() self.nextGen() sleep(self.rate) ...
python
def start(self): """ Game logic """ self.initGrid() self.win.clear() self.state = 'running' while self.state == 'running': if self.hud: self.drawHUD() self.drawGrid() self.nextGen() sleep(self.rate) ...
[ "def", "start", "(", "self", ")", ":", "self", ".", "initGrid", "(", ")", "self", ".", "win", ".", "clear", "(", ")", "self", ".", "state", "=", "'running'", "while", "self", ".", "state", "==", "'running'", ":", "if", "self", ".", "hud", ":", "s...
Game logic
[ "Game", "logic" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L233-L268
train
Start the current state of the object.
iiSeymour/game-of-life
conway/gol.py
gol.restart
def restart(self): """ Restart the game from a new generation 0 """ self.initGrid() self.win.clear() self.current_gen = 1 self.start
python
def restart(self): """ Restart the game from a new generation 0 """ self.initGrid() self.win.clear() self.current_gen = 1 self.start
[ "def", "restart", "(", "self", ")", ":", "self", ".", "initGrid", "(", ")", "self", ".", "win", ".", "clear", "(", ")", "self", ".", "current_gen", "=", "1", "self", ".", "start" ]
Restart the game from a new generation 0
[ "Restart", "the", "game", "from", "a", "new", "generation", "0" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L278-L285
train
Restart the game from a new generation 0
iiSeymour/game-of-life
conway/gol.py
gol.end
def end(self): """ Game Finished - Restart or Quit """ if self.loop: self.restart return self.addstr(2, self.x_grid / 2 - 4, "GAMEOVER", 7) if self.hud: self.addstr(2, self.x_pad + 13, len(self.grid), 5) self.addstr(3, sel...
python
def end(self): """ Game Finished - Restart or Quit """ if self.loop: self.restart return self.addstr(2, self.x_grid / 2 - 4, "GAMEOVER", 7) if self.hud: self.addstr(2, self.x_pad + 13, len(self.grid), 5) self.addstr(3, sel...
[ "def", "end", "(", "self", ")", ":", "if", "self", ".", "loop", ":", "self", ".", "restart", "return", "self", ".", "addstr", "(", "2", ",", "self", ".", "x_grid", "/", "2", "-", "4", ",", "\"GAMEOVER\"", ",", "7", ")", "if", "self", ".", "hud"...
Game Finished - Restart or Quit
[ "Game", "Finished", "-", "Restart", "or", "Quit" ]
288bc87179ffd986ca066bcd98ea6e0951dd7970
https://github.com/iiSeymour/game-of-life/blob/288bc87179ffd986ca066bcd98ea6e0951dd7970/conway/gol.py#L288-L309
train
End the game.
guaix-ucm/numina
numina/array/combine.py
mean
def mean(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None): """Combine arrays using the mean, with masks and offsets. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. ...
python
def mean(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None): """Combine arrays using the mean, with masks and offsets. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. ...
[ "def", "mean", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ",", "weights", "=", "None", ")", ":", "return", "generic_combine", "(", "intl_combine...
Combine arrays using the mean, with masks and offsets. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an array with one more dimension than the inputs and with size (3, shape). out[0] contains...
[ "Combine", "arrays", "using", "the", "mean", "with", "masks", "and", "offsets", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L22-L59
train
Combine arrays using the mean method.
guaix-ucm/numina
numina/array/combine.py
median
def median(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None): """Combine arrays using the median, with masks. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The...
python
def median(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None): """Combine arrays using the median, with masks. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The...
[ "def", "median", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ",", "weights", "=", "None", ")", ":", "return", "generic_combine", "(", "intl_combi...
Combine arrays using the median, with masks. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an array with one more dimension than the inputs and with size (3, shape). out[0] contains the mean,...
[ "Combine", "arrays", "using", "the", "median", "with", "masks", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L62-L85
train
Combine arrays using the median method.
guaix-ucm/numina
numina/array/combine.py
sigmaclip
def sigmaclip(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None, low=3., high=3.): """Combine arrays using the sigma-clipping, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have...
python
def sigmaclip(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None, low=3., high=3.): """Combine arrays using the sigma-clipping, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have...
[ "def", "sigmaclip", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ",", "weights", "=", "None", ",", "low", "=", "3.", ",", "high", "=", "3.", ...
Combine arrays using the sigma-clipping, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an array with one more dimension than the inputs and with size (3, shape). out[0] contains t...
[ "Combine", "arrays", "using", "the", "sigma", "-", "clipping", "with", "masks", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L88-L112
train
Combine arrays using the sigma - clipping with masks.
guaix-ucm/numina
numina/array/combine.py
minmax
def minmax(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None, nmin=1, nmax=1): """Combine arrays using mix max rejection, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape al...
python
def minmax(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None, nmin=1, nmax=1): """Combine arrays using mix max rejection, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape al...
[ "def", "minmax", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ",", "weights", "=", "None", ",", "nmin", "=", "1", ",", "nmax", "=", "1", ")"...
Combine arrays using mix max rejection, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an array with one more dimension than the inputs and with size (3, shape). out[0] contains th...
[ "Combine", "arrays", "using", "mix", "max", "rejection", "with", "masks", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L115-L138
train
Combine arrays using mix max rejection with masks.
guaix-ucm/numina
numina/array/combine.py
quantileclip
def quantileclip(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None, fclip=0.10): """Combine arrays using the sigma-clipping, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks ...
python
def quantileclip(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None, fclip=0.10): """Combine arrays using the sigma-clipping, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks ...
[ "def", "quantileclip", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ",", "weights", "=", "None", ",", "fclip", "=", "0.10", ")", ":", "return", ...
Combine arrays using the sigma-clipping, with masks. Inputs and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an array with one more dimension than the inputs and with size (3, shape). out[0] contains t...
[ "Combine", "arrays", "using", "the", "sigma", "-", "clipping", "with", "masks", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L141-L163
train
Combine arrays using the sigma - clipping method.
guaix-ucm/numina
numina/array/combine.py
flatcombine
def flatcombine(arrays, masks=None, dtype=None, scales=None, low=3.0, high=3.0, blank=1.0): """Combine flat arrays. :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param out: optional output, with one...
python
def flatcombine(arrays, masks=None, dtype=None, scales=None, low=3.0, high=3.0, blank=1.0): """Combine flat arrays. :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param out: optional output, with one...
[ "def", "flatcombine", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "scales", "=", "None", ",", "low", "=", "3.0", ",", "high", "=", "3.0", ",", "blank", "=", "1.0", ")", ":", "result", "=", "sigmaclip", "(", "arrays", ...
Combine flat arrays. :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param out: optional output, with one more axis than the input arrays :param blank: non-positive values are substituted by this on output :retur...
[ "Combine", "flat", "arrays", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L166-L188
train
Combine a list of arrays into a single array with mask arrays.
guaix-ucm/numina
numina/array/combine.py
zerocombine
def zerocombine(arrays, masks, dtype=None, scales=None): """Combine zero arrays. :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param scales: :return: median, variance of the median and number of points stored ...
python
def zerocombine(arrays, masks, dtype=None, scales=None): """Combine zero arrays. :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param scales: :return: median, variance of the median and number of points stored ...
[ "def", "zerocombine", "(", "arrays", ",", "masks", ",", "dtype", "=", "None", ",", "scales", "=", "None", ")", ":", "result", "=", "median", "(", "arrays", ",", "masks", "=", "masks", ",", "dtype", "=", "dtype", ",", "scales", "=", "scales", ")", "...
Combine zero arrays. :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param scales: :return: median, variance of the median and number of points stored
[ "Combine", "zero", "arrays", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L191-L204
train
Combine zero arrays.
guaix-ucm/numina
numina/array/combine.py
sum
def sum(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None): """Combine arrays by addition, with masks and offsets. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an ar...
python
def sum(arrays, masks=None, dtype=None, out=None, zeros=None, scales=None): """Combine arrays by addition, with masks and offsets. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an ar...
[ "def", "sum", "(", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ")", ":", "return", "generic_combine", "(", "intl_combine", ".", "sum_method", "(", ")"...
Combine arrays by addition, with masks and offsets. Arrays and masks are a list of array objects. All input arrays have the same shape. If present, the masks have the same shape also. The function returns an array with one more dimension than the inputs and with size (3, shape). out[0] contains th...
[ "Combine", "arrays", "by", "addition", "with", "masks", "and", "offsets", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L207-L242
train
Combine arrays by addition with masks and offsets.
guaix-ucm/numina
numina/array/combine.py
generic_combine
def generic_combine(method, arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None): """Stack arrays using different methods. :param method: the combination method :type method: PyCObject :param arrays: a list of arrays :param masks: a list of mask array...
python
def generic_combine(method, arrays, masks=None, dtype=None, out=None, zeros=None, scales=None, weights=None): """Stack arrays using different methods. :param method: the combination method :type method: PyCObject :param arrays: a list of arrays :param masks: a list of mask array...
[ "def", "generic_combine", "(", "method", ",", "arrays", ",", "masks", "=", "None", ",", "dtype", "=", "None", ",", "out", "=", "None", ",", "zeros", "=", "None", ",", "scales", "=", "None", ",", "weights", "=", "None", ")", ":", "arrays", "=", "[",...
Stack arrays using different methods. :param method: the combination method :type method: PyCObject :param arrays: a list of arrays :param masks: a list of mask arrays, True values are masked :param dtype: data type of the output :param zeros: :param scales: :param weights: :return:...
[ "Stack", "arrays", "using", "different", "methods", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/combine.py#L245-L281
train
Generic combination of arrays and masks.
guaix-ucm/numina
numina/array/fwhm.py
compute_fwhm_1d_simple
def compute_fwhm_1d_simple(Y, xc, X=None): """Compute the FWHM.""" return compute_fw_at_frac_max_1d_simple(Y, xc, X=X, f=0.5)
python
def compute_fwhm_1d_simple(Y, xc, X=None): """Compute the FWHM.""" return compute_fw_at_frac_max_1d_simple(Y, xc, X=X, f=0.5)
[ "def", "compute_fwhm_1d_simple", "(", "Y", ",", "xc", ",", "X", "=", "None", ")", ":", "return", "compute_fw_at_frac_max_1d_simple", "(", "Y", ",", "xc", ",", "X", "=", "X", ",", "f", "=", "0.5", ")" ]
Compute the FWHM.
[ "Compute", "the", "FWHM", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/fwhm.py#L63-L65
train
Compute the FWHM at fraction max.
guaix-ucm/numina
numina/array/fwhm.py
compute_fw_at_frac_max_1d_simple
def compute_fw_at_frac_max_1d_simple(Y, xc, X=None, f=0.5): """Compute the full width at fraction f of the maximum""" yy = np.asarray(Y) if yy.ndim != 1: raise ValueError('array must be 1-d') if yy.size == 0: raise ValueError('array is empty') if X is None: xx = np.arange...
python
def compute_fw_at_frac_max_1d_simple(Y, xc, X=None, f=0.5): """Compute the full width at fraction f of the maximum""" yy = np.asarray(Y) if yy.ndim != 1: raise ValueError('array must be 1-d') if yy.size == 0: raise ValueError('array is empty') if X is None: xx = np.arange...
[ "def", "compute_fw_at_frac_max_1d_simple", "(", "Y", ",", "xc", ",", "X", "=", "None", ",", "f", "=", "0.5", ")", ":", "yy", "=", "np", ".", "asarray", "(", "Y", ")", "if", "yy", ".", "ndim", "!=", "1", ":", "raise", "ValueError", "(", "'array must...
Compute the full width at fraction f of the maximum
[ "Compute", "the", "full", "width", "at", "fraction", "f", "of", "the", "maximum" ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/fwhm.py#L68-L92
train
Compute the full width at fraction f of the maximum
guaix-ucm/numina
numina/array/fwhm.py
_fwhm_side_lineal
def _fwhm_side_lineal(uu, vv): '''Compute r12 using linear interpolation.''' res1, = np.nonzero(vv < 0) if len(res1) == 0: return 0, 1 # error, no negative value else: # first value i2 = res1[0] i1 = i2 - 1 dx = uu[i2] - uu[i1] dy = vv[i2] - vv[i1] ...
python
def _fwhm_side_lineal(uu, vv): '''Compute r12 using linear interpolation.''' res1, = np.nonzero(vv < 0) if len(res1) == 0: return 0, 1 # error, no negative value else: # first value i2 = res1[0] i1 = i2 - 1 dx = uu[i2] - uu[i1] dy = vv[i2] - vv[i1] ...
[ "def", "_fwhm_side_lineal", "(", "uu", ",", "vv", ")", ":", "res1", ",", "=", "np", ".", "nonzero", "(", "vv", "<", "0", ")", "if", "len", "(", "res1", ")", "==", "0", ":", "return", "0", ",", "1", "# error, no negative value", "else", ":", "# firs...
Compute r12 using linear interpolation.
[ "Compute", "r12", "using", "linear", "interpolation", "." ]
6c829495df8937f77c2de9383c1038ffb3e713e3
https://github.com/guaix-ucm/numina/blob/6c829495df8937f77c2de9383c1038ffb3e713e3/numina/array/fwhm.py#L95-L107
train
Compute r12 using linear interpolation.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
get_ZPE
def get_ZPE(viblist): """Returns the zero point energy from a list of frequencies. Parameters ---------- viblist : List of numbers or string of list of numbers. Returns ------- ZPE : Zero point energy in eV. """ if type(viblist) is str: l = ast.literal_eval(viblist) els...
python
def get_ZPE(viblist): """Returns the zero point energy from a list of frequencies. Parameters ---------- viblist : List of numbers or string of list of numbers. Returns ------- ZPE : Zero point energy in eV. """ if type(viblist) is str: l = ast.literal_eval(viblist) els...
[ "def", "get_ZPE", "(", "viblist", ")", ":", "if", "type", "(", "viblist", ")", "is", "str", ":", "l", "=", "ast", ".", "literal_eval", "(", "viblist", ")", "else", ":", "l", "=", "viblist", "l", "=", "[", "float", "(", "w", ")", "for", "w", "in...
Returns the zero point energy from a list of frequencies. Parameters ---------- viblist : List of numbers or string of list of numbers. Returns ------- ZPE : Zero point energy in eV.
[ "Returns", "the", "zero", "point", "energy", "from", "a", "list", "of", "frequencies", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L276-L293
train
Returns the zero point energy from a list of frequencies.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
auto_labels
def auto_labels(df): """Transforms atomic system information into well-formatted labels. Parameters ---------- df : Pandas DataFrame. Returns ------- labels : list of system labels. """ systems = list(df.system) facets = list(df.facet) systems_labels = [w.replace('_', '\ ')...
python
def auto_labels(df): """Transforms atomic system information into well-formatted labels. Parameters ---------- df : Pandas DataFrame. Returns ------- labels : list of system labels. """ systems = list(df.system) facets = list(df.facet) systems_labels = [w.replace('_', '\ ')...
[ "def", "auto_labels", "(", "df", ")", ":", "systems", "=", "list", "(", "df", ".", "system", ")", "facets", "=", "list", "(", "df", ".", "facet", ")", "systems_labels", "=", "[", "w", ".", "replace", "(", "'_'", ",", "'\\ '", ")", "for", "w", "in...
Transforms atomic system information into well-formatted labels. Parameters ---------- df : Pandas DataFrame. Returns ------- labels : list of system labels.
[ "Transforms", "atomic", "system", "information", "into", "well", "-", "formatted", "labels", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L295-L321
train
Transforms atomic system information into well - formatted labels.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
proton_hydroxide_free_energy
def proton_hydroxide_free_energy(temperature, pressure, pH): """Returns the Gibbs free energy of proton in bulk solution. Parameters ---------- pH : pH of bulk solution temperature : numeric temperature in K pressure : numeric pressure in mbar Returns ------- G_H, G_...
python
def proton_hydroxide_free_energy(temperature, pressure, pH): """Returns the Gibbs free energy of proton in bulk solution. Parameters ---------- pH : pH of bulk solution temperature : numeric temperature in K pressure : numeric pressure in mbar Returns ------- G_H, G_...
[ "def", "proton_hydroxide_free_energy", "(", "temperature", ",", "pressure", ",", "pH", ")", ":", "H2", "=", "GasMolecule", "(", "'H2'", ")", "H2O", "=", "GasMolecule", "(", "'H2O'", ")", "G_H2", "=", "H2", ".", "get_free_energy", "(", "temperature", "=", "...
Returns the Gibbs free energy of proton in bulk solution. Parameters ---------- pH : pH of bulk solution temperature : numeric temperature in K pressure : numeric pressure in mbar Returns ------- G_H, G_OH : Gibbs free energy of proton and hydroxide.
[ "Returns", "the", "Gibbs", "free", "energy", "of", "proton", "in", "bulk", "solution", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L323-L344
train
Returns the Gibbs free energy of proton and hydroxide in bulk solution.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
get_FEC
def get_FEC(molecule_list, temperature, pressure, electronic_energy='Default'): """Returns the Gibbs free energy corrections to be added to raw reaction energies. Parameters ---------- molecule_list : list of strings temperature : numeric temperature in K pressure : numeric press...
python
def get_FEC(molecule_list, temperature, pressure, electronic_energy='Default'): """Returns the Gibbs free energy corrections to be added to raw reaction energies. Parameters ---------- molecule_list : list of strings temperature : numeric temperature in K pressure : numeric press...
[ "def", "get_FEC", "(", "molecule_list", ",", "temperature", ",", "pressure", ",", "electronic_energy", "=", "'Default'", ")", ":", "if", "not", "temperature", "or", "not", "pressure", ":", "return", "(", "0", ")", "else", ":", "molecule_list", "=", "[", "m...
Returns the Gibbs free energy corrections to be added to raw reaction energies. Parameters ---------- molecule_list : list of strings temperature : numeric temperature in K pressure : numeric pressure in mbar Returns ------- G_H, G_OH : Gibbs free energy of proton and hy...
[ "Returns", "the", "Gibbs", "free", "energy", "corrections", "to", "be", "added", "to", "raw", "reaction", "energies", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L346-L385
train
Returns the Gibbs free energy corrections for a given list of Molecules.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
plot_reaction_scheme
def plot_reaction_scheme(df, temperature, pressure, potential, pH, e_lim=None): """Returns a matplotlib object with the plotted reaction path. Parameters ---------- df : Pandas DataFrame generated by reaction_network temperature : numeric temperature in K pressure : numeric press...
python
def plot_reaction_scheme(df, temperature, pressure, potential, pH, e_lim=None): """Returns a matplotlib object with the plotted reaction path. Parameters ---------- df : Pandas DataFrame generated by reaction_network temperature : numeric temperature in K pressure : numeric press...
[ "def", "plot_reaction_scheme", "(", "df", ",", "temperature", ",", "pressure", ",", "potential", ",", "pH", ",", "e_lim", "=", "None", ")", ":", "ncols", "=", "int", "(", "(", "df", ".", "shape", "[", "0", "]", "/", "20", ")", ")", "+", "1", "fig...
Returns a matplotlib object with the plotted reaction path. Parameters ---------- df : Pandas DataFrame generated by reaction_network temperature : numeric temperature in K pressure : numeric pressure in mbar pH : PH in bulk solution potential : Electric potential vs. SHE in ...
[ "Returns", "a", "matplotlib", "object", "with", "the", "plotted", "reaction", "path", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L389-L474
train
Plots the reaction scheme.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
select_data
def select_data(db_file, slab=None, facet=None): """Gathers relevant data from SQL database generated by CATHUB. Parameters ---------- db_file : Path to database slab : Which metal (slab) to select. facet : Which facets to select. Returns ------- data : SQL cursor output. """ ...
python
def select_data(db_file, slab=None, facet=None): """Gathers relevant data from SQL database generated by CATHUB. Parameters ---------- db_file : Path to database slab : Which metal (slab) to select. facet : Which facets to select. Returns ------- data : SQL cursor output. """ ...
[ "def", "select_data", "(", "db_file", ",", "slab", "=", "None", ",", "facet", "=", "None", ")", ":", "con", "=", "sql", ".", "connect", "(", "db_file", ")", "cur", "=", "con", ".", "cursor", "(", ")", "if", "slab", "and", "facet", ":", "select_comm...
Gathers relevant data from SQL database generated by CATHUB. Parameters ---------- db_file : Path to database slab : Which metal (slab) to select. facet : Which facets to select. Returns ------- data : SQL cursor output.
[ "Gathers", "relevant", "data", "from", "SQL", "database", "generated", "by", "CATHUB", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L476-L501
train
Returns relevant data from SQL database generated by CATHUB.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
file_to_df
def file_to_df(file_name): """Read in file and return pandas data_frame. Parameters ---------- filename : Filename including path. Returns ------- df : pandas data frame """ filename, file_extension = os.path.splitext(file_name) if file_extension=='.csv': df = pd.read_c...
python
def file_to_df(file_name): """Read in file and return pandas data_frame. Parameters ---------- filename : Filename including path. Returns ------- df : pandas data frame """ filename, file_extension = os.path.splitext(file_name) if file_extension=='.csv': df = pd.read_c...
[ "def", "file_to_df", "(", "file_name", ")", ":", "filename", ",", "file_extension", "=", "os", ".", "path", ".", "splitext", "(", "file_name", ")", "if", "file_extension", "==", "'.csv'", ":", "df", "=", "pd", ".", "read_csv", "(", "file_name", ",", "sep...
Read in file and return pandas data_frame. Parameters ---------- filename : Filename including path. Returns ------- df : pandas data frame
[ "Read", "in", "file", "and", "return", "pandas", "data_frame", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L503-L521
train
Read in file and return pandas data frame.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
db_to_df
def db_to_df(db_file, slabs=None, facet=None): """Transforms database to data frame. Parameters ---------- db_file : Path to database slabs : Which metals (slabs) to select. facet : Which facets to select. Returns ------- df : Data frame. """ systems = [] data = [] ...
python
def db_to_df(db_file, slabs=None, facet=None): """Transforms database to data frame. Parameters ---------- db_file : Path to database slabs : Which metals (slabs) to select. facet : Which facets to select. Returns ------- df : Data frame. """ systems = [] data = [] ...
[ "def", "db_to_df", "(", "db_file", ",", "slabs", "=", "None", ",", "facet", "=", "None", ")", ":", "systems", "=", "[", "]", "data", "=", "[", "]", "if", "slabs", ":", "for", "slab", "in", "slabs", ":", "data_tmp", "=", "select_data", "(", "db_file...
Transforms database to data frame. Parameters ---------- db_file : Path to database slabs : Which metals (slabs) to select. facet : Which facets to select. Returns ------- df : Data frame.
[ "Transforms", "database", "to", "data", "frame", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L523-L571
train
Transforms database to data frame.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
unique_reactions
def unique_reactions(df): """Identifies unique elementary reactions in data frame. Parameters ---------- df : Data frame. Returns ------- reaction_list : List of unique elementary reactions. """ reaction_list =[] for idx, entry in enumerate(df['reactants']): reaction = ...
python
def unique_reactions(df): """Identifies unique elementary reactions in data frame. Parameters ---------- df : Data frame. Returns ------- reaction_list : List of unique elementary reactions. """ reaction_list =[] for idx, entry in enumerate(df['reactants']): reaction = ...
[ "def", "unique_reactions", "(", "df", ")", ":", "reaction_list", "=", "[", "]", "for", "idx", ",", "entry", "in", "enumerate", "(", "df", "[", "'reactants'", "]", ")", ":", "reaction", "=", "[", "]", "for", "x", "in", "entry", ":", "reaction", ".", ...
Identifies unique elementary reactions in data frame. Parameters ---------- df : Data frame. Returns ------- reaction_list : List of unique elementary reactions.
[ "Identifies", "unique", "elementary", "reactions", "in", "data", "frame", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L573-L596
train
Identifies unique elementary reactions in data frame.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
Adsorbate.get_helmholtz_energy
def get_helmholtz_energy(self, temperature, electronic_energy=0, verbose=False): """Returns the Helmholtz energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV verbose...
python
def get_helmholtz_energy(self, temperature, electronic_energy=0, verbose=False): """Returns the Helmholtz energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV verbose...
[ "def", "get_helmholtz_energy", "(", "self", ",", "temperature", ",", "electronic_energy", "=", "0", ",", "verbose", "=", "False", ")", ":", "thermo_object", "=", "HarmonicThermo", "(", "vib_energies", "=", "self", ".", "vib_energies", ",", "potentialenergy", "="...
Returns the Helmholtz energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV verbose : boolean whether to print ASE thermochemistry output Returns ...
[ "Returns", "the", "Helmholtz", "energy", "of", "an", "adsorbed", "molecule", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L131-L151
train
Returns the Helmholtz energy of an adsorbed molecule.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
Adsorbate.get_internal_energy
def get_internal_energy(self, temperature, electronic_energy=0, verbose=False): """Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV verbose :...
python
def get_internal_energy(self, temperature, electronic_energy=0, verbose=False): """Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV verbose :...
[ "def", "get_internal_energy", "(", "self", ",", "temperature", ",", "electronic_energy", "=", "0", ",", "verbose", "=", "False", ")", ":", "thermo_object", "=", "HarmonicThermo", "(", "vib_energies", "=", "self", ".", "vib_energies", ",", "potentialenergy", "=",...
Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV verbose : boolean whether to print ASE thermochemistry output Returns -...
[ "Returns", "the", "internal", "energy", "of", "an", "adsorbed", "molecule", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L153-L173
train
Returns the internal energy of an adsorbed molecule.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
GasMolecule.get_free_energy
def get_free_energy(self, temperature, pressure = 'Default', electronic_energy = 'Default', overbinding = True): """Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric ...
python
def get_free_energy(self, temperature, pressure = 'Default', electronic_energy = 'Default', overbinding = True): """Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric ...
[ "def", "get_free_energy", "(", "self", ",", "temperature", ",", "pressure", "=", "'Default'", ",", "electronic_energy", "=", "'Default'", ",", "overbinding", "=", "True", ")", ":", "if", "not", "temperature", "or", "not", "pressure", ":", "# either None or 0", ...
Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV pressure : numeric pressure in mbar Returns ------- internal_energ...
[ "Returns", "the", "internal", "energy", "of", "an", "adsorbed", "molecule", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L187-L230
train
Returns the internal energy of an adsorbed molecule.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
GasMolecule.get_enthalpy
def get_enthalpy(self, temperature, electronic_energy = 'Default'): """Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV Returns ------- ...
python
def get_enthalpy(self, temperature, electronic_energy = 'Default'): """Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV Returns ------- ...
[ "def", "get_enthalpy", "(", "self", ",", "temperature", ",", "electronic_energy", "=", "'Default'", ")", ":", "if", "not", "temperature", ":", "# either None or 0", "return", "(", "0", ",", "0", ",", "0", ")", "if", "electronic_energy", "==", "'Default'", ":...
Returns the internal energy of an adsorbed molecule. Parameters ---------- temperature : numeric temperature in K electronic_energy : numeric energy in eV Returns ------- internal_energy : numeric Internal energy in eV
[ "Returns", "the", "internal", "energy", "of", "an", "adsorbed", "molecule", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L232-L263
train
Returns the internal energy of an adsorbed molecule.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
GasMolecule.get_vib_energies
def get_vib_energies(self): """Returns a list of vibration in energy units eV. Returns ------- vibs : list of vibrations in eV """ vibs = self.molecule_dict[self.name]['vibrations'] vibs = np.array(vibs) * cm2ev return (vibs)
python
def get_vib_energies(self): """Returns a list of vibration in energy units eV. Returns ------- vibs : list of vibrations in eV """ vibs = self.molecule_dict[self.name]['vibrations'] vibs = np.array(vibs) * cm2ev return (vibs)
[ "def", "get_vib_energies", "(", "self", ")", ":", "vibs", "=", "self", ".", "molecule_dict", "[", "self", ".", "name", "]", "[", "'vibrations'", "]", "vibs", "=", "np", ".", "array", "(", "vibs", ")", "*", "cm2ev", "return", "(", "vibs", ")" ]
Returns a list of vibration in energy units eV. Returns ------- vibs : list of vibrations in eV
[ "Returns", "a", "list", "of", "vibration", "in", "energy", "units", "eV", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L265-L274
train
Returns a list of vibration in energy units eV.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
ReactionNetwork.set_intermediates
def set_intermediates(self, intermediates, betas=None, transition_states=None): """Sets up intermediates and specifies whether it's an electrochemical step. Either provide individual contributions or net contributions. If both are given, only the net contributions are used. intermediate...
python
def set_intermediates(self, intermediates, betas=None, transition_states=None): """Sets up intermediates and specifies whether it's an electrochemical step. Either provide individual contributions or net contributions. If both are given, only the net contributions are used. intermediate...
[ "def", "set_intermediates", "(", "self", ",", "intermediates", ",", "betas", "=", "None", ",", "transition_states", "=", "None", ")", ":", "self", ".", "intermediates", "=", "intermediates", "self", ".", "betas", "=", "betas", "self", ".", "transition_states",...
Sets up intermediates and specifies whether it's an electrochemical step. Either provide individual contributions or net contributions. If both are given, only the net contributions are used. intermediate_list: list of basestrings transition_states: list of True and False electr...
[ "Sets", "up", "intermediates", "and", "specifies", "whether", "it", "s", "an", "electrochemical", "step", ".", "Either", "provide", "individual", "contributions", "or", "net", "contributions", ".", "If", "both", "are", "given", "only", "the", "net", "contributio...
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L689-L721
train
Sets up the intermediates and specifies whether it s an electrochemical step.
SUNCAT-Center/CatHub
cathub/reaction_networks.py
ReactionNetwork.reaction_scheme
def reaction_scheme(self, df, temperature, pressure, pH, potential): """Returns a dataframe with Gibbs free reaction energies. Parameters ---------- df : Pandas DataFrame generated by db_to_df temperature : numeric temperature in K pressure : numeric ...
python
def reaction_scheme(self, df, temperature, pressure, pH, potential): """Returns a dataframe with Gibbs free reaction energies. Parameters ---------- df : Pandas DataFrame generated by db_to_df temperature : numeric temperature in K pressure : numeric ...
[ "def", "reaction_scheme", "(", "self", ",", "df", ",", "temperature", ",", "pressure", ",", "pH", ",", "potential", ")", ":", "# set reaction scheme", "reactions", "=", "self", ".", "intermediates", "df_param", "=", "self", ".", "df_reaction_parameters", ".", ...
Returns a dataframe with Gibbs free reaction energies. Parameters ---------- df : Pandas DataFrame generated by db_to_df temperature : numeric temperature in K pressure : numeric pressure in mbar pH : PH in bulk solution potential : Electri...
[ "Returns", "a", "dataframe", "with", "Gibbs", "free", "reaction", "energies", "." ]
324625d1d8e740673f139658b2de4c9e1059739e
https://github.com/SUNCAT-Center/CatHub/blob/324625d1d8e740673f139658b2de4c9e1059739e/cathub/reaction_networks.py#L749-L848
train
Returns a dataframe with Gibbs free reaction energies.
ryanpetrello/sdb
sdb.py
debugger
def debugger(): """Return the current debugger instance, or create if none.""" sdb = _current[0] if sdb is None or not sdb.active: sdb = _current[0] = Sdb() return sdb
python
def debugger(): """Return the current debugger instance, or create if none.""" sdb = _current[0] if sdb is None or not sdb.active: sdb = _current[0] = Sdb() return sdb
[ "def", "debugger", "(", ")", ":", "sdb", "=", "_current", "[", "0", "]", "if", "sdb", "is", "None", "or", "not", "sdb", ".", "active", ":", "sdb", "=", "_current", "[", "0", "]", "=", "Sdb", "(", ")", "return", "sdb" ]
Return the current debugger instance, or create if none.
[ "Return", "the", "current", "debugger", "instance", "or", "create", "if", "none", "." ]
4a198757a17e753ac88081d192ecc952b4228a36
https://github.com/ryanpetrello/sdb/blob/4a198757a17e753ac88081d192ecc952b4228a36/sdb.py#L268-L273
train
Return the current debugger instance or create if none.
ryanpetrello/sdb
sdb.py
SocketCompleter.global_matches
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ matches = [] n = len(text) for word in self.namespace: if wor...
python
def global_matches(self, text): """Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match. """ matches = [] n = len(text) for word in self.namespace: if wor...
[ "def", "global_matches", "(", "self", ",", "text", ")", ":", "matches", "=", "[", "]", "n", "=", "len", "(", "text", ")", "for", "word", "in", "self", ".", "namespace", ":", "if", "word", "[", ":", "n", "]", "==", "text", "and", "word", "!=", "...
Compute matches when text is a simple name. Return a list of all keywords, built-in functions and names currently defined in self.namespace that match.
[ "Compute", "matches", "when", "text", "is", "a", "simple", "name", ".", "Return", "a", "list", "of", "all", "keywords", "built", "-", "in", "functions", "and", "names", "currently", "defined", "in", "self", ".", "namespace", "that", "match", "." ]
4a198757a17e753ac88081d192ecc952b4228a36
https://github.com/ryanpetrello/sdb/blob/4a198757a17e753ac88081d192ecc952b4228a36/sdb.py#L65-L75
train
Compute matches when text is a simple name.
restran/mountains
mountains/django/model.py
set_dict_none_default
def set_dict_none_default(dict_item, default_value): """ 对字典中为None的值,重新设置默认值 :param dict_item: :param default_value: :return: """ for (k, v) in iteritems(dict_item): if v is None: dict_item[k] = default_value
python
def set_dict_none_default(dict_item, default_value): """ 对字典中为None的值,重新设置默认值 :param dict_item: :param default_value: :return: """ for (k, v) in iteritems(dict_item): if v is None: dict_item[k] = default_value
[ "def", "set_dict_none_default", "(", "dict_item", ",", "default_value", ")", ":", "for", "(", "k", ",", "v", ")", "in", "iteritems", "(", "dict_item", ")", ":", "if", "v", "is", "None", ":", "dict_item", "[", "k", "]", "=", "default_value" ]
对字典中为None的值,重新设置默认值 :param dict_item: :param default_value: :return:
[ "对字典中为None的值,重新设置默认值", ":", "param", "dict_item", ":", ":", "param", "default_value", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/django/model.py#L36-L45
train
Set dict_item to default_value if None
restran/mountains
mountains/django/model.py
auto_model_name_recognize
def auto_model_name_recognize(model_name): """ 自动将 site-user 识别成 SiteUser :param model_name: :return: """ name_list = model_name.split('-') return ''.join(['%s%s' % (name[0].upper(), name[1:]) for name in name_list])
python
def auto_model_name_recognize(model_name): """ 自动将 site-user 识别成 SiteUser :param model_name: :return: """ name_list = model_name.split('-') return ''.join(['%s%s' % (name[0].upper(), name[1:]) for name in name_list])
[ "def", "auto_model_name_recognize", "(", "model_name", ")", ":", "name_list", "=", "model_name", ".", "split", "(", "'-'", ")", "return", "''", ".", "join", "(", "[", "'%s%s'", "%", "(", "name", "[", "0", "]", ".", "upper", "(", ")", ",", "name", "["...
自动将 site-user 识别成 SiteUser :param model_name: :return:
[ "自动将", "site", "-", "user", "识别成", "SiteUser", ":", "param", "model_name", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/django/model.py#L48-L55
train
Auto model name recognize.
restran/mountains
mountains/django/model.py
model_to_select_list
def model_to_select_list(model_class, filter_dict=None, q_filter=None): """ 只选择 id 和 name,用来做列表选择 :param model_class: :param filter_dict: :param q_filter: :return: """ if filter_dict is None: filter_dict = {} if q_filter is not None: filter_list = [q_filter] else...
python
def model_to_select_list(model_class, filter_dict=None, q_filter=None): """ 只选择 id 和 name,用来做列表选择 :param model_class: :param filter_dict: :param q_filter: :return: """ if filter_dict is None: filter_dict = {} if q_filter is not None: filter_list = [q_filter] else...
[ "def", "model_to_select_list", "(", "model_class", ",", "filter_dict", "=", "None", ",", "q_filter", "=", "None", ")", ":", "if", "filter_dict", "is", "None", ":", "filter_dict", "=", "{", "}", "if", "q_filter", "is", "not", "None", ":", "filter_list", "="...
只选择 id 和 name,用来做列表选择 :param model_class: :param filter_dict: :param q_filter: :return:
[ "只选择", "id", "和", "name,用来做列表选择", ":", "param", "model_class", ":", ":", "param", "filter_dict", ":", ":", "param", "q_filter", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/django/model.py#L100-L119
train
Convert a model class to a list of objects.
restran/mountains
mountains/django/model.py
model_to_list
def model_to_list(model_class, filter_dict=None, order_by_list=None, select_related_fields=None, q_filter=None, values=None, to_json_method='to_json'): """ 不分页 :param values: :param to_json_method: :param model_class: :param filter_dict: ...
python
def model_to_list(model_class, filter_dict=None, order_by_list=None, select_related_fields=None, q_filter=None, values=None, to_json_method='to_json'): """ 不分页 :param values: :param to_json_method: :param model_class: :param filter_dict: ...
[ "def", "model_to_list", "(", "model_class", ",", "filter_dict", "=", "None", ",", "order_by_list", "=", "None", ",", "select_related_fields", "=", "None", ",", "q_filter", "=", "None", ",", "values", "=", "None", ",", "to_json_method", "=", "'to_json'", ")", ...
不分页 :param values: :param to_json_method: :param model_class: :param filter_dict: :param order_by_list: :param select_related_fields: :param q_filter: :return:
[ "不分页", ":", "param", "values", ":", ":", "param", "to_json_method", ":", ":", "param", "model_class", ":", ":", "param", "filter_dict", ":", ":", "param", "order_by_list", ":", ":", "param", "select_related_fields", ":", ":", "param", "q_filter", ":", ":", ...
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/django/model.py#L122-L141
train
Convert a model to a list of objects.
restran/mountains
mountains/django/model.py
model_to_page_list
def model_to_page_list(model_class, page_num, page_size=DEFAULT_PAGE_SIZE, filter_dict=None, order_by_list=None, select_related_fields=None, q_filter=None, values=None, to_json_method='to_json', max_page_s...
python
def model_to_page_list(model_class, page_num, page_size=DEFAULT_PAGE_SIZE, filter_dict=None, order_by_list=None, select_related_fields=None, q_filter=None, values=None, to_json_method='to_json', max_page_s...
[ "def", "model_to_page_list", "(", "model_class", ",", "page_num", ",", "page_size", "=", "DEFAULT_PAGE_SIZE", ",", "filter_dict", "=", "None", ",", "order_by_list", "=", "None", ",", "select_related_fields", "=", "None", ",", "q_filter", "=", "None", ",", "value...
:param max_page_size: :param model_class: :param page_num: :param page_size: :param filter_dict: :param order_by_list: :param select_related_fields: :param q_filter: Q(uuid__contains=keyword) | Q(memo__contains=keyword) :param values: :param to_json_method: :return:
[ ":", "param", "max_page_size", ":", ":", "param", "model_class", ":", ":", "param", "page_num", ":", ":", "param", "page_size", ":", ":", "param", "filter_dict", ":", ":", "param", "order_by_list", ":", ":", "param", "select_related_fields", ":", ":", "param...
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/django/model.py#L144-L204
train
Returns a list of objects from a model class to a page list.
restran/mountains
mountains/http/__init__.py
request
def request(method, url, headers=None, data=None, session=None): """ :type session requests.session :param method: :param url: :param headers: :param data: :param session: :return: """ base_headers = { 'User-Agent': random_agent() } if headers is None: hea...
python
def request(method, url, headers=None, data=None, session=None): """ :type session requests.session :param method: :param url: :param headers: :param data: :param session: :return: """ base_headers = { 'User-Agent': random_agent() } if headers is None: hea...
[ "def", "request", "(", "method", ",", "url", ",", "headers", "=", "None", ",", "data", "=", "None", ",", "session", "=", "None", ")", ":", "base_headers", "=", "{", "'User-Agent'", ":", "random_agent", "(", ")", "}", "if", "headers", "is", "None", ":...
:type session requests.session :param method: :param url: :param headers: :param data: :param session: :return:
[ ":", "type", "session", "requests", ".", "session", ":", "param", "method", ":", ":", "param", "url", ":", ":", "param", "headers", ":", ":", "param", "data", ":", ":", "param", "session", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/http/__init__.py#L32-L60
train
A convenience function for making a request to a node.
restran/mountains
mountains/http/__init__.py
read_request
def read_request(file_name, **params): """ 从文件中读取请求头,并根据格式化字符串模板,进行字符串格式化 :param file_name: :param params: :return: """ with open(file_name, 'r') as f: data = f.read() return read_request_from_str(data, **params)
python
def read_request(file_name, **params): """ 从文件中读取请求头,并根据格式化字符串模板,进行字符串格式化 :param file_name: :param params: :return: """ with open(file_name, 'r') as f: data = f.read() return read_request_from_str(data, **params)
[ "def", "read_request", "(", "file_name", ",", "*", "*", "params", ")", ":", "with", "open", "(", "file_name", ",", "'r'", ")", "as", "f", ":", "data", "=", "f", ".", "read", "(", ")", "return", "read_request_from_str", "(", "data", ",", "*", "*", "...
从文件中读取请求头,并根据格式化字符串模板,进行字符串格式化 :param file_name: :param params: :return:
[ "从文件中读取请求头,并根据格式化字符串模板,进行字符串格式化", ":", "param", "file_name", ":", ":", "param", "params", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/http/__init__.py#L63-L72
train
read a request from a file
restran/mountains
mountains/http/__init__.py
read_request_from_str
def read_request_from_str(data, **params): """ 从字符串中读取请求头,并根据格式化字符串模板,进行字符串格式化 :param data: :param params: :return: """ method, uri = None, None headers = {} host = '' try: split_list = data.split('\n\n') headers_text = split_list[0] body = '\n\n'.join(sp...
python
def read_request_from_str(data, **params): """ 从字符串中读取请求头,并根据格式化字符串模板,进行字符串格式化 :param data: :param params: :return: """ method, uri = None, None headers = {} host = '' try: split_list = data.split('\n\n') headers_text = split_list[0] body = '\n\n'.join(sp...
[ "def", "read_request_from_str", "(", "data", ",", "*", "*", "params", ")", ":", "method", ",", "uri", "=", "None", ",", "None", "headers", "=", "{", "}", "host", "=", "''", "try", ":", "split_list", "=", "data", ".", "split", "(", "'\\n\\n'", ")", ...
从字符串中读取请求头,并根据格式化字符串模板,进行字符串格式化 :param data: :param params: :return:
[ "从字符串中读取请求头,并根据格式化字符串模板,进行字符串格式化", ":", "param", "data", ":", ":", "param", "params", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/http/__init__.py#L75-L119
train
Reads a request from a string.
restran/mountains
mountains/http/__init__.py
query_str_2_dict
def query_str_2_dict(query_str): """ 将查询字符串,转换成字典 a=123&b=456 {'a': '123', 'b': '456'} :param query_str: :return: """ if query_str: query_list = query_str.split('&') query_dict = {} for t in query_list: x = t.split('=') query_dict[x[0]] = x...
python
def query_str_2_dict(query_str): """ 将查询字符串,转换成字典 a=123&b=456 {'a': '123', 'b': '456'} :param query_str: :return: """ if query_str: query_list = query_str.split('&') query_dict = {} for t in query_list: x = t.split('=') query_dict[x[0]] = x...
[ "def", "query_str_2_dict", "(", "query_str", ")", ":", "if", "query_str", ":", "query_list", "=", "query_str", ".", "split", "(", "'&'", ")", "query_dict", "=", "{", "}", "for", "t", "in", "query_list", ":", "x", "=", "t", ".", "split", "(", "'='", "...
将查询字符串,转换成字典 a=123&b=456 {'a': '123', 'b': '456'} :param query_str: :return:
[ "将查询字符串,转换成字典", "a", "=", "123&b", "=", "456", "{", "a", ":", "123", "b", ":", "456", "}", ":", "param", "query_str", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/http/__init__.py#L122-L138
train
converts a query string to a dictionary
restran/mountains
mountains/utils/email.py
EmailHandler.do_send_mail
def do_send_mail(self, is_ssl, mail_to_list, subject, content, file_name_list): """ 发送邮件 :param is_ssl: 使用SSL的方式发生 :param mail_to_list: 收件人列表 :param subject: 邮件主题 :param content: 邮件正文 :param file_name_list: 附近的文件路径列表 :return: """ if is_ssl:...
python
def do_send_mail(self, is_ssl, mail_to_list, subject, content, file_name_list): """ 发送邮件 :param is_ssl: 使用SSL的方式发生 :param mail_to_list: 收件人列表 :param subject: 邮件主题 :param content: 邮件正文 :param file_name_list: 附近的文件路径列表 :return: """ if is_ssl:...
[ "def", "do_send_mail", "(", "self", ",", "is_ssl", ",", "mail_to_list", ",", "subject", ",", "content", ",", "file_name_list", ")", ":", "if", "is_ssl", ":", "smtp", "=", "smtplib", ".", "SMTP_SSL", "(", "self", ".", "smtp_server", ",", "self", ".", "smt...
发送邮件 :param is_ssl: 使用SSL的方式发生 :param mail_to_list: 收件人列表 :param subject: 邮件主题 :param content: 邮件正文 :param file_name_list: 附近的文件路径列表 :return:
[ "发送邮件", ":", "param", "is_ssl", ":", "使用SSL的方式发生", ":", "param", "mail_to_list", ":", "收件人列表", ":", "param", "subject", ":", "邮件主题", ":", "param", "content", ":", "邮件正文", ":", "param", "file_name_list", ":", "附近的文件路径列表", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/utils/email.py#L38-L74
train
Send an email.
restran/mountains
mountains/utils/email.py
PostfixEmailHandler.send_email
def send_email(self, mail_to, subject, content, content_type='plain', files=None): """ :param content_type: 如果 text 是html,则需要设置 _subtype='html' :param mail_to: :param subject: :param content: :param files: (f_name, f_data) :return: """ assert type(...
python
def send_email(self, mail_to, subject, content, content_type='plain', files=None): """ :param content_type: 如果 text 是html,则需要设置 _subtype='html' :param mail_to: :param subject: :param content: :param files: (f_name, f_data) :return: """ assert type(...
[ "def", "send_email", "(", "self", ",", "mail_to", ",", "subject", ",", "content", ",", "content_type", "=", "'plain'", ",", "files", "=", "None", ")", ":", "assert", "type", "(", "mail_to", ")", "==", "list", "server", "=", "self", ".", "smtp_server", ...
:param content_type: 如果 text 是html,则需要设置 _subtype='html' :param mail_to: :param subject: :param content: :param files: (f_name, f_data) :return:
[ ":", "param", "content_type", ":", "如果", "text", "是html,则需要设置", "_subtype", "=", "html", ":", "param", "mail_to", ":", ":", "param", "subject", ":", ":", "param", "content", ":", ":", "param", "files", ":", "(", "f_name", "f_data", ")", ":", "return", ...
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/utils/email.py#L83-L117
train
Send an email.
restran/mountains
mountains/logging/__init__.py
init_log
def init_log(*handlers, **kwargs): """ :param handlers: :return: """ disable_existing_loggers = kwargs.get('disable_existing_loggers', False) handlers_config = [t.get_handler() for t in handlers] new_handlers_config = {} for t in handlers_config: new_handlers_config.update(t) ...
python
def init_log(*handlers, **kwargs): """ :param handlers: :return: """ disable_existing_loggers = kwargs.get('disable_existing_loggers', False) handlers_config = [t.get_handler() for t in handlers] new_handlers_config = {} for t in handlers_config: new_handlers_config.update(t) ...
[ "def", "init_log", "(", "*", "handlers", ",", "*", "*", "kwargs", ")", ":", "disable_existing_loggers", "=", "kwargs", ".", "get", "(", "'disable_existing_loggers'", ",", "False", ")", "handlers_config", "=", "[", "t", ".", "get_handler", "(", ")", "for", ...
:param handlers: :return:
[ ":", "param", "handlers", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/logging/__init__.py#L195-L226
train
Initializes the log module with the given list of handlers.
restran/mountains
mountains/django/utils.py
get_client_ip
def get_client_ip(request): """ 获取客户端的IP :param request: :return: """ x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') x_real_ip = request.META.get('HTTP_X_REAL_IP') if x_real_ip: ip = x_real_ip elif x_forwarded_for: ip = x_forwarded_for.split(',')[0] el...
python
def get_client_ip(request): """ 获取客户端的IP :param request: :return: """ x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') x_real_ip = request.META.get('HTTP_X_REAL_IP') if x_real_ip: ip = x_real_ip elif x_forwarded_for: ip = x_forwarded_for.split(',')[0] el...
[ "def", "get_client_ip", "(", "request", ")", ":", "x_forwarded_for", "=", "request", ".", "META", ".", "get", "(", "'HTTP_X_FORWARDED_FOR'", ")", "x_real_ip", "=", "request", ".", "META", ".", "get", "(", "'HTTP_X_REAL_IP'", ")", "if", "x_real_ip", ":", "ip"...
获取客户端的IP :param request: :return:
[ "获取客户端的IP", ":", "param", "request", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/django/utils.py#L6-L20
train
Get client IP from request.
restran/mountains
mountains/json/__init__.py
json_default
def json_default(obj): """ 对一些数据类型的 json 序列化, 默认情况下 json 没有对 datetime 和 Decimal 进行序列化 如果不指定的话,会抛异常 :param obj: :return: """ if isinstance(obj, datetime): return obj.strftime("%Y-%m-%d %H:%M:%S") elif isinstance(obj, Decimal): return float(obj) elif isinstance(obj,...
python
def json_default(obj): """ 对一些数据类型的 json 序列化, 默认情况下 json 没有对 datetime 和 Decimal 进行序列化 如果不指定的话,会抛异常 :param obj: :return: """ if isinstance(obj, datetime): return obj.strftime("%Y-%m-%d %H:%M:%S") elif isinstance(obj, Decimal): return float(obj) elif isinstance(obj,...
[ "def", "json_default", "(", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "datetime", ")", ":", "return", "obj", ".", "strftime", "(", "\"%Y-%m-%d %H:%M:%S\"", ")", "elif", "isinstance", "(", "obj", ",", "Decimal", ")", ":", "return", "float", "(...
对一些数据类型的 json 序列化, 默认情况下 json 没有对 datetime 和 Decimal 进行序列化 如果不指定的话,会抛异常 :param obj: :return:
[ "对一些数据类型的", "json", "序列化,", "默认情况下", "json", "没有对", "datetime", "和", "Decimal", "进行序列化", "如果不指定的话,会抛异常", ":", "param", "obj", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/json/__init__.py#L21-L41
train
json_default - 参数对 datetime Decimal UUID UUID
restran/mountains
mountains/json/__init__.py
dumps
def dumps(dict_data, ensure_ascii=True, indent=None, sort_keys=False, encoding='utf-8', **kwargs): """ 返回json数据 :param encoding: :param ensure_ascii: :param sort_keys: :param indent: :param dict_data: :return: """ return json.dumps(dict_data, default=json_default, ...
python
def dumps(dict_data, ensure_ascii=True, indent=None, sort_keys=False, encoding='utf-8', **kwargs): """ 返回json数据 :param encoding: :param ensure_ascii: :param sort_keys: :param indent: :param dict_data: :return: """ return json.dumps(dict_data, default=json_default, ...
[ "def", "dumps", "(", "dict_data", ",", "ensure_ascii", "=", "True", ",", "indent", "=", "None", ",", "sort_keys", "=", "False", ",", "encoding", "=", "'utf-8'", ",", "*", "*", "kwargs", ")", ":", "return", "json", ".", "dumps", "(", "dict_data", ",", ...
返回json数据 :param encoding: :param ensure_ascii: :param sort_keys: :param indent: :param dict_data: :return:
[ "返回json数据", ":", "param", "encoding", ":", ":", "param", "ensure_ascii", ":", ":", "param", "sort_keys", ":", ":", "param", "indent", ":", ":", "param", "dict_data", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/json/__init__.py#L51-L65
train
JSON 数据 处理
restran/mountains
mountains/file/excel.py
read_excel
def read_excel(file_name, offset=1, sheet_index=0): """ 读取 Excel :param sheet_index: :param file_name: :param offset: 偏移,一般第一行是表头,不需要读取数据 :return: """ try: workbook = xlrd.open_workbook(file_name) except Exception as e: return None if len(workbook.sheets()) <= 0:...
python
def read_excel(file_name, offset=1, sheet_index=0): """ 读取 Excel :param sheet_index: :param file_name: :param offset: 偏移,一般第一行是表头,不需要读取数据 :return: """ try: workbook = xlrd.open_workbook(file_name) except Exception as e: return None if len(workbook.sheets()) <= 0:...
[ "def", "read_excel", "(", "file_name", ",", "offset", "=", "1", ",", "sheet_index", "=", "0", ")", ":", "try", ":", "workbook", "=", "xlrd", ".", "open_workbook", "(", "file_name", ")", "except", "Exception", "as", "e", ":", "return", "None", "if", "le...
读取 Excel :param sheet_index: :param file_name: :param offset: 偏移,一般第一行是表头,不需要读取数据 :return:
[ "读取", "Excel", ":", "param", "sheet_index", ":", ":", "param", "file_name", ":", ":", "param", "offset", ":", "偏移,一般第一行是表头,不需要读取数据", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/file/excel.py#L18-L56
train
read an Excel file and return a list of dicts
restran/mountains
mountains/utils/string_utils.py
fixed_length_split
def fixed_length_split(s, width): """ 固定长度分割字符串 :param s: :param width: :return: """ # 使用正则的方法 # import re # split = re.findall(r'.{%s}' % width, string) return [s[x: x + width] for x in range(0, len(s), width)]
python
def fixed_length_split(s, width): """ 固定长度分割字符串 :param s: :param width: :return: """ # 使用正则的方法 # import re # split = re.findall(r'.{%s}' % width, string) return [s[x: x + width] for x in range(0, len(s), width)]
[ "def", "fixed_length_split", "(", "s", ",", "width", ")", ":", "# 使用正则的方法", "# import re", "# split = re.findall(r'.{%s}' % width, string)", "return", "[", "s", "[", "x", ":", "x", "+", "width", "]", "for", "x", "in", "range", "(", "0", ",", "len", "(", "s...
固定长度分割字符串 :param s: :param width: :return:
[ "固定长度分割字符串", ":", "param", "s", ":", ":", "param", "width", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/utils/string_utils.py#L7-L17
train
Split a string into fixed length words.
restran/mountains
mountains/utils/string_utils.py
line_break
def line_break(s, length=76): """ 将字符串分割成一行一行 :param s: :param length: :return: """ x = '\n'.join(s[pos:pos + length] for pos in range(0, len(s), length)) return x
python
def line_break(s, length=76): """ 将字符串分割成一行一行 :param s: :param length: :return: """ x = '\n'.join(s[pos:pos + length] for pos in range(0, len(s), length)) return x
[ "def", "line_break", "(", "s", ",", "length", "=", "76", ")", ":", "x", "=", "'\\n'", ".", "join", "(", "s", "[", "pos", ":", "pos", "+", "length", "]", "for", "pos", "in", "range", "(", "0", ",", "len", "(", "s", ")", ",", "length", ")", "...
将字符串分割成一行一行 :param s: :param length: :return:
[ "将字符串分割成一行一行", ":", "param", "s", ":", ":", "param", "length", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/utils/string_utils.py#L20-L28
train
line break 将字符串分割成一行一行
restran/mountains
mountains/tornado/__init__.py
AsyncHTTPExecutor.get_proxy
def get_proxy(self): """ 获取下一个可用的代理 :return: proxy_host, proxy_port, proxy_username, proxy_password """ if self.proxy_list is None or len(self.proxy_list) <= 0: return None, None, None, None self.proxy_index += 1 self.proxy_index = self.proxy_index % l...
python
def get_proxy(self): """ 获取下一个可用的代理 :return: proxy_host, proxy_port, proxy_username, proxy_password """ if self.proxy_list is None or len(self.proxy_list) <= 0: return None, None, None, None self.proxy_index += 1 self.proxy_index = self.proxy_index % l...
[ "def", "get_proxy", "(", "self", ")", ":", "if", "self", ".", "proxy_list", "is", "None", "or", "len", "(", "self", ".", "proxy_list", ")", "<=", "0", ":", "return", "None", ",", "None", ",", "None", ",", "None", "self", ".", "proxy_index", "+=", "...
获取下一个可用的代理 :return: proxy_host, proxy_port, proxy_username, proxy_password
[ "获取下一个可用的代理", ":", "return", ":", "proxy_host", "proxy_port", "proxy_username", "proxy_password" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/tornado/__init__.py#L68-L81
train
get_proxy - Get the proxy host port username password
restran/mountains
mountains/file/__init__.py
read_dict
def read_dict(file_name, clear_none=False, encoding='utf-8'): """ 读取字典文件 :param encoding: :param clear_none: :param file_name: :return: """ with open(file_name, 'rb') as f: data = f.read() if encoding is not None: data = data.decode(encoding) line_list = data.sp...
python
def read_dict(file_name, clear_none=False, encoding='utf-8'): """ 读取字典文件 :param encoding: :param clear_none: :param file_name: :return: """ with open(file_name, 'rb') as f: data = f.read() if encoding is not None: data = data.decode(encoding) line_list = data.sp...
[ "def", "read_dict", "(", "file_name", ",", "clear_none", "=", "False", ",", "encoding", "=", "'utf-8'", ")", ":", "with", "open", "(", "file_name", ",", "'rb'", ")", "as", "f", ":", "data", "=", "f", ".", "read", "(", ")", "if", "encoding", "is", "...
读取字典文件 :param encoding: :param clear_none: :param file_name: :return:
[ "读取字典文件", ":", "param", "encoding", ":", ":", "param", "clear_none", ":", ":", "param", "file_name", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/file/__init__.py#L9-L36
train
read a dict from file
restran/mountains
mountains/file/__init__.py
read_file
def read_file(file_name, encoding='utf-8'): """ 读文本文件 :param encoding: :param file_name: :return: """ with open(file_name, 'rb') as f: data = f.read() if encoding is not None: data = data.decode(encoding) return data
python
def read_file(file_name, encoding='utf-8'): """ 读文本文件 :param encoding: :param file_name: :return: """ with open(file_name, 'rb') as f: data = f.read() if encoding is not None: data = data.decode(encoding) return data
[ "def", "read_file", "(", "file_name", ",", "encoding", "=", "'utf-8'", ")", ":", "with", "open", "(", "file_name", ",", "'rb'", ")", "as", "f", ":", "data", "=", "f", ".", "read", "(", ")", "if", "encoding", "is", "not", "None", ":", "data", "=", ...
读文本文件 :param encoding: :param file_name: :return:
[ "读文本文件", ":", "param", "encoding", ":", ":", "param", "file_name", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/file/__init__.py#L60-L73
train
read file from file_name
restran/mountains
mountains/encoding/__init__.py
utf8
def utf8(value, encoding=None): """Converts a string argument to a byte string. """ if isinstance(value, _UTF8_TYPES): return value if not isinstance(value, text_type): raise TypeError( "Expected bytes, unicode, or None; got %r" % type(value) ) if encoding is not...
python
def utf8(value, encoding=None): """Converts a string argument to a byte string. """ if isinstance(value, _UTF8_TYPES): return value if not isinstance(value, text_type): raise TypeError( "Expected bytes, unicode, or None; got %r" % type(value) ) if encoding is not...
[ "def", "utf8", "(", "value", ",", "encoding", "=", "None", ")", ":", "if", "isinstance", "(", "value", ",", "_UTF8_TYPES", ")", ":", "return", "value", "if", "not", "isinstance", "(", "value", ",", "text_type", ")", ":", "raise", "TypeError", "(", "\"E...
Converts a string argument to a byte string.
[ "Converts", "a", "string", "argument", "to", "a", "byte", "string", "." ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/encoding/__init__.py#L12-L28
train
Converts a string argument to a byte string.
restran/mountains
mountains/encoding/__init__.py
to_unicode
def to_unicode(value, encoding=None): """Converts a string argument to a unicode string. """ if isinstance(value, text_type): return value elif isinstance(value, type(None)): return text_type(value) if not isinstance(value, bytes): raise TypeError( "Expected byte...
python
def to_unicode(value, encoding=None): """Converts a string argument to a unicode string. """ if isinstance(value, text_type): return value elif isinstance(value, type(None)): return text_type(value) if not isinstance(value, bytes): raise TypeError( "Expected byte...
[ "def", "to_unicode", "(", "value", ",", "encoding", "=", "None", ")", ":", "if", "isinstance", "(", "value", ",", "text_type", ")", ":", "return", "value", "elif", "isinstance", "(", "value", ",", "type", "(", "None", ")", ")", ":", "return", "text_typ...
Converts a string argument to a unicode string.
[ "Converts", "a", "string", "argument", "to", "a", "unicode", "string", "." ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/encoding/__init__.py#L31-L55
train
Converts a string argument to a unicode string.
restran/mountains
mountains/encoding/converter.py
dec2bin
def dec2bin(s): """ dec2bin 十进制 to 二进制: bin() :param s: :return: """ if not isinstance(s, int): num = int(s) else: num = s mid = [] while True: if num == 0: break num, rem = divmod(num, 2) mid.append(base[rem]) return ''.jo...
python
def dec2bin(s): """ dec2bin 十进制 to 二进制: bin() :param s: :return: """ if not isinstance(s, int): num = int(s) else: num = s mid = [] while True: if num == 0: break num, rem = divmod(num, 2) mid.append(base[rem]) return ''.jo...
[ "def", "dec2bin", "(", "s", ")", ":", "if", "not", "isinstance", "(", "s", ",", "int", ")", ":", "num", "=", "int", "(", "s", ")", "else", ":", "num", "=", "s", "mid", "=", "[", "]", "while", "True", ":", "if", "num", "==", "0", ":", "break...
dec2bin 十进制 to 二进制: bin() :param s: :return:
[ "dec2bin", "十进制", "to", "二进制", ":", "bin", "()", ":", "param", "s", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/encoding/converter.py#L63-L81
train
dec2bin 十进制 to 二进制
restran/mountains
mountains/encoding/converter.py
hex2dec
def hex2dec(s): """ hex2dec 十六进制 to 十进制 :param s: :return: """ if not isinstance(s, str): s = str(s) return int(s.upper(), 16)
python
def hex2dec(s): """ hex2dec 十六进制 to 十进制 :param s: :return: """ if not isinstance(s, str): s = str(s) return int(s.upper(), 16)
[ "def", "hex2dec", "(", "s", ")", ":", "if", "not", "isinstance", "(", "s", ",", "str", ")", ":", "s", "=", "str", "(", "s", ")", "return", "int", "(", "s", ".", "upper", "(", ")", ",", "16", ")" ]
hex2dec 十六进制 to 十进制 :param s: :return:
[ "hex2dec", "十六进制", "to", "十进制", ":", "param", "s", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/encoding/converter.py#L84-L93
train
hex2dec 十六进制 to 十进制
restran/mountains
mountains/encoding/converter.py
hex2bin
def hex2bin(s): """ hex2tobin 十六进制 to 二进制: bin(int(str,16)) :param s: :return: """ if len(s) % 2 != 0: s += '0' result = [] for i in range(len(s) // 2): t = s[i * 2:(i + 1) * 2] x = dec2bin(hex2dec(t.upper())) padding_length = (8 - len(x) % 8) % 8 ...
python
def hex2bin(s): """ hex2tobin 十六进制 to 二进制: bin(int(str,16)) :param s: :return: """ if len(s) % 2 != 0: s += '0' result = [] for i in range(len(s) // 2): t = s[i * 2:(i + 1) * 2] x = dec2bin(hex2dec(t.upper())) padding_length = (8 - len(x) % 8) % 8 ...
[ "def", "hex2bin", "(", "s", ")", ":", "if", "len", "(", "s", ")", "%", "2", "!=", "0", ":", "s", "+=", "'0'", "result", "=", "[", "]", "for", "i", "in", "range", "(", "len", "(", "s", ")", "//", "2", ")", ":", "t", "=", "s", "[", "i", ...
hex2tobin 十六进制 to 二进制: bin(int(str,16)) :param s: :return:
[ "hex2tobin", "十六进制", "to", "二进制", ":", "bin", "(", "int", "(", "str", "16", "))", ":", "param", "s", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/encoding/converter.py#L118-L137
train
hex2bin 十六进制 to 二进制
restran/mountains
mountains/encoding/converter.py
bin2hex
def bin2hex(s): """ bin2hex 二进制 to 十六进制: hex(int(str,2)) :param s: :return: """ padding_length = (8 - len(s) % 8) % 8 # 从前往后解码,不足8个的,在后面补0 encode_str = '%s%s' % (s, '0' * padding_length) # 解码后是 0xab1234,需要去掉前面的 0x return hex(int(encode_str, 2))[2:].rstrip('L')
python
def bin2hex(s): """ bin2hex 二进制 to 十六进制: hex(int(str,2)) :param s: :return: """ padding_length = (8 - len(s) % 8) % 8 # 从前往后解码,不足8个的,在后面补0 encode_str = '%s%s' % (s, '0' * padding_length) # 解码后是 0xab1234,需要去掉前面的 0x return hex(int(encode_str, 2))[2:].rstrip('L')
[ "def", "bin2hex", "(", "s", ")", ":", "padding_length", "=", "(", "8", "-", "len", "(", "s", ")", "%", "8", ")", "%", "8", "# 从前往后解码,不足8个的,在后面补0", "encode_str", "=", "'%s%s'", "%", "(", "s", ",", "'0'", "*", "padding_length", ")", "# 解码后是 0xab1234,需要去掉...
bin2hex 二进制 to 十六进制: hex(int(str,2)) :param s: :return:
[ "bin2hex", "二进制", "to", "十六进制", ":", "hex", "(", "int", "(", "str", "2", "))", ":", "param", "s", ":", ":", "return", ":" ]
a97fee568b112f4e10d878f815d0db3dd0a98d74
https://github.com/restran/mountains/blob/a97fee568b112f4e10d878f815d0db3dd0a98d74/mountains/encoding/converter.py#L140-L151
train
bin2hex 二进制 to 十六进制