Author: bugman Date: Fri Dec 7 18:24:38 2012 New Revision: 18083 URL: http://svn.gna.org/viewcvs/relax?rev=18083&view=rev Log: Merged revisions 18079-18081 via svnmerge from svn+ssh://bugman@xxxxxxxxxxx/svn/relax/trunk ........ r18079 | bugman | 2012-12-07 17:45:38 +0100 (Fri, 07 Dec 2012) | 3 lines Shifted and renamed the arg_check.check_float() function to check_types.is_float(). ........ r18080 | bugman | 2012-12-07 18:15:41 +0100 (Fri, 07 Dec 2012) | 5 lines The relax_io.write_spin_data() function now formats floating point numbers better. This affects the printouts of many data loading user functions. ........ r18081 | bugman | 2012-12-07 18:22:45 +0100 (Fri, 07 Dec 2012) | 3 lines Better printouts from the rdc.read user function - the numbers are now formatted. ........ Modified: branches/frame_order_testing/ (props changed) branches/frame_order_testing/arg_check.py branches/frame_order_testing/check_types.py branches/frame_order_testing/data/relax_xml.py branches/frame_order_testing/generic_fns/rdc.py branches/frame_order_testing/relax_io.py Propchange: branches/frame_order_testing/ ------------------------------------------------------------------------------ --- svnmerge-integrated (original) +++ svnmerge-integrated Fri Dec 7 18:24:38 2012 @@ -1,1 +1,1 @@ -/trunk:1-18074 +/trunk:1-18081 Modified: branches/frame_order_testing/arg_check.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/arg_check.py?rev=18083&r1=18082&r2=18083&view=diff ============================================================================== --- branches/frame_order_testing/arg_check.py (original) +++ branches/frame_order_testing/arg_check.py Fri Dec 7 18:24:38 2012 @@ -23,48 +23,13 @@ """Argument checking functions for the relax user functions.""" # Python module imports. -from numpy import float32, float64, ndarray -try: - from numpy import float16 -except ImportError: - float16 = float32 # Support for old numpy versions. -try: - from numpy import float128 -except ImportError: - float128 = float64 # Support for 32-bit numpy versions. +from numpy import ndarray # relax module imports. -from check_types import is_filetype +import check_types from relax_errors import RelaxBoolError, RelaxFloatError, RelaxFunctionError, RelaxIntError, RelaxIntListIntError, RelaxListFloatError, RelaxListIntError, RelaxMatrixFloatError, RelaxNoneFloatError, RelaxNoneFunctionError, RelaxListNumError, RelaxListStrError, RelaxNoneError, RelaxNoneIntError, RelaxNoneIntListIntError, RelaxNoneListFloatError, RelaxNoneListIntError, RelaxNoneMatrixFloatError, RelaxNoneListNumError, RelaxNoneListStrError, RelaxNoneNumError, RelaxNoneNumStrListNumStrError, RelaxNoneNumTupleNumError, RelaxNoneStrError, RelaxNoneStrFileError, RelaxNoneStrListNumError, RelaxNoneStrListStrError, RelaxNoneTupleError, RelaxNumError, RelaxNumStrListNumStrError, RelaxNumTupleNumError, RelaxStrError, RelaxStrFileError, RelaxStrListNumError, RelaxStrListStrError, RelaxTupleError, RelaxTupleNumError, RelaxNoneValListValError, RelaxValListValError from relax_io import DummyFileObject from types import FunctionType, MethodType - - -def check_float(num): - """Check if the given number is a Python or numpy float. - - @param num: The number to check. - @type num: anything. - @return: True if the number is a float, False otherwise. - @rtype: bool - """ - - # Standard float. - if isinstance(num, float): - return True - - # Numpy floats. - if isinstance(num, float16): - return True - if isinstance(num, float32): - return True - if isinstance(num, float64): - return True - if isinstance(num, float128): - return True - - # Not a float. - return False def is_bool(arg, name=None, raise_error=True): @@ -114,7 +79,7 @@ return True # Check for a float. - if check_float(arg): + if check_types.is_float(arg): return True # Fail. @@ -164,7 +129,7 @@ else: for i in range(len(arg)): # Fail if not a float. - if not check_float(arg[i]): + if not check_types.is_float(arg[i]): fail = True # Fail. @@ -239,7 +204,7 @@ # Check for float elements. for j in range(len(arg[i])): - if not check_float(arg[i][j]): + if not check_types.is_float(arg[i][j]): fail = True # Fail. @@ -578,7 +543,7 @@ return True # Check for floats and integers (avoiding Booleans). - if (check_float(arg) or isinstance(arg, int)) and not isinstance(arg, bool): + if (check_types.is_float(arg) or isinstance(arg, int)) and not isinstance(arg, bool): return True # Fail. @@ -634,7 +599,7 @@ # Fail if not numbers. for i in range(len(arg)): - if (not check_float(arg[i]) and not isinstance(arg[i], int)) or isinstance(arg, bool): + if (not check_types.is_float(arg[i]) and not isinstance(arg[i], int)) or isinstance(arg, bool): fail = True # Fail. @@ -765,7 +730,7 @@ # Fail if not numbers. for i in range(len(arg)): - if (not check_float(arg[i]) and not isinstance(arg[i], int)) or isinstance(arg, bool): + if (not check_types.is_float(arg[i]) and not isinstance(arg[i], int)) or isinstance(arg, bool): fail = True # Fail. @@ -917,7 +882,7 @@ return True # Check for a string. - if isinstance(arg, str) or is_filetype(arg) or isinstance(arg, DummyFileObject): + if isinstance(arg, str) or check_types.is_filetype(arg) or isinstance(arg, DummyFileObject): return True # Fail. Modified: branches/frame_order_testing/check_types.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/check_types.py?rev=18083&r1=18082&r2=18083&view=diff ============================================================================== --- branches/frame_order_testing/check_types.py (original) +++ branches/frame_order_testing/check_types.py Fri Dec 7 18:24:38 2012 @@ -29,6 +29,15 @@ file = None except ImportError: io_module = False +from numpy import float32, float64, ndarray +try: + from numpy import float16 +except ImportError: + float16 = float32 # Support for old numpy versions. +try: + from numpy import float128 +except ImportError: + float128 = float64 # Support for 32-bit numpy versions. def is_filetype(obj): @@ -49,6 +58,33 @@ return isinstance(obj, file) +def is_float(num): + """Check if the given number is a Python or numpy float. + + @param num: The number to check. + @type num: anything. + @return: True if the number is a float, False otherwise. + @rtype: bool + """ + + # Standard float. + if isinstance(num, float): + return True + + # Numpy floats. + if isinstance(num, float16): + return True + if isinstance(num, float32): + return True + if isinstance(num, float64): + return True + if isinstance(num, float128): + return True + + # Not a float. + return False + + def is_unicode(obj): """Check if the given Python object is a unicode string. Modified: branches/frame_order_testing/data/relax_xml.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/data/relax_xml.py?rev=18083&r1=18082&r2=18083&view=diff ============================================================================== --- branches/frame_order_testing/data/relax_xml.py (original) +++ branches/frame_order_testing/data/relax_xml.py Fri Dec 7 18:24:38 2012 @@ -24,15 +24,7 @@ # Python module imports. import numpy -from numpy import set_printoptions, array, float32, float64, inf, nan, ndarray, zeros -try: - from numpy import float16 -except ImportError: - float16 = float32 # Support for old numpy versions. -try: - from numpy import float128 -except ImportError: - float128 = float64 # Support for 32-bit numpy versions. +from numpy import set_printoptions, array, inf, nan, ndarray, zeros from re import search # Modify numpy for better output of numbers and structures. @@ -40,6 +32,7 @@ # relax module imports. import arg_check +import check_types from float import floatAsByteArray, packBytesAsPyFloat from relax_errors import RelaxError @@ -136,19 +129,19 @@ elem.setAttribute('type', py_type) # Store floats as IEEE-754 byte arrays (for full precision storage). - if arg_check.check_float(value): + if check_types.is_float(value): val_elem = doc.createElement('ieee_754_byte_array') elem.appendChild(val_elem) val_elem.appendChild(doc.createTextNode(repr(floatAsByteArray(value)))) # Store lists with floats as IEEE-754 byte arrays. - elif (isinstance(value, list) or isinstance(value, ndarray)) and len(value) and arg_check.check_float(value[0]): + elif (isinstance(value, list) or isinstance(value, ndarray)) and len(value) and check_types.is_float(value[0]): # The converted list. ieee_obj = [] conv = False for i in range(len(value)): # A float. - if arg_check.check_float(value[i]): + if check_types.is_float(value[i]): ieee_obj.append(floatAsByteArray(value[i])) conv = True @@ -171,7 +164,7 @@ ieee_obj = {} conv = False for key in list(value.keys()): - if arg_check.check_float(value[key]): + if check_types.is_float(value[key]): ieee_obj[key] = floatAsByteArray(value[key]) conv = True Modified: branches/frame_order_testing/generic_fns/rdc.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/generic_fns/rdc.py?rev=18083&r1=18082&r2=18083&view=diff ============================================================================== --- branches/frame_order_testing/generic_fns/rdc.py (original) +++ branches/frame_order_testing/generic_fns/rdc.py Fri Dec 7 18:24:38 2012 @@ -31,7 +31,7 @@ from warnings import warn # relax module imports. -from arg_check import is_float +from check_types import is_float from float import nan from generic_fns import grace, pipes from generic_fns.align_tensor import get_tensor_index @@ -94,7 +94,7 @@ raise RelaxSpinTypeError(interatom.spin_id2) # Single vector. - if is_float(interatom.vector[0], raise_error=False): + if is_float(interatom.vector[0]): vectors = [interatom.vector] else: vectors = interatom.vector @@ -674,7 +674,15 @@ interatom.rdc_err[align_id] = error # Append the data for printout. - data.append([spin_id1, spin_id2, repr(value), repr(error)]) + data.append([spin_id1, spin_id2]) + if is_float(value): + data[-1].append("%20.15f" % value) + else: + data[-1].append("%20s" % value) + if is_float(error): + data[-1].append("%20.15f" % error) + else: + data[-1].append("%20s" % error) # No data, so fail hard! if not len(data): Modified: branches/frame_order_testing/relax_io.py URL: http://svn.gna.org/viewcvs/relax/branches/frame_order_testing/relax_io.py?rev=18083&r1=18082&r2=18083&view=diff ============================================================================== --- branches/frame_order_testing/relax_io.py (original) +++ branches/frame_order_testing/relax_io.py Fri Dec 7 18:24:38 2012 @@ -49,7 +49,7 @@ from warnings import warn # relax module imports. -from check_types import is_filetype +from check_types import is_filetype, is_float import generic_fns from relax_errors import RelaxError, RelaxFileError, RelaxFileOverwriteError, RelaxInvalidSeqError, RelaxMissingBinaryError, RelaxNoInPathError, RelaxNonExecError from relax_warnings import RelaxWarning, RelaxFileEmptyWarning @@ -883,7 +883,7 @@ out.write('\n') -def write_spin_data(file, dir=None, sep=None, spin_ids=None, mol_names=None, res_nums=None, res_names=None, spin_nums=None, spin_names=None, force=False, data=None, data_name=None, error=None, error_name=None): +def write_spin_data(file, dir=None, sep=None, spin_ids=None, mol_names=None, res_nums=None, res_names=None, spin_nums=None, spin_names=None, force=False, data=None, data_name=None, error=None, error_name=None, float_format="%20.15f"): """Generator function for reading the spin specific data from file. Description @@ -922,6 +922,8 @@ @type error: list or list of lists @keyword error_name: A name corresponding to the error argument. If the error argument is a list of lists, then this must also be a list with the same length at the second dimension of the error arg. @type error_name: str or list of str + @keyword float_format: A float formatting string to use for the data and error whenever a float is found. + @type float_format: str """ # Data argument tests. @@ -1059,20 +1061,32 @@ # Loop over the list. for i in range(len(data[0])): # The data. - file_data[-1].append(repr(data[spin_index][i])) + if is_float(data[spin_index][i]): + file_data[-1].append(float_format % data[spin_index][i]) + else: + file_data[-1].append(repr(data[spin_index][i])) # The error. if error: - file_data[-1].append(repr(error[spin_index][i])) + if is_float(error[spin_index][i]): + file_data[-1].append(float_format % error[spin_index][i]) + else: + file_data[-1].append(repr(error[spin_index][i])) # Simple list. else: # The data. - file_data[-1].append(repr(data[spin_index])) + if is_float(data[spin_index]): + file_data[-1].append(float_format % data[spin_index]) + else: + file_data[-1].append(repr(data[spin_index])) # The error. if error: - file_data[-1].append(repr(error[spin_index])) + if is_float(error[spin_index]): + file_data[-1].append(float_format % error[spin_index]) + else: + file_data[-1].append(repr(error[spin_index])) # Only errors. elif error: