Bases: object
Physical field or quantity with units
Physical Fields can be constructed in one of two ways:
PhysicalField(*value*, *unit*), where *value* is a number of arbitrary type and *unit* is a string containing the unit name
>>> print PhysicalField(value = 10., unit = 'm') 10.0 mPhysicalField(*string*), where *string* contains both the value and the unit. This form is provided to make interactive use more convenient
>>> print PhysicalField(value = "10. m") 10.0 m
Dimensionless quantities, with a unit of 1, can be specified in several ways
>>> print PhysicalField(value = "1")
1.0 1
>>> print PhysicalField(value = 2., unit = " ")
2.0 1
>>> print PhysicalField(value = 2.)
2.0 1
Physical arrays are also possible (and are the reason this code was adapted from Konrad Hinsen‘s original PhysicalQuantity). The value can be a Numeric array:
>>> a = numerix.array(((3.,4.),(5.,6.)))
>>> print PhysicalField(value = a, unit = "m")
[[ 3. 4.]
[ 5. 6.]] m
or a tuple:
>>> print PhysicalField(value = ((3.,4.),(5.,6.)), unit = "m")
[[ 3. 4.]
[ 5. 6.]] m
or as a single value to be applied to every element of a supplied array:
>>> print PhysicalField(value = 2., unit = "m", array = a)
[[ 2. 2.]
[ 2. 2.]] m
Every element in an array has the same unit, which is stored only once for the whole array.
Add two physical quantities, so long as their units are compatible. The unit of the result is the unit of the first operand.
>>> print PhysicalField(10., 'km') + PhysicalField(10., 'm')
10.01 km
>>> print PhysicalField(10., 'km') + PhysicalField(10., 'J')
Traceback (most recent call last):
...
TypeError: Incompatible units
This function tests whether or not self and other are equal subject to the given relative and absolute tolerances. The formula used is:
| self - other | < atol + rtol * | other |
This means essentially that both elements are small compared to atol or their difference divided by other‘s value is small compared to rtol.
This function tests whether or not self and other are exactly equal.
Return the inverse cosine of the PhysicalField in radians
>>> print PhysicalField(0).arccos().allclose("1.57079632679 rad")
1
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1 m").arccos(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the inverse hyperbolic cosine of the PhysicalField
>>> print numerix.allclose(PhysicalField(2).arccosh(),
... 1.31695789692)
1
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1. m").arccosh(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the inverse sine of the PhysicalField in radians
>>> print PhysicalField(1).arcsin().allclose("1.57079632679 rad")
1
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1 m").arcsin(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the arctangent of the PhysicalField in radians
>>> print numerix.round_(PhysicalField(1).arctan(), 6)
0.785398
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1 m").arctan(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the arctangent of self divided by other in radians
>>> print numerix.round_(PhysicalField(2.).arctan2(PhysicalField(5.)), 6)
0.380506
The input PhysicalField objects must be in the same dimensions
>>> print numerix.round_(PhysicalField(2.54, "cm").arctan2(PhysicalField(1., "inch")), 6)
0.785398
>>> print numerix.round_(PhysicalField(2.).arctan2(PhysicalField("5. m")), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the inverse hyperbolic tangent of the PhysicalField
>>> print PhysicalField(0.5).arctanh()
0.549306144334
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1 m").arctanh(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the smallest integer greater than or equal to the PhysicalField.
>>> print PhysicalField(2.2,"m").ceil()
3.0 m
Return the complex conjugate of the PhysicalField.
>>> print PhysicalField(2.2 - 3j,"ohm").conjugate() == PhysicalField(2.2 + 3j,"ohm")
True
Changes the unit to unit and adjusts the value such that the combination is equivalent. The new unit is by a string containing its name. The new unit must be compatible with the previous unit of the object.
>>> e = PhysicalField('2.7 Hartree*Nav')
>>> e.convertToUnit('kcal/mol')
>>> print e
1694.27557621 kcal/mol
Make a duplicate.
>>> a = PhysicalField(1, unit = 'inch')
>>> b = a.copy()
The duplicate will not reflect changes made to the original
>>> a.convertToUnit('cm')
>>> print a
2.54 cm
>>> print b
1 inch
Likewise for arrays
>>> a = PhysicalField(numerix.array((0,1,2)), unit = 'm')
>>> b = a.copy()
>>> a[0] = 3
>>> print a
[3 1 2] m
>>> print b
[0 1 2] m
Return the cosine of the PhysicalField
>>> print numerix.round_(PhysicalField(2*numerix.pi/6,"rad").cos(), 6)
0.5
>>> print numerix.round_(PhysicalField(60.,"deg").cos(), 6)
0.5
The units of the PhysicalField must be an angle
>>> PhysicalField(60.,"m").cos()
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the hyperbolic cosine of the PhysicalField
>>> PhysicalField(0.).cosh()
1.0
The units of the PhysicalField must be dimensionless
>>> PhysicalField(60.,"m").cosh()
Traceback (most recent call last):
...
TypeError: Incompatible units
Divide two physical quantities. The unit of the result is the unit of the first operand divided by the unit of the second.
>>> print PhysicalField(10., 'm') / PhysicalField(2., 's')
5.0 m/s
As a special case, if the result is dimensionless, the value is returned without units, rather than with a dimensionless unit of 1. This facilitates passing physical quantities to packages such as Numeric that cannot use units, while ensuring the quantities have the desired units
>>> print (PhysicalField(1., 'inch')
... / PhysicalField(1., 'mm'))
25.4
Return the dot product of self with other. The resulting unit is the product of the units of self and other.
>>> v = PhysicalField(((5.,6.),(7.,8.)), "m")
>>> print PhysicalField(((1.,2.),(3.,4.)), "m").dot(v)
[ 26. 44.] m**2
Return the largest integer less than or equal to the PhysicalField.
>>> print PhysicalField(2.2,"m").floor()
2.0 m
Deprecated since version 3.0: use the numericValue property instead
Returns the Numpy sctype of the underlying array.
>>> PhysicalField(1, 'm').getsctype() == numerix.NUMERIX.obj2sctype(numerix.array(1))
True
>>> PhysicalField(1., 'm').getsctype() == numerix.NUMERIX.obj2sctype(numerix.array(1.))
True
>>> PhysicalField((1,1.), 'm').getsctype() == numerix.NUMERIX.obj2sctype(numerix.array((1., 1.)))
True
Return the quantity with all units reduced to their base SI elements.
>>> e = PhysicalField('2.7 Hartree*Nav')
>>> print e.inBaseUnits().allclose("7088849.01085 kg*m**2/s**2/mol")
1
Returns the numerical value of a dimensionless quantity.
>>> print PhysicalField(((2.,3.),(4.,5.))).inDimensionless()
[[ 2. 3.]
[ 4. 5.]]
It’s an error to convert a quantity with units
>>> print PhysicalField(((2.,3.),(4.,5.)),"m").inDimensionless()
Traceback (most recent call last):
...
TypeError: Incompatible units
Converts an angular quantity to radians and returns the numerical value.
>>> print PhysicalField(((2.,3.),(4.,5.)),"rad").inRadians()
[[ 2. 3.]
[ 4. 5.]]
>>> print PhysicalField(((2.,3.),(4.,5.)),"deg").inRadians()
[[ 0.03490659 0.05235988]
[ 0.06981317 0.08726646]]
As a special case, assumes a dimensionless quantity is already in radians.
>>> print PhysicalField(((2.,3.),(4.,5.))).inRadians()
[[ 2. 3.]
[ 4. 5.]]
It’s an error to convert a quantity with non-angular units
>>> print PhysicalField(((2.,3.),(4.,5.)),"m").inRadians()
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the quantity with all units reduced to SI-compatible elements.
>>> e = PhysicalField('2.7 Hartree*Nav')
>>> print e.inSIUnits().allclose("7088849.01085 kg*m**2/s**2/mol")
1
Returns one or more PhysicalField objects that express the same physical quantity in different units. The units are specified by strings containing their names. The units must be compatible with the unit of the object. If one unit is specified, the return value is a single PhysicalField.
>>> freeze = PhysicalField('0 degC')
>>> print freeze.inUnitsOf('degF').allclose("32.0 degF")
1
If several units are specified, the return value is a tuple of PhysicalField instances with with one element per unit such that the sum of all quantities in the tuple equals the the original quantity and all the values except for the last one are integers. This is used to convert to irregular unit systems like hour/minute/second. The original object will not be changed.
>>> t = PhysicalField(314159., 's')
>>> print numerix.allclose([e.allclose(v) for (e, v) in zip(t.inUnitsOf('d','h','min','s'),
... ['3.0 d', '15.0 h', '15.0 min', '59.0 s'])],
... True)
1
Assign the value of a scalar array, performing appropriate conversions.
>>> a = PhysicalField(4.,"m")
>>> a.itemset(PhysicalField("6 ft"))
>>> print a.allclose("1.8288 m")
1
>>> a = PhysicalField(((3.,4.),(5.,6.)),"m")
>>> a.itemset(PhysicalField("6 ft"))
Traceback (most recent call last):
...
ValueError: can only place a scalar for an array of size 1
>>> a.itemset(PhysicalField("2 min"))
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the natural logarithm of the PhysicalField
>>> print numerix.round_(PhysicalField(10).log(), 6)
2.302585
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1. m").log(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the base-10 logarithm of the PhysicalField
>>> print numerix.round_(PhysicalField(10.).log10(), 6)
1.0
The input PhysicalField must be dimensionless
>>> print numerix.round_(PhysicalField("1. m").log10(), 6)
Traceback (most recent call last):
...
TypeError: Incompatible units
Multiply two physical quantities. The unit of the result is the product of the units of the operands.
>>> print PhysicalField(10., 'N') * PhysicalField(10., 'm')
100.0 m*N
As a special case, if the result is dimensionless, the value is returned without units, rather than with a dimensionless unit of 1. This facilitates passing physical quantities to packages such as Numeric that cannot use units, while ensuring the quantities have the desired units.
>>> print (PhysicalField(10., 's') * PhysicalField(2., 'Hz'))
20.0
Return the PhysicalField without units, after conversion to base SI units.
>>> print numerix.round_(PhysicalField("1 inch").numericValue, 6)
0.0254
put is the opposite of take. The values of self at the locations specified in indices are set to the corresponding value of values.
The indices can be any integer sequence object with values suitable for indexing into the flat form of self. The values must be any sequence of values that can be converted to the typecode of self.
>>> f = PhysicalField((1.,2.,3.),"m")
>>> f.put((2,0), PhysicalField((2.,3.),"inch"))
>>> print f
[ 0.0762 2. 0.0508] m
The units of values must be compatible with self.
>>> f.put(1, PhysicalField(3,"kg"))
Traceback (most recent call last):
...
TypeError: Incompatible units
Changes the shape of self to that specified in shape
>>> print PhysicalField((1.,2.,3.,4.),"m").reshape((2,2))
[[ 1. 2.]
[ 3. 4.]] m
The new shape must have the same size as the existing one.
>>> print PhysicalField((1.,2.,3.,4.),"m").reshape((2,3))
Traceback (most recent call last):
...
ValueError: total size of new array must be unchanged
Tuple of array dimensions.
Return the sign of the quantity. The unit is unchanged.
>>> from fipy.tools.numerix import sign
>>> print sign(PhysicalField(((3.,-2.),(-1.,4.)), 'm'))
[[ 1. -1.]
[-1. 1.]]
Return the sine of the PhysicalField
>>> print PhysicalField(numerix.pi/6,"rad").sin()
0.5
>>> print PhysicalField(30.,"deg").sin()
0.5
The units of the PhysicalField must be an angle
>>> PhysicalField(30.,"m").sin()
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the hyperbolic sine of the PhysicalField
>>> PhysicalField(0.).sinh()
0.0
The units of the PhysicalField must be dimensionless
>>> PhysicalField(60.,"m").sinh()
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the square root of the PhysicalField
>>> print PhysicalField("100. m**2").sqrt()
10.0 m
The resulting unit must be integral
>>> print PhysicalField("100. m").sqrt()
Traceback (most recent call last):
...
TypeError: Illegal exponent
Subtract two physical quantities, so long as their units are compatible. The unit of the result is the unit of the first operand.
>>> print PhysicalField(10., 'km') - PhysicalField(10., 'm')
9.99 km
>>> print PhysicalField(10., 'km') - PhysicalField(10., 'J')
Traceback (most recent call last):
...
TypeError: Incompatible units
Returns the sum of all of the elements in self along the specified axis (first axis by default).
>>> print PhysicalField(((1.,2.),(3.,4.)), "m").sum()
[ 4. 6.] m
>>> print PhysicalField(((1.,2.),(3.,4.)), "m").sum(1)
[ 3. 7.] m
Return the elements of self specified by the elements of indices. The resulting PhysicalField array has the same units as the original.
>>> print PhysicalField((1.,2.,3.),"m").take((2,0))
[ 3. 1.] m
The optional third argument specifies the axis along which the selection occurs, and the default value (as in the example above) is 0, the first axis.
>>> print PhysicalField(((1.,2.,3.),(4.,5.,6.)),"m").take((2,0), axis = 1)
[[ 3. 1.]
[ 6. 4.]] m
Return the tangent of the PhysicalField
>>> numerix.round_(PhysicalField(numerix.pi/4,"rad").tan(), 6)
1.0
>>> numerix.round_(PhysicalField(45,"deg").tan(), 6)
1.0
The units of the PhysicalField must be an angle
>>> PhysicalField(45.,"m").tan()
Traceback (most recent call last):
...
TypeError: Incompatible units
Return the hyperbolic tangent of the PhysicalField
>>> print numerix.allclose(PhysicalField(1.).tanh(), 0.761594155956)
True
The units of the PhysicalField must be dimensionless
>>> PhysicalField(60.,"m").tanh()
Traceback (most recent call last):
...
TypeError: Incompatible units
Return human-readable form of a physical quantity
>>> p = PhysicalField(value = (3., 3.14159), unit = "eV")
>>> print p.tostring(precision = 3, separator = '|')
[ 3. | 3.142] eV
Return the unit object of self.
>>> PhysicalField("1 m").unit
<PhysicalUnit m>
Bases: xml.dom.minidom.Document
Returns XML formatted information about current FiPy environment
append some additional information, possibly about a project under a separate svn repository
Bases: distutils.cmd.Command
Create and initialize a new Command object. Most importantly, invokes the ‘initialize_options()’ method, which is the real initializer and depends on the actual command being instantiated.
Issues a DeprecationWarning to use the appropriate property, rather than the get/set method of the same name
This function may also be used as a decorator.
| Parameters : | func : function
old_name : str, optional
new_name : str, optional
message : str, optional
|
|---|---|
| Returns : | old_func : function
|
Issues a DeprecationWarning to use the appropriate ufunc from numerix, rather than the method of the same name
This function may also be used as a decorator.
| Parameters : | func : function
old_name : str, optional
new_name : str, optional
message : str, optional
|
|---|---|
| Returns : | old_func : function
|
Pickle an object and write it to a file. Wrapper for cPickle.dump().
| Parameters : |
|
|---|
Test to check pickling and unpickling.
>>> from fipy.meshes import Grid1D
>>> old = Grid1D(nx = 2)
>>> f, tempfile = write(old)
>>> new = read(tempfile, f)
>>> print old.numberOfCells == new.numberOfCells
True
Read a pickled object from a file. Returns the unpickled object. Wrapper for cPickle.load().
| Parameters : |
|
|---|
Replacement module for NumPy
Attention
This module should be the only place in the code where numpy is explicitly imported and you should always import this module and not numpy in your own code. The documentation for numpy remains canonical for all functions and classes not explicitly documented here.
The functions provided in ths module replace and augment the NumPy module. The functions work with Variables, arrays or numbers. For example, create a Variable.
>>> from fipy.variables.variable import Variable
>>> var = Variable(value=0)
Take the tangent of such a variable. The returned value is itself a Variable.
>>> v = tan(var)
>>> v
tan(Variable(value=array(0)))
>>> print float(v)
0.0
Take the tangent of a int.
>>> tan(0)
0.0
Take the tangent of an array.
>>> print tan(array((0,0,0)))
[ 0. 0. 0.]
return array of vector dot-products of v1 and v2 for arrays a1 and a2 of vectors v1 and v2
We can’t use numpy.dot() on an array of vectors
Test that Variables are returned as Variables.
>>> from fipy.meshes import Grid2D
>>> mesh = Grid2D(nx=2, ny=1)
>>> from fipy.variables.cellVariable import CellVariable
>>> v1 = CellVariable(mesh=mesh, value=((0,1),(2,3)), rank=1)
>>> v2 = CellVariable(mesh=mesh, value=((0,1),(2,3)), rank=1)
>>> dot(v1, v2)._variableClass
<class 'fipy.variables.cellVariable.CellVariable'>
>>> dot(v2, v1)._variableClass
<class 'fipy.variables.cellVariable.CellVariable'>
>>> print rank(dot(v2, v1))
0
>>> print dot(v1, v2)
[ 4 10]
>>> dot(v1, v1)._variableClass
<class 'fipy.variables.cellVariable.CellVariable'>
>>> print dot(v1, v1)
[ 4 10]
>>> v3 = array(((0,1),(2,3)))
>>> print type(dot(v3, v3)) is type(array(1))
1
>>> print dot(v3, v3)
[ 4 10]
indices(dimensions,typecode=None) returns an array representing a grid of indices with row-only, and column-only variation.
>>> NUMERIX.allclose(NUMERIX.array(indices((4, 6))), NUMERIX.indices((4,6)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((4, 6, 2))), NUMERIX.indices((4, 6, 2)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((1,))), NUMERIX.indices((1,)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((5,))), NUMERIX.indices((5,)))
1
Tests whether or not first and second are equal, subect to the given relative and absolute tolerances, such that:
|first - second| < atol + rtol * |second|
This means essentially that both elements are small compared to atol or their difference divided by second‘s value is small compared to rtol.
Selects the elements of a corresponding to indices.
Change the shape of arr to shape, as long as the product of all the lenghts of all the axes is constant (the total number of elements does not change).
The opposite of take. The values of arr at the locations specified by ids are set to the corresponding value of values.
The following is to test improvments to puts with masked arrays. Places in the code were assuming incorrect put behavior.
>>> maskValue = 999999
>>> arr = zeros(3, 'l')
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values) ## this should work
>>> print arr
[0 0 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## works as expected
[-- 5 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((maskValue, 2), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## should be [-- 5 --] maybe??
[-- 5 999999]
The sum of all the elements of arr along the specified axis.
Test whether all array elements along a given axis evaluate to True.
| Parameters : | a : array_like
axis : int, optional
out : ndarray, optional
|
|---|
Get the rank of sequence a (the number of dimensions, not a matrix rank) The rank of a scalar is zero.
Note
The rank of a MeshVariable is for any single element. E.g., A CellVariable containing scalars at each cell, and defined on a 9 element Grid1D, has rank 0. If it is defined on a 3x3 Grid2D, it is still rank 0.
Selects the elements of a corresponding to indices.
Change the shape of arr to shape, as long as the product of all the lenghts of all the axes is constant (the total number of elements does not change).
The opposite of take. The values of arr at the locations specified by ids are set to the corresponding value of values.
The following is to test improvments to puts with masked arrays. Places in the code were assuming incorrect put behavior.
>>> maskValue = 999999
>>> arr = zeros(3, 'l')
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values) ## this should work
>>> print arr
[0 0 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## works as expected
[-- 5 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((maskValue, 2), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## should be [-- 5 --] maybe??
[-- 5 999999]
The sum of all the elements of arr along the specified axis.
Test whether all array elements along a given axis evaluate to True.
| Parameters : | a : array_like
axis : int, optional
out : ndarray, optional
|
|---|
Get the rank of sequence a (the number of dimensions, not a matrix rank) The rank of a scalar is zero.
Note
The rank of a MeshVariable is for any single element. E.g., A CellVariable containing scalars at each cell, and defined on a 9 element Grid1D, has rank 0. If it is defined on a 3x3 Grid2D, it is still rank 0.
Test whether all array elements along a given axis evaluate to True.
| Parameters : | a : array_like
axis : int, optional
out : ndarray, optional
|
|---|
Tests whether or not first and second are equal, subect to the given relative and absolute tolerances, such that:
|first - second| < atol + rtol * |second|
This means essentially that both elements are small compared to atol or their difference divided by second‘s value is small compared to rtol.
Returns true if every element of first is equal to the corresponding element of second.
return array of vector dot-products of v1 and v2 for arrays a1 and a2 of vectors v1 and v2
We can’t use numpy.dot() on an array of vectors
Test that Variables are returned as Variables.
>>> from fipy.meshes import Grid2D
>>> mesh = Grid2D(nx=2, ny=1)
>>> from fipy.variables.cellVariable import CellVariable
>>> v1 = CellVariable(mesh=mesh, value=((0,1),(2,3)), rank=1)
>>> v2 = CellVariable(mesh=mesh, value=((0,1),(2,3)), rank=1)
>>> dot(v1, v2)._variableClass
<class 'fipy.variables.cellVariable.CellVariable'>
>>> dot(v2, v1)._variableClass
<class 'fipy.variables.cellVariable.CellVariable'>
>>> print rank(dot(v2, v1))
0
>>> print dot(v1, v2)
[ 4 10]
>>> dot(v1, v1)._variableClass
<class 'fipy.variables.cellVariable.CellVariable'>
>>> print dot(v1, v1)
[ 4 10]
>>> v3 = array(((0,1),(2,3)))
>>> print type(dot(v3, v3)) is type(array(1))
1
>>> print dot(v3, v3)
[ 4 10]
Return the shape of arr
>>> getShape(1)
()
>>> getShape(1.)
()
>>> from fipy.variables.variable import Variable
>>> getShape(Variable(1))
()
>>> getShape(Variable(1.))
()
>>> getShape(Variable(1., unit="m"))
()
>>> getShape(Variable("1 m"))
()
indices(dimensions,typecode=None) returns an array representing a grid of indices with row-only, and column-only variation.
>>> NUMERIX.allclose(NUMERIX.array(indices((4, 6))), NUMERIX.indices((4,6)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((4, 6, 2))), NUMERIX.indices((4, 6, 2)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((1,))), NUMERIX.indices((1,)))
1
>>> NUMERIX.allclose(NUMERIX.array(indices((5,))), NUMERIX.indices((5,)))
1
Returns which elements of first and second are equal, subect to the given relative and absolute tolerances, such that:
|first - second| < atol + rtol * |second|
This means essentially that both elements are small compared to atol or their difference divided by second‘s value is small compared to rtol.
| Parameters : |
|
|---|---|
| Returns : |
|
| Parameters : |
|
|---|---|
| Returns : |
|
| Parameters : |
|
|---|---|
| Returns : |
|
find the indices of data that are closest to points
>>> from fipy import *
>>> m0 = Grid2D(dx=(.1, 1., 10.), dy=(.1, 1., 10.))
>>> m1 = Grid2D(nx=2, ny=2, dx=5., dy=5.)
>>> print nearest(m0.cellCenters.globalValue, m1.cellCenters.globalValue)
[4 5 7 8]
>>> print nearest(m0.cellCenters.globalValue, m1.cellCenters.globalValue, max_mem=100)
[4 5 7 8]
>>> print nearest(m0.cellCenters.globalValue, m1.cellCenters.globalValue, max_mem=10000)
[4 5 7 8]
The opposite of take. The values of arr at the locations specified by ids are set to the corresponding value of values.
The following is to test improvments to puts with masked arrays. Places in the code were assuming incorrect put behavior.
>>> maskValue = 999999
>>> arr = zeros(3, 'l')
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values) ## this should work
>>> print arr
[0 0 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((2, maskValue), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## works as expected
[-- 5 4]
>>> arr = MA.masked_values((maskValue, 5, 10), maskValue)
>>> ids = MA.masked_values((maskValue, 2), maskValue)
>>> values = MA.masked_values((4, maskValue), maskValue)
>>> put(arr, ids, values)
>>> print arr ## should be [-- 5 --] maybe??
[-- 5 999999]
Get the rank of sequence a (the number of dimensions, not a matrix rank) The rank of a scalar is zero.
Note
The rank of a MeshVariable is for any single element. E.g., A CellVariable containing scalars at each cell, and defined on a 9 element Grid1D, has rank 0. If it is defined on a 3x3 Grid2D, it is still rank 0.
Change the shape of arr to shape, as long as the product of all the lenghts of all the axes is constant (the total number of elements does not change).
Return array of square roots of vector dot-products for arrays a1 and a2 of vectors v1 and v2
Usually used with v1==v2 to return magnitude of v1.
The sum of all the elements of arr along the specified axis.
Selects the elements of a corresponding to indices.
Returns a textual representation of a number or field of numbers. Each dimension is indicated by a pair of matching square brackets ([]), within which each subset of the field is output. The orientation of the dimensions is as follows: the last (rightmost) dimension is always horizontal, so that the frequent rank-1 fields use a minimum of screen real-estate. The next-to-last dimesnion is displayed vertically if present and any earlier dimension is displayed with additional bracket divisions.
| Parameters : |
|
|---|
This is a wrapper function for the python optparse module. Unfortunately optparse does not allow command line arguments to be ignored. See the documentation for optparse for more details. Returns the argument value.
| Parameters : |
|
|---|
Vector utility functions that are inexplicably absent from Numeric
This is a temporary replacement for Numeric.put as it was not doing what we thought it was doing.
removes elements with indices i = start + shift * n where n = 0, 1, 2, ...
>>> prune(numerix.arange(10), 3, 5)
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> prune(numerix.arange(10), 3, 2)
array([0, 1, 3, 4, 6, 7, 9])
>>> prune(numerix.arange(10), 3)
array([1, 2, 4, 5, 7, 8])
>>> prune(numerix.arange(4, 7), 3)
array([5, 6])
Bases: xml.dom.minidom.Document
Returns XML formatted information about current FiPy environment
append some additional information, possibly about a project under a separate svn repository