rem
stringlengths 1
322k
| add
stringlengths 0
2.05M
| context
stringlengths 4
228k
| meta
stringlengths 156
215
|
---|---|---|---|
Let us compute longest paths on random graphs with random weights. Each time, we ensure the resulting graph is indeed a path:: | Let us compute longest paths on random graphs with random weights. Each time, we ensure the resulting graph is indeed a path:: | def longest_path(self, s=None, t=None, weighted=False, algorithm="MILP", solver=None, verbose=0): r""" Returns a longest path of ``self``. | 34c1e50f6f1e024964d30bd503da4e0a040658da /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/34c1e50f6f1e024964d30bd503da4e0a040658da/generic_graph.py |
This can be very helpful in showing certain features of plots. | This can be very helpful in showing certain features of plots. :: sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) | sage: def maple_leaf(t): | c10e2b47ad18a174d81ccda4e0cc7692a9ede9df /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/c10e2b47ad18a174d81ccda4e0cc7692a9ede9df/plot.py |
sage: plot(1.5/(1+e^(-x)), (x, -10, 10)) | sage: def maple_leaf(t): | c10e2b47ad18a174d81ccda4e0cc7692a9ede9df /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/c10e2b47ad18a174d81ccda4e0cc7692a9ede9df/plot.py |
|
of `pi`. | of `\pi`. | sage: def maple_leaf(t): | c10e2b47ad18a174d81ccda4e0cc7692a9ede9df /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/c10e2b47ad18a174d81ccda4e0cc7692a9ede9df/plot.py |
for best style in that case. | for best style in that case. :: sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=["latex",pi]) | sage: def maple_leaf(t): | c10e2b47ad18a174d81ccda4e0cc7692a9ede9df /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/c10e2b47ad18a174d81ccda4e0cc7692a9ede9df/plot.py |
sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=["latex",pi]) | sage: def maple_leaf(t): | c10e2b47ad18a174d81ccda4e0cc7692a9ede9df /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/c10e2b47ad18a174d81ccda4e0cc7692a9ede9df/plot.py |
|
def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=None): | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): """ Return the Lagrange interpolation polynomial in ``self`` associated to the given list of points. | 465de735fa7de0284b94ba6fee7486033b515273 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/465de735fa7de0284b94ba6fee7486033b515273/polynomial_ring.py |
- ``previous_row`` -- (default: ``[]``) This option is only relevant | - ``previous_row`` -- (default: ``None``) This option is only relevant | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): """ Return the Lagrange interpolation polynomial in ``self`` associated to the given list of points. | 465de735fa7de0284b94ba6fee7486033b515273 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/465de735fa7de0284b94ba6fee7486033b515273/polynomial_ring.py |
The return value should always be an element of ``self'', in the case of ``divided_difference'', or a list of elements of ``self'', in the case of ``neville'':: | Make sure that ticket be an element of ``self`` in the case of ``divided_difference``, or a list of elements of ``self`` in the case of ``neville``. :: | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): """ Return the Lagrange interpolation polynomial in ``self`` associated to the given list of points. | 465de735fa7de0284b94ba6fee7486033b515273 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/465de735fa7de0284b94ba6fee7486033b515273/polynomial_ring.py |
sage: J.is_S_integral(J.[K.ideal(5)]) | sage: J.is_S_integral([K.ideal(5)]) | def is_S_integral(self,S): r""" Return True if this fractional ideal is integral with respect to the list of primes ``S``. | 0401b35b186901fc27d9669b7b0c53c0910effb2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/0401b35b186901fc27d9669b7b0c53c0910effb2/number_field_ideal.py |
A.append(chr(ascii_integer(b[8*i : 8*(i+1)]))) | A.append(chr(ascii_integer(b[8*i: 8*(i+1)]))) | def bin_to_ascii(B): r""" Return the ASCII representation of the binary string ``B``. INPUT: - ``B`` -- a non-empty binary string or a non-empty list of bits. The number of bits in ``B`` must be a multiple of 8. OUTPUT: - The ASCII string corresponding to ``B``. ALGORITHM: Consider a block of bits `B = b_0 b_1 \cdots b_{n-1}` where each sub-block `b_i` is a binary string of length 8. Then the total number of bits is a multiple of 8 and is given by `8n`. Let `c_i` be the integer representation of `b_i`. We can consider `c_i` as the integer representation of an ASCII character. Then the ASCII representation `A` of `B` is `A = a_0 a_1 \cdots a_{n-1}`. EXAMPLES: Convert some ASCII strings to their binary representations and recover the ASCII strings from the binary representations:: sage: from sage.crypto.util import ascii_to_bin sage: from sage.crypto.util import bin_to_ascii sage: A = "Abc" sage: B = ascii_to_bin(A); B 010000010110001001100011 sage: bin_to_ascii(B) 'Abc' sage: bin_to_ascii(B) == A True :: sage: A = "123 \" #" sage: B = ascii_to_bin(A); B 00110001001100100011001100100000001000100010000000100011 sage: bin_to_ascii(B) '123 " #' sage: bin_to_ascii(B) == A True This function also accepts strings and lists of bits:: sage: from sage.crypto.util import bin_to_ascii sage: bin_to_ascii("010000010110001001100011") 'Abc' sage: bin_to_ascii([0, 1, 0, 0, 0, 0, 0, 1]) 'A' TESTS: The number of bits in ``B`` must be non-empty and a multiple of 8:: sage: from sage.crypto.util import bin_to_ascii sage: bin_to_ascii("") Traceback (most recent call last): ... ValueError: B must be a non-empty binary string. sage: bin_to_ascii([]) Traceback (most recent call last): ... ValueError: B must be a non-empty binary string. sage: bin_to_ascii(" ") Traceback (most recent call last): ... ValueError: The number of bits in B must be a multiple of 8. sage: bin_to_ascii("101") Traceback (most recent call last): ... ValueError: The number of bits in B must be a multiple of 8. sage: bin_to_ascii([1, 0, 1]) Traceback (most recent call last): ... ValueError: The number of bits in B must be a multiple of 8. """ # sanity checks n = len(B) if n == 0: raise ValueError("B must be a non-empty binary string.") if mod(n, 8) != 0: raise ValueError("The number of bits in B must be a multiple of 8.") # perform conversion to ASCII string b = map(lambda x: int(str(x)), list(B)) A = [] # the number of 8-bit blocks k = n / 8 for i in xrange(k): # Convert from 8-bit string to ASCII integer. Then convert the # ASCII integer to the corresponding ASCII character. A.append(chr(ascii_integer(b[8*i : 8*(i+1)]))) return "".join(A) | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
bug reported in trac | Bug reported in trac | sage: def my_carmichael(n): | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
import sage.rings.integer n = sage.rings.integer.Integer(n) | n = Integer(n) | sage: def my_carmichael(n): | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
sage: def my_carmichael(n): | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
||
if e < 3: e = e-1 else: e = e-2 t.append(1<<e) | if e < 3: e = e - 1 else: e = e - 2 t.append(1 << e) | sage: def my_carmichael(n): | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
t += [ p**(k-1)*(p-1) for p,k in L ] | t += [p**(k - 1) * (p - 1) for p, k in L] | sage: def my_carmichael(n): | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
return map(lambda x: int(x), list(n.binary()[-k:])) | return map(int, list(n.binary()[-k:])) | def least_significant_bits(n, k): r""" Return the ``k`` least significant bits of ``n``. INPUT: - ``n`` -- an integer. - ``k`` -- a positive integer. OUTPUT: - The ``k`` least significant bits of the integer ``n``. If ``k=1``, then return the parity bit of the integer ``n``. Let `b` be the binary representation of ``n``, where `m` is the length of the binary string `b`. If `k \geq m`, then return the binary representation of ``n``. EXAMPLES: Obtain the parity bits of some integers:: sage: from sage.crypto.util import least_significant_bits sage: least_significant_bits(0, 1) [0] sage: least_significant_bits(2, 1) [0] sage: least_significant_bits(3, 1) [1] sage: least_significant_bits(-2, 1) [0] sage: least_significant_bits(-3, 1) [1] Obtain the 4 least significant bits of some integers:: sage: least_significant_bits(101, 4) [0, 1, 0, 1] sage: least_significant_bits(-101, 4) [0, 1, 0, 1] sage: least_significant_bits(124, 4) [1, 1, 0, 0] sage: least_significant_bits(-124, 4) [1, 1, 0, 0] The binary representation of 123:: sage: n = 123; b = n.binary(); b '1111011' sage: least_significant_bits(n, len(b)) [1, 1, 1, 1, 0, 1, 1] """ return map(lambda x: int(x), list(n.binary()[-k:])) | aebff8f354a41a04afb74b90325076d3d8890a6a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/aebff8f354a41a04afb74b90325076d3d8890a6a/util.py |
non negative integer | non negative real number | def height(self): r""" Returns the height of self. | 9778e6e357f80e24f134e6467cc55d87104aeb8f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/9778e6e357f80e24f134e6467cc55d87104aeb8f/paths.py |
non negative integer | non negative real number | def width(self): r""" Returns the width of self. | 9778e6e357f80e24f134e6467cc55d87104aeb8f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/9778e6e357f80e24f134e6467cc55d87104aeb8f/paths.py |
def tikz_trajectory(self): r""" Returns the trajectory of self as a tikz str. | 9778e6e357f80e24f134e6467cc55d87104aeb8f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/9778e6e357f80e24f134e6467cc55d87104aeb8f/paths.py |
||
def tikz_trajectory(self): r""" Returns the trajectory of self as a tikz str. | 9778e6e357f80e24f134e6467cc55d87104aeb8f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/9778e6e357f80e24f134e6467cc55d87104aeb8f/paths.py |
||
class _python_object_alphabet(object): | class _python_object_alphabet(UniqueRepresentation): | def __contains__(self, x): """ Returns True if x is contained in self. | f8ac97cfb9c2830fb49fe687aece163acb2bdd82 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f8ac97cfb9c2830fb49fe687aece163acb2bdd82/words.py |
""" | r""" | def strip_answer(self, s): """ Returns the string s with Matlab's answer prompt removed. | 158cf0a8ce2e4bbf3ba05e93b02a4f869f056e7e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/158cf0a8ce2e4bbf3ba05e93b02a4f869f056e7e/matlab.py |
""" Returns the image `\{f(x) x in self\}` of this combinatorial | r""" Returns the image `\{f(x) | x \in \text{self}\}` of this combinatorial | def map(self, f, name=None): """ Returns the image `\{f(x) x in self\}` of this combinatorial class by `f`, as a combinatorial class. | 2100c662ee361cfb10d1f946fd4c75e7591d8485 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/2100c662ee361cfb10d1f946fd4c75e7591d8485/combinat.py |
sage: browse_sage_doc(identity_matrix, 'rst')[-60:-5] 'MatrixSpace of 3 by 3 sparse matrices over Integer Ring' | sage: browse_sage_doc(identity_matrix, 'rst')[-107:-47] 'Full MatrixSpace of 3 by 3 sparse matrices over Integer Ring' | 'def identity_matrix' | 88c6636fa4d7063c99eaf26d5727e3439fbc8099 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/88c6636fa4d7063c99eaf26d5727e3439fbc8099/sagedoc.py |
for i in xrange(0, l - 2): | for i in xrange(0, l-1): | def is_square_free(self): r""" Returns True if self does not contain squares, and False otherwise. | f544ac737c51764dde59f8a338c136fafc79ce7c /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f544ac737c51764dde59f8a338c136fafc79ce7c/finite_word.py |
Initializes base class Disk. | Initializes base class ``Disk``. | def __init__(self, point, r, angle, options): """ Initializes base class Disk. | 3f21439afc8f5abeb4fe65a598d336e1421e1daa /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/3f21439afc8f5abeb4fe65a598d336e1421e1daa/disk.py |
EXAMPLES: | EXAMPLES:: | def get_minmax_data(self): """ Returns a dictionary with the bounding box data. | 3f21439afc8f5abeb4fe65a598d336e1421e1daa /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/3f21439afc8f5abeb4fe65a598d336e1421e1daa/disk.py |
Return the allowed options for the Disk class. | Return the allowed options for the ``Disk`` class. | def _allowed_options(self): """ Return the allowed options for the Disk class. | 3f21439afc8f5abeb4fe65a598d336e1421e1daa /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/3f21439afc8f5abeb4fe65a598d336e1421e1daa/disk.py |
String representation of Disk primitive. | String representation of ``Disk`` primitive. | def _repr_(self): """ String representation of Disk primitive. | 3f21439afc8f5abeb4fe65a598d336e1421e1daa /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/3f21439afc8f5abeb4fe65a598d336e1421e1daa/disk.py |
EXAMPLES: | EXAMPLES:: | def plot3d(self, z=0, **kwds): """ Plots a 2D disk (actually a 52-gon) in 3D, with default height zero. | 3f21439afc8f5abeb4fe65a598d336e1421e1daa /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/3f21439afc8f5abeb4fe65a598d336e1421e1daa/disk.py |
""" S = self.__heilbronn_operator(self, [[-d,0, 0,d]], 1) | We test that the sign issue at sage: M = Newforms(Gamma1(13),names = 'a')[0].modular_symbols(sign=0) sage: M.diamond_bracket_operator(4) Hecke module morphism defined by the matrix [ 0 0 1 -1] [-1 -1 0 1] [-1 -1 0 0] [ 0 -1 1 -1] Domain: Modular Symbols subspace of dimension 4 of Modular Symbols space ... Codomain: Modular Symbols subspace of dimension 4 of Modular Symbols space ... """ S = self.__heilbronn_operator(self, [[d,0, 0,d]], 1) | def diamond_bracket_operator(self, d): r""" Return the diamond bracket d operator on this modular symbols space. | 68b1a176f6aaeccb935dcddb989af090ba262e7b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/68b1a176f6aaeccb935dcddb989af090ba262e7b/ambient.py |
pass | def cycle_index(self, parent = None): r""" INPUT: - ``self`` - a permutation group `G` - ``parent`` -- a free module with basis indexed by partitions, or behave as such, with a ``term`` and ``sum`` method (default: the symmetric functions over the rational field in the p basis) Returns the *cycle index* of `G`, which is a gadget counting the elements of `G` by cycle type, averaged over the group: .. math:: P = \frac{1}{|G|} \sum_{g\in G} p_{ \operatorname{cycle\ type}(g) } EXAMPLES: Among the permutations of the symmetric group `S_4`, there is the identity, 6 cycles of length 2, 3 products of two cycles of length 2, 8 cycles of length 3, and 6 cycles of length 4:: sage: S4 = SymmetricGroup(4) sage: P = S4.cycle_index() sage: 24 * P p[1, 1, 1, 1] + 6*p[2, 1, 1] + 3*p[2, 2] + 8*p[3, 1] + 6*p[4] If `l = (l_1,\dots,l_k)` is a partition, ``|G| P[l]`` is the number of elements of `G` with cycles of length `(p_1,\dots,p_k)`:: sage: 24 * P[ Partition([3,1]) ] 8 The cycle index plays an important role in the enumeration of objects modulo the action of a group (Polya enumeration), via the use of symmetric functions and plethysms. It is therefore encoded as a symmetric function, expressed in the powersum basis:: sage: P.parent() Symmetric Function Algebra over Rational Field, Power symmetric functions as basis This symmetric function can have some nice properties; for example, for the symmetric group `S_n`, we get the complete symmetric function `h_n`:: sage: S = SymmetricFunctions(QQ); h = S.h() sage: h( P ) h[4] TODO: add some simple examples of Polya enumeration, once it will be easy to expand symmetric functions on any alphabet. Here are the cycle indices of some permutation groups:: sage: 6 * CyclicPermutationGroup(6).cycle_index() p[1, 1, 1, 1, 1, 1] + p[2, 2, 2] + 2*p[3, 3] + 2*p[6] sage: 60 * AlternatingGroup(5).cycle_index() p[1, 1, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 24*p[5] sage: for G in TransitiveGroups(5): ... G.cardinality() * G.cycle_index() p[1, 1, 1, 1, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 5*p[2, 2, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 5*p[2, 2, 1] + 10*p[4, 1] + 4*p[5] p[1, 1, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 24*p[5] p[1, 1, 1, 1, 1] + 10*p[2, 1, 1, 1] + 15*p[2, 2, 1] + 20*p[3, 1, 1] + 20*p[3, 2] + 30*p[4, 1] + 24*p[5] One may specify another parent for the result:: sage: F = CombinatorialFreeModule(QQ, Partitions()) sage: P = CyclicPermutationGroup(6).cycle_index(parent = F) sage: 6 * P B[[1, 1, 1, 1, 1, 1]] + B[[2, 2, 2]] + 2*B[[3, 3]] + 2*B[[6]] sage: P.parent() is F True This parent should have a ``term`` and ``sum`` method:: sage: CyclicPermutationGroup(6).cycle_index(parent = QQ) Traceback (most recent call last): ... AssertionError: `parent` should be (or behave as) a free module with basis indexed by partitions REFERENCES: .. [Ker1991] A. Kerber. Algebraic combinatorics via finite group actions, 2.2 p. 70. BI-Wissenschaftsverlag, Mannheim, 1991. AUTHORS: - Nicolas Borie and Nicolas M. Thiery TESTS:: sage: P = PermutationGroup([]); P Permutation Group with generators [()] sage: P.cycle_index() p[1] sage: P = PermutationGroup([[(1)]]); P Permutation Group with generators [()] sage: P.cycle_index() p[1] """ from sage.combinat.permutation import Permutation if parent is None: from sage.rings.rational_field import QQ from sage.combinat.sf.sf import SymmetricFunctions parent = SymmetricFunctions(QQ).powersum() else: assert hasattr(parent, "term") and hasattr(parent, "sum"), \ "`parent` should be (or behave as) a free module with basis indexed by partitions" base_ring = parent.base_ring() from sage.interfaces.gap import gap CC = ([Permutation(self(C.Representative())).cycle_type(), base_ring(C.Size())] for C in gap(self).ConjugacyClasses()) return parent.sum( parent.term( partition, coeff ) for (partition, coeff) in CC)/self.cardinality() | def example(self): """ Returns an example of finite permutation group, as per :meth:`Category.example`. | ca9bebe2b3aab51b8e131e27d8020ae4121f4b93 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/ca9bebe2b3aab51b8e131e27d8020ae4121f4b93/finite_permutation_groups.py |
To see a list of all word constructors, type "words." and then | To see a list of all word constructors, type ``words.`` and then | def __new__(cls, *args, **kwds): r""" TEST: sage: from sage.combinat.words.word_generators import ChristoffelWord_Lower sage: w = ChristoffelWord_Lower(1,0); w doctest:1: DeprecationWarning: ChristoffelWord_Lower is deprecated, use LowerChristoffelWord instead word: 1 """ from sage.misc.misc import deprecation deprecation("ChristoffelWord_Lower is deprecated, use LowerChristoffelWord instead") return LowerChristoffelWord.__new__(cls, *args, **kwds) | 7dc11f32f8d3378d59dc015acd15e327a01e4eec /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/7dc11f32f8d3378d59dc015acd15e327a01e4eec/word_generators.py |
This function is an automatic generated pexpect wrapper around the Singular | This function is an automatically generated pexpect wrapper around the Singular | def _sage_doc_(self): """ EXAMPLES:: | bbe79acf173957c802cb14a22ed39e76c62398c7 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/bbe79acf173957c802cb14a22ed39e76c62398c7/singular.py |
module.include_dirs.append(sage_inc) | def add_base_flags(module): incdirs = filter(os.path.exists, [os.path.join(p, 'include') for p in basedir[sys.platform] ]) libdirs = filter(os.path.exists, [os.path.join(p, 'lib') for p in basedir[sys.platform] ]+ [os.path.join(p, 'lib64') for p in basedir[sys.platform] ] ) module.include_dirs.extend(incdirs) module.include_dirs.append('.') module.include_dirs.append(sage_inc) module.library_dirs.extend(libdirs) module.library_dirs.extend([sage_lib]) | f3295df895aea7d383dd5cd7e643ea00ab239263 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f3295df895aea7d383dd5cd7e643ea00ab239263/setupext.py |
|
module.library_dirs.extend([sage_lib]) | def add_base_flags(module): incdirs = filter(os.path.exists, [os.path.join(p, 'include') for p in basedir[sys.platform] ]) libdirs = filter(os.path.exists, [os.path.join(p, 'lib') for p in basedir[sys.platform] ]+ [os.path.join(p, 'lib64') for p in basedir[sys.platform] ] ) module.include_dirs.extend(incdirs) module.include_dirs.append('.') module.include_dirs.append(sage_inc) module.library_dirs.extend(libdirs) module.library_dirs.extend([sage_lib]) | f3295df895aea7d383dd5cd7e643ea00ab239263 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f3295df895aea7d383dd5cd7e643ea00ab239263/setupext.py |
|
print_message( 'numpy 1.1 or later is required; you have %s' % numpy.__version__) return False | if not int(nn[0]) >= 1: print_message( 'numpy 1.1 or later is required; you have %s' % numpy.__version__) return False | def check_for_numpy(): try: import numpy except ImportError: print_status("numpy", "no") print_message("You must install numpy 1.1 or later to build matplotlib.") return False nn = numpy.__version__.split('.') if not (int(nn[0]) >= 1 and int(nn[1]) >= 1): print_message( 'numpy 1.1 or later is required; you have %s' % numpy.__version__) return False module = Extension('test', []) add_numpy_flags(module) add_base_flags(module) print_status("numpy", numpy.__version__) if not find_include_file(module.include_dirs, os.path.join("numpy", "arrayobject.h")): print_message("Could not find the headers for numpy. You may need to install the development package.") return False return True | f3295df895aea7d383dd5cd7e643ea00ab239263 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f3295df895aea7d383dd5cd7e643ea00ab239263/setupext.py |
tk_lib_dir = tcl_lib_dir.replace('Tcl', 'Tk').replace('tcl', 'tk') | (head, tail) = os.path.split(tcl_lib_dir) tail = tail.replace('Tcl', 'Tk').replace('tcl', 'tk') tk_lib_dir = os.path.join(head, tail) if not os.path.exists(tk_lib_dir): tk_lib_dir = tcl_lib_dir.replace('Tcl', 'Tk').replace('tcl', 'tk') | def query_tcltk(): """Tries to open a Tk window in order to query the Tk object about its library paths. This should never be called more than once by the same process, as Tk intricacies may cause the Python interpreter to hang. The function also has a workaround if no X server is running (useful for autobuild systems).""" global TCL_TK_CACHE # Use cached values if they exist, which ensures this function only executes once if TCL_TK_CACHE is not None: return TCL_TK_CACHE # By this point, we already know that Tkinter imports correctly import Tkinter tcl_lib_dir = '' tk_lib_dir = '' # First try to open a Tk window (requires a running X server) try: tk = Tkinter.Tk() except Tkinter.TclError: # Next, start Tcl interpreter without opening a Tk window (no need for X server) # This feature is available in python version 2.4 and up try: tcl = Tkinter.Tcl() except AttributeError: # Python version not high enough pass except Tkinter.TclError: # Something went wrong while opening Tcl pass else: tcl_lib_dir = str(tcl.getvar('tcl_library')) # Guess Tk location based on Tcl location tk_lib_dir = tcl_lib_dir.replace('Tcl', 'Tk').replace('tcl', 'tk') else: # Obtain Tcl and Tk locations from Tk widget tk.withdraw() tcl_lib_dir = str(tk.getvar('tcl_library')) tk_lib_dir = str(tk.getvar('tk_library')) tk.destroy() # Save directories and version string to cache TCL_TK_CACHE = tcl_lib_dir, tk_lib_dir, str(Tkinter.TkVersion)[:3] return TCL_TK_CACHE | f3295df895aea7d383dd5cd7e643ea00ab239263 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f3295df895aea7d383dd5cd7e643ea00ab239263/setupext.py |
define_macros=[('PY_ARRAYAUNIQUE_SYMBOL', 'MPL_ARRAY_API')]) | define_macros=[('PY_ARRAY_UNIQUE_SYMBOL', 'MPL_ARRAY_API')]) | def build_ft2font(ext_modules, packages): global BUILT_FT2FONT if BUILT_FT2FONT: return # only build it if you you haven't already deps = ['src/ft2font.cpp', 'src/mplutils.cpp'] deps.extend(glob.glob('CXX/*.cxx')) deps.extend(glob.glob('CXX/*.c')) module = Extension('matplotlib.ft2font', deps, define_macros=[('PY_ARRAYAUNIQUE_SYMBOL', 'MPL_ARRAY_API')]) add_ft2font_flags(module) ext_modules.append(module) BUILT_FT2FONT = True | f3295df895aea7d383dd5cd7e643ea00ab239263 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/f3295df895aea7d383dd5cd7e643ea00ab239263/setupext.py |
EXAMPLES: | Load and *execute* the content of ``filename`` in Macaulay2. :param filename: the name of the file to be loaded and executed. :type filename: string :returns: Macaulay2 command loading and executing commands in ``filename``, that is, ``'load "filename"'``. :rtype: string TESTS:: | def _read_in_file_command(self, filename): """ EXAMPLES: sage: from sage.misc.misc import tmp_filename sage: filename = tmp_filename() sage: f = open(filename, "w") sage: f.write("Hello") sage: f.close() sage: command = macaulay2._read_in_file_command(filename) sage: macaulay2.eval(command) #optional Hello sage: import os sage: os.unlink(filename) """ return 'get "%s"'%filename | d6bc649fdd3f63906043d3b39068bfca64befdcc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/d6bc649fdd3f63906043d3b39068bfca64befdcc/macaulay2.py |
sage: f.write("Hello") | sage: f.write("sage_test = 7;") | def _read_in_file_command(self, filename): """ EXAMPLES: sage: from sage.misc.misc import tmp_filename sage: filename = tmp_filename() sage: f = open(filename, "w") sage: f.write("Hello") sage: f.close() sage: command = macaulay2._read_in_file_command(filename) sage: macaulay2.eval(command) #optional Hello sage: import os sage: os.unlink(filename) """ return 'get "%s"'%filename | d6bc649fdd3f63906043d3b39068bfca64befdcc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/d6bc649fdd3f63906043d3b39068bfca64befdcc/macaulay2.py |
Hello | sage: macaulay2.eval("sage_test") 7 | def _read_in_file_command(self, filename): """ EXAMPLES: sage: from sage.misc.misc import tmp_filename sage: filename = tmp_filename() sage: f = open(filename, "w") sage: f.write("Hello") sage: f.close() sage: command = macaulay2._read_in_file_command(filename) sage: macaulay2.eval(command) #optional Hello sage: import os sage: os.unlink(filename) """ return 'get "%s"'%filename | d6bc649fdd3f63906043d3b39068bfca64befdcc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/d6bc649fdd3f63906043d3b39068bfca64befdcc/macaulay2.py |
""" return 'get "%s"'%filename | sage: macaulay2._read_in_file_command("test") 'load "test"' sage: macaulay2(10^10000) == 10^10000 True """ return 'load "%s"' % filename | def _read_in_file_command(self, filename): """ EXAMPLES: sage: from sage.misc.misc import tmp_filename sage: filename = tmp_filename() sage: f = open(filename, "w") sage: f.write("Hello") sage: f.close() sage: command = macaulay2._read_in_file_command(filename) sage: macaulay2.eval(command) #optional Hello sage: import os sage: os.unlink(filename) """ return 'get "%s"'%filename | d6bc649fdd3f63906043d3b39068bfca64befdcc /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/d6bc649fdd3f63906043d3b39068bfca64befdcc/macaulay2.py |
sage: c = c2 = 1 | sage: c == c2 calling __eq__ defined in Metaclass True """ def __eq__(self, other): print "calling __eq__ defined in Metaclass" return (type(self) == type(other)) and (self.reduce_args == other.reduce_args) | def metaclass(name, bases): """ Creates a new class in this metaclass INPUT:: - name: a string - bases: a tuple of classes EXAMPLES:: sage: from sage.misc.test_class_pickling import metaclass, bar sage: c = metaclass("foo2", (object, bar,)) constructing class sage: c <class 'sage.misc.test_class_pickling.foo2'> sage: type(c) <class 'sage.misc.test_class_pickling.Metaclass'> sage: c.__bases__ (<type 'object'>, <class sage.misc.test_class_pickling.bar at ...>) """ print "constructing class" result = Metaclass(name, bases, dict()) result.reduce_args = (name, bases) return result | d70cd18bc305341f145da93bb4ec4e8fd0f4eaf2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/d70cd18bc305341f145da93bb4ec4e8fd0f4eaf2/test_class_pickling.py |
""" | def metaclass(name, bases): """ Creates a new class in this metaclass INPUT:: - name: a string - bases: a tuple of classes EXAMPLES:: sage: from sage.misc.test_class_pickling import metaclass, bar sage: c = metaclass("foo2", (object, bar,)) constructing class sage: c <class 'sage.misc.test_class_pickling.foo2'> sage: type(c) <class 'sage.misc.test_class_pickling.Metaclass'> sage: c.__bases__ (<type 'object'>, <class sage.misc.test_class_pickling.bar at ...>) """ print "constructing class" result = Metaclass(name, bases, dict()) result.reduce_args = (name, bases) return result | d70cd18bc305341f145da93bb4ec4e8fd0f4eaf2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/d70cd18bc305341f145da93bb4ec4e8fd0f4eaf2/test_class_pickling.py |
|
L = [] for k in xrange(icount): L.append(start) start += step if include_endpoint: L.append(end) return L def xsrange(start, end=None, step=1, universe=None, check=True, include_endpoint=False, endpoint_tolerance=1e-5): """ Return an iterator over numbers ``a, a+step, ..., a+k*step``, where ``a+k*step < b`` and ``a+(k+1)*step > b``. INPUT: universe -- Parent or type where all the elements should live (default: deduce from inputs) check -- make sure a, b, and step all lie in the same universe include_endpoint -- whether or not to include the endpoint (default: False) endpoint_tolerance -- used to determine whether or not the endpoint is hit for inexact rings (default 1e-5) - ``a`` - number - ``b`` - number - ``step`` - number (default: 1) OUTPUT: iterator Unlike range, a and b can be any type of numbers, and the resulting iterator involves numbers of that type. .. seealso:: :func:`srange` .. note:: This function is called ``xsrange`` to distinguish it from the builtin Python ``xrange`` command. EXAMPLES:: sage: list(xsrange(1,10)) [1, 2, 3, 4, 5, 6, 7, 8, 9] sage: Q = RationalField() sage: list(xsrange(1, 10, Q('1/2'))) [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2] sage: list(xsrange(1, 5, 0.5)) [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] sage: list(xsrange(0, 1, 0.4)) [0.000000000000000, 0.400000000000000, 0.800000000000000] Negative ranges are also allowed:: sage: list(xrange(4,1,-1)) [4, 3, 2] sage: list(sxrange(4,1,-1)) [4, 3, 2] sage: list(sxrange(4,1,-1/2)) [4, 7/2, 3, 5/2, 2, 3/2] """ from sage.structure.sequence import Sequence from sage.rings.all import ZZ if end is None: end = start start = 0 if check: if universe is None: universe = Sequence([start, end, step]).universe() start, end, step = universe(start), universe(end), universe(step) if universe in [int, long, ZZ]: if include_endpoint and (end-start) % step == 0: end += step include_endpoint = False if universe is not ZZ: return xrange(start, end, step) count = (end-start)/step if universe is long or not isinstance(universe, type) and universe.is_exact(): icount = int(math.ceil(float(count))) if icount != count: include_endpoint = False else: icount = int(math.ceil(float(count) - endpoint_tolerance)) if abs(float(count) - icount) > endpoint_tolerance: include_endpoint = False | def srange(start, end=None, step=1, universe=None, check=True, include_endpoint=False, endpoint_tolerance=1e-5): r""" Return list of numbers ``a, a+step, ..., a+k*step``, where ``a+k*step < b`` and ``a+(k+1)*step >= b`` over exact rings, and makes a best attempt for inexact rings (see note below). This provides one way to iterate over Sage integers as opposed to Python int's. It also allows you to specify step sizes for such an iteration. Note, however, that what is returned is a full list of Integers and not an iterator. It is potentially much slower than the Python range function, depending on the application. The function xsrange() provides an iterator with similar functionality which would usually be more efficient than using srange(). INPUT: - ``a`` - number - ``b`` - number (default: None) - ``step`` - number (default: 1) - ``universe`` - Parent or type where all the elements should live (default: deduce from inputs) - ``check`` - make sure a, b, and step all lie in the same universe - ``include_endpoint`` - whether or not to include the endpoint (default: False) - ``endpoint_tolerance`` - used to determine whether or not the endpoint is hit for inexact rings (default 1e-5) OUTPUT: - list If b is None, then b is set equal to a and a is set equal to the 0 in the parent of b. Unlike range, a and b can be any type of numbers, and the resulting list involves numbers of that type. .. note:: The list elements are computed via repeated addition rather than multiplication, which may produce slightly different results with inexact rings. For example:: sage: sum([1.1] * 10) == 1.1 * 10 False Also, the question of whether the endpoint is hit exactly for a given ``a + k*step`` is fuzzy for an inexact ring. If ``a + k*step = b`` for some k within ``endpoint_tolerance`` of being integral, it is considered an exact hit, thus avoiding spurious values falling just below the endpoint. .. note:: This function is called ``srange`` to distinguish it from the built-in Python ``range`` command. The s at the beginning of the name stands for "Sage". .. seealso: :func:`xsrange` -- iterator version EXAMPLES:: sage: v = srange(5); v [0, 1, 2, 3, 4] sage: type(v[2]) <type 'sage.rings.integer.Integer'> sage: srange(1, 10) [1, 2, 3, 4, 5, 6, 7, 8, 9] sage: srange(10, 1, -1) [10, 9, 8, 7, 6, 5, 4, 3, 2] sage: srange(10,1,-1, include_endpoint=True) [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] sage: srange(1, 10, universe=RDF) [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0] sage: srange(1, 10, 1/2) [1, 3/2, 2, 5/2, 3, 7/2, 4, 9/2, 5, 11/2, 6, 13/2, 7, 15/2, 8, 17/2, 9, 19/2] sage: srange(1, 5, 0.5) [1.00000000000000, 1.50000000000000, 2.00000000000000, 2.50000000000000, 3.00000000000000, 3.50000000000000, 4.00000000000000, 4.50000000000000] sage: srange(0, 1, 0.4) [0.000000000000000, 0.400000000000000, 0.800000000000000] sage: srange(1.0, 5.0, include_endpoint=True) [1.00000000000000, 2.00000000000000, 3.00000000000000, 4.00000000000000, 5.00000000000000] sage: srange(1.0, 1.1) [1.00000000000000] sage: srange(1.0, 1.0) [] sage: V = VectorSpace(QQ, 2) sage: srange(V([0,0]), V([5,5]), step=V([2,2])) [(0, 0), (2, 2), (4, 4)] Including the endpoint:: sage: srange(0, 10, step=2, include_endpoint=True) [0, 2, 4, 6, 8, 10] sage: srange(0, 10, step=3, include_endpoint=True) [0, 3, 6, 9] Try some inexact rings:: sage: srange(0.5, 1.1, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.8, 0.9, 1.0] sage: srange(0.5, 1, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.8, 0.9] sage: srange(0.5, 0.9, 0.1, universe=RDF, include_endpoint=False) [0.5, 0.6, 0.7, 0.8] sage: srange(0, 1.1, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1] sage: srange(0, 0.2, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2] sage: srange(0, 0.3, 0.1, universe=RDF, include_endpoint=True) [0.0, 0.1, 0.2, 0.3] """ from sage.structure.sequence import Sequence from sage.rings.all import ZZ if end is None: end = start start = 0 if check: if universe is None: universe = Sequence([start, end, step]).universe() start, end, step = universe(start), universe(end), universe(step) if universe in [int, long, ZZ]: if include_endpoint and (end-start) % step == 0: end += step if universe is ZZ: return ZZ.range(start, end, step) else: # universe is int or universe is long: return range(start, end, step) count = (end-start)/step if not isinstance(universe, type) and universe.is_exact(): icount = int(math.ceil(float(count))) if icount != count: include_endpoint = False else: icount = int(math.ceil(float(count) - endpoint_tolerance)) if abs(float(count) - icount) > endpoint_tolerance: include_endpoint = False L = [] for k in xrange(icount): L.append(start) start += step if include_endpoint: L.append(end) return L | 20ebd212371c8f080196f4eda13fdbd0a7b6d5e2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/20ebd212371c8f080196f4eda13fdbd0a7b6d5e2/misc.py |
|
cur = start for k in xrange(icount): yield cur cur += step if include_endpoint: yield end | if icount >=0: cur = start for k in xrange(icount): yield cur cur += step if include_endpoint: yield end | def generic_xsrange(): cur = start for k in xrange(icount): yield cur cur += step if include_endpoint: yield end | 20ebd212371c8f080196f4eda13fdbd0a7b6d5e2 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/9417/20ebd212371c8f080196f4eda13fdbd0a7b6d5e2/misc.py |
self.data = self._fixAxes(data.astype(np.uint8)) | self.data = self._fixAxes(data) | def _newVolume(self,data,copyFrom=None,rescale=True): """Takes a numpy array and makes a geoprobe volume. This volume can then be written to disk using the write() method.""" | 6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092/volume.py |
"""Writes a geoprobe volume to disk using memmapped arrays""" | """Writes a geoprobe volume to disk.""" | def write(self, filename): """Writes a geoprobe volume to disk using memmapped arrays""" # Write header values self._infile = BinaryFile(filename, 'w') for varname, info in _headerDef.iteritems(): value = getattr(self, varname, info['default']) self._infile.seek(info['offset']) self._infile.writeBinary(info['type'], value) | 6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092/volume.py |
self._infile = BinaryFile(filename, 'w') | outfile = BinaryFile(filename, 'w') | def write(self, filename): """Writes a geoprobe volume to disk using memmapped arrays""" # Write header values self._infile = BinaryFile(filename, 'w') for varname, info in _headerDef.iteritems(): value = getattr(self, varname, info['default']) self._infile.seek(info['offset']) self._infile.writeBinary(info['type'], value) | 6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092/volume.py |
self._infile.seek(info['offset']) self._infile.writeBinary(info['type'], value) self._infile.seek(_headerLength) self.data.ravel('F').tofile(self._infile, format='B') self._infile.close() | outfile.seek(info['offset']) outfile.writeBinary(info['type'], value) outfile.seek(_headerLength) self.data.T.tofile(outfile, format='B') outfile.close() | def write(self, filename): """Writes a geoprobe volume to disk using memmapped arrays""" # Write header values self._infile = BinaryFile(filename, 'w') for varname, info in _headerDef.iteritems(): value = getattr(self, varname, info['default']) self._infile.seek(info['offset']) self._infile.writeBinary(info['type'], value) | 6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092/volume.py |
newData = np.asarray(newData).astype(np.uint8) | newData = np.asarray(newData, dtype=np.uint8) | def _setData(self, newData): newData = np.asarray(newData).astype(np.uint8) try: self._nx, self._ny, self._nz = newData.shape except ValueError, AttributeError: raise TypeError('Data must be a 3D numpy array') # We don't update dv and d0 here. This is to avoid overwriting the "real" # dv and d0 when you're manipulating the data in some way. When making a # new volume object from an existing numpy array (in _newVolume), dv and d0 are set self._data = newData | 6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6dc8a94ae9d8ef661f2e32f2d35d1a1f96340092/volume.py |
self.data = self._file.read() | self.data = self._file.read_all() | def _readHorizon(self,filename): self._file = HorizonFile(filename, 'r') | c4d19988bf93cda0175cd909647976ef228ad58f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/c4d19988bf93cda0175cd909647976ef228ad58f/horizon.py |
def read(self): | def read_all(self): | def read(self): """ Reads in the entire horizon file and returns a numpy array with the fields ('x', 'y', 'z', 'conf', 'type', 'herid', 'tileSize') for each point in the horizon. """ # Note: The total number of points in the file is not directly stored # on disk. Therefore, we must read through the entire file, store # each section's points in a list, and then create a contigious array # from them. Using numpy.append is much simpler, but quite slow. | c4d19988bf93cda0175cd909647976ef228ad58f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/c4d19988bf93cda0175cd909647976ef228ad58f/horizon.py |
(self.originalNx, self.originalNy, self.originalNz) = data.shape | (self.originalnx, self.originalny, self.originalnz) = data.shape | def _newVolume(self,data,copyFrom=None,rescale=True): """Takes a numpy array and makes a geoprobe volume. This volume can then be written to disk using the write() method.""" | f745519840b98e4706f7c2270367a2d141efbb7c /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/f745519840b98e4706f7c2270367a2d141efbb7c/volume.py |
self.x = self.data['x'] self.y = self.data['y'] self.z = self.data['z'] | def __init__(self, input): """Takes either a filename or a numpy array""" | 4074ebc8c65d730ea4a2c2df0b470eb33eb5343e /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/4074ebc8c65d730ea4a2c2df0b470eb33eb5343e/horizon.py |
|
surface = kwargs.pop('surface', None), | surface = kwargs.pop('surface', None) | def _parse_new_horizon_input(self, *args, **kwargs): """Parse input when given something other than a filename""" #-- Parse Arguments --------------------------------------------------- if len(args) == 1: # Assume argument is data (numpy array with dtype of _point_dtype) self.data = self._ensure_correct_dtype(args[0]) self.surface = self.data elif len(args) == 2: # Assume arguments are surface + lines init_from_surface_lines(self, surface=args[0], lines=args[1]) | 755fec4c82b51a78f3784962a0e5c98c795c584a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/755fec4c82b51a78f3784962a0e5c98c795c584a/horizon.py |
grid = np.ones((self.y.ptp() + 1, self.x.ptp() +1 ), dtype=np.float32) | x, y, z = self.x, self.y, self.z grid = np.ones((y.ptp() + 1, x.ptp() +1 ), dtype=np.float32) | def _get_grid(self): """An nx by ny numpy array (dtype=float32) of the z values contained in the horizon file""" grid = np.ones((self.y.ptp() + 1, self.x.ptp() +1 ), dtype=np.float32) grid *= self.nodata I = np.array(self.x - self.xmin, dtype=np.int) J = np.array(self.y - self.ymin, dtype=np.int) for k in xrange(I.size): i, j, d = I[k], J[k], self.z[k] grid[j,i] = d return grid | a146a41636dcdfd374d5fba306147e4067b66367 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/a146a41636dcdfd374d5fba306147e4067b66367/horizon.py |
I = np.array(self.x - self.xmin, dtype=np.int) J = np.array(self.y - self.ymin, dtype=np.int) | I = np.array(x - x.min(), dtype=np.int) J = np.array(y - y.min(), dtype=np.int) | def _get_grid(self): """An nx by ny numpy array (dtype=float32) of the z values contained in the horizon file""" grid = np.ones((self.y.ptp() + 1, self.x.ptp() +1 ), dtype=np.float32) grid *= self.nodata I = np.array(self.x - self.xmin, dtype=np.int) J = np.array(self.y - self.ymin, dtype=np.int) for k in xrange(I.size): i, j, d = I[k], J[k], self.z[k] grid[j,i] = d return grid | a146a41636dcdfd374d5fba306147e4067b66367 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/a146a41636dcdfd374d5fba306147e4067b66367/horizon.py |
i, j, d = I[k], J[k], self.z[k] | i, j, d = I[k], J[k], z[k] | def _get_grid(self): """An nx by ny numpy array (dtype=float32) of the z values contained in the horizon file""" grid = np.ones((self.y.ptp() + 1, self.x.ptp() +1 ), dtype=np.float32) grid *= self.nodata I = np.array(self.x - self.xmin, dtype=np.int) J = np.array(self.y - self.ymin, dtype=np.int) for k in xrange(I.size): i, j, d = I[k], J[k], self.z[k] grid[j,i] = d return grid | a146a41636dcdfd374d5fba306147e4067b66367 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/a146a41636dcdfd374d5fba306147e4067b66367/horizon.py |
volID = testvol.magic | volID = testvol.magicNum | def isValidVolume(filename): """Tests whether a filename is a valid geoprobe file. Returns boolean True/False.""" try: testvol = vol(filename) except: return False volID = testvol.magic volSize = os.stat(filename).st_size predSize = testvol.nx*testvol.ny*testvol.nz + _headerLength # VolID == 43970 is a version 2 geoprobe volume (The only type currently supported) if (volID!=43970) or (volSize!=predSize): return False else: return True | c76c117f11480b602bba7866a81841bbd5e87a36 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/c76c117f11480b602bba7866a81841bbd5e87a36/volume.py |
vol = geoprobe.volume('data/Volumes/example.vol') | vol = geoprobe.volume(datadir + 'Volumes/example.vol') | def main(): # Read an existing geoprobe volume vol = geoprobe.volume('data/Volumes/example.vol') # Print some info print_info(vol) # Example plots plot(vol) | bb98e94dcf6ad31ce64250c1a886f032a06c4407 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/bb98e94dcf6ad31ce64250c1a886f032a06c4407/basic_volume_usage.py |
return self.cached_value | value = self.cached_value() if value is None: raise AttributeError | def __call__(self, *args): try: return self.cached_value except AttributeError: self.cached_value = self.function(*args) return self.cached_value | 7af4f0b8b747f0c4769367e1f28941d2a56f00f3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/7af4f0b8b747f0c4769367e1f28941d2a56f00f3/common.py |
self.cached_value = self.function(*args) return self.cached_value | retval = self.function(*args) self.cached_value = weakref.ref(retval) value = self.cached_value() return value | def __call__(self, *args): try: return self.cached_value except AttributeError: self.cached_value = self.function(*args) return self.cached_value | 7af4f0b8b747f0c4769367e1f28941d2a56f00f3 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/7af4f0b8b747f0c4769367e1f28941d2a56f00f3/common.py |
init_from_xyz(self, *args) | self._init_from_xyz(self, *args) | def _parse_new_horizon_input(self, *args, **kwargs): """Parse input when given something other than a filename""" #-- Parse Arguments --------------------------------------------------- if len(args) == 1: # Assume argument is data (numpy array with dtype of _point_dtype) self.data = self._ensure_correct_dtype(args[0]) self.surface = self.data elif len(args) == 2: # Assume arguments are surface + lines init_from_surface_lines(self, surface=args[0], lines=args[1]) | 2c4f317b90517f552811ee955fedd2846f2dbf5a /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/2c4f317b90517f552811ee955fedd2846f2dbf5a/horizon.py |
dtype = [('x', '>f4'), ('y', '>f4'), ('traces', '%i>u1'%self._numSamples)] | dtype = [('x', '>f4'), ('y', '>f4'), ('tracenum', '>f4'), ('traces', '%i>u1'%self._numSamples)] | def _readTraces(self): dtype = [('x', '>f4'), ('y', '>f4'), ('traces', '%i>u1'%self._numSamples)] self._infile.seek(_headerLength) data = np.fromfile(self._infile, dtype=dtype, count=self._numTraces) self.x = data['x'] self.y = data['y'] self.data = data['traces'] | 66d28608b523552b920be74a0bf8dda177a4322b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/66d28608b523552b920be74a0bf8dda177a4322b/data2d.py |
data = data.strip('\x00') | item = item.strip('\x00') | def readBinary(self,fmt): """ Read and unpack a binary value from the file based on string fmt (see the struct module for details). """ size = struct.calcsize(fmt) data = self.read(size) # Reading beyond the end of the file just returns '' if len(data) != size: raise EOFError('End of file reached') data = struct.unpack(fmt, data) | 4bcdf1a1a693fab2774834b6b5c53cf1dde361eb /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/4bcdf1a1a693fab2774834b6b5c53cf1dde361eb/common.py |
return subVolume | return subVolume.squeeze() | def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizon(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes nodata = depth != hor.nodata depth[nodata] -= vol.zmin depth[nodata] /= abs(vol.dz) depth = depth.astype(np.int) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast window_size = upper + lower + 1 subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] return subVolume | d3a904dc4e287886507aef7deecd329a599f591f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/d3a904dc4e287886507aef7deecd329a599f591f/utilities.py |
grid = self.nodata*np.ones((self.data.y.ptp()+1,self.data.x.ptp()+1),dtype=np.float32) | grid = self.nodata*np.ones((self.y.ptp()+1,self.x.ptp()+1),dtype=np.float32) | def _get_grid(self): """An nx by ny numpy array (dtype=float32) of the z values contained in the horizon file""" try: return self._grid except AttributeError: grid = self.nodata*np.ones((self.data.y.ptp()+1,self.data.x.ptp()+1),dtype=np.float32) I = np.array(self.x-self.xmin,np.int) J = np.array(self.y-self.ymin,np.int) for k in xrange(I.size): i,j,d = I[k],J[k],self.z[k] grid[j,i] = d self._grid = grid return grid | 1629a37de552a7d5be55362e6294b4421de903ed /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/1629a37de552a7d5be55362e6294b4421de903ed/horizon.py |
self._file = _horizonFile(filename, 'r') | self._file = HorizonFile(filename, 'r') | def _readHorizon(self,filename): self._file = _horizonFile(filename, 'r') | 8a264e6f2ba6be78ab4f925241fd8d2ac7de1b8b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/8a264e6f2ba6be78ab4f925241fd8d2ac7de1b8b/horizon.py |
self._dtype = [] for name, fmt in zip(_pointNames, _pointFormat): self._dtype.append((name,fmt)) | self.point_dtype = [] for name, fmt in zip(self._pointNames, self._pointFormat): self.point_dtype.append((name,fmt)) | def __init__(self, *args, **kwargs): """Accepts the same argument set as a standard python file object""" # Initalize the file object as normal file.__init__(self, *args, **kwargs) | 8a264e6f2ba6be78ab4f925241fd8d2ac7de1b8b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/8a264e6f2ba6be78ab4f925241fd8d2ac7de1b8b/horizon.py |
self._pointSize = sum(map(struct.calcsize, _pointFormat)) | self._pointSize = sum(map(struct.calcsize, self._pointFormat)) | def __init__(self, *args, **kwargs): """Accepts the same argument set as a standard python file object""" # Initalize the file object as normal file.__init__(self, *args, **kwargs) | 8a264e6f2ba6be78ab4f925241fd8d2ac7de1b8b /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/8a264e6f2ba6be78ab4f925241fd8d2ac7de1b8b/horizon.py |
Ypos = self.model2index(Ypos) | Ypos = self.model2index(Ypos, axis='y') | def YSlice(self, Ypos): """Takes a slice of the volume at a constant y-value (i.e. the slice is in the direction of the x-axis) This is a convience function to avoid calling volume.model2index before slicing and transposing (for easier plotting) after. Input: Ypos: Y-Value given in model coordinates Output: A 2D (NZ x NX) numpy array""" Ypos = self.model2index(Ypos) return self.data[:,Ypos,:].transpose() | 2dc4da754117039ce86cc20ca029f51a0ab6d79f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/2dc4da754117039ce86cc20ca029f51a0ab6d79f/volume.py |
Zpos = self.model2index(Zpos) | Zpos = self.model2index(Zpos, axis='z') | def ZSlice(self, Zpos): """Takes a slice of the volume at a constant z-value (i.e. a depth slice) This is a convience function to avoid calling volume.model2index before slicing and transposing (for easier plotting) after. Input: Zpos: Z-Value given in model coordinates Output: A 2D (NY x NX) numpy array""" Zpos = self.model2index(Zpos) return self.data[:,:,Zpos].transpose() | 2dc4da754117039ce86cc20ca029f51a0ab6d79f /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/2dc4da754117039ce86cc20ca029f51a0ab6d79f/volume.py |
elif ('surface' in kwargs) and ('lines' in kwargs): self._init_from_surface_lines(kwargs['surface'], kwargs['lines']) elif 'surface' in kwargs: self._init_from_surface_lines(surface=surface) elif 'lines' in kwargs: self._init_from_surface_lines(lines=lines) | elif ('surface' in kwargs) or ('lines' in kwargs): surface, lines = kwargs.pop('surface', None), kwargs.pop('lines', None) self._init_from_surface_lines(surface, lines) | def _parse_new_horizon_input(self, *args, **kwargs): """Parse input when given something other than a filename""" #-- Parse Arguments --------------------------------------------------- if len(args) == 0: pass elif len(args) == 1: # Assume argument is data (numpy array with dtype of _point_dtype) self.data = np.asarray(args[0], dtype=_point_dtype) self.surface = self.data elif len(args) == 2: # Assume arguments are surface + lines init_from_surface_lines(self, surface=args[0], lines=args[1]) | 711be31cd41013081068ef642983ee598c872e38 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/711be31cd41013081068ef642983ee598c872e38/horizon.py |
def init_from_surface_lines(self, surface=None, lines=None): | def _init_from_surface_lines(self, surface=None, lines=None): | def init_from_surface_lines(self, surface=None, lines=None): """Make a new horizon object from either a surface array or a list of line arrays""" if surface is not None: surface = np.asarray(surface, dtype=_point_dtype) | 711be31cd41013081068ef642983ee598c872e38 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/711be31cd41013081068ef642983ee598c872e38/horizon.py |
self.lines.append(info, data[i:i+item.size]) | self.lines.append((info, self.data[i:i+item.size])) i += item.size | def init_from_surface_lines(self, surface=None, lines=None): """Make a new horizon object from either a surface array or a list of line arrays""" if surface is not None: surface = np.asarray(surface, dtype=_point_dtype) | 711be31cd41013081068ef642983ee598c872e38 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/711be31cd41013081068ef642983ee598c872e38/horizon.py |
if numPoints > 0: points = np.fromfile(self, count=numPoints, dtype=self.point_dtype) return points else: return [] | points = np.fromfile(self, count=numPoints, dtype=self.point_dtype) return points | def readPoints(self): numPoints = self.readBinary('>I') if numPoints > 0: points = np.fromfile(self, count=numPoints, dtype=self.point_dtype) return points # apparently, len(points) is not 0 when numPoints is 0... else: return [] | 12b694e913b9b7fa035609605ead508b5355d270 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/12b694e913b9b7fa035609605ead508b5355d270/horizon.py |
def sectionType(self): # No idea what the difference between #34 and #28, #2, etc is... (pos, neg, 0, pick??) secFmt = '>I' secID = self.readBinary(secFmt) if secID == 19: sectype = 'Points' else: sectype = 'Lines' return sectype | 12b694e913b9b7fa035609605ead508b5355d270 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/12b694e913b9b7fa035609605ead508b5355d270/horizon.py |
||
self.readHeader() lines = [] secType = None self.readHeader() | self.readHeader() | def points(self): """A numpy array with the fields ('x', 'y', 'z', 'conf', 'type', 'herid', 'tileSize') for each point in the horizon (regardless of whehter it's a manual pick (line) or surface)""" self.readHeader() # Initalize an empty recarray to store things in lines = [] # To store line objects in secType = None self.readHeader() # Jump to start of file, past header | 12b694e913b9b7fa035609605ead508b5355d270 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/12b694e913b9b7fa035609605ead508b5355d270/horizon.py |
points = self.readPoints() | temp_points = [self.readPoints()] | def points(self): """A numpy array with the fields ('x', 'y', 'z', 'conf', 'type', 'herid', 'tileSize') for each point in the horizon (regardless of whehter it's a manual pick (line) or surface)""" self.readHeader() # Initalize an empty recarray to store things in lines = [] # To store line objects in secType = None self.readHeader() # Jump to start of file, past header | 12b694e913b9b7fa035609605ead508b5355d270 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/12b694e913b9b7fa035609605ead508b5355d270/horizon.py |
lines.append((lineInfo, currentPoints)) np.append(points, currentPoints) | temp_points.append(currentPoints) | def points(self): """A numpy array with the fields ('x', 'y', 'z', 'conf', 'type', 'herid', 'tileSize') for each point in the horizon (regardless of whehter it's a manual pick (line) or surface)""" self.readHeader() # Initalize an empty recarray to store things in lines = [] # To store line objects in secType = None self.readHeader() # Jump to start of file, past header | 12b694e913b9b7fa035609605ead508b5355d270 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/12b694e913b9b7fa035609605ead508b5355d270/horizon.py |
pass self.lines = lines | pass numpoints = sum(map(np.size, temp_points)) points = np.zeros(numpoints, dtype=self.point_dtype) i = 0 for item in temp_points: points[i : i + item.size] = item i += item.size | def points(self): """A numpy array with the fields ('x', 'y', 'z', 'conf', 'type', 'herid', 'tileSize') for each point in the horizon (regardless of whehter it's a manual pick (line) or surface)""" self.readHeader() # Initalize an empty recarray to store things in lines = [] # To store line objects in secType = None self.readHeader() # Jump to start of file, past header | 12b694e913b9b7fa035609605ead508b5355d270 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/12b694e913b9b7fa035609605ead508b5355d270/horizon.py |
hor = horizion(hor) | hor = horizon(hor) | def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizion(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes nodata = depth != hor.nodata depth[nodata] -= vol.zmin depth[nodata] /= abs(vol.dz) depth = depth.astype(np.int) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast window_size = upper + lower + 1 subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] return subVolume | 6ad5ce7deaf76daf0f8a485426a4b9dc15b4ead0 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6ad5ce7deaf76daf0f8a485426a4b9dc15b4ead0/utilities.py |
value = value + (n-1) * d | value = value + (n-1) * abs(d) | def _setVolumeBound(self, value, axis, max=True): axisLetter = ['x','y','z'][axis] n = [self.nx, self.ny, self.nz][axis] d = [self.dx, self.dy, self.dz][axis] offset = [self.x0, self.y0, self.z0][axis] if ((max is True) & (d>0)) or ((max is False) & (d<0)): value = value + (n-1) * d setattr(self, axisLetter+'0', value) | 895b589400a4e8e2f8e8415c1f96c01f25bd52e0 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/895b589400a4e8e2f8e8415c1f96c01f25bd52e0/volume.py |
self._pointSize = struct.calcsize(''.join(_pointFormat)) | self._pointSize = sum(map(struct.calcsize, _pointFormat)) | def __init__(self, *args, **kwargs): """Accepts the same argument set as a standard python file object""" # Initalize the file object as normal file.__init__(self, *args, **kwargs) | 87c3ea8635b85e50ecc59f38a939297921968c20 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/87c3ea8635b85e50ecc59f38a939297921968c20/horizon.py |
self._init_from_xyz(self, *args) | self._init_from_xyz(*args) | def _parse_new_horizon_input(self, *args, **kwargs): """Parse input when given something other than a filename""" #-- Parse Arguments --------------------------------------------------- if len(args) == 1: # Assume argument is data (numpy array with dtype of _point_dtype) self.data = self._ensure_correct_dtype(args[0]) self.surface = self.data elif len(args) == 2: # Assume arguments are surface + lines init_from_surface_lines(self, surface=args[0], lines=args[1]) | a2cc696bd5c4f45ad4388fa30e5eca52c92a59c8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/a2cc696bd5c4f45ad4388fa30e5eca52c92a59c8/horizon.py |
self.surface = data | self.surface = self.data | def _init_from_xyz(self, x, y, z): """Make a new horizon object from x, y, and z arrays""" x,y,z = [np.asarray(item, dtype=np.float32) for item in [x,y,z]] if x.size == y.size == z.size: self.data = np.zeros(x.size, dtype=self.POINT_DTYPE) self.x = x self.y = y self.z = z self.surface = data else: raise ValueError('x, y, and z arrays must be the same length') | a2cc696bd5c4f45ad4388fa30e5eca52c92a59c8 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/a2cc696bd5c4f45ad4388fa30e5eca52c92a59c8/horizon.py |
self.data = self._file.read_all() | self.data = self._file.read() | def _readHorizon(self,filename): self._file = HorizonFile(filename, 'r') | 147335947f0d0b7d637daf9d3f674676e5230f23 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/147335947f0d0b7d637daf9d3f674676e5230f23/horizon.py |
print 'Setting!' | def _set_grid(self, value): print 'Setting!' self._grid = value | 147335947f0d0b7d637daf9d3f674676e5230f23 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/147335947f0d0b7d637daf9d3f674676e5230f23/horizon.py |
|
def read_all(self): | def read(self): | def read_all(self): """ Reads in the entire horizon file and returns a numpy array with the fields ('x', 'y', 'z', 'conf', 'type', 'herid', 'tileSize') for each point in the horizon. """ # Note: The total number of points in the file is not directly stored # on disk. Therefore, we must read through the entire file, store # each section's points in a list, and then create a contigious array # from them. Using numpy.append is much simpler, but quite slow. | 147335947f0d0b7d637daf9d3f674676e5230f23 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/147335947f0d0b7d637daf9d3f674676e5230f23/horizon.py |
region: (default, full extent of horizion) sub-region to use instead of full extent | region: (default, overlap between horizion and volume) sub-region to use instead of full extent. Must be a 4-tuple of (xmin, xmax, ymin, ymax) | def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None, masked=False): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent masked: (default, False) if True, return a masked array where nodata values in the horizon are masked. Otherwise, return an array where the nodata values are filled with 0. Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizon(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes depth -= vol.zmin depth /= abs(vol.dz) depth = depth.astype(np.int) # Initalize the output array window_size = upper + lower + 1 # Not creating a masked array here due to speed problems when iterating through ma's subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast mask = depth.mask # Need to preserve the mask for later depth = depth.filled() # Iterating through masked arrays is much slower, apparently for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] # If masked is True (input option), return a masked array if masked: nx,ny,nz = subVolume.shape mask = mask.reshape((nx,ny,1)) mask = np.tile(mask, (1,1,nz)) subVolume = np.ma.array(subVolume, mask=mask) # If upper==lower==0, (default) subVolume will be (nx,ny,1), so return 2D array instead subVolume = subVolume.squeeze() return subVolume | dceb3c211f4a1c6f7674a73f1d609f79925468ae /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/dceb3c211f4a1c6f7674a73f1d609f79925468ae/utilities.py |
if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region | vol_extents = [vol.xmin, vol.xmax, vol.ymin, vol.ymax] hor_extents = [hor.xmin, hor.xmax, hor.ymin, hor.ymax] extents = bbox_overlap(hor_extents, vol_extents) if extents is None: raise ValueError('Input horizon and volume do not intersect!') if region is not None: extents = bbox_overlap(extents, region) if extents is None: raise ValueError('Specified region does not overlap with horizon and volume') elif len(extents) != 4: raise ValueError('"extents" must be a 4-tuple of (xmin, xmax, ymin, ymax)') xmin, xmax, ymin, ymax = extents | def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None, masked=False): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent masked: (default, False) if True, return a masked array where nodata values in the horizon are masked. Otherwise, return an array where the nodata values are filled with 0. Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizon(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes depth -= vol.zmin depth /= abs(vol.dz) depth = depth.astype(np.int) # Initalize the output array window_size = upper + lower + 1 # Not creating a masked array here due to speed problems when iterating through ma's subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast mask = depth.mask # Need to preserve the mask for later depth = depth.filled() # Iterating through masked arrays is much slower, apparently for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] # If masked is True (input option), return a masked array if masked: nx,ny,nz = subVolume.shape mask = mask.reshape((nx,ny,1)) mask = np.tile(mask, (1,1,nz)) subVolume = np.ma.array(subVolume, mask=mask) # If upper==lower==0, (default) subVolume will be (nx,ny,1), so return 2D array instead subVolume = subVolume.squeeze() return subVolume | dceb3c211f4a1c6f7674a73f1d609f79925468ae /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/dceb3c211f4a1c6f7674a73f1d609f79925468ae/utilities.py |
def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None, masked=False): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent masked: (default, False) if True, return a masked array where nodata values in the horizon are masked. Otherwise, return an array where the nodata values are filled with 0. Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizon(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes depth -= vol.zmin depth /= abs(vol.dz) depth = depth.astype(np.int) # Initalize the output array window_size = upper + lower + 1 # Not creating a masked array here due to speed problems when iterating through ma's subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast mask = depth.mask # Need to preserve the mask for later depth = depth.filled() # Iterating through masked arrays is much slower, apparently for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] # If masked is True (input option), return a masked array if masked: nx,ny,nz = subVolume.shape mask = mask.reshape((nx,ny,1)) mask = np.tile(mask, (1,1,nz)) subVolume = np.ma.array(subVolume, mask=mask) # If upper==lower==0, (default) subVolume will be (nx,ny,1), so return 2D array instead subVolume = subVolume.squeeze() return subVolume | dceb3c211f4a1c6f7674a73f1d609f79925468ae /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/dceb3c211f4a1c6f7674a73f1d609f79925468ae/utilities.py |
||
def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None, masked=False): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent masked: (default, False) if True, return a masked array where nodata values in the horizon are masked. Otherwise, return an array where the nodata values are filled with 0. Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizon(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes depth -= vol.zmin depth /= abs(vol.dz) depth = depth.astype(np.int) # Initalize the output array window_size = upper + lower + 1 # Not creating a masked array here due to speed problems when iterating through ma's subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast mask = depth.mask # Need to preserve the mask for later depth = depth.filled() # Iterating through masked arrays is much slower, apparently for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] # If masked is True (input option), return a masked array if masked: nx,ny,nz = subVolume.shape mask = mask.reshape((nx,ny,1)) mask = np.tile(mask, (1,1,nz)) subVolume = np.ma.array(subVolume, mask=mask) # If upper==lower==0, (default) subVolume will be (nx,ny,1), so return 2D array instead subVolume = subVolume.squeeze() return subVolume | dceb3c211f4a1c6f7674a73f1d609f79925468ae /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/dceb3c211f4a1c6f7674a73f1d609f79925468ae/utilities.py |
||
def extractWindow(hor, vol, upper=0, lower=None, offset=0, region=None, masked=False): """Extracts a window around a horizion out of a geoprobe volume Input: hor: a geoprobe horizion object or horizion filename vol: a geoprobe volume object or volume filename upper: (default, 0) upper window interval around horizion lower: (default, upper) lower window interval around horizion offset: (default, 0) amount (in voxels) to offset the horizion by along the Z-axis region: (default, full extent of horizion) sub-region to use instead of full extent masked: (default, False) if True, return a masked array where nodata values in the horizon are masked. Otherwise, return an array where the nodata values are filled with 0. Output: returns a numpy volume "flattened" along the horizion """ # If the lower window isn't specified, assume it's equal to the upper window if lower == None: lower=upper # If filenames are input instead of volume/horizion objects, create the objects if type(hor) == type('String'): hor = horizon(hor) if type(vol) == type('String'): vol = volume(vol) #Gah, changed the way hor.grid works... Should probably change it back depth = hor.grid.T # If extents are not set, use the full extent of the horizion (assumes horizion is smaller than volume) if region == None: xmin, xmax, ymin, ymax = hor.xmin, hor.xmax, hor.ymin, hor.ymax else: xmin, xmax, ymin, ymax = region #-- Select region of overlap between volume and horizon # Convert region to volume indicies xstart, ystart = xmin - vol.xmin, ymin - vol.ymin xstop, ystop = xmax - vol.xmin, ymax - vol.ymin # Select only the volume data within the region of interest data = vol.data[xstart:xstop, ystart:ystop, :] # Convert region to horizion grid indicies xstart, ystart = xmin - hor.xmin, ymin - hor.ymin xstop, ystop = xmax - hor.xmin, ymax - hor.ymin # Select only the volume data within the region of interest depth = depth[xstart:xstop, ystart:ystop] nx,ny,nz = data.shape # convert z coords of horizion to volume indexes depth -= vol.zmin depth /= abs(vol.dz) depth = depth.astype(np.int) # Initalize the output array window_size = upper + lower + 1 # Not creating a masked array here due to speed problems when iterating through ma's subVolume = np.zeros((nx,ny,window_size), dtype=np.uint8) # Using fancy indexing to do this uses tons of memory... # As it turns out, simple iteration is much, much more memory efficient, and almost as fast mask = depth.mask # Need to preserve the mask for later depth = depth.filled() # Iterating through masked arrays is much slower, apparently for i in xrange(nx): for j in xrange(ny): if depth[i,j] != hor.nodata: # Where are we in data indicies z = depth[i,j] + offset top = z - upper bottom = z + lower + 1 # Be careful to extract the right vertical region in cases where the # window goes outside the data bounds (find region of overlap) data_top = max([top, 0]) data_bottom = min([bottom, nz]) window_top = max([0, window_size - bottom]) window_bottom = min([window_size, nz - top]) # Extract the window out of data and store it in subVolume subVolume[i,j,window_top:window_bottom] = data[i,j,data_top:data_bottom] # If masked is True (input option), return a masked array if masked: nx,ny,nz = subVolume.shape mask = mask.reshape((nx,ny,1)) mask = np.tile(mask, (1,1,nz)) subVolume = np.ma.array(subVolume, mask=mask) # If upper==lower==0, (default) subVolume will be (nx,ny,1), so return 2D array instead subVolume = subVolume.squeeze() return subVolume | dceb3c211f4a1c6f7674a73f1d609f79925468ae /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/dceb3c211f4a1c6f7674a73f1d609f79925468ae/utilities.py |
||
print extents | def intersects(bbox1, bbox2): # Check for intersection xmin1, xmax1, ymin1, ymax1 = bbox1 xmin2, xmax2, ymin2, ymax2 = bbox2 xdist = abs( (xmin1 + xmax1) / 2.0 - (xmin2 + xmax2) / 2.0 ) ydist = abs( (ymin1 + ymax1) / 2.0 - (ymin2 + ymax2) / 2.0 ) xwidth = (xmax1 - xmin1 + xmax2 - xmin2) / 2.0 ywidth = (ymax1 - ymin1 + ymax2 - ymin2) / 2.0 return (xdist <= xwidth) and (ydist <= ywidth) | 294e07b691aa03e50fb02c6b40e7fd6642ec2ced /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/294e07b691aa03e50fb02c6b40e7fd6642ec2ced/utilities.py |
|
self.x = self.data.x self.y = self.data.y self.z = self.data.z | self.x = self.data['x'] self.y = self.data['y'] self.z = self.data['z'] | def __init__(self, input): """Takes either a filename or a numpy array""" | 6f9825ea37bea9bb989e7d9e97be1c94db41c421 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/10472/6f9825ea37bea9bb989e7d9e97be1c94db41c421/horizon.py |
( (associativity(token) == 'left' and precedence(token) <= ops[-1]) \ or (associativity(token) == 'right' and precedence(token) < ops[-1]) ): | ( (associativity(token) == 'left' and precedence(token) <= precedence(ops[-1])) \ or (associativity(token) == 'right' and precedence(token) < precedence(ops[-1])) ): | def infix_to_prefix(expr): """converts the infix expression to prefix using the shunting yard algorithm""" ops = [] results = [] for token in tokenize(expr): #print ops, results if is_op(token): #If the token is an operator, o1, then: #while there is an operator token, o2, at the top of the stack, and #either o1 is left-associative and its precedence is less than or equal to that of o2, #or o1 is right-associative and its precedence is less than that of o2, #pop o2 off the stack, onto the output queue; #push o1 onto the stack. while len(ops) > 0 and is_op(ops[-1]) and \ ( (associativity(token) == 'left' and precedence(token) <= ops[-1]) \ or (associativity(token) == 'right' and precedence(token) < ops[-1]) ): results.append(ops.pop()) ops.append(token) #If the token is a left parenthesis, then push it onto the stack. elif is_left_paran(token): ops.append(token) #If the token is a right parenthesis: elif is_right_paran(token): #Until the token at the top of the stack is a left parenthesis, pop operators off the stack onto the output queue. while len(ops) > 0 and not is_left_paran(ops[-1]): results.append(ops.pop()) #Pop the left parenthesis from the stack, but not onto the output queue. #If the stack runs out without finding a left parenthesis, then there are mismatched parentheses. if len(ops) == 0: print "error: mismatched parentheses" exit() if is_left_paran(ops[-1]): ops.pop() else: #If the token is a number, then add it to the output queue. results.append(token) #When there are no more tokens to read: #While there are still operator tokens in the stack: while len(ops) > 0: #If the operator token on the top of the stack is a parenthesis, then there are mismatched parentheses. if is_right_paran(ops[-1]) or is_left_paran(ops[-1]): print "error: mismatched parentheses" exit() #Pop the operator onto the output queue. results.append(ops.pop()) return results | e767b12033e64b5042fe38b01fa3dd7f6b9765d9 /local1/tlutelli/issta_data/temp/all_python//python/2010_temp/2010/14576/e767b12033e64b5042fe38b01fa3dd7f6b9765d9/shuntingyard.py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.