pencil.backpack.pidly ===================== .. py:module:: pencil.backpack.pidly .. autoapi-nested-parse:: pIDLy 0.2.7: IDL within Python. Control ITT's IDL (Interactive Data Language) from within Python. https://github.com/anthonyjsmith/pIDLy http://pypi.python.org/pypi/pIDLy/ Requirements: * Pexpect * NumPy Usage: >>> import pidly >>> idl = pidly.IDL() >> print(idl.__doc__) Consult the docstrings or README.txt in the source distribution for further information. Copyright (c) 2008-2017, Anthony Smith anthonysmith80@gmail.com Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. Attributes ---------- .. autoapisummary:: pencil.backpack.pidly.now pencil.backpack.pidly.STR_DELIMITER pencil.backpack.pidly.weakrefs_to_pidly_sessions Exceptions ---------- .. autoapisummary:: pencil.backpack.pidly.IDLInputOverflowError Classes ------- .. autoapisummary:: pencil.backpack.pidly.IDL pencil.backpack.pidly.TestPidly Functions --------- .. autoapisummary:: pencil.backpack.pidly.close_all pencil.backpack.pidly.test Module Contents --------------- .. py:data:: now .. py:data:: STR_DELIMITER :value: '!@#' .. py:data:: weakrefs_to_pidly_sessions :value: [] .. py:function:: close_all() .. py:exception:: IDLInputOverflowError Bases: :py:obj:`Exception` Expression too long for IDL to receive. Initialize self. See help(type(self)) for accurate signature. .. py:class:: IDL(*arguments, **kwargs) Bases: :py:obj:`pexpect.spawn` pidly.IDL() : Launch IDL session within Python. The IDL class inherits from pexpect.spawn. Consult pexpect documentation for details of further methods. Usage: Initiate: >>> import pidly >>> idl = pidly.IDL() Or: idl = pidly.IDL('/path/to/idl') Execute commands: >>> idl('x = total([1, 1], /int)') Retrieve values: >>> print(idl.ev('x')) 2 Or (slightly slower): >>> print(idl.x) 2 Evaluate expressions: >>> print(idl.ev('x ^ 2')) 4 Use cache (IDL save) to handle large arrays: >>> idl('x=[1,2,3,4,5,6]') >>> print(idl.ev('x', use_cache=True)) [1 2 3 4 5 6] Transfer a list of IDL variables, using cache: >>> idl('y=[1,2,3,4,5,6]') >>> xy = idl.ev_list(['x','y'], use_cache=True) >>> print(sorted(xy.keys())) ['x', 'y'] >>> print(xy['x']) [1 2 3 4 5 6] Assign value from Python expression: >>> idl.x = 2 + 2 >>> print(idl.x) 4 Or: >>> idl('x', 2 + 2) >>> print(idl.x) 4 Perform IDL function on Python expression(s): >>> idl.func('reform', range(4), 2, 2) array([[0, 1], [2, 3]]) Or (slightly slower): >>> idl.reform(range(4), 2, 2) array([[0, 1], [2, 3]]) With keywords (/L64 -> L64=True or L64=1) >>> x = idl.histogram(range(4), binsize=3, L64=True) >>> print(x) [3 1] >>> print(x.dtype) int64 IDL procedure with Python argument(s): >>> idl.pro('plot', range(10), range(10), xstyle=True, ystyle=True) Interactive mode: >> idl.interact() IDL> print, x 4 IDL> ^D >>> Close: >>> idl.close() pIDLy supports the transfer of: * ints, longs, ... * floats, doubles, ... * strings * arrays of the above types, with arbitrary size and shape * dictionaries <-> structures & lists of dicts <-> arrays of structures but with certain limitations on transfer from Python to IDL [NB if getting Syntax Errors when passing large arrays to IDL, try using >> idl = pidly.IDL(long_delay=0.05) default is 0.02.] .. py:attribute:: short_delay .. py:attribute:: long_delay .. py:attribute:: use_cache .. py:attribute:: max_sendline .. py:attribute:: max_idl_code_area .. py:attribute:: max_n_elements_code_area .. py:attribute:: idl_prompt .. py:attribute:: delaybeforesend .. py:attribute:: ready :value: True .. py:method:: close() Close IDL session. Try to call IDL exit function - this way you may still be able to terminate IDL if it is a called indirectly through a script. .. py:method:: ex(expression, assignment_value=None, print_output=True, ret=False) Execute a command in IDL. If assignment_value is set (to a Python expression), this value is assigned to the IDL variable named in expression. .. py:method:: ev(expression, print_output=True, use_cache=None) Return the value of an IDL expression as a numpy.ndarray. .. py:method:: ev_list(names, print_output=True, use_cache=None) Return a dictionary containing values of IDL variables in list names. .. py:method:: interact(show_prompt=True, **kwargs) Interactive IDL shell. Press ^D to return to Python. .. py:method:: variables() Return list of names of defined IDL variables. .. py:method:: func(name, *args, **kwargs) Evaluate IDL function. .. py:method:: pro(name, *args, **kwargs) Execute IDL procedure. .. py:class:: TestPidly(methodName='runTest') Bases: :py:obj:`unittest.TestCase` Unit tests for pIDLy. Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name. .. py:method:: setUp() Hook method for setting up the test fixture before exercising it. .. py:method:: tearDown() Hook method for deconstructing the test fixture after testing it. .. py:method:: sendAndReceive(x) .. py:method:: test_idl_dead() .. py:method:: test_longest_line() .. py:method:: test_longest_string() .. py:method:: test_longest_string_overflow() .. py:method:: test_20_function_calls() .. py:method:: test_20_function_calls_explicit() .. py:method:: test_20_function_calls_really_explicit() .. py:method:: test_long_function_call() .. py:method:: test_long_function_dicts() .. py:method:: test_longish_function_call() .. py:method:: test_single_integer() .. py:method:: test_single_element_list_int() .. py:method:: test_single_float() .. py:method:: test_single_float32() .. py:method:: test_huge_double() .. py:method:: test_infinity() .. py:method:: test_infinity_neg() .. py:method:: test_nan() .. py:method:: test_inf_nan_array() .. py:method:: test_single_string() .. py:method:: test_multi_word_string() .. py:method:: test_list_of_strings() .. py:method:: test_3d_list_of_strings() .. py:method:: test_long_integer() .. py:method:: test_int_array() .. py:method:: test_long_int_array() .. py:method:: test_2d_int_array() .. py:method:: test_3d_int_array() .. py:method:: test_mixed_array_warning() .. py:method:: test_simple_dictionary() .. py:method:: test_3_element_dict() .. py:method:: test_dict_string_arrays() .. py:method:: test_3_3_element_dicts() .. py:method:: test_100_dicts_float32_double_string() .. py:method:: test_4d_int_array() .. py:method:: test_6d_int_array_tests_max_n_elements_code_area() .. py:method:: test_8d_int_array() .. py:method:: test_50_doubles() .. py:method:: test_50_float32() .. py:method:: test_50_doubles_1e30() .. py:method:: test_50_float32_1e30() .. py:method:: test_speed_20000_doubles() .. py:method:: test_speed_5000_doubles_one_by_one() .. py:method:: test_ev_with_cache() .. py:method:: test_ev_list() .. py:method:: test_ev_list_with_cache() .. py:function:: test() Run full tests on pIDLy.