comments
stringlengths
2
31.4k
"""Simulate detachment limited sediment transport. Landlab component that simulates detachment limited sediment transport is more general than the stream power component. Doesn't require the upstream node order, links to flow receiver and flow receiver fields. Instead, takes in the discharge values on NODES calculated by the OverlandFlow class and erodes the landscape in response to the output discharge. As of right now, this component relies on the OverlandFlow component for stability. There are no stability criteria implemented in this class. To ensure model stability, use StreamPowerEroder or FastscapeEroder components instead. .. codeauthor:: NAME import numpy as np >>> from landlab import RasterModelGrid >>> from landlab.components import DetachmentLtdErosion Create a grid on which to calculate detachment ltd sediment transport. >>> grid = RasterModelGrid((4, 5)) The grid will need some data to provide the detachment limited sediment transport component. To check the names of the fields that provide input to the detachment ltd transport component, use the *input_var_names* class property. Create fields of data for each of these input variables. >>> grid.at_node['topographic__elevation'] = np.array([ ... 0., 0., 0., 0., 0., ... 1., 1., 1., 1., 1., ... 2., 2., 2., 2., 2., ... 3., 3., 3., 3., 3.]) Using the set topography, now we will calculate slopes on all nodes. >>> grid.at_node['topographic__slope'] = np.array([ ... -0. , -0. , -0. , -0. , -0, ... 0.70710678, 1. , 1. , 1. , 0.70710678, ... 0.70710678, 1. , 1. , 1. , 0.70710678, ... 0.70710678, 1. , 1. , 1. , 0.70710678]) Now we will arbitrarily add water discharge to each node for simplicity. >>> grid.at_node['surface_water__discharge'] = np.array([ ... 30., 30., 30., 30., 30., ... 20., 20., 20., 20., 20., ... 10., 10., 10., 10., 10., ... 5., 5., 5., 5., 5.]) Instantiate the `DetachmentLtdErosion` component to work on this grid, and run it. In this simple case, we need to pass it a time step ('dt') >>> dt = 10.0 >>> dle = DetachmentLtdErosion(grid) >>> dle.erode(dt=dt) After calculating the erosion rate, the elevation field is updated in the grid. Use the *output_var_names* property to see the names of the fields that have been changed. >>> dle.output_var_names ('topographic__elevation',) The `topographic__elevation` field is defined at nodes. >>> dle.var_loc('topographic__elevation') 'node' Now we test to see how the topography changed as a function of the erosion rate. >>> grid.at_node['topographic__elevation'] # doctest: +NORMALIZE_WHITESPACE array([ 0. , 0. , 0. , 0. , 0. , 0.99936754, 0.99910557, 0.99910557, 0.99910557, 0.99936754, 1.99955279, 1.99936754, 1.99936754, 1.99936754, 1.99955279, 2.99968377, 2.99955279, 2.99955279, 2.99955279, 2.99968377]) """
""" # ggame The simple cross-platform sprite and game platform for Brython Server (Pygame, Tkinter to follow?). Ggame stands for a couple of things: "good game" (of course!) and also "git game" or "github game" because it is designed to operate with [Brython Server](http://runpython.com) in concert with Github as a backend file store. Ggame is **not** intended to be a full-featured gaming API, with every bell and whistle. Ggame is designed primarily as a tool for teaching computer programming, recognizing that the ability to create engaging and interactive games is a powerful motivator for many progamming students. Accordingly, any functional or performance enhancements that *can* be reasonably implemented by the user are left as an exercise. ## Functionality Goals The ggame library is intended to be trivially easy to use. For example: from ggame import App, ImageAsset, Sprite # Create a displayed object at 100,100 using an image asset Sprite(ImageAsset("ggame/bunny.png"), (100,100)) # Create the app, with a 500x500 pixel stage app = App(500,500) # Run the app app.run() ## Overview There are three major components to the `ggame` system: Assets, Sprites and the App. ### Assets Asset objects (i.e. `ggame.ImageAsset`, etc.) typically represent separate files that are provided by the "art department". These might be background images, user interface images, or images that represent objects in the game. In addition, `ggame.SoundAsset` is used to represent sound files (`.wav` or `.mp3` format) that can be played in the game. Ggame also extends the asset concept to include graphics that are generated dynamically at run-time, such as geometrical objects, e.g. rectangles, lines, etc. ### Sprites All of the visual aspects of the game are represented by instances of `ggame.Sprite` or subclasses of it. ### App Every ggame application must create a single instance of the `ggame.App` class (or a sub-class of it). Creating an instance of the `ggame.App` class will initiate creation of a pop-up window on your browser. Executing the app's `run` method will begin the process of refreshing the visual assets on the screen. ### Events No game is complete without a player and players produce events. Your code handles user input by registering to receive keyboard and mouse events using `ggame.App.listenKeyEvent` and `ggame.App.listenMouseEvent` methods. ## Execution Environment Ggame is designed to be executed in a web browser using [Brython](http://brython.info/), [Pixi.js](http://www.pixijs.com/) and [Buzz](http://buzz.jaysalvat.com/). The easiest way to do this is by executing from [runpython](http://runpython.com), with source code residing on [github](http://github.com). When using [runpython](http://runpython.com), you will have to configure your browser to allow popup windows. To use Ggame in your own application, you will minimally need to create a folder called `ggame` in your project. Within `ggame`, copy the `ggame.py`, `sysdeps.py` and `__init__.py` files from the [ggame project](https://github.com/BrythonServer/ggame). ### Include Ggame as a Git Subtree From the same directory as your own python sources (note: you must have an existing git repository with committed files in order for the following to work properly), execute the following terminal commands: git remote add -f ggame https://github.com/BrythonServer/ggame.git git merge -s ours --no-commit ggame/master mkdir ggame git read-tree --prefix=ggame/ -u ggame/master git commit -m "Merge ggame project as our subdirectory" If you want to pull in updates from ggame in the future: git pull -s subtree ggame master You can see an example of how a ggame subtree is used by examining the [Brython Server Spacewar](https://github.com/BrythonServer/Spacewar) repo on Github. ## Geometry When referring to screen coordinates, note that the x-axis of the computer screen is *horizontal* with the zero position on the left hand side of the screen. The y-axis is *vertical* with the zero position at the **top** of the screen. Increasing positive y-coordinates correspond to the downward direction on the computer screen. Note that this is **different** from the way you may have learned about x and y coordinates in math class! """
""" IPy - class and tools for handling of IPv4 and IPv6 Addresses and Networks. $HeadURL: http://svn.23.nu/svn/repos/IPy/trunk/IPy.py $ $Id: IPy.py,v 1.1 2007/08/14 09:39:00 cristian Exp $ The IP class allows a comfortable parsing and handling for most notations in use for IPv4 and IPv6 Addresses and Networks. It was greatly inspired bei RIPE's Perl module NET::IP's interface but doesn't share the Implementation. It doesn't share non-CIDR netmasks, so funky stuff lixe a netmask 0xffffff0f can't be done here. >>> ip = IP('IP_ADDRESS/30') >>> for x in ip: ... print x ... IP_ADDRESS IP_ADDRESS IP_ADDRESS IP_ADDRESS >>> ip2 = IP('0x7f000000/30') >>> ip == ip2 1 >>> ip.reverseNames() ['IP_ADDRESS.in-addr.arpa.', 'IP_ADDRESS.in-addr.arpa.', 'IP_ADDRESS.in-addr.arpa.', 'IP_ADDRESS.in-addr.arpa.'] >>> ip.reverseName() '0-IP_ADDRESS.in-addr.arpa.' >>> ip.iptype() 'PRIVATE' It can detect about a dozen different ways of expressing IP addresses and networks, parse them and distinguish between IPv4 and IPv6 addresses. >>> IP('IP_ADDRESS/8').version() 4 >>> IP('::1').version() 6 >>> print IP(0x7f000001) IP_ADDRESS >>> print IP('0x7f000001') IP_ADDRESS >>> print IP('IP_ADDRESS') IP_ADDRESS >>> print IP('10') IP_ADDRESS >>> print IP('1080:0:0:0:8:800:200C:417A') IP_ADDRESS >>> print IP('1080::8:800:200C:417A') IP_ADDRESS >>> print IP('::1') IP_ADDRESS >>> print IP('::IP_ADDRESS') IP_ADDRESS3 >>> print IP('IP_ADDRESS/8') IP_ADDRESS/8 >>> print IP('IP_ADDRESS/IP_ADDRESS') IP_ADDRESS/8 >>> print IP('IP_ADDRESS-IP_ADDRESS') IP_ADDRESS/8 Nearly all class methods which return a string have an optional parameter 'wantprefixlen' which controlles if the prefixlen or netmask is printed. Per default the prefilen is always shown if the net contains more than one address. wantprefixlen == 0 / None don't return anything IP_ADDRESS wantprefixlen == 1 /prefix IP_ADDRESS/24 wantprefixlen == 2 /netmask IP_ADDRESS/IP_ADDRESS wantprefixlen == 3 -lastip IP_ADDRESS-IP_ADDRESS You can also change the defaults on an per-object basis by fiddeling with the class members NoPrefixForSingleIp WantPrefixLen >>> IP('IP_ADDRESS/32').strNormal() 'IP_ADDRESS' >>> IP('IP_ADDRESS/24').strNormal() 'IP_ADDRESS/24' >>> IP('IP_ADDRESS/24').strNormal(0) 'IP_ADDRESS' >>> IP('IP_ADDRESS/24').strNormal(1) 'IP_ADDRESS/24' >>> IP('IP_ADDRESS/24').strNormal(2) 'IP_ADDRESS/IP_ADDRESS' >>> IP('IP_ADDRESS/24').strNormal(3) 'IP_ADDRESS-IP_ADDRESS' >>> ip = IP('IP_ADDRESS') >>> print ip IP_ADDRESS >>> ip.NoPrefixForSingleIp = None >>> print ip IP_ADDRESS/32 >>> ip.WantPrefixLen = 3 >>> print ip IP_ADDRESS-IP_ADDRESS Further Information might be available at http://c0re.jp/c0de/IPy/ Hacked 2001 by EMAIL * better comparison (__cmp__ and friends) * tests for __cmp__ * always write hex values lowercase * interpret IP_ADDRESS as IP_ADDRESS * move size in bits into class variables to get rid of some "if self._ipversion ..." * support for base85 encoding * support for output of IPv6 encoded IPv4 Addresses * update address type tables * first-last notation should be allowed for IPv6 * add IPv6 docstring examples * check better for negative parameters * add addition / aggregation * move reverse name stuff out of the classes and refactor it * support for aggregation of more than two nets at once * support for aggregation with "holes" * support for finding common prefix * '>>' and '<<' for prefix manipulation * add our own exceptions instead ValueError all the time * rename checkPrefix to checkPrefixOk * add more documentation and doctests * refactor """
#!/usr/bin/env python # -*- coding: utf-8 -*- # ***********************IMPORTANT NMAP LICENSE TERMS************************ # * * # * The Nmap Security Scanner is (C) 1996-2013 Insecure.Com LLC. Nmap is * # * also a registered trademark of Insecure.Com LLC. This program is free * # * software; you may redistribute and/or modify it under the terms of the * # * GNU General Public License as published by the Free Software * # * Foundation; Version 2 ("GPL"), BUT ONLY WITH ALL OF THE CLARIFICATIONS * # * AND EXCEPTIONS DESCRIBED HEREIN. This guarantees your right to use, * # * modify, and redistribute this software under certain conditions. If * # * you wish to embed Nmap technology into proprietary software, we sell * # * alternative licenses (contact EMAIL Dozens of software * # * vendors already license Nmap technology such as host discovery, port * # * scanning, OS detection, version detection, and the Nmap Scripting * # * Engine. * # * * # * Note that the GPL places important restrictions on "derivative works", * # * yet it does not provide a detailed definition of that term. To avoid * # * misunderstandings, we interpret that term as broadly as copyright law * # * allows. For example, we consider an application to constitute a * # * derivative work for the purpose of this license if it does any of the * # * following with any software or content covered by this license * # * ("Covered Software"): * # * * # * o Integrates source code from Covered Software. * # * * # * o Reads or includes copyrighted data files, such as Nmap's nmap-os-db * # * or nmap-service-probes. * # * * # * o Is designed specifically to execute Covered Software and parse the * # * results (as opposed to typical shell or execution-menu apps, which will * # * execute anything you tell them to). * # * * # * o Includes Covered Software in a proprietary executable installer. The * # * installers produced by InstallShield are an example of this. Including * # * Nmap with other software in compressed or archival form does not * # * trigger this provision, provided appropriate open source decompression * # * or de-archiving software is widely available for no charge. For the * # * purposes of this license, an installer is considered to include Covered * # * Software even if it actually retrieves a copy of Covered Software from * # * another source during runtime (such as by downloading it from the * # * Internet). * # * * # * o Links (statically or dynamically) to a library which does any of the * # * above. * # * * # * o Executes a helper program, module, or script to do any of the above. * # * * # * This list is not exclusive, but is meant to clarify our interpretation * # * of derived works with some common examples. Other people may interpret * # * the plain GPL differently, so we consider this a special exception to * # * the GPL that we apply to Covered Software. Works which meet any of * # * these conditions must conform to all of the terms of this license, * # * particularly including the GPL Section 3 requirements of providing * # * source code and allowing free redistribution of the work as a whole. * # * * # * As another special exception to the GPL terms, Insecure.Com LLC grants * # * permission to link the code of this program with any version of the * # * OpenSSL library which is distributed under a license identical to that * # * listed in the included docs/licenses/OpenSSL.txt file, and distribute * # * linked combinations including the two. * # * * # * Any redistribution of Covered Software, including any derived works, * # * must obey and carry forward all of the terms of this license, including * # * obeying all GPL rules and restrictions. For example, source code of * # * the whole work must be provided and free redistribution must be * # * allowed. All GPL references to "this License", are to be treated as * # * including the special and conditions of the license text as well. * # * * # * Because this license imposes special exceptions to the GPL, Covered * # * Work may not be combined (even as part of a larger work) with plain GPL * # * software. The terms, conditions, and exceptions of this license must * # * be included as well. This license is incompatible with some other open * # * source licenses as well. In some cases we can relicense portions of * # * Nmap or grant special permissions to use it in other open source * # * software. Please contact EMAIL with any such requests. * # * Similarly, we don't incorporate incompatible open source software into * # * Covered Software without special permission from the copyright holders. * # * * # * If you have any questions about the licensing restrictions on using * # * Nmap in other works, are happy to help. As mentioned above, we also * # * offer alternative license to integrate Nmap into proprietary * # * applications and appliances. These contracts have been sold to dozens * # * of software vendors, and generally include a perpetual license as well * # * as providing for priority support and updates. They also fund the * # * continued development of Nmap. Please email EMAIL for * # * further information. * # * * # * If you received these files with a written license agreement or * # * contract stating terms other than the terms above, then that * # * alternative license agreement takes precedence over these comments. * # * * # * Source is provided to this software because we believe users have a * # * right to know exactly what a program is going to do before they run it. * # * This also allows you to audit the software for security holes (none * # * have been found so far). * # * * # * Source code also allows you to port Nmap to new platforms, fix bugs, * # * and add new features. You are highly encouraged to send your changes * # * to the EMAIL mailing list for possible incorporation into the * # * main distribution. By sending these changes to Fyodor or one of the * # * Insecure.Org development mailing lists, or checking them into the Nmap * # * source code repository, it is understood (unless you specify otherwise) * # * that you are offering the Nmap Project (Insecure.Com LLC) the * # * unlimited, non-exclusive right to reuse, modify, and relicense the * # * code. Nmap will always be available Open Source, but this is important * # * because the inability to relicense code has caused devastating problems * # * for other Free Software projects (such as KDE and NASM). We also * # * occasionally relicense the code to third parties as discussed above. * # * If you wish to specify special license conditions of your * # * contributions, just say so when you send them. * # * * # * This program is distributed in the hope that it will be useful, but * # * WITHOUT ANY WARRANTY; without even the implied warranty of * # * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Nmap * # * license file for more details (it's in a COPYING file included with * # * Nmap, and also available from https://svn.nmap.org/nmap/COPYING * # * * # ***************************************************************************/
""" ===================================== Structured Arrays (and Record Arrays) ===================================== Introduction ============ Numpy provides powerful capabilities to create arrays of structs or records. These arrays permit one to manipulate the data by the structs or by fields of the struct. A simple example will show what is meant.: :: >>> x = np.zeros((2,),dtype=('i4,f4,a10')) >>> x[:] = [(1,2.,'Hello'),(2,3.,"World")] >>> x array([(1, 2.0, 'Hello'), (2, 3.0, 'World')], dtype=[('f0', '>i4'), ('f1', '>f4'), ('f2', '|S10')]) Here we have created a one-dimensional array of length 2. Each element of this array is a record that contains three items, a 32-bit integer, a 32-bit float, and a string of length 10 or less. If we index this array at the second position we get the second record: :: >>> x[1] (2,3.,"World") Conveniently, one can access any field of the array by indexing using the string that names that field. In this case the fields have received the default names 'f0', 'f1' and 'f2'. :: >>> y = x['f1'] >>> y array([ 2., 3.], dtype=float32) >>> y[:] = 2*y >>> y array([ 4., 6.], dtype=float32) >>> x array([(1, 4.0, 'Hello'), (2, 6.0, 'World')], dtype=[('f0', '>i4'), ('f1', '>f4'), ('f2', '|S10')]) In these examples, y is a simple float array consisting of the 2nd field in the record. But, rather than being a copy of the data in the structured array, it is a view, i.e., it shares exactly the same memory locations. Thus, when we updated this array by doubling its values, the structured array shows the corresponding values as doubled as well. Likewise, if one changes the record, the field view also changes: :: >>> x[1] = (-1,-1.,"Master") >>> x array([(1, 4.0, 'Hello'), (-1, -1.0, 'Master')], dtype=[('f0', '>i4'), ('f1', '>f4'), ('f2', '|S10')]) >>> y array([ 4., -1.], dtype=float32) Defining Structured Arrays ========================== One defines a structured array through the dtype object. There are **several** alternative ways to define the fields of a record. Some of these variants provide backward compatibility with Numeric, numarray, or another module, and should not be used except for such purposes. These will be so noted. One specifies record structure in one of four alternative ways, using an argument (as supplied to a dtype function keyword or a dtype object constructor itself). This argument must be one of the following: 1) string, 2) tuple, 3) list, or 4) dictionary. Each of these is briefly described below. 1) String argument (as used in the above examples). In this case, the constructor expects a comma-separated list of type specifiers, optionally with extra shape information. The type specifiers can take 4 different forms: :: a) b1, i1, i2, i4, i8, u1, u2, u4, u8, f2, f4, f8, c8, c16, a<n> (representing bytes, ints, unsigned ints, floats, complex and fixed length strings of specified byte lengths) b) int8,...,uint8,...,float16, float32, float64, complex64, complex128 (this time with bit sizes) c) older Numeric/numarray type specifications (e.g. Float32). Don't use these in new code! d) Single character type specifiers (e.g H for unsigned short ints). Avoid using these unless you must. Details can be found in the Numpy book These different styles can be mixed within the same string (but why would you want to do that?). Furthermore, each type specifier can be prefixed with a repetition number, or a shape. In these cases an array element is created, i.e., an array within a record. That array is still referred to as a single field. An example: :: >>> x = np.zeros(3, dtype='3int8, float32, (2,3)float64') >>> x array([([0, 0, 0], 0.0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), ([0, 0, 0], 0.0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), ([0, 0, 0], 0.0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])], dtype=[('f0', '|i1', 3), ('f1', '>f4'), ('f2', '>f8', (2, 3))]) By using strings to define the record structure, it precludes being able to name the fields in the original definition. The names can be changed as shown later, however. 2) Tuple argument: The only relevant tuple case that applies to record structures is when a structure is mapped to an existing data type. This is done by pairing in a tuple, the existing data type with a matching dtype definition (using any of the variants being described here). As an example (using a definition using a list, so see 3) for further details): :: >>> x = np.zeros(3, dtype=('i4',[('r','u1'), ('g','u1'), ('b','u1'), ('a','u1')])) >>> x array([0, 0, 0]) >>> x['r'] array([0, 0, 0], dtype=uint8) In this case, an array is produced that looks and acts like a simple int32 array, but also has definitions for fields that use only one byte of the int32 (a bit like Fortran equivalencing). 3) List argument: In this case the record structure is defined with a list of tuples. Each tuple has 2 or 3 elements specifying: 1) The name of the field ('' is permitted), 2) the type of the field, and 3) the shape (optional). For example:: >>> x = np.zeros(3, dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))]) >>> x array([(0.0, 0.0, [[0.0, 0.0], [0.0, 0.0]]), (0.0, 0.0, [[0.0, 0.0], [0.0, 0.0]]), (0.0, 0.0, [[0.0, 0.0], [0.0, 0.0]])], dtype=[('x', '>f4'), ('y', '>f4'), ('value', '>f4', (2, 2))]) 4) Dictionary argument: two different forms are permitted. The first consists of a dictionary with two required keys ('names' and 'formats'), each having an equal sized list of values. The format list contains any type/shape specifier allowed in other contexts. The names must be strings. There are two optional keys: 'offsets' and 'titles'. Each must be a correspondingly matching list to the required two where offsets contain integer offsets for each field, and titles are objects containing metadata for each field (these do not have to be strings), where the value of None is permitted. As an example: :: >>> x = np.zeros(3, dtype={'names':['col1', 'col2'], 'formats':['i4','f4']}) >>> x array([(0, 0.0), (0, 0.0), (0, 0.0)], dtype=[('col1', '>i4'), ('col2', '>f4')]) The other dictionary form permitted is a dictionary of name keys with tuple values specifying type, offset, and an optional title. :: >>> x = np.zeros(3, dtype={'col1':('i1',0,'title 1'), 'col2':('f4',1,'title 2')}) >>> x array([(0, 0.0), (0, 0.0), (0, 0.0)], dtype=[(('title 1', 'col1'), '|i1'), (('title 2', 'col2'), '>f4')]) Accessing and modifying field names =================================== The field names are an attribute of the dtype object defining the record structure. For the last example: :: >>> x.dtype.names ('col1', 'col2') >>> x.dtype.names = ('x', 'y') >>> x array([(0, 0.0), (0, 0.0), (0, 0.0)], dtype=[(('title 1', 'x'), '|i1'), (('title 2', 'y'), '>f4')]) >>> x.dtype.names = ('x', 'y', 'z') # wrong number of names <type 'exceptions.ValueError'>: must replace all names at once with a sequence of length 2 Accessing field titles ==================================== The field titles provide a standard place to put associated info for fields. They do not have to be strings. :: >>> x.dtype.fields['x'][2] 'title 1' Accessing multiple fields at once ==================================== You can access multiple fields at once using a list of field names: :: >>> x = np.array([(1.5,2.5,(1.0,2.0)),(3.,4.,(4.,5.)),(1.,3.,(2.,6.))], dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))]) Notice that `x` is created with a list of tuples. :: >>> x[['x','y']] array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)], dtype=[('x', '<f4'), ('y', '<f4')]) >>> x[['x','value']] array([(1.5, [[1.0, 2.0], [1.0, 2.0]]), (3.0, [[4.0, 5.0], [4.0, 5.0]]), (1.0, [[2.0, 6.0], [2.0, 6.0]])], dtype=[('x', '<f4'), ('value', '<f4', (2, 2))]) Notice that the fields are always returned in the same order regardless of the sequence they are asked for. :: >>> x[['y','x']] array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)], dtype=[('x', '<f4'), ('y', '<f4')]) Filling structured arrays ========================= Structured arrays can be filled by field or row by row. :: >>> arr = np.zeros((5,), dtype=[('var1','f8'),('var2','f8')]) >>> arr['var1'] = np.arange(5) If you fill it in row by row, it takes a take a tuple (but not a list or array!):: >>> arr[0] = (10,20) >>> arr array([(10.0, 20.0), (1.0, 0.0), (2.0, 0.0), (3.0, 0.0), (4.0, 0.0)], dtype=[('var1', '<f8'), ('var2', '<f8')]) More information ==================================== You can find some more information on recarrays and structured arrays (including the difference between the two) `here <http://www.scipy.org/Cookbook/Recarray>`_. """
"""The tests for the MQTT light platform. Configuration for RGB Version with brightness: light: platform: mqtt name: "Office Light RGB" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" brightness_state_topic: "office/rgb1/brightness/status" brightness_command_topic: "office/rgb1/brightness/set" rgb_state_topic: "office/rgb1/rgb/status" rgb_command_topic: "office/rgb1/rgb/set" qos: 0 payload_on: "on" payload_off: "off" Configuration for XY Version with brightness: light: platform: mqtt name: "Office Light XY" state_topic: "office/xy1/light/status" command_topic: "office/xy1/light/switch" brightness_state_topic: "office/xy1/brightness/status" brightness_command_topic: "office/xy1/brightness/set" xy_state_topic: "office/xy1/xy/status" xy_command_topic: "office/xy1/xy/set" qos: 0 payload_on: "on" payload_off: "off" config without RGB: light: platform: mqtt name: "Office Light" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" brightness_state_topic: "office/rgb1/brightness/status" brightness_command_topic: "office/rgb1/brightness/set" qos: 0 payload_on: "on" payload_off: "off" config without RGB and brightness: light: platform: mqtt name: "Office Light" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" qos: 0 payload_on: "on" payload_off: "off" config for RGB Version with brightness and scale: light: platform: mqtt name: "Office Light RGB" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" brightness_state_topic: "office/rgb1/brightness/status" brightness_command_topic: "office/rgb1/brightness/set" brightness_scale: 99 rgb_state_topic: "office/rgb1/rgb/status" rgb_command_topic: "office/rgb1/rgb/set" rgb_scale: 99 qos: 0 payload_on: "on" payload_off: "off" config with brightness and color temp light: platform: mqtt name: "Office Light Color Temp" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" brightness_state_topic: "office/rgb1/brightness/status" brightness_command_topic: "office/rgb1/brightness/set" brightness_scale: 99 color_temp_state_topic: "office/rgb1/color_temp/status" color_temp_command_topic: "office/rgb1/color_temp/set" qos: 0 payload_on: "on" payload_off: "off" config with brightness and effect light: platform: mqtt name: "Office Light Color Temp" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" brightness_state_topic: "office/rgb1/brightness/status" brightness_command_topic: "office/rgb1/brightness/set" brightness_scale: 99 effect_state_topic: "office/rgb1/effect/status" effect_command_topic: "office/rgb1/effect/set" effect_list: - rainbow - colorloop qos: 0 payload_on: "on" payload_off: "off" config for RGB Version with white value and scale: light: platform: mqtt name: "Office Light RGB" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" white_value_state_topic: "office/rgb1/white_value/status" white_value_command_topic: "office/rgb1/white_value/set" white_value_scale: 99 rgb_state_topic: "office/rgb1/rgb/status" rgb_command_topic: "office/rgb1/rgb/set" rgb_scale: 99 qos: 0 payload_on: "on" payload_off: "off" config for RGB Version with RGB command template: light: platform: mqtt name: "Office Light RGB" state_topic: "office/rgb1/light/status" command_topic: "office/rgb1/light/switch" rgb_state_topic: "office/rgb1/rgb/status" rgb_command_topic: "office/rgb1/rgb/set" rgb_command_template: "{{ '#%02x%02x%02x' | format(red, green, blue)}}" qos: 0 payload_on: "on" payload_off: "off" Configuration for HS Version with brightness: light: platform: mqtt name: "Office Light HS" state_topic: "office/hs1/light/status" command_topic: "office/hs1/light/switch" brightness_state_topic: "office/hs1/brightness/status" brightness_command_topic: "office/hs1/brightness/set" hs_state_topic: "office/hs1/hs/status" hs_command_topic: "office/hs1/hs/set" qos: 0 payload_on: "on" payload_off: "off" """
# Yeh exercise hai # Har line of code se pehle aapko ek line mei comment mei daal kar likhna hai, ki uss line of code ka matlab kya hai # Aap jyada comments bhi likh sakte hai, jitne jyada comments likhenge, utna aapkya fayda hoga # Question 1 # Pehle ke variable_list mein 0 se 100 integers ki list banayein # Fir aapne iss list pe iterate karte hue 3 nayi list banani hai: # - Pehli_list naam ki list mein variable_list ke items ko 3 se multiply karke jo result aaya hai, woh hona chaiye # - Dusri_list naam ki list mein variable_list ke items ko 4 se divide karke jo result aata hai, woh hona chaiye. # Iss dusri list mein saari items `float` honi chaiye # - Teesri_list naam ki list variable_list ke items ko "NavGurukul" string ke saath jodna hai. Jaise: # Agar variable_list ka pehla item 0 hai, iss teesri_list ka pehla item "NavGurukul0" hona chaiye # Dusra item "NavGurukul1" # Teesra item "NavGurukul2" # Iss program mein bas list banani hai. Kuch print nahi karna. #Question 2 # - Ek number ka factorial 1 se leke uss number tak ke saare numbers ko ek saath multiply karke nikalta hai. # Jaise 3 ka factorial 6 hai. Kyunki - # 1 * 2 * 3 ko calculate karke 6 aata hai # 4 ka factorial 24 hai. Kyunki - # 1 * 2 * 3 * 4 ko calculate karke 24 aata hai # Aise hi 7 ka factorial 5040 hai. Kyunki - # 1 * 2 * 3 * 4 * 5 * 6 * 7 ko calculate karke 5040 aata hai # Ab aap ek program likhoge jo ki user se ek integer input lega aur fir uska factorial print karega. # Agar user 3 dalega ko 6 print karega, 7 dalega toh 5040 print karega aur aise hi dusre numbers ke lie. # Note: Abhi ke liye yeh soch lo ki user sirf positive integers hi dalega. Negative integers kabhi nahi dalega. # Question 3 # numbers_list naam ki ek list banayein jisme 1 se 10000 (das hazar) tak integers hon # Ab numbers_list ke saare numbers ka sum nikalne ka code likhein. # End mein sum ko print karein # Socho aapko paas ek list hai jisme kuch values baar baar aa rahi hain. # Ek aisa code likho jisse aap ek nayi list banayein jisme iss list ki items ek ek baar hi aaye. # Jaise: # string_list = ["Rishabh", "Rishabh", "Abhishek", "Rishabh", "Divyashish", "Divyashish"] # Aapke code ko iss string_list se ek nayi list banani chaiye jo yeh hogi: # new_list = ["Rishabh", "Abhishek", "Divyashish"] # Yeh list dekhiye isme saare naam ek ek baar aa rahe hain. Farak nahi padta ki pichli list mein kitne baar aa rahe the. # Samajhne ke liye ek aur example padho # string_list = ["Delhi", "Delhi", "Mumbai", "Mumbai", "Delhi", "Chennai", 'Chennai'] # Isse aapke code ko yeh nayi list banani hogi: # new_list = ["Delhi", "Mumbai", "Chennai"] # Iss nayi list mein sirf saare shehron ka naam sirf ek baar aa raha hai. # Yeh rahi aapki pehli items repeat hone waali list:
""" Discrete Fourier Transform (:mod:`numpy.fft`) ============================================= .. currentmodule:: numpy.fft Standard FFTs ------------- .. autosummary:: :toctree: generated/ fft Discrete Fourier transform. ifft Inverse discrete Fourier transform. fft2 Discrete Fourier transform in two dimensions. ifft2 Inverse discrete Fourier transform in two dimensions. fftn Discrete Fourier transform in N-dimensions. ifftn Inverse discrete Fourier transform in N dimensions. Real FFTs --------- .. autosummary:: :toctree: generated/ rfft Real discrete Fourier transform. irfft Inverse real discrete Fourier transform. rfft2 Real discrete Fourier transform in two dimensions. irfft2 Inverse real discrete Fourier transform in two dimensions. rfftn Real discrete Fourier transform in N dimensions. irfftn Inverse real discrete Fourier transform in N dimensions. Hermitian FFTs -------------- .. autosummary:: :toctree: generated/ hfft Hermitian discrete Fourier transform. ihfft Inverse Hermitian discrete Fourier transform. Helper routines --------------- .. autosummary:: :toctree: generated/ fftfreq Discrete Fourier Transform sample frequencies. fftshift Shift zero-frequency component to center of spectrum. ifftshift Inverse of fftshift. Background information ---------------------- Fourier analysis is fundamentally a method for expressing a function as a sum of periodic components, and for recovering the signal from those components. When both the function and its Fourier transform are replaced with discretized counterparts, it is called the discrete Fourier transform (DFT). The DFT has become a mainstay of numerical computing in part because of a very fast algorithm for computing it, called the Fast Fourier Transform (FFT), which was known to Gauss (1805) and was brought to light in its current form by Cooley and Tukey [CT]_. Press et al. [NR]_ provide an accessible introduction to Fourier analysis and its applications. Because the discrete Fourier transform separates its input into components that contribute at discrete frequencies, it has a great number of applications in digital signal processing, e.g., for filtering, and in this context the discretized input to the transform is customarily referred to as a *signal*, which exists in the *time domain*. The output is called a *spectrum* or *transform* and exists in the *frequency domain*. There are many ways to define the DFT, varying in the sign of the exponent, normalization, etc. In this implementation, the DFT is defined as .. math:: A_k = \\sum_{m=0}^{n-1} a_m \\exp\\left\\{-2\\pi i{mk \\over n}\\right\\} \\qquad k = 0,\\ldots,n-1. The DFT is in general defined for complex inputs and outputs, and a single-frequency component at linear frequency :math:`f` is represented by a complex exponential :math:`a_m = \\exp\\{2\\pi i\\,f m\\Delta t\\}`, where :math:`\\Delta t` is the sampling interval. The values in the result follow so-called "standard" order: If ``A = fft(a, n)``, then ``A[0]`` contains the zero-frequency term (the mean of the signal), which is always purely real for real inputs. Then ``A[1:n/2]`` contains the positive-frequency terms, and ``A[n/2+1:]`` contains the negative-frequency terms, in order of decreasingly negative frequency. For an even number of input points, ``A[n/2]`` represents both positive and negative Nyquist frequency, and is also purely real for real input. For an odd number of input points, ``A[(n-1)/2]`` contains the largest positive frequency, while ``A[(n+1)/2]`` contains the largest negative frequency. The routine ``np.fft.fftfreq(A)`` returns an array giving the frequencies of corresponding elements in the output. The routine ``np.fft.fftshift(A)`` shifts transforms and their frequencies to put the zero-frequency components in the middle, and ``np.fft.ifftshift(A)`` undoes that shift. When the input `a` is a time-domain signal and ``A = fft(a)``, ``np.abs(A)`` is its amplitude spectrum and ``np.abs(A)**2`` is its power spectrum. The phase spectrum is obtained by ``np.angle(A)``. The inverse DFT is defined as .. math:: a_m = \\frac{1}{n}\\sum_{k=0}^{n-1}A_k\\exp\\left\\{2\\pi i{mk\\over n}\\right\\} \\qquad n = 0,\\ldots,n-1. It differs from the forward transform by the sign of the exponential argument and the normalization by :math:`1/n`. Real and Hermitian transforms ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When the input is purely real, its transform is Hermitian, i.e., the component at frequency :math:`f_k` is the complex conjugate of the component at frequency :math:`-f_k`, which means that for real inputs there is no information in the negative frequency components that is not already available from the positive frequency components. The family of `rfft` functions is designed to operate on real inputs, and exploits this symmetry by computing only the positive frequency components, up to and including the Nyquist frequency. Thus, ``n`` input points produce ``n/2+1`` complex output points. The inverses of this family assumes the same symmetry of its input, and for an output of ``n`` points uses ``n/2+1`` input points. Correspondingly, when the spectrum is purely real, the signal is Hermitian. The `hfft` family of functions exploits this symmetry by using ``n/2+1`` complex points in the input (time) domain for ``n`` real points in the frequency domain. In higher dimensions, FFTs are used, e.g., for image analysis and filtering. The computational efficiency of the FFT means that it can also be a faster way to compute large convolutions, using the property that a convolution in the time domain is equivalent to a point-by-point multiplication in the frequency domain. In two dimensions, the DFT is defined as .. math:: A_{kl} = \\sum_{m=0}^{M-1} \\sum_{n=0}^{N-1} a_{mn}\\exp\\left\\{-2\\pi i \\left({mk\\over M}+{nl\\over N}\\right)\\right\\} \\qquad k = 0, \\ldots, N-1;\\quad l = 0, \\ldots, M-1, which extends in the obvious way to higher dimensions, and the inverses in higher dimensions also extend in the same way. References ^^^^^^^^^^ .. [CT] NAME NAME and NAME Tukey, 1965, "An algorithm for the machine calculation of complex Fourier series," *Math. Comput.* 19: 297-301. .. [NR] NAME NAME NAME and NAME 2007, *Numerical Recipes: The Art of Scientific Computing*, ch. 12-13. Cambridge Univ. Press, Cambridge, UK. Examples ^^^^^^^^ For examples, see the various functions. """
""" ============ Array basics ============ Array types and conversions between types ========================================= Numpy supports a much greater variety of numerical types than Python does. This section shows which are available, and how to modify an array's data-type. ========== ========================================================= Data type Description ========== ========================================================= bool Boolean (True or False) stored as a byte int Platform integer (normally either ``int32`` or ``int64``) int8 Byte (-128 to 127) int16 Integer (-32768 to 32767) int32 Integer (-2147483648 to 2147483647) int64 Integer (9223372036854775808 to 9223372036854775807) uint8 Unsigned integer (0 to 255) uint16 Unsigned integer (0 to 65535) uint32 Unsigned integer (0 to 4294967295) uint64 Unsigned integer (0 to 18446744073709551615) float Shorthand for ``float64``. float16 Half precision float: sign bit, 5 bits exponent, 10 bits mantissa float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa complex Shorthand for ``complex128``. complex64 Complex number, represented by two 32-bit floats (real and imaginary components) complex128 Complex number, represented by two 64-bit floats (real and imaginary components) ========== ========================================================= Numpy numerical types are instances of ``dtype`` (data-type) objects, each having unique characteristics. Once you have imported NumPy using :: >>> import numpy as np the dtypes are available as ``np.bool``, ``np.float32``, etc. Advanced types, not listed in the table above, are explored in section :ref:`structured_arrays`. There are 5 basic numerical types representing booleans (bool), integers (int), unsigned integers (uint) floating point (float) and complex. Those with numbers in their name indicate the bitsize of the type (i.e. how many bits are needed to represent a single value in memory). Some types, such as ``int`` and ``intp``, have differing bitsizes, dependent on the platforms (e.g. 32-bit vs. 64-bit machines). This should be taken into account when interfacing with low-level code (such as C or Fortran) where the raw memory is addressed. Data-types can be used as functions to convert python numbers to array scalars (see the array scalar section for an explanation), python sequences of numbers to arrays of that type, or as arguments to the dtype keyword that many numpy functions or methods accept. Some examples:: >>> import numpy as np >>> x = np.float32(1.0) >>> x 1.0 >>> y = np.int_([1,2,4]) >>> y array([1, 2, 4]) >>> z = np.arange(3, dtype=np.uint8) >>> z array([0, 1, 2], dtype=uint8) Array types can also be referred to by character codes, mostly to retain backward compatibility with older packages such as Numeric. Some documentation may still refer to these, for example:: >>> np.array([1, 2, 3], dtype='f') array([ 1., 2., 3.], dtype=float32) We recommend using dtype objects instead. To convert the type of an array, use the .astype() method (preferred) or the type itself as a function. For example: :: >>> z.astype(float) #doctest: +NORMALIZE_WHITESPACE array([ 0., 1., 2.]) >>> np.int8(z) array([0, 1, 2], dtype=int8) Note that, above, we use the *Python* float object as a dtype. NumPy knows that ``int`` refers to ``np.int``, ``bool`` means ``np.bool`` and that ``float`` is ``np.float``. The other data-types do not have Python equivalents. To determine the type of an array, look at the dtype attribute:: >>> z.dtype dtype('uint8') dtype objects also contain information about the type, such as its bit-width and its byte-order. The data type can also be used indirectly to query properties of the type, such as whether it is an integer:: >>> d = np.dtype(int) >>> d dtype('int32') >>> np.issubdtype(d, int) True >>> np.issubdtype(d, float) False Array Scalars ============= Numpy generally returns elements of arrays as array scalars (a scalar with an associated dtype). Array scalars differ from Python scalars, but for the most part they can be used interchangeably (the primary exception is for versions of Python older than v2.x, where integer array scalars cannot act as indices for lists and tuples). There are some exceptions, such as when code requires very specific attributes of a scalar or when it checks specifically whether a value is a Python scalar. Generally, problems are easily fixed by explicitly converting array scalars to Python scalars, using the corresponding Python type function (e.g., ``int``, ``float``, ``complex``, ``str``, ``unicode``). The primary advantage of using array scalars is that they preserve the array type (Python may not have a matching scalar type available, e.g. ``int16``). Therefore, the use of array scalars ensures identical behaviour between arrays and scalars, irrespective of whether the value is inside an array or not. NumPy scalars also have many of the same methods arrays do. """
# Copyright (c) 2013 The Native Client Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. ################################################################################ # File format: # three columns separated by commas. Each line describes one instruction. # Notation for argument types and sizes and for opcodes is based on # AMD64 Architecture Programmer's Manual. ################################################################################ # First column: instruction description. # Includes name of the instruction and arguments. # # Arguments consist of four parts: # 1. Read/write attribute (optional). # 2. Argument type. # 3. Argument size. # 4. Implicit argument mark (optional). # # Read/write attribute: # ': Instruction does not use this argument (lea or nop). # =: Instruction reads from this argument. # !: Instruction writes to this argument. # &: Instruction reads this argument and writes the result to it. # By default one- and two-operand instructions are assumed to read all # operands and store result to the last one, while instructions with # three or more operands are assumed to read all operands except last one # which is used to store the result of the execution. # Possible argument types: # a: Accumulator: %al/%ax/%eax/%rax/%xmm0 (depending on size). # c: Counter register: %cl/%cx/%ecx/%rcx (depending on size). # d: Data register: %dl/%dx/%edx/%rdx (depending on size). # f: x87 register in opcode (3 least significant bits). # i: Second immediate value encoded in the instruction. # o: I/O port in %dx (used in "in"/"out" instructions). # r: Register in opcode (3 least significant bits plus rex.B). # t: Top of the x87 stack (%st). # x: A memory operand addressed by the %ds:(%[er]bx). See "xlat". # B: General purpose register specified by the VEX/XOP.vvvv field. # C: Control register specified by the ModRM.reg field. # D: Debug register specified by the ModRM.reg field. # E: General purpose register or memory operand specified by the r/m # field of the ModRM byte. For memory operands, the ModRM byte may # be followed by a SIB byte to specify one of the indexed # register-indirect addressing forms. # G: General purpose register specified by the reg field of ModRM. # H: YMM or XMM register specified by the VEX/XOP.vvvv field. # I: Immediate value encoded in the instruction. # J: The instruction encoding includes a relative offset that is added to # the rIP. # L: YMM or XMM register specified using the most-significant 4 bits of # the last byte of the instruction. In legacy or compatibility mode # the most significant bit is ignored. # M: A memory operand specified by the {mod, r/m} field of the ModRM byte. # ModRM.mod != 11b. # N: 64-bit MMX register specified by the ModRM.r/m field. The ModRM.mod # field must be 11b. # O: The offset of an operand is encoded in the instruction. There is no # ModRM byte in the instruction encoding. Indexed register-indirect # addressing using the SIB byte is not supported. # P: 64-bit MMX register specified by the ModRM.reg field. # Q: 64-bit MMX-register or memory operand specified by the {mod, r/m} # field of the ModRM byte. For memory operands, the ModRM byte may # be followed by a SIB byte to specify one of the indexed # register-indirect addressing forms. # R: General purpose register specified by the ModRM.r/m field. # The ModRM.mod field must be 11b. # S: Segment register specified by the ModRM.reg field. # U: YMM/XMM register specified by the ModRM.r/m field. # The ModRM.mod field must be 11b. # V: YMM/XMM register specified by the ModRM.reg field. # W: YMM/XMM register or memory operand specified by the {mod, r/m} field # of the ModRM byte. For memory operands, the ModRM byte may be # followed by a SIB byte to specify one of the indexed # register-indirect addressing forms. # X: A memory operand addressed by the %ds:%[er]si registers. Used in # string instructions. # Y: A memory operand addressed by the %es:%[er]di registers. Used in # string instructions. # Possible sizes: # (no size provided): # A byte, word, doubleword, or quadword (in 64-bit mode), # depending on the effective operand size. # 2: Two bits (see VPERMIL2Px instruction). # 7: x87 register %st(N). # b: A byte, irrespective of the effective operand size. # d: A doubleword (32-bit), irrespective of the effective operand size. # do: A double octword (256 bits), irrespective of the effective operand # size. # dq: A double quadword (128 bits), irrespective of the effective # operand size. # fq: A quadra quadword (256 bits), irrespective of the effective # operand size. # o: An octword (128 bits), irrespective of the effective operand size. # p: A 32-bit or 48-bit far pointer, depending on the effective operand # size. # pb: A Vector with byte-wide (8-bit) elements (packed byte). # pd: A double-precision (64-bit) floating-point vector operand (packed # double-precision). # pdw: Vector composed of 32-bit doublewords. # pdwx: Vector composed of 32-bit doublewords. L bit selects 256bit YMM # registers. # pdx: A double-precision (64-bit) floating-point vector operand (packed # double-precision). L bit selects 256bit YMM registers. # ph: A half-precision (16-bit) floating-point vector operand (packed # half-precision). # phx: A half-precision (16-bit) floating-point vector operand (packed # half-precision). L bit selects 256bit YMM registers. # pi: Vector composed of 16-bit integers (packed integer). # pj: Vector composed of 32-bit integers (packed double integer). # pjx: Vector composed of 32-bit integers (packed double integer). # L bit selects 256bit YMM registers. # pk: Vector composed of 8-bit integers (packed half-word integer). # pkx: Vector composed of 8-bit integers (packed half-word integer). # L bit selects 256bit YMM registers. # pq: Vector composed of 64-bit integers (packed quadword integer). # pqw: Vector composed of 64-bit quadwords (packed quadword). # pqwx: Vector composed of 64-bit quadwords (packed quadword). L bit # selects 256bit YMM registers. # pqx: Vector composed of 64-bit integers (packed quadword integer). # L bit selects 256bit YMM registers. # ps: A single-precision floating-point vector operand (packed # single-precision). # psx: A single-precision floating-point vector operand (packed # single-precision). L bit selects 256bit YMM registers. # pw: Vector composed of 16-bit words (packed word). # q: A quadword (64-bit), irrespective of the effective operand size. # r: Register size (32bit in 32bit mode, 64bit in 64bit mode). # s: Segment register (if register operand). # s: A 6-byte or 10-byte pseudo-descriptor (if memory operand). # sb: A scalar 10-byte packed BCD value (scalar BCD). # sd: A scalar double-precision floating-point operand (scalar double). # se: A 14-byte or 28-byte x87 environment. # si: A scalar doubleword (32-bit) integer operand (scalar integer). # sq: A scalar quadword (64-bit) integer operand (scalar integer). # sr: A 94-byte or 108-byte x87 state. # ss: A scalar single-precision floating-point operand (scalar single). # st: A scalar 80bit-precision floating-point operand (scalar tenbytes). # sw: A scalar word (16-bit) integer operand (scalar integer). # sx: A 512-byte extended x87/MMX/XMM state. # v: A word, doubleword, or quadword (in 64-bit mode), depending on # the effective operand size. # w: A word, irrespective of the effective operand size. # x: Instruction supports both vector sizes (128 bits or 256 bits). # Size is encoded using the VEX/XOP.L field. (L=0: 128 bits; # L=1: 256 bits). Usually this symbol is appended to ps or pd, but # sometimes it is used alone. For gen_dfa psx, pdx and x # are the same. # y: A doubleword or quadword depending on effective operand size. # z: A word if the effective operand size is 16 bits, or a doubleword # if the effective operand size is 32 or 64 bits. # Implicit argument mark: # *: This argument is implicit. It's not shown in the diassembly listing. ################################################################################ # Second column: instruction opcodes. # Includes all opcode bytes. If first opcode bytes is 0x66/data16, # 0xf2/repnz, or 0xf3/rep/repz then they can be moved before other prefixes # (and will be moved before REX prefix if it's allowed). Note: data16, repnz, # and rep/repz opcodes will set appropriate flags while 0x66, 0xf2, and 0xf3 # will not. # If part of the opcode is stored in ModRM byte then opcode should include the # usual "/0", "/1", ..., "/7" "bytes". # For VEX/XOP instructions it is expected that first three opcode bytes are # specified in the following form: # 0xc4 (or 0x8f) # RXB.<map_select> # <W>.<vvvv>.<L>.<pp> # (so they describe long form of VEX prefix; short form is deduced # automatically when appropriate) ################################################################################ # Third column: additional instruction notes. # Different kind of notes for the instruction: non-typical prefixes (for # example "lock" prefix or "rep" prefix), CPUID checks, etc. # # Possible prefixes: # branch_hint: branch hint prefixes are allowed (0x2E, 0x3E) # condrep: prefixes "repnz" and "repz" are allowed for the instruction # lock: prefix "lock" is allowed for the instruction # rep: prefix "rep" is allowed for the instruction (it's alias of "repz") # no_memory_access: command does not access memory in detectable way: lea, # nop, prefetch* instructions... # norex: "rex" prefix can not be used with this instruction (various "nop" # instructions use this flag) # norexw: "rex.W" can not be used with this instruction (usually used when # instruction with "rex.W" have a different name: e.g. "movd"/"movq") # # Instruction enabling/disabling: # ia32: ia32-only instruction # amd64: amd64-only instruction # nacl-forbidden: instruction is not supported in NaCl sandbox # nacl-ia32-forbidden: instruction is not supported in ia32 NaCl sandbox # nacl-amd64-forbidden: instruction is not supported in amd64 NaCl sandbox # # Special marks: # nacl-amd64-zero-extends: instruction can be used to zero-extend register # in amd64 mode # nacl-amd64-modifiable: instruction can be modified in amd64 mode # att-show-name-suffix-{b,l,ll,t,s,q,x,y,w}: instruction is shown with the # given suffix by objdump in AT&T mode # # CPU features are defined in validator_internal.h. ################################################################################ # Technically, columns are separated with mere ',' followed by spaces for # readability, but there are quoted instruction names that include commas # not followed by spaces (see nops.def). # For simplicity I choose to rely on this coincidence and use split-based parser # instead of proper recursive descent one. # If by accident somebody put ', ' in quoted instruction name, it will fail # loudly, because closing quote then will fall into second or third column and # will cause parse error. # TODO(shcherbina): use for column separator something that is never encountered # in columns, like semicolon?
#fe0000 #fd0000 #fc0000 #fb0000 #fa0000 #f90000 #f80000 #f70000 #f60000 #f50000 #f40000 #f30000 #f20000 #f10000 #f00000 #ef0000 #ee0000 #ed0000 #ec0000 #eb0000 #ea0000 #e90000 #e80000 #e70000 #e60000 #e50000 #e40000 #e30000 #e20000 #e10000 #e00000 #df0000 #de0000 #dd0000 #dc0000 #db0000 #da0000 #d90000 #d80000 #d70000 #d60000 #d50000 #d40000 #d30000 #d20000 #d10000 #d00000 #cf0000 #ce0000 #cd0000 #cc0000 #cb0000 #ca0000 #c90000 #c80000 #c70000 #c60000 #c50000 #c40000 #c30000 #c20000 #c10000 #c00000 #bf0000 #bf0000 #be0000 #bd0000 #bc0000 #bb0000 #ba0000 #b90000 #b80000 #b70000 #b60000 #b50000 #b40000 #b30000 #b20000 #b10000 #b00000 #af0000 #ae0000 #ad0000 #ac0000 #ab0000 #aa0000 #a90000 #a80000 #a70000 #a60000 #a50000 #a40000 #a30000 #a20000 #a10000 #a00000 #9f0000 #9e0000 #9d0000 #9c0000 #9b0000 #9a0000 #990000 #980000 #970000 #960000 #950000 #940000 #930000 #920000 #910000 #900000 #8f0000 #8e0000 #8d0000 #8c0000 #8b0000 #8a0000 #890000 #880000 #870000 #860000 #850000 #840000 #830000 #820000 #810000 #800000 #7f0000 #7e0000 #7d0000 #7c0000 #7b0000 #7a0000 #790000 #780000 #770000 #760000 #750000 #740000 #730000 #720000 #710000 #700000 #6f0000 #6e0000 #6d0000 #6c0000 #6b0000 #6a0000 #690000 #680000 #670000 #660000 #650000 #640000 #630000 #620000 #610000 #600000 #5f0000 #5e0000 #5d0000 #5c0000 #5b0000 #5a0000 #590000 #580000 #570000 #560000 #550000 #540000 #530000 #520000 #510000 #500000 #4f0000 #4e0000 #4d0000 #4c0000 #4b0000 #4a0000 #490000 #480000 #470000 #460000 #450000 #440000 #430000 #420000 #410000 #400000 #400000 #3f0000 #3e0000 #3d0000 #3c0000 #3b0000 #3a0000 #390000 #380000 #370000 #360000 #350000 #340000 #330000 #320000 #310000 #300000 #2f0000 #2e0000 #2d0000 #2c0000 #2b0000 #2a0000 #290000 #280000 #270000 #260000 #250000 #240000 #230000 #220000 #210000 #200000 #1f0000 #1e0000 #1d0000 #1c0000 #1b0000 #1a0000 #190000 #180000 #170000 #160000 #150000 #140000 #130000 #120000 #110000 #100000 #0f0000 #0e0000 #0d0000 #0c0000 #0b0000 #0a0000 #090000 #080000 #070000 #060000 #050000 #040000 #030000 #020000 #010000
#!/usr/bin/env python # (c) 2013, NAME <EMAIL> # # This file is part of Ansible. # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # # # Author: NAME <EMAIL> # # Description: # This module queries local or remote Docker daemons and generates # inventory information. # # This plugin does not support targeting of specific hosts using the --host # flag. Instead, it queries the Docker API for each container, running # or not, and returns this data all once. # # The plugin returns the following custom attributes on Docker containers: # docker_args # docker_config # docker_created # docker_driver # docker_exec_driver # docker_host_config # docker_hostname_path # docker_hosts_path # docker_id # docker_image # docker_name # docker_network_settings # docker_path # docker_resolv_conf_path # docker_state # docker_volumes # docker_volumes_rw # # Requirements: # The docker-py module: https://github.com/dotcloud/docker-py # # Notes: # A config file can be used to configure this inventory module, and there # are several environment variables that can be set to modify the behavior # of the plugin at runtime: # DOCKER_CONFIG_FILE # DOCKER_HOST # DOCKER_VERSION # DOCKER_TIMEOUT # DOCKER_PRIVATE_SSH_PORT # DOCKER_DEFAULT_IP # # Environment Variables: # environment variable: DOCKER_CONFIG_FILE # description: # - A path to a Docker inventory hosts/defaults file in YAML format # - A sample file has been provided, colocated with the inventory # file called 'docker.yml' # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_HOST # description: # - The socket on which to connect to a Docker daemon API # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_VERSION # description: # - Version of the Docker API to use # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_TIMEOUT # description: # - Timeout in seconds for connections to Docker daemon API # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_PRIVATE_SSH_PORT # description: # - The private port (container port) on which SSH is listening # for connections # default: 22 # required: false # environment variable: DOCKER_DEFAULT_IP # description: # - This environment variable overrides the container SSH connection # IP address (aka, 'ansible_ssh_host') # # This option allows one to override the ansible_ssh_host whenever # Docker has exercised its default behavior of binding private ports # to all interfaces of the Docker host. This behavior, when dealing # with remote Docker hosts, does not allow Ansible to determine # a proper host IP address on which to connect via SSH to containers. # By default, this inventory module assumes all IP_ADDRESS-exposed # ports to be bound to localhost:<port>. To override this # behavior, for example, to bind a container's SSH port to the public # interface of its host, one must manually set this IP. # # It is preferable to begin to launch Docker containers with # ports exposed on publicly accessible IP addresses, particularly # if the containers are to be targeted by Ansible for remote # configuration, not accessible via localhost SSH connections. # # Docker containers can be explicitly exposed on IP addresses by # a) starting the daemon with the --ip argument # b) running containers with the -P/--publish ip::containerPort # argument # default: IP_ADDRESS if port exposed on IP_ADDRESS by Docker # required: false # # Examples: # Use the config file: # DOCKER_CONFIG_FILE=./docker.yml docker.py --list # # Connect to docker instance on localhost port 4243 # DOCKER_HOST=tcp://localhost:4243 docker.py --list # # Any container's ssh port exposed on IP_ADDRESS will mapped to # another IP address (where Ansible will attempt to connect via SSH) # DOCKER_DEFAULT_IP=IP_ADDRESS docker.py --list
# # XML-RPC CLIENT LIBRARY # $Id$ # # an XML-RPC client interface for Python. # # the marshalling and response parser code can also be used to # implement XML-RPC servers. # # Notes: # this version is designed to work with Python 2.1 or newer. # # History: # 1999-01-14 fl Created # 1999-01-15 fl Changed dateTime to use localtime # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service # 1999-01-19 fl Fixed array data element (from Skip Montanaro) # 1999-01-21 fl Fixed dateTime constructor, etc. # 1999-02-02 fl Added fault handling, handle empty sequences, etc. # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro) # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8) # 2000-11-28 fl Changed boolean to check the truth value of its argument # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1) # 2001-03-28 fl Make sure response tuple is a singleton # 2001-03-29 fl Don't require empty params element (from NAME 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2) # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from NAME 2001-09-03 fl Allow Transport subclass to override getparser # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup) # 2001-10-01 fl Remove containers from memo cache when done with them # 2001-10-01 fl Use faster escape method (80% dumps speedup) # 2001-10-02 fl More dumps microtuning # 2001-10-04 fl Make sure import expat gets a parser (from NAME 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems) # 2001-11-12 fl Use repr() to marshal doubles (from NAME 2002-03-17 fl Avoid buffered read when possible (from NAME 2002-04-07 fl Added pythondoc comments # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers # 2002-05-15 fl Added error constants (from NAME 2002-06-27 fl Merged with Python CVS version # 2002-10-22 fl Added basic authentication (based on code from NAME 2003-01-22 sm Add support for the bool type # 2003-02-27 gvr Remove apply calls # 2003-04-24 sm Use cStringIO if available # 2003-04-25 ak Add support for nil # 2003-06-15 gn Add support for time.struct_time # 2003-07-12 gp Correct marshalling of Faults # 2003-10-31 mvl Add multicall support # 2004-08-20 mvl Bump minimum supported Python version to 2.1 # # Copyright (c) 1999-2002 by Secret Labs AB. # Copyright (c) 1999-2002 by NAME EMAIL http://www.pythonware.com # # -------------------------------------------------------------------- # The XML-RPC client interface is # # Copyright (c) 1999-2002 by Secret Labs AB # Copyright (c) 1999-2002 by NAME By obtaining, using, and/or copying this software and/or its # associated documentation, you agree that you have read, understood, # and will comply with the following terms and conditions: # # Permission to use, copy, modify, and distribute this software and # its associated documentation for any purpose and without fee is # hereby granted, provided that the above copyright notice appears in # all copies, and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of # Secret Labs AB or the author not be used in advertising or publicity # pertaining to distribution of the software without specific, written # prior permission. # # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. # -------------------------------------------------------------------- # # things to look into some day: # TODO: sort out True/False/boolean issues for Python 2.3
#!/usr/bin/python # # pySerial based upload & interpreter interaction module for amforth. # # Copyright 2011 NAME (EMAIL) # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as # published by the Free Software Foundation. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Patcher remarks: # ================ # # This uploader saves dictionary space and words clutter by substituting # uC register names and application constants with numbers. The # appl_defs.frt (Forth) file in the application's local directory # provides the constant definitions. In appl_defs.frt put each constant # on a line of its own. The first line, if it begins with a backslash # comment, would be echoed to the screen when uploading the Forth # code. It is recommended to place in appl_defs.frt global constant # definitions which would affect compilation of the library and the # project code. For example: # # \ Project Name # $d5 constant CRC8MSB # 10 constant max_number_of_users # # Invoke the shell with the argument --log log.frt to collect the lines # which were uploaded to the AmForth system that received an " ok" # response (log.frt is just a file-name example). This file can later be # uploaded to another system using a tool simpler than the shell. Leave # the shell by #exit to close log.frt properly. # # Invoke the shell with the argument --rtscts to enable serial port # RTS/CTS hardware handshake connection. # # ===================================================================== # DOCUMENTATION # ===================================================================== # This module module may be used as a script or imported for use as a # part of a larger python program. # # Script Usage # ------------ # When used as a script this module provides two main functions, the # ability to reliably upload files to the amforth interpreter and an # interpreter interaction mode with line editing, word completion and # previous input history. For information on how to access these # features when invoking the module as a script, execute it with the # --help option and read the following sections on the interaction # protocol and local directives. # # # Interaction Protocol # -------------------- # The amforth interaction protocol used by this module is to send a # line to amforth character by character, reading the echos as quickly # as possible. Once the entire line has been sent it then reads the # response up until the " ok" prompt or a prompt that looks like an # error response. The character by character handling of echos # appears to eliminate unexpected device resets when compared to the # line by line method used by previous tools, possibly by eliminating # the possibility of serial tx overrun on the device. # # To further optimize interaction with the device lines are evaluated # before sending and redundant whitespace is compressed out. Lines # which are all whitespace or whitespace and comments are not sent and # the next line is handled. # # # Local Directives # ---------------- # A number of special directives are supported which instruct the # script to do something and are handled locally without being sent to # amforth. Directives may be specified within comments or outside # comments as controlled by the "#directive" directive. They must be # the only contents of a line or they will be ignored. The directives # include: # # #install <file> # Upload the named <file> before proceeding further. # # #include <file> # Like #install but would skip if <file> was already uploaded # during the shell session. # # #cd <dir> # Change the current local directory to the location specified. # During uploads, this directive affects the current file and # files it includes. Once the current file is complete the old # value will be restored. # # #directive <config> # Change how directives are discovered. The valid values for # <config> are: # none : Stop looking for any directives # commented : Only look for directives within comments # Commented directives must be the first word of the # comment. The remaining text in the comment is the # argument provided to the directive. There must # not be any other non-whitespace text other than # the comment start and (if required) end characters # and the directive and any directive argument on a # commented directive line. If any other text is # present on the line an error will be generated. # uncommented : Only look for directives outside comments. # Uncommented directives must be the first word of a # line and extend to the end of the line. If a # directive name exists in a subsequent word of a # line it will be sent to the interpreter as a word # like any other. # all : Allow both commented and uncommented directives. # This is the default. # During uploads, this directive affects the current file and # files it includes. Once the current file is complete the old # value will be restored. # # #timeout <float> # Change the timeout value to <float> seconds. Fractional # values are supported. During uploads, this directive affects # the current file and files it includes. Once the current file # is complete the old value will be restored. # # #timeout-next <float> # Change the timeout value for the next line sent to the # interpreter to <float> seconds. Fractional values are # supported. The timeout returns to its previous value after # the next line is sent to the interpreter. If this directive # is encountered as the very last line of an upload file it will # have no effect. # # #error-on-output [<yes-or-no>] # Controls whether an error is generated if unexpected output # occurs during an upload. The default is yes. This directive # can not be used in interactive mode as it would not have any # effect. During uploads it affects the rest of the current file # and any files it includes. The argument is optional. If not # given it is assumed to be "yes". # # #ignore-error [<yes-or-no>] # Ignore any error that occurs later in the current upload file # or a file it includes. The argument is optional. If given # the behavior is set as specified. If not given it is assumed # to be "yes". # # #ignore-error-next [<yes-or-no>] # Ignore any error that occurs on the next line. The argument # is optional. If given the behavior is set as specified. If # not given it is assumed to be "yes". # # #expect-output-next [<regexp>] # Expect specific output on the next line. The argument is # optional. If it is not specified a default regular expression # of ".*" (match everything) is assumed. This overrides the # #error-on-output directive. An error is raised if the output # doesn't match the regular expression. It will be ignored if # #ignore-error is yes. Use of this directive without an # argument is the way to prevent an error on output when # #error-on-output is yes # # #start-string-word <word> # Add a word that starts a string. The string will end when a # double quote character is read. # # #quote-char-word <word> # Add a word that quotes the immediately next word # # #interact # Start an interactive session before proceeding with file upload. # This only makes sense during a file upload. # # #edit [<filename>] # Edit a file. The filename is optional. If it is provided the # named file will be edited. If it is not provided and the last # upload ended in an error the file that had the error will be # edited at the location of the error. If there was no previous # upload or the last upload completed successfully but an #edit # directive was previously issued with a filename, edit the file # previously named. Finally, if none of these apply an error is # printed. The editor used can be specified with the --editor # option when starting the program or through the EDITOR # environment variable. # # #update-words # This directive is only available in an interactive session. # It cause the interaction code to reload the list of words used # for completion from the amforth interpreter. Typically it is # not required as words are updated automatically when the # session starts and any time a file is uploaded as a results of # a #include directive. The case where it is required is when # completion is needed for words defined interactively during # the session. # # #update-cpu # This directive is only available in an interactive session. # It causes the interaction code to read the controller name # from the device and tries to load a specific python module # which contains names for registers and addresses. These names # can be used in forth code and get replace with the corresponding # numbers. # # #exit # Exit an interactive session or the current upload immediately. # If encountered during an upload, no further lines from the # file will be processed. # # # Programmatic Usage # ------------------ # For programmatic usage, a single class named AMForth is provided. # It can be instantiated with no arguments but typically a serial port # device and port speed will be provided as the defaults are unlikely # to be correct. # # Once an instance is obtained, and connected the high-level entry # points are the "upload_file" and "interact" methods, the former # uploading a file to the AMForth interperter and the latter providing # an interative interpreter shell with command history and word # completion. These methods provide progress information in various # cases by calling the function stored in the "progress_callback" # property with three arguments, the type of progress being reported, # a line number if available (otherwise it is None) and a message with # further information. The default progress callback prints this # information to the screen in a terse format. Other programs may # wish to replace this with their own progress presentation function. # # Low-level interaction with the AMForth interpreter would typically # use the "send_line" and "read_response" methods. Before these can # be used the serial connection must be established. The # serial_connected property indicates whether a connection currently # exists. A good way to obtain a connection and rule out errors in # serial communication is to call "find_prompt" which ensures the # existence of a serial connection and sends a newline to the AMForth # interperter and watches for the echo. This is usually the best way # of establishing a connection but the "serial_connect" method will # open a connection without sending anything if that is required. # # Elimination of whitespace and discovery of directives (see below) is # provided through the "preprocess_line" method and directives that # have common implementations can be handled with the # "handle_common_directives" method. # TODO: - Update comments on most functions explaining what they do.
{ '"update" is an optional expression like "field1=\'newvalue\'". You cannot update or delete the results of a JOIN': '"\xd0\x98\xd0\xb7\xd0\xbc\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x82\xd1\x8c" - \xd0\xbd\xd0\xb5\xd0\xbe\xd0\xb1\xd1\x8f\xd0\xb7\xd0\xb0\xd1\x82\xd0\xb5\xd0\xbb\xd1\x8c\xd0\xbd\xd0\xbe\xd0\xb5 \xd0\xb2\xd1\x8b\xd1\x80\xd0\xb0\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xb2\xd0\xb8\xd0\xb4\xd0\xb0 "field1=\'\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xbe\xd0\xb5 \xd0\xb7\xd0\xbd\xd0\xb0\xd1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5\'". \xd0\xa0\xd0\xb5\xd0\xb7\xd1\x83\xd0\xbb\xd1\x8c\xd1\x82\xd0\xb0\xd1\x82\xd1\x8b \xd0\xbe\xd0\xbf\xd0\xb5\xd1\x80\xd0\xb0\xd1\x86\xd0\xb8\xd0\xb8 JOIN \xd0\xbd\xd0\xb5\xd0\xbb\xd1\x8c\xd0\xb7\xd1\x8f \xd0\xb8\xd0\xb7\xd0\xbc\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x82\xd1\x8c \xd0\xb8\xd0\xbb\xd0\xb8 \xd1\x83\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xb8\xd1\x82\xd1\x8c.', '%Y-%m-%d': '%Y-%m-%d', '%Y-%m-%d %H:%M:%S': '%Y-%m-%d %H:%M:%S', '%s rows deleted': '%s \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba \xd1\x83\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xbe', '%s rows updated': '%s \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba \xd0\xb8\xd0\xb7\xd0\xbc\xd0\xb5\xd0\xbd\xd0\xb5\xd0\xbd\xd0\xbe', 'Available databases and tables': '\xd0\x91\xd0\xb0\xd0\xb7\xd1\x8b \xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd1\x85 \xd0\xb8 \xd1\x82\xd0\xb0\xd0\xb1\xd0\xbb\xd0\xb8\xd1\x86\xd1\x8b', 'Cannot be empty': '\xd0\x9f\xd1\x83\xd1\x81\xd1\x82\xd0\xbe\xd0\xb5 \xd0\xb7\xd0\xbd\xd0\xb0\xd1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xbd\xd0\xb5\xd0\xb4\xd0\xbe\xd0\xbf\xd1\x83\xd1\x81\xd1\x82\xd0\xb8\xd0\xbc\xd0\xbe', 'Change Password': PASSWORD to delete': '\xd0\xa3\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xb8\xd1\x82\xd1\x8c', 'Check to delete:': '\xd0\xa3\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xb8\xd1\x82\xd1\x8c:', 'Current request': '\xd0\xa2\xd0\xb5\xd0\xba\xd1\x83\xd1\x89\xd0\xb8\xd0\xb9 \xd0\xb7\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81', 'Current response': '\xd0\xa2\xd0\xb5\xd0\xba\xd1\x83\xd1\x89\xd0\xb8\xd0\xb9 \xd0\xbe\xd1\x82\xd0\xb2\xd0\xb5\xd1\x82', 'Current session': '\xd0\xa2\xd0\xb5\xd0\xba\xd1\x83\xd1\x89\xd0\xb0\xd1\x8f \xd1\x81\xd0\xb5\xd1\x81\xd1\x81\xd0\xb8\xd1\x8f', 'Delete:': '\xd0\xa3\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xb8\xd1\x82\xd1\x8c:', 'Edit Profile': '\xd0\xa0\xd0\xb5\xd0\xb4\xd0\xb0\xd0\xba\xd1\x82\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c \xd0\xbf\xd1\x80\xd0\xbe\xd1\x84\xd0\xb0\xd0\xb9\xd0\xbb', 'Edit current record': '\xd0\xa0\xd0\xb5\xd0\xb4\xd0\xb0\xd0\xba\xd1\x82\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c \xd1\x82\xd0\xb5\xd0\xba\xd1\x83\xd1\x89\xd1\x83\xd1\x8e \xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd1\x8c', 'Hello World': '\xd0\x97\xd0\xb0\xd1\x80\xd0\xb0\xd0\xb1\xd0\xbe\xd1\x82\xd0\xb0\xd0\xbb\xd0\xbe!', 'Import/Export': '\xd0\x98\xd0\xbc\xd0\xbf\xd0\xbe\xd1\x80\xd1\x82/\xd1\x8d\xd0\xba\xd1\x81\xd0\xbf\xd0\xbe\xd1\x80\xd1\x82', 'Internal State': '\xd0\x92\xd0\xbd\xd1\x83\xd1\x82\xd1\x80\xd0\xb5\xd0\xbd\xd0\xbd\xd0\xb5 \xd1\x81\xd0\xbe\xd1\x81\xd1\x82\xd0\xbe\xd1\x8f\xd0\xbd\xd0\xb8\xd0\xb5', 'Invalid Query': '\xd0\x9d\xd0\xb5\xd0\xb2\xd0\xb5\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xb7\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81', 'Invalid email': '\xd0\x9d\xd0\xb5\xd0\xb2\xd0\xb5\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb9 email', 'Login': '\xd0\x92\xd1\x85\xd0\xbe\xd0\xb4', 'Logout': '\xd0\x92\xd1\x8b\xd1\x85\xd0\xbe\xd0\xb4', 'Lost Password': '\xd0\x97\xd0\xb0\xd0\xb1\xd1\x8b\xd0\xbb\xd0\xb8 \xd0\xbf\xd0\xb0\xd1\x80\xd0\xbe\xd0\xbb\xd1\x8c?', 'New Record': '\xd0\x9d\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x8f \xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd1\x8c', 'No databases in this application': '\xd0\x92 \xd0\xbf\xd1\x80\xd0\xb8\xd0\xbb\xd0\xbe\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb8 \xd0\xbd\xd0\xb5\xd1\x82 \xd0\xb1\xd0\xb0\xd0\xb7 \xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd1\x85', "Password fields don't match": '\xd0\x9f\xd0\xb0\xd1\x80\xd0\xbe\xd0\xbb\xd0\xb8 \xd0\xbd\xd0\xb5 \xd1\x81\xd0\xbe\xd0\xb2\xd0\xbf\xd0\xb0\xd0\xb4\xd0\xb0\xd1\x8e\xd1\x82', 'Query:': '\xd0\x97\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81:', 'Register': '\xd0\x97\xd0\xb0\xd1\x80\xd0\xb5\xd0\xb3\xd0\xb8\xd1\x81\xd1\x82\xd1\x80\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c\xd1\x81\xd1\x8f', 'Rows in table': '\xd0\xa1\xd1\x82\xd1\x80\xd0\xbe\xd0\xba \xd0\xb2 \xd1\x82\xd0\xb0\xd0\xb1\xd0\xbb\xd0\xb8\xd1\x86\xd0\xb5', 'Rows selected': '\xd0\x92\xd1\x8b\xd0\xb4\xd0\xb5\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xbe \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba', 'Submit': '\xd0\x9e\xd1\x82\xd0\xbf\xd1\x80\xd0\xb0\xd0\xb2\xd0\xb8\xd1\x82\xd1\x8c', 'Sure you want to delete this object?': '\xd0\x9f\xd0\xbe\xd0\xb4\xd1\x82\xd0\xb2\xd0\xb5\xd1\x80\xd0\xb4\xd0\xb8\xd1\x82\xd0\xb5 \xd1\x83\xd0\xb4\xd0\xb0\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xbe\xd0\xb1\xd1\x8a\xd0\xb5\xd0\xba\xd1\x82\xd0\xb0', 'The "query" is a condition like "db.table1.field1==\'value\'". Something like "db.table1.field1==db.table2.field2" results in a SQL JOIN.': '"\xd0\x97\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81" - \xd1\x8d\xd1\x82\xd0\xbe \xd1\x83\xd1\x81\xd0\xbb\xd0\xbe\xd0\xb2\xd0\xb8\xd0\xb5 \xd0\xb2\xd0\xb8\xd0\xb4\xd0\xb0 "db.table1.field1==\'\xd0\xb7\xd0\xbd\xd0\xb0\xd1\x87\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5\'". \xd0\x92\xd1\x8b\xd1\x80\xd0\xb0\xd0\xb6\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd0\xb2\xd0\xb8\xd0\xb4\xd0\xb0 "db.table1.field1==db.table2.field2" \xd1\x84\xd0\xbe\xd1\x80\xd0\xbc\xd0\xb8\xd1\x80\xd1\x83\xd0\xb5\xd1\x82 SQL JOIN.', 'Update:': '\xd0\x98\xd0\xb7\xd0\xbc\xd0\xb5\xd0\xbd\xd0\xb8\xd1\x82\xd1\x8c:', 'Use (...)&(...) for AND, (...)|(...) for OR, and ~(...) for NOT to build more complex queries.': '\xd0\x94\xd0\xbb\xd1\x8f \xd0\xbf\xd0\xbe\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb5\xd0\xbd\xd0\xb8\xd0\xb5 \xd1\x81\xd0\xbb\xd0\xbe\xd0\xb6\xd0\xbd\xd1\x8b\xd1\x85 \xd0\xb7\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81\xd0\xbe\xd0\xb2 \xd0\xb8\xd1\x81\xd0\xbf\xd0\xbe\xd0\xbb\xd1\x8c\xd0\xb7\xd1\x83\xd0\xb9\xd1\x82\xd0\xb5 \xd0\xbe\xd0\xbf\xd0\xb5\xd1\x80\xd0\xb0\xd1\x82\xd0\xbe\xd1\x80\xd1\x8b "\xd0\x98": (...)&(...), "\xd0\x98\xd0\x9b\xd0\x98": (...)|(...), "\xd0\x9d\xd0\x95": ~(...).', 'User %(id)s Registered': '\xd0\x9f\xd0\xbe\xd0\xbb\xd1\x8c\xd0\xb7\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd0\xb5\xd0\xbb\xd1\x8c %(id)s \xd0\xb7\xd0\xb0\xd1\x80\xd0\xb5\xd0\xb3\xd0\xb8\xd1\x81\xd1\x82\xd1\x80\xd0\xb8\xd1\x80\xd0\xbe\xd0\xb2\xd0\xb0\xd0\xbd', 'Verify Password': PASSWORD\xd0\xb5 \xd0\xbf\xd0\xb0\xd1\x80\xd0\xbe\xd0\xbb\xd1\x8c', 'Welcome to web2py': '\xd0\x94\xd0\xbe\xd0\xb1\xd1\x80\xd0\xbe \xd0\xbf\xd0\xbe\xd0\xb6\xd0\xb0\xd0\xbb\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x82\xd1\x8c \xd0\xb2 web2py', 'click here for online examples': '\xd0\xbf\xd1\x80\xd0\xb8\xd0\xbc\xd0\xb5\xd1\x80\xd1\x8b \xd0\xbe\xd0\xbd-\xd0\xbb\xd0\xb0\xd0\xb9\xd0\xbd', 'click here for the administrative interface': '\xd0\xb0\xd0\xb4\xd0\xbc\xd0\xb8\xd0\xbd\xd0\xb8\xd1\x81\xd1\x82\xd1\x80\xd0\xb0\xd1\x82\xd0\xb8\xd0\xb2\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xb8\xd0\xbd\xd1\x82\xd0\xb5\xd1\x80\xd1\x84\xd0\xb5\xd0\xb9\xd1\x81', 'customize me!': '\xd0\xbd\xd0\xb0\xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xb9\xd1\x82\xd0\xb5 \xd0\xb2\xd0\xbd\xd0\xb5\xd1\x88\xd0\xbd\xd0\xb8\xd0\xb9 \xd0\xb2\xd0\xb8\xd0\xb4!', 'data uploaded': '\xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd0\xb5 \xd0\xb7\xd0\xb0\xd0\xb3\xd1\x80\xd1\x83\xd0\xb6\xd0\xb5\xd0\xbd\xd1\x8b', 'database': '\xd0\xb1\xd0\xb0\xd0\xb7\xd0\xb0 \xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd1\x85', 'database %s select': '\xd0\xb2\xd1\x8b\xd0\xb1\xd0\xbe\xd1\x80 \xd0\xb1\xd0\xb0\xd0\xb7\xd1\x8b \xd0\xb4\xd0\xb0\xd0\xbd\xd0\xbd\xd1\x8b\xd1\x85 %s', 'db': '\xd0\x91\xd0\x94', 'design': '\xd0\xb4\xd0\xb8\xd0\xb7\xd0\xb0\xd0\xb9\xd0\xbd', 'done!': '\xd0\xb3\xd0\xbe\xd1\x82\xd0\xbe\xd0\xb2\xd0\xbe!', 'export as csv file': '\xd1\x8d\xd0\xba\xd1\x81\xd0\xbf\xd0\xbe\xd1\x80\xd1\x82 \xd0\xb2 csv-\xd1\x84\xd0\xb0\xd0\xb9\xd0\xbb', 'insert new': '\xd0\xb4\xd0\xbe\xd0\xb1\xd0\xb0\xd0\xb2\xd0\xb8\xd1\x82\xd1\x8c', 'insert new %s': '\xd0\xb4\xd0\xbe\xd0\xb1\xd0\xb0\xd0\xb2\xd0\xb8\xd1\x82\xd1\x8c %s', 'invalid request': '\xd0\xbd\xd0\xb5\xd0\xb2\xd0\xb5\xd1\x80\xd0\xbd\xd1\x8b\xd0\xb9 \xd0\xb7\xd0\xb0\xd0\xbf\xd1\x80\xd0\xbe\xd1\x81', 'new record inserted': '\xd0\xbd\xd0\xbe\xd0\xb2\xd0\xb0\xd1\x8f \xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd1\x8c \xd0\xb4\xd0\xbe\xd0\xb1\xd0\xb0\xd0\xb2\xd0\xbb\xd0\xb5\xd0\xbd\xd0\xb0', 'next 100 rows': '\xd1\x81\xd0\xbb\xd0\xb5\xd0\xb4\xd1\x83\xd1\x8e\xd1\x89\xd0\xb8\xd0\xb5 100 \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba', 'or import from csv file': '\xd0\xb8\xd0\xbb\xd0\xb8 \xd0\xb8\xd0\xbc\xd0\xbf\xd0\xbe\xd1\x80\xd1\x82 \xd0\xb8\xd0\xb7 csv-\xd1\x84\xd0\xb0\xd0\xb9\xd0\xbb\xd0\xb0', 'previous 100 rows': '\xd0\xbf\xd1\x80\xd0\xb5\xd0\xb4\xd1\x8b\xd0\xb4\xd1\x83\xd1\x89\xd0\xb8\xd0\xb5 100 \xd1\x81\xd1\x82\xd1\x80\xd0\xbe\xd0\xba', 'record does not exist': '\xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd1\x8c \xd0\xbd\xd0\xb5 \xd0\xbd\xd0\xb0\xd0\xb9\xd0\xb4\xd0\xb5\xd0\xbd\xd0\xb0', 'record id': 'id \xd0\xb7\xd0\xb0\xd0\xbf\xd0\xb8\xd1\x81\xd0\xb8', 'selected': '\xd0\xb2\xd1\x8b\xd0\xb1\xd1\x80\xd0\xb0\xd0\xbd\xd0\xbe', 'state': '\xd1\x81\xd0\xbe\xd1\x81\xd1\x82\xd0\xbe\xd1\x8f\xd0\xbd\xd0\xb8\xd0\xb5', 'table': '\xd1\x82\xd0\xb0\xd0\xb1\xd0\xbb\xd0\xb8\xd1\x86\xd0\xb0', 'unable to parse csv file': '\xd0\xbd\xd0\xb5\xd1\x87\xd0\xb8\xd1\x82\xd0\xb0\xd0\xb5\xd0\xbc\xd1\x8b\xd0\xb9 csv-\xd1\x84\xd0\xb0\xd0\xb9\xd0\xbb', }
"""Handles conversion between the set of time intervals used in the `SosModel` There are three main classes, which are currently rather intertwined. :class:`Interval` represents an individual definition of a period within a year. This is specified using the ISO8601 period syntax and exposes methods which use the isodate library to parse this into an internal hourly representation of the period. :class:`TimeIntervalRegister` holds the definitions of time-interval sets specified for the sector models at the :class:`~smif.sos_model.SosModel` level. This class exposes one public method, :py:meth:`~TimeIntervalRegister.add_interval_set` which allows the SosModel to add an interval definition from a model configuration to the register. Quantities ---------- Quantities are associated with a duration, period or interval. For example 120 GWh of electricity generated during each week of February.:: Week 1: 120 GW Week 2: 120 GW Week 3: 120 GW Week 4: 120 GW Other examples of quantities: - greenhouse gas emissions - demands for infrastructure services - materials use - counts of cars past a junction - costs of investments, operation and maintenance Upscale: Divide ~~~~~~~~~~~~~~~ To convert to a higher temporal resolution, the values need to be apportioned across the new time scale. In the above example, the 120 GWh of electricity would be divided over the days of February to produce a daily time series of generation. For example:: 1st Feb: 17 GWh 2nd Feb: 17 GWh 3rd Feb: 17 GWh ... Downscale: Sum ~~~~~~~~~~~~~~ To resample weekly values to a lower temporal resolution, the values would need to be accumulated. A monthly total would be:: Feb: 480 GWh Remapping --------- Remapping quantities, as is required in the conversion from energy demand (hourly values over a year) to energy supply (hourly values for one week for each of four seasons) requires additional averaging operations. The quantities are averaged over the many-to-one relationship of hours to time-slices, so that the seasonal-hourly timeslices in the model approximate the hourly profiles found across the particular seasons in the year. For example:: hour 1: 20 GWh hour 2: 15 GWh hour 3: 10 GWh ... hour 8592: 16 GWh hour 8593: 12 GWh hour 8594: 21 GWh ... hour 8760: 43 GWh To:: season 1 hour 1: 20+16+.../4 GWh # Denominator number hours in sample season 1 hour 2: 15+12+.../4 GWh season 1 hour 3: 10+21+.../4 GWh ... Prices ------ Unlike quantities, prices are associated with a point in time. For example a spot price of £870/GWh. An average price can be associated with a duration, but even then, we are just assigning a price to any point in time within a range of times. Upscale: Fill ~~~~~~~~~~~~~ Given a timeseries of monthly spot prices, converting these to a daily price can be done by a fill operation. E.g. copying the monthly price to each day. From:: Feb: £870/GWh To:: 1st Feb: £870/GWh 2nd Feb: £870/GWh ... Downscale: Average ~~~~~~~~~~~~~~~~~~ On the other hand, going down scale, such as from daily prices to a monthly price requires use of an averaging function. From:: 1st Feb: £870/GWh 2nd Feb: £870/GWh ... To:: Feb: £870/GWh Development Notes ----------------- - We could use :py:meth:`numpy.convolve` to compare time intervals as hourly arrays before adding them to the set of intervals """
""" ============================= Byteswapping and byte order ============================= Introduction to byte ordering and ndarrays ========================================== The ``ndarray`` is an object that provide a python array interface to data in memory. It often happens that the memory that you want to view with an array is not of the same byte ordering as the computer on which you are running Python. For example, I might be working on a computer with a little-endian CPU - such as an Intel Pentium, but I have loaded some data from a file written by a computer that is big-endian. Let's say I have loaded 4 bytes from a file written by a Sun (big-endian) computer. I know that these 4 bytes represent two 16-bit integers. On a big-endian machine, a two-byte integer is stored with the Most Significant Byte (MSB) first, and then the Least Significant Byte (LSB). Thus the bytes are, in memory order: #. MSB integer 1 #. LSB integer 1 #. MSB integer 2 #. LSB integer 2 Let's say the two integers were in fact 1 and 770. Because 770 = 256 * 3 + 2, the 4 bytes in memory would contain respectively: 0, 1, 3, 2. The bytes I have loaded from the file would have these contents: >>> big_end_str = chr(0) + chr(1) + chr(3) + chr(2) >>> big_end_str '\\x00\\x01\\x03\\x02' We might want to use an ``ndarray`` to access these integers. In that case, we can create an array around this memory, and tell numpy that there are two integers, and that they are 16 bit and big-endian: >>> import numpy as np >>> big_end_arr = np.ndarray(shape=(2,),dtype='>i2', buffer=big_end_str) >>> big_end_arr[0] 1 >>> big_end_arr[1] 770 Note the array ``dtype`` above of ``>i2``. The ``>`` means 'big-endian' (``<`` is little-endian) and ``i2`` means 'signed 2-byte integer'. For example, if our data represented a single unsigned 4-byte little-endian integer, the dtype string would be ``<u4``. In fact, why don't we try that? >>> little_end_u4 = np.ndarray(shape=(1,),dtype='<u4', buffer=big_end_str) >>> little_end_u4[0] == 1 * 256**1 + 3 * 256**2 + 2 * 256**3 True Returning to our ``big_end_arr`` - in this case our underlying data is big-endian (data endianness) and we've set the dtype to match (the dtype is also big-endian). However, sometimes you need to flip these around. .. warning:: Scalars currently do not include byte order information, so extracting a scalar from an array will return an integer in native byte order. Hence: >>> big_end_arr[0].dtype.byteorder == little_end_u4[0].dtype.byteorder True Changing byte ordering ====================== As you can imagine from the introduction, there are two ways you can affect the relationship between the byte ordering of the array and the underlying memory it is looking at: * Change the byte-ordering information in the array dtype so that it interprets the undelying data as being in a different byte order. This is the role of ``arr.newbyteorder()`` * Change the byte-ordering of the underlying data, leaving the dtype interpretation as it was. This is what ``arr.byteswap()`` does. The common situations in which you need to change byte ordering are: #. Your data and dtype endianess don't match, and you want to change the dtype so that it matches the data. #. Your data and dtype endianess don't match, and you want to swap the data so that they match the dtype #. Your data and dtype endianess match, but you want the data swapped and the dtype to reflect this Data and dtype endianness don't match, change dtype to match data ----------------------------------------------------------------- We make something where they don't match: >>> wrong_end_dtype_arr = np.ndarray(shape=(2,),dtype='<i2', buffer=big_end_str) >>> wrong_end_dtype_arr[0] 256 The obvious fix for this situation is to change the dtype so it gives the correct endianness: >>> fixed_end_dtype_arr = wrong_end_dtype_arr.newbyteorder() >>> fixed_end_dtype_arr[0] 1 Note the the array has not changed in memory: >>> fixed_end_dtype_arr.tobytes() == big_end_str True Data and type endianness don't match, change data to match dtype ---------------------------------------------------------------- You might want to do this if you need the data in memory to be a certain ordering. For example you might be writing the memory out to a file that needs a certain byte ordering. >>> fixed_end_mem_arr = wrong_end_dtype_arr.byteswap() >>> fixed_end_mem_arr[0] 1 Now the array *has* changed in memory: >>> fixed_end_mem_arr.tobytes() == big_end_str False Data and dtype endianness match, swap data and dtype ---------------------------------------------------- You may have a correctly specified array dtype, but you need the array to have the opposite byte order in memory, and you want the dtype to match so the array values make sense. In this case you just do both of the previous operations: >>> swapped_end_arr = big_end_arr.byteswap().newbyteorder() >>> swapped_end_arr[0] 1 >>> swapped_end_arr.tobytes() == big_end_str False An easier way of casting the data to a specific dtype and byte ordering can be achieved with the ndarray astype method: >>> swapped_end_arr = big_end_arr.astype('<i2') >>> swapped_end_arr[0] 1 >>> swapped_end_arr.tobytes() == big_end_str False """
""" ======================================= Signal processing (:mod:`scipy.signal`) ======================================= Convolution =========== .. autosummary:: :toctree: generated/ convolve -- N-dimensional convolution. correlate -- N-dimensional correlation. fftconvolve -- N-dimensional convolution using the FFT. convolve2d -- 2-dimensional convolution (more options). correlate2d -- 2-dimensional correlation (more options). sepfir2d -- Convolve with a 2-D separable FIR filter. choose_conv_method -- Chooses faster of FFT and direct convolution methods. B-splines ========= .. autosummary:: :toctree: generated/ bspline -- B-spline basis function of order n. cubic -- B-spline basis function of order 3. quadratic -- B-spline basis function of order 2. gauss_spline -- Gaussian approximation to the B-spline basis function. cspline1d -- Coefficients for 1-D cubic (3rd order) B-spline. qspline1d -- Coefficients for 1-D quadratic (2nd order) B-spline. cspline2d -- Coefficients for 2-D cubic (3rd order) B-spline. qspline2d -- Coefficients for 2-D quadratic (2nd order) B-spline. cspline1d_eval -- Evaluate a cubic spline at the given points. qspline1d_eval -- Evaluate a quadratic spline at the given points. spline_filter -- Smoothing spline (cubic) filtering of a rank-2 array. Filtering ========= .. autosummary:: :toctree: generated/ order_filter -- N-dimensional order filter. medfilt -- N-dimensional median filter. medfilt2d -- 2-dimensional median filter (faster). wiener -- N-dimensional wiener filter. symiirorder1 -- 2nd-order IIR filter (cascade of first-order systems). symiirorder2 -- 4th-order IIR filter (cascade of second-order systems). lfilter -- 1-dimensional FIR and IIR digital linear filtering. lfiltic -- Construct initial conditions for `lfilter`. lfilter_zi -- Compute an initial state zi for the lfilter function that -- corresponds to the steady state of the step response. filtfilt -- A forward-backward filter. savgol_filter -- Filter a signal using the Savitzky-Golay filter. deconvolve -- 1-d deconvolution using lfilter. sosfilt -- 1-dimensional IIR digital linear filtering using -- a second-order sections filter representation. sosfilt_zi -- Compute an initial state zi for the sosfilt function that -- corresponds to the steady state of the step response. sosfiltfilt -- A forward-backward filter for second-order sections. hilbert -- Compute 1-D analytic signal, using the Hilbert transform. hilbert2 -- Compute 2-D analytic signal, using the Hilbert transform. decimate -- Downsample a signal. detrend -- Remove linear and/or constant trends from data. resample -- Resample using Fourier method. resample_poly -- Resample using polyphase filtering method. upfirdn -- Upsample, apply FIR filter, downsample. Filter design ============= .. autosummary:: :toctree: generated/ bilinear -- Digital filter from an analog filter using -- the bilinear transform. findfreqs -- Find array of frequencies for computing filter response. firls -- FIR filter design using least-squares error minimization. firwin -- Windowed FIR filter design, with frequency response -- defined as pass and stop bands. firwin2 -- Windowed FIR filter design, with arbitrary frequency -- response. freqs -- Analog filter frequency response. freqz -- Digital filter frequency response. sosfreqz -- Digital filter frequency response for SOS format filter. group_delay -- Digital filter group delay. iirdesign -- IIR filter design given bands and gains. iirfilter -- IIR filter design given order and critical frequencies. kaiser_atten -- Compute the attenuation of a Kaiser FIR filter, given -- the number of taps and the transition width at -- discontinuities in the frequency response. kaiser_beta -- Compute the Kaiser parameter beta, given the desired -- FIR filter attenuation. kaiserord -- Design a Kaiser window to limit ripple and width of -- transition region. savgol_coeffs -- Compute the FIR filter coefficients for a Savitzky-Golay -- filter. remez -- Optimal FIR filter design. unique_roots -- Unique roots and their multiplicities. residue -- Partial fraction expansion of b(s) / a(s). residuez -- Partial fraction expansion of b(z) / a(z). invres -- Inverse partial fraction expansion for analog filter. invresz -- Inverse partial fraction expansion for digital filter. BadCoefficients -- Warning on badly conditioned filter coefficients Lower-level filter design functions: .. autosummary:: :toctree: generated/ abcd_normalize -- Check state-space matrices and ensure they are rank-2. band_stop_obj -- Band Stop Objective Function for order minimization. besselap -- Return (z,p,k) for analog prototype of Bessel filter. buttap -- Return (z,p,k) for analog prototype of Butterworth filter. cheb1ap -- Return (z,p,k) for type I Chebyshev filter. cheb2ap -- Return (z,p,k) for type II Chebyshev filter. cmplx_sort -- Sort roots based on magnitude. ellipap -- Return (z,p,k) for analog prototype of elliptic filter. lp2bp -- Transform a lowpass filter prototype to a bandpass filter. lp2bs -- Transform a lowpass filter prototype to a bandstop filter. lp2hp -- Transform a lowpass filter prototype to a highpass filter. lp2lp -- Transform a lowpass filter prototype to a lowpass filter. normalize -- Normalize polynomial representation of a transfer function. Matlab-style IIR filter design ============================== .. autosummary:: :toctree: generated/ butter -- Butterworth buttord cheby1 -- Chebyshev Type I cheb1ord cheby2 -- Chebyshev Type II cheb2ord ellip -- Elliptic (Cauer) ellipord bessel -- Bessel (no order selection available -- try butterod) Continuous-Time Linear Systems ============================== .. autosummary:: :toctree: generated/ lti -- Continuous-time linear time invariant system base class. StateSpace -- Linear time invariant system in state space form. TransferFunction -- Linear time invariant system in transfer function form. ZerosPolesGain -- Linear time invariant system in zeros, poles, gain form. lsim -- continuous-time simulation of output to linear system. lsim2 -- like lsim, but `scipy.integrate.odeint` is used. impulse -- impulse response of linear, time-invariant (LTI) system. impulse2 -- like impulse, but `scipy.integrate.odeint` is used. step -- step response of continous-time LTI system. step2 -- like step, but `scipy.integrate.odeint` is used. freqresp -- frequency response of a continuous-time LTI system. bode -- Bode magnitude and phase data (continuous-time LTI). Discrete-Time Linear Systems ============================ .. autosummary:: :toctree: generated/ dlti -- Discrete-time linear time invariant system base class. StateSpace -- Linear time invariant system in state space form. TransferFunction -- Linear time invariant system in transfer function form. ZerosPolesGain -- Linear time invariant system in zeros, poles, gain form. dlsim -- simulation of output to a discrete-time linear system. dimpulse -- impulse response of a discrete-time LTI system. dstep -- step response of a discrete-time LTI system. dfreqresp -- frequency response of a discrete-time LTI system. dbode -- Bode magnitude and phase data (discrete-time LTI). LTI Representations =================== .. autosummary:: :toctree: generated/ tf2zpk -- transfer function to zero-pole-gain. tf2sos -- transfer function to second-order sections. tf2ss -- transfer function to state-space. zpk2tf -- zero-pole-gain to transfer function. zpk2sos -- zero-pole-gain to second-order sections. zpk2ss -- zero-pole-gain to state-space. ss2tf -- state-pace to transfer function. ss2zpk -- state-space to pole-zero-gain. sos2zpk -- second-order sections to zero-pole-gain. sos2tf -- second-order sections to transfer function. cont2discrete -- continuous-time to discrete-time LTI conversion. place_poles -- pole placement. Waveforms ========= .. autosummary:: :toctree: generated/ chirp -- Frequency swept cosine signal, with several freq functions. gausspulse -- Gaussian modulated sinusoid max_len_seq -- Maximum length sequence sawtooth -- Periodic sawtooth square -- Square wave sweep_poly -- Frequency swept cosine signal; freq is arbitrary polynomial unit_impulse -- Discrete unit impulse Window functions ================ .. autosummary:: :toctree: generated/ get_window -- Return a window of a given length and type. barthann -- Bartlett-Hann window bartlett -- Bartlett window blackman -- Blackman window blackmanharris -- Minimum 4-term Blackman-Harris window bohman -- Bohman window boxcar -- Boxcar window chebwin -- Dolph-Chebyshev window cosine -- Cosine window exponential -- Exponential window flattop -- Flat top window gaussian -- Gaussian window general_gaussian -- Generalized Gaussian window hamming -- Hamming window hann -- Hann window hanning -- Hann window kaiser -- Kaiser window nuttall -- Nuttall's minimum 4-term Blackman-Harris window parzen -- Parzen window slepian -- Slepian window triang -- Triangular window tukey -- Tukey window Wavelets ======== .. autosummary:: :toctree: generated/ cascade -- compute scaling function and wavelet from coefficients daub -- return low-pass morlet -- Complex Morlet wavelet. qmf -- return quadrature mirror filter from low-pass ricker -- return ricker wavelet cwt -- perform continuous wavelet transform Peak finding ============ .. autosummary:: :toctree: generated/ find_peaks_cwt -- Attempt to find the peaks in the given 1-D array argrelmin -- Calculate the relative minima of data argrelmax -- Calculate the relative maxima of data argrelextrema -- Calculate the relative extrema of data Spectral Analysis ================= .. autosummary:: :toctree: generated/ periodogram -- Compute a (modified) periodogram welch -- Compute a periodogram using Welch's method csd -- Compute the cross spectral density, using Welch's method coherence -- Compute the magnitude squared coherence, using Welch's method spectrogram -- Compute the spectrogram lombscargle -- Computes the Lomb-Scargle periodogram vectorstrength -- Computes the vector strength """
# # XML-RPC CLIENT LIBRARY # $Id$ # # an XML-RPC client interface for Python. # # the marshalling and response parser code can also be used to # implement XML-RPC servers. # # Notes: # this version is designed to work with Python 2.1 or newer. # # History: # 1999-01-14 fl Created # 1999-01-15 fl Changed dateTime to use localtime # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service # 1999-01-19 fl Fixed array data element (from Skip Montanaro) # 1999-01-21 fl Fixed dateTime constructor, etc. # 1999-02-02 fl Added fault handling, handle empty sequences, etc. # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro) # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8) # 2000-11-28 fl Changed boolean to check the truth value of its argument # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1) # 2001-03-28 fl Make sure response tuple is a singleton # 2001-03-29 fl Don't require empty params element (from NAME 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2) # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from NAME 2001-09-03 fl Allow Transport subclass to override getparser # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup) # 2001-10-01 fl Remove containers from memo cache when done with them # 2001-10-01 fl Use faster escape method (80% dumps speedup) # 2001-10-02 fl More dumps microtuning # 2001-10-04 fl Make sure import expat gets a parser (from NAME 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems) # 2001-11-12 fl Use repr() to marshal doubles (from NAME 2002-03-17 fl Avoid buffered read when possible (from NAME 2002-04-07 fl Added pythondoc comments # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers # 2002-05-15 fl Added error constants (from NAME 2002-06-27 fl Merged with Python CVS version # 2002-10-22 fl Added basic authentication (based on code from NAME 2003-01-22 sm Add support for the bool type # 2003-02-27 gvr Remove apply calls # 2003-04-24 sm Use cStringIO if available # 2003-04-25 ak Add support for nil # 2003-06-15 gn Add support for time.struct_time # 2003-07-12 gp Correct marshalling of Faults # 2003-10-31 mvl Add multicall support # 2004-08-20 mvl Bump minimum supported Python version to 2.1 # # Copyright (c) 1999-2002 by Secret Labs AB. # Copyright (c) 1999-2002 by NAME EMAIL http://www.pythonware.com # # -------------------------------------------------------------------- # The XML-RPC client interface is # # Copyright (c) 1999-2002 by Secret Labs AB # Copyright (c) 1999-2002 by NAME By obtaining, using, and/or copying this software and/or its # associated documentation, you agree that you have read, understood, # and will comply with the following terms and conditions: # # Permission to use, copy, modify, and distribute this software and # its associated documentation for any purpose and without fee is # hereby granted, provided that the above copyright notice appears in # all copies, and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of # Secret Labs AB or the author not be used in advertising or publicity # pertaining to distribution of the software without specific, written # prior permission. # # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. # -------------------------------------------------------------------- # # things to look into some day: # TODO: sort out True/False/boolean issues for Python 2.3
""" TestCmd.py: a testing framework for commands and scripts. The TestCmd module provides a framework for portable automated testing of executable commands and scripts (in any language, not just Python), especially commands and scripts that require file system interaction. In addition to running tests and evaluating conditions, the TestCmd module manages and cleans up one or more temporary workspace directories, and provides methods for creating files and directories in those workspace directories from in-line data, here-documents), allowing tests to be completely self-contained. A TestCmd environment object is created via the usual invocation: import TestCmd test = TestCmd.TestCmd() There are a bunch of keyword arguments available at instantiation: test = TestCmd.TestCmd(description = 'string', program = 'program_or_script_to_test', interpreter = 'script_interpreter', workdir = 'prefix', subdir = 'subdir', verbose = Boolean, match = default_match_function, diff = default_diff_function, combine = Boolean) There are a bunch of methods that let you do different things: test.verbose_set(1) test.description_set('string') test.program_set('program_or_script_to_test') test.interpreter_set('script_interpreter') test.interpreter_set(['script_interpreter', 'arg']) test.workdir_set('prefix') test.workdir_set('') test.workpath('file') test.workpath('subdir', 'file') test.subdir('subdir', ...) test.rmdir('subdir', ...) test.write('file', "contents\n") test.write(['subdir', 'file'], "contents\n") test.read('file') test.read(['subdir', 'file']) test.read('file', mode) test.read(['subdir', 'file'], mode) test.writable('dir', 1) test.writable('dir', None) test.preserve(condition, ...) test.cleanup(condition) test.command_args(program = 'program_or_script_to_run', interpreter = 'script_interpreter', arguments = 'arguments to pass to program') test.run(program = 'program_or_script_to_run', interpreter = 'script_interpreter', arguments = 'arguments to pass to program', chdir = 'directory_to_chdir_to', stdin = 'input to feed to the program\n') universal_newlines = True) p = test.start(program = 'program_or_script_to_run', interpreter = 'script_interpreter', arguments = 'arguments to pass to program', universal_newlines = None) test.finish(self, p) test.pass_test() test.pass_test(condition) test.pass_test(condition, function) test.fail_test() test.fail_test(condition) test.fail_test(condition, function) test.fail_test(condition, function, skip) test.no_result() test.no_result(condition) test.no_result(condition, function) test.no_result(condition, function, skip) test.stdout() test.stdout(run) test.stderr() test.stderr(run) test.symlink(target, link) test.banner(string) test.banner(string, width) test.diff(actual, expected) test.match(actual, expected) test.match_exact("actual 1\nactual 2\n", "expected 1\nexpected 2\n") test.match_exact(["actual 1\n", "actual 2\n"], ["expected 1\n", "expected 2\n"]) test.match_re("actual 1\nactual 2\n", regex_string) test.match_re(["actual 1\n", "actual 2\n"], list_of_regexes) test.match_re_dotall("actual 1\nactual 2\n", regex_string) test.match_re_dotall(["actual 1\n", "actual 2\n"], list_of_regexes) test.tempdir() test.tempdir('temporary-directory') test.sleep() test.sleep(seconds) test.where_is('foo') test.where_is('foo', 'PATH1:PATH2') test.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4') test.unlink('file') test.unlink('subdir', 'file') The TestCmd module provides pass_test(), fail_test(), and no_result() unbound functions that report test results for use with the Aegis change management system. These methods terminate the test immediately, reporting PASSED, FAILED, or NO RESULT respectively, and exiting with status 0 (success), 1 or 2 respectively. This allows for a distinction between an actual failed test and a test that could not be properly evaluated because of an external condition (such as a full file system or incorrect permissions). import TestCmd TestCmd.pass_test() TestCmd.pass_test(condition) TestCmd.pass_test(condition, function) TestCmd.fail_test() TestCmd.fail_test(condition) TestCmd.fail_test(condition, function) TestCmd.fail_test(condition, function, skip) TestCmd.no_result() TestCmd.no_result(condition) TestCmd.no_result(condition, function) TestCmd.no_result(condition, function, skip) The TestCmd module also provides unbound functions that handle matching in the same way as the match_*() methods described above. import TestCmd test = TestCmd.TestCmd(match = TestCmd.match_exact) test = TestCmd.TestCmd(match = TestCmd.match_re) test = TestCmd.TestCmd(match = TestCmd.match_re_dotall) The TestCmd module provides unbound functions that can be used for the "diff" argument to TestCmd.TestCmd instantiation: import TestCmd test = TestCmd.TestCmd(match = TestCmd.match_re, diff = TestCmd.diff_re) test = TestCmd.TestCmd(diff = TestCmd.simple_diff) The "diff" argument can also be used with standard difflib functions: import difflib test = TestCmd.TestCmd(diff = difflib.context_diff) test = TestCmd.TestCmd(diff = difflib.unified_diff) Lastly, the where_is() method also exists in an unbound function version. import TestCmd TestCmd.where_is('foo') TestCmd.where_is('foo', 'PATH1:PATH2') TestCmd.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4') """
""" ======== Glossary ======== along an axis Axes are defined for arrays with more than one dimension. A 2-dimensional array has two corresponding axes: the first running vertically downwards across rows (axis 0), and the second running horizontally across columns (axis 1). Many operation can take place along one of these axes. For example, we can sum each row of an array, in which case we operate along columns, or axis 1:: >>> x = np.arange(12).reshape((3,4)) >>> x array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> x.sum(axis=1) array([ 6, 22, 38]) array A homogeneous container of numerical elements. Each element in the array occupies a fixed amount of memory (hence homogeneous), and can be a numerical element of a single type (such as float, int or complex) or a combination (such as ``(float, int, float)``). Each array has an associated data-type (or ``dtype``), which describes the numerical type of its elements:: >>> x = np.array([1, 2, 3], float) >>> x array([ 1., 2., 3.]) >>> x.dtype # floating point number, 64 bits of memory per element dtype('float64') # More complicated data type: each array element is a combination of # and integer and a floating point number >>> np.array([(1, 2.0), (3, 4.0)], dtype=[('x', int), ('y', float)]) array([(1, 2.0), (3, 4.0)], dtype=[('x', '<i4'), ('y', '<f8')]) Fast element-wise operations, called `ufuncs`_, operate on arrays. array_like Any sequence that can be interpreted as an ndarray. This includes nested lists, tuples, scalars and existing arrays. attribute A property of an object that can be accessed using ``obj.attribute``, e.g., ``shape`` is an attribute of an array:: >>> x = np.array([1, 2, 3]) >>> x.shape (3,) BLAS `Basic Linear Algebra Subprograms <http://en.wikipedia.org/wiki/BLAS>`_ broadcast NumPy can do operations on arrays whose shapes are mismatched:: >>> x = np.array([1, 2]) >>> y = np.array([[3], [4]]) >>> x array([1, 2]) >>> y array([[3], [4]]) >>> x + y array([[4, 5], [5, 6]]) See `doc.broadcasting`_ for more information. C order See `row-major` column-major A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In column-major order, the leftmost index "varies the fastest": for example the array:: [[1, 2, 3], [4, 5, 6]] is represented in the column-major order as:: [1, 4, 2, 5, 3, 6] Column-major order is also known as the Fortran order, as the Fortran programming language uses it. decorator An operator that transforms a function. For example, a ``log`` decorator may be defined to print debugging information upon function execution:: >>> def log(f): ... def new_logging_func(*args, **kwargs): ... print "Logging call with parameters:", args, kwargs ... return f(*args, **kwargs) ... ... return new_logging_func Now, when we define a function, we can "decorate" it using ``log``:: >>> @log ... def add(a, b): ... return a + b Calling ``add`` then yields: >>> add(1, 2) Logging call with parameters: (1, 2) {} 3 dictionary Resembling a language dictionary, which provides a mapping between words and descriptions thereof, a Python dictionary is a mapping between two objects:: >>> x = {1: 'one', 'two': [1, 2]} Here, `x` is a dictionary mapping keys to values, in this case the integer 1 to the string "one", and the string "two" to the list ``[1, 2]``. The values may be accessed using their corresponding keys:: >>> x[1] 'one' >>> x['two'] [1, 2] Note that dictionaries are not stored in any specific order. Also, most mutable (see *immutable* below) objects, such as lists, may not be used as keys. For more information on dictionaries, read the `Python tutorial <http://docs.python.org/tut>`_. Fortran order See `column-major` flattened Collapsed to a one-dimensional array. See `ndarray.flatten`_ for details. immutable An object that cannot be modified after execution is called immutable. Two common examples are strings and tuples. instance A class definition gives the blueprint for constructing an object:: >>> class House(object): ... wall_colour = 'white' Yet, we have to *build* a house before it exists:: >>> h = House() # build a house Now, ``h`` is called a ``House`` instance. An instance is therefore a specific realisation of a class. iterable A sequence that allows "walking" (iterating) over items, typically using a loop such as:: >>> x = [1, 2, 3] >>> [item**2 for item in x] [1, 4, 9] It is often used in combintion with ``enumerate``:: >>> keys = ['a','b','c'] >>> for n, k in enumerate(keys): ... print "Key %d: %s" % (n, k) ... Key 0: a Key 1: b Key 2: c list A Python container that can hold any number of objects or items. The items do not have to be of the same type, and can even be lists themselves:: >>> x = [2, 2.0, "two", [2, 2.0]] The list `x` contains 4 items, each which can be accessed individually:: >>> x[2] # the string 'two' 'two' >>> x[3] # a list, containing an integer 2 and a float 2.0 [2, 2.0] It is also possible to select more than one item at a time, using *slicing*:: >>> x[0:2] # or, equivalently, x[:2] [2, 2.0] In code, arrays are often conveniently expressed as nested lists:: >>> np.array([[1, 2], [3, 4]]) array([[1, 2], [3, 4]]) For more information, read the section on lists in the `Python tutorial <http://docs.python.org/tut>`_. For a mapping type (key-value), see *dictionary*. mask A boolean array, used to select only certain elements for an operation:: >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> mask = (x > 2) >>> mask array([False, False, False, True, True], dtype=bool) >>> x[mask] = -1 >>> x array([ 0, 1, 2, -1, -1]) masked array Array that suppressed values indicated by a mask:: >>> x = np.ma.masked_array([np.nan, 2, np.nan], [True, False, True]) >>> x masked_array(data = [-- 2.0 --], mask = [ True False True], fill_value = 1e+20) <BLANKLINE> >>> x + [1, 2, 3] masked_array(data = [-- 4.0 --], mask = [ True False True], fill_value = 1e+20) <BLANKLINE> Masked arrays are often used when operating on arrays containing missing or invalid entries. matrix A 2-dimensional ndarray that preserves its two-dimensional nature throughout operations. It has certain special operations, such as ``*`` (matrix multiplication) and ``**`` (matrix power), defined:: >>> x = np.mat([[1, 2], [3, 4]]) >>> x matrix([[1, 2], [3, 4]]) >>> x**2 matrix([[ 7, 10], [15, 22]]) method A function associated with an object. For example, each ndarray has a method called ``repeat``:: >>> x = np.array([1, 2, 3]) >>> x.repeat(2) array([1, 1, 2, 2, 3, 3]) ndarray See *array*. reference If ``a`` is a reference to ``b``, then ``(a is b) == True``. Therefore, ``a`` and ``b`` are different names for the same Python object. row-major A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In row-major order, the rightmost index "varies the fastest": for example the array:: [[1, 2, 3], [4, 5, 6]] is represented in the row-major order as:: [1, 2, 3, 4, 5, 6] Row-major order is also known as the C order, as the C programming language uses it. New Numpy arrays are by default in row-major order. self Often seen in method signatures, ``self`` refers to the instance of the associated class. For example: >>> class Paintbrush(object): ... color = 'blue' ... ... def paint(self): ... print "Painting the city %s!" % self.color ... >>> p = Paintbrush() >>> p.color = 'red' >>> p.paint() # self refers to 'p' Painting the city red! slice Used to select only certain elements from a sequence:: >>> x = range(5) >>> x [0, 1, 2, 3, 4] >>> x[1:3] # slice from 1 to 3 (excluding 3 itself) [1, 2] >>> x[1:5:2] # slice from 1 to 5, but skipping every second element [1, 3] >>> x[::-1] # slice a sequence in reverse [4, 3, 2, 1, 0] Arrays may have more than one dimension, each which can be sliced individually:: >>> x = np.array([[1, 2], [3, 4]]) >>> x array([[1, 2], [3, 4]]) >>> x[:, 1] array([2, 4]) tuple A sequence that may contain a variable number of types of any kind. A tuple is immutable, i.e., once constructed it cannot be changed. Similar to a list, it can be indexed and sliced:: >>> x = (1, 'one', [1, 2]) >>> x (1, 'one', [1, 2]) >>> x[0] 1 >>> x[:2] (1, 'one') A useful concept is "tuple unpacking", which allows variables to be assigned to the contents of a tuple:: >>> x, y = (1, 2) >>> x, y = 1, 2 This is often used when a function returns multiple values: >>> def return_many(): ... return 1, 'alpha', None >>> a, b, c = return_many() >>> a, b, c (1, 'alpha', None) >>> a 1 >>> b 'alpha' ufunc Universal function. A fast element-wise array operation. Examples include ``add``, ``sin`` and ``logical_or``. view An array that does not own its data, but refers to another array's data instead. For example, we may create a view that only shows every second element of another array:: >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> y = x[::2] >>> y array([0, 2, 4]) >>> x[0] = 3 # changing x changes y as well, since y is a view on x >>> y array([3, 2, 4]) wrapper Python is a high-level (highly abstracted, or English-like) language. This abstraction comes at a price in execution speed, and sometimes it becomes necessary to use lower level languages to do fast computations. A wrapper is code that provides a bridge between high and the low level languages, allowing, e.g., Python to execute code written in C or Fortran. Examples include ctypes, SWIG and Cython (which wraps C and C++) and f2py (which wraps Fortran). """
""" =================== Universal Functions =================== Ufuncs are, generally speaking, mathematical functions or operations that are applied element-by-element to the contents of an array. That is, the result in each output array element only depends on the value in the corresponding input array (or arrays) and on no other array elements. NumPy comes with a large suite of ufuncs, and scipy extends that suite substantially. The simplest example is the addition operator: :: >>> np.array([0,2,3,4]) + np.array([1,1,-1,2]) array([1, 3, 2, 6]) The unfunc module lists all the available ufuncs in numpy. Documentation on the specific ufuncs may be found in those modules. This documentation is intended to address the more general aspects of unfuncs common to most of them. All of the ufuncs that make use of Python operators (e.g., +, -, etc.) have equivalent functions defined (e.g. add() for +) Type coercion ============= What happens when a binary operator (e.g., +,-,\\*,/, etc) deals with arrays of two different types? What is the type of the result? Typically, the result is the higher of the two types. For example: :: float32 + float64 -> float64 int8 + int32 -> int32 int16 + float32 -> float32 float32 + complex64 -> complex64 There are some less obvious cases generally involving mixes of types (e.g. uints, ints and floats) where equal bit sizes for each are not capable of saving all the information in a different type of equivalent bit size. Some examples are int32 vs float32 or uint32 vs int32. Generally, the result is the higher type of larger size than both (if available). So: :: int32 + float32 -> float64 uint32 + int32 -> int64 Finally, the type coercion behavior when expressions involve Python scalars is different than that seen for arrays. Since Python has a limited number of types, combining a Python int with a dtype=np.int8 array does not coerce to the higher type but instead, the type of the array prevails. So the rules for Python scalars combined with arrays is that the result will be that of the array equivalent the Python scalar if the Python scalar is of a higher 'kind' than the array (e.g., float vs. int), otherwise the resultant type will be that of the array. For example: :: Python int + int8 -> int8 Python float + int8 -> float64 ufunc methods ============= Binary ufuncs support 4 methods. **.reduce(arr)** applies the binary operator to elements of the array in sequence. For example: :: >>> np.add.reduce(np.arange(10)) # adds all elements of array 45 For multidimensional arrays, the first dimension is reduced by default: :: >>> np.add.reduce(np.arange(10).reshape(2,5)) array([ 5, 7, 9, 11, 13]) The axis keyword can be used to specify different axes to reduce: :: >>> np.add.reduce(np.arange(10).reshape(2,5),axis=1) array([10, 35]) **.accumulate(arr)** applies the binary operator and generates an an equivalently shaped array that includes the accumulated amount for each element of the array. A couple examples: :: >>> np.add.accumulate(np.arange(10)) array([ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) >>> np.multiply.accumulate(np.arange(1,9)) array([ 1, 2, 6, 24, 120, 720, 5040, 40320]) The behavior for multidimensional arrays is the same as for .reduce(), as is the use of the axis keyword). **.reduceat(arr,indices)** allows one to apply reduce to selected parts of an array. It is a difficult method to understand. See the documentation at: **.outer(arr1,arr2)** generates an outer operation on the two arrays arr1 and arr2. It will work on multidimensional arrays (the shape of the result is the concatenation of the two input shapes.: :: >>> np.multiply.outer(np.arange(3),np.arange(4)) array([[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]) Output arguments ================ All ufuncs accept an optional output array. The array must be of the expected output shape. Beware that if the type of the output array is of a different (and lower) type than the output result, the results may be silently truncated or otherwise corrupted in the downcast to the lower type. This usage is useful when one wants to avoid creating large temporary arrays and instead allows one to reuse the same array memory repeatedly (at the expense of not being able to use more convenient operator notation in expressions). Note that when the output argument is used, the ufunc still returns a reference to the result. >>> x = np.arange(2) >>> np.add(np.arange(2),np.arange(2.),x) array([0, 2]) >>> x array([0, 2]) and & or as ufuncs ================== Invariably people try to use the python 'and' and 'or' as logical operators (and quite understandably). But these operators do not behave as normal operators since Python treats these quite differently. They cannot be overloaded with array equivalents. Thus using 'and' or 'or' with an array results in an error. There are two alternatives: 1) use the ufunc functions logical_and() and logical_or(). 2) use the bitwise operators & and \\|. The drawback of these is that if the arguments to these operators are not boolean arrays, the result is likely incorrect. On the other hand, most usages of logical_and and logical_or are with boolean arrays. As long as one is careful, this is a convenient way to apply these operators. """
# # ElementTree # $Id$ # # light-weight XML support for Python 2.2 and later. # # history: # 2001-10-20 fl created (from various sources) # 2001-11-01 fl return root from parse method # 2002-02-16 fl sort attributes in lexical order # 2002-04-06 fl TreeBuilder refactoring, added PythonDoc markup # 2002-05-01 fl finished TreeBuilder refactoring # 2002-07-14 fl added basic namespace support to ElementTree.write # 2002-07-25 fl added QName attribute support # 2002-10-20 fl fixed encoding in write # 2002-11-24 fl changed default encoding to ascii; fixed attribute encoding # 2002-11-27 fl accept file objects or file names for parse/write # 2002-12-04 fl moved XMLTreeBuilder back to this module # 2003-01-11 fl fixed entity encoding glitch for us-ascii # 2003-02-13 fl added XML literal factory # 2003-02-21 fl added ProcessingInstruction/PI factory # 2003-05-11 fl added tostring/fromstring helpers # 2003-05-26 fl added ElementPath support # 2003-07-05 fl added makeelement factory method # 2003-07-28 fl added more well-known namespace prefixes # 2003-08-15 fl fixed typo in ElementTree.findtext (Thomas NAME 2003-09-04 fl fall back on emulator if ElementPath is not installed # 2003-10-31 fl markup updates # 2003-11-15 fl fixed nested namespace bug # 2004-03-28 fl added XMLID helper # 2004-06-02 fl added default support to findtext # 2004-06-08 fl fixed encoding of non-ascii element/attribute names # 2004-08-23 fl take advantage of post-2.1 expat features # 2004-09-03 fl made Element class visible; removed factory # 2005-02-01 fl added iterparse implementation # 2005-03-02 fl fixed iterparse support for pre-2.2 versions # 2005-11-12 fl added tostringlist/fromstringlist helpers # 2006-07-05 fl merged in selected changes from the 1.3 sandbox # 2006-07-05 fl removed support for 2.1 and earlier # 2007-06-21 fl added deprecation/future warnings # 2007-08-25 fl added doctype hook, added parser version attribute etc # 2007-08-26 fl added new serializer code (better namespace handling, etc) # 2007-08-27 fl warn for broken /tag searches on tree level # 2007-09-02 fl added html/text methods to serializer (experimental) # 2007-09-05 fl added method argument to tostring/tostringlist # 2007-09-06 fl improved error handling # # Copyright (c) 1999-2007 by NAME All rights reserved. # # EMAIL http://www.pythonware.com # # -------------------------------------------------------------------- # The ElementTree toolkit is # # Copyright (c) 1999-2007 by NAME By obtaining, using, and/or copying this software and/or its # associated documentation, you agree that you have read, understood, # and will comply with the following terms and conditions: # # Permission to use, copy, modify, and distribute this software and # its associated documentation for any purpose and without fee is # hereby granted, provided that the above copyright notice appears in # all copies, and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of # Secret Labs AB or the author not be used in advertising or publicity # pertaining to distribution of the software without specific, written # prior permission. # # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. # --------------------------------------------------------------------
#!/usr/bin/env python # (c) 2013, NAME <EMAIL> # # This file is part of Ansible. # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # # # Author: NAME <EMAIL> # # Description: # This module queries local or remote Docker daemons and generates # inventory information. # # This plugin does not support targeting of specific hosts using the --host # flag. Instead, it queries the Docker API for each container, running # or not, and returns this data all once. # # The plugin returns the following custom attributes on Docker containers: # docker_args # docker_config # docker_created # docker_driver # docker_exec_driver # docker_host_config # docker_hostname_path # docker_hosts_path # docker_id # docker_image # docker_name # docker_network_settings # docker_path # docker_resolv_conf_path # docker_state # docker_volumes # docker_volumes_rw # # Requirements: # The docker-py module: https://github.com/dotcloud/docker-py # # Notes: # A config file can be used to configure this inventory module, and there # are several environment variables that can be set to modify the behavior # of the plugin at runtime: # DOCKER_CONFIG_FILE # DOCKER_HOST # DOCKER_VERSION # DOCKER_TIMEOUT # DOCKER_PRIVATE_SSH_PORT # DOCKER_DEFAULT_IP # # Environment Variables: # environment variable: DOCKER_CONFIG_FILE # description: # - A path to a Docker inventory hosts/defaults file in YAML format # - A sample file has been provided, colocated with the inventory # file called 'docker.yml' # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_HOST # description: # - The socket on which to connect to a Docker daemon API # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_VERSION # description: # - Version of the Docker API to use # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_TIMEOUT # description: # - Timeout in seconds for connections to Docker daemon API # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_PRIVATE_SSH_PORT # description: # - The private port (container port) on which SSH is listening # for connections # default: 22 # required: false # environment variable: DOCKER_DEFAULT_IP # description: # - This environment variable overrides the container SSH connection # IP address (aka, 'ansible_ssh_host') # # This option allows one to override the ansible_ssh_host whenever # Docker has exercised its default behavior of binding private ports # to all interfaces of the Docker host. This behavior, when dealing # with remote Docker hosts, does not allow Ansible to determine # a proper host IP address on which to connect via SSH to containers. # By default, this inventory module assumes all IP_ADDRESS-exposed # ports to be bound to localhost:<port>. To override this # behavior, for example, to bind a container's SSH port to the public # interface of its host, one must manually set this IP. # # It is preferable to begin to launch Docker containers with # ports exposed on publicly accessible IP addresses, particularly # if the containers are to be targeted by Ansible for remote # configuration, not accessible via localhost SSH connections. # # Docker containers can be explicitly exposed on IP addresses by # a) starting the daemon with the --ip argument # b) running containers with the -P/--publish ip::containerPort # argument # default: IP_ADDRESS if port exposed on IP_ADDRESS by Docker # required: false # # Examples: # Use the config file: # DOCKER_CONFIG_FILE=./docker.yml docker.py --list # # Connect to docker instance on localhost port 4243 # DOCKER_HOST=tcp://localhost:4243 docker.py --list # # Any container's ssh port exposed on IP_ADDRESS will mapped to # another IP address (where Ansible will attempt to connect via SSH) # DOCKER_DEFAULT_IP=IP_ADDRESS docker.py --list
""" ======================== Broadcasting over arrays ======================== .. note:: See `this article <https://numpy.org/devdocs/user/theory.broadcasting.html>`_ for illustrations of broadcasting concepts. The term broadcasting describes how numpy treats arrays with different shapes during arithmetic operations. Subject to certain constraints, the smaller array is "broadcast" across the larger array so that they have compatible shapes. Broadcasting provides a means of vectorizing array operations so that looping occurs in C instead of Python. It does this without making needless copies of data and usually leads to efficient algorithm implementations. There are, however, cases where broadcasting is a bad idea because it leads to inefficient use of memory that slows computation. NumPy operations are usually done on pairs of arrays on an element-by-element basis. In the simplest case, the two arrays must have exactly the same shape, as in the following example: >>> a = np.array([1.0, 2.0, 3.0]) >>> b = np.array([2.0, 2.0, 2.0]) >>> a * b array([ 2., 4., 6.]) NumPy's broadcasting rule relaxes this constraint when the arrays' shapes meet certain constraints. The simplest broadcasting example occurs when an array and a scalar value are combined in an operation: >>> a = np.array([1.0, 2.0, 3.0]) >>> b = 2.0 >>> a * b array([ 2., 4., 6.]) The result is equivalent to the previous example where ``b`` was an array. We can think of the scalar ``b`` being *stretched* during the arithmetic operation into an array with the same shape as ``a``. The new elements in ``b`` are simply copies of the original scalar. The stretching analogy is only conceptual. NumPy is smart enough to use the original scalar value without actually making copies, so that broadcasting operations are as memory and computationally efficient as possible. The code in the second example is more efficient than that in the first because broadcasting moves less memory around during the multiplication (``b`` is a scalar rather than an array). General Broadcasting Rules ========================== When operating on two arrays, NumPy compares their shapes element-wise. It starts with the trailing dimensions, and works its way forward. Two dimensions are compatible when 1) they are equal, or 2) one of them is 1 If these conditions are not met, a ``ValueError: operands could not be broadcast together`` exception is thrown, indicating that the arrays have incompatible shapes. The size of the resulting array is the maximum size along each dimension of the input arrays. Arrays do not need to have the same *number* of dimensions. For example, if you have a ``256x256x3`` array of RGB values, and you want to scale each color in the image by a different value, you can multiply the image by a one-dimensional array with 3 values. Lining up the sizes of the trailing axes of these arrays according to the broadcast rules, shows that they are compatible:: Image (3d array): 256 x 256 x 3 Scale (1d array): 3 Result (3d array): 256 x 256 x 3 When either of the dimensions compared is one, the other is used. In other words, dimensions with size 1 are stretched or "copied" to match the other. In the following example, both the ``A`` and ``B`` arrays have axes with length one that are expanded to a larger size during the broadcast operation:: A (4d array): 8 x 1 x 6 x 1 B (3d array): 7 x 1 x 5 Result (4d array): 8 x 7 x 6 x 5 Here are some more examples:: A (2d array): 5 x 4 B (1d array): 1 Result (2d array): 5 x 4 A (2d array): 5 x 4 B (1d array): 4 Result (2d array): 5 x 4 A (3d array): 15 x 3 x 5 B (3d array): 15 x 1 x 5 Result (3d array): 15 x 3 x 5 A (3d array): 15 x 3 x 5 B (2d array): 3 x 5 Result (3d array): 15 x 3 x 5 A (3d array): 15 x 3 x 5 B (2d array): 3 x 1 Result (3d array): 15 x 3 x 5 Here are examples of shapes that do not broadcast:: A (1d array): 3 B (1d array): 4 # trailing dimensions do not match A (2d array): 2 x 1 B (3d array): 8 x 4 x 3 # second from last dimensions mismatched An example of broadcasting in practice:: >>> x = np.arange(4) >>> xx = x.reshape(4,1) >>> y = np.ones(5) >>> z = np.ones((3,4)) >>> x.shape (4,) >>> y.shape (5,) >>> x + y ValueError: operands could not be broadcast together with shapes (4,) (5,) >>> xx.shape (4, 1) >>> y.shape (5,) >>> (xx + y).shape (4, 5) >>> xx + y array([[ 1., 1., 1., 1., 1.], [ 2., 2., 2., 2., 2.], [ 3., 3., 3., 3., 3.], [ 4., 4., 4., 4., 4.]]) >>> x.shape (4,) >>> z.shape (3, 4) >>> (x + z).shape (3, 4) >>> x + z array([[ 1., 2., 3., 4.], [ 1., 2., 3., 4.], [ 1., 2., 3., 4.]]) Broadcasting provides a convenient way of taking the outer product (or any other outer operation) of two arrays. The following example shows an outer addition operation of two 1-d arrays:: >>> a = np.array([0.0, 10.0, 20.0, 30.0]) >>> b = np.array([1.0, 2.0, 3.0]) >>> a[:, np.newaxis] + b array([[ 1., 2., 3.], [ 11., 12., 13.], [ 21., 22., 23.], [ 31., 32., 33.]]) Here the ``newaxis`` index operator inserts a new axis into ``a``, making it a two-dimensional ``4x1`` array. Combining the ``4x1`` array with ``b``, which has shape ``(3,)``, yields a ``4x3`` array. """
""" Stockholm format (:mod:`skbio.io.format.stockholm`) =================================================== .. currentmodule:: skbio.io.format.stockholm The Stockholm format is a multiple sequence alignment format (MSA) that optionally supports storing arbitrary alignment features (metadata). Features can be placed into four different categories: GF, GS, GR, and GC (described in more detail below). An example Stockholm file, taken from [1]_: .. code-block:: none # STOCKHOLM 1.0 #=GF ID UPSK #=GF SE Predicted; Infernal #=GF SS Published; PMID 9223489 #=GF RN [1] #=GF RM 9223489 #=GF RT The role of the pseudoknot at the 3' end of turnip yellow mosaic #=GF RT virus RNA in minus-strand synthesis by the viral RNA-dependent \ RNA #=GF RT polymerase. #=GF RA Deiman BA, Kortlever RM, Pleij CW; #=GF RL J Virol 1997;71:5990-5996. AF035635.1/619-641 UGAGUUCUCGAUCUCUAAAAUCG M24804.1/82-104 UGAGUUCUCUAUCUCUAAAAUCG J04373.1/6212-6234 UAAGUUCUCGAUCUUUAAAAUCG M24803.1/1-23 UAAGUUCUCGAUCUCUAAAAUCG #=GC SS_cons .AAA....<<<<aaa....>>>> // Format Support -------------- **Has Sniffer: Yes** **State: Experimental as of 0.4.2.** +------+------+---------------------------------------------------------------+ |Reader|Writer| Object Class | +======+======+===============================================================+ |Yes |Yes |:mod:`skbio.alignment.TabularMSA` | +------+------+---------------------------------------------------------------+ Format Specification -------------------- The Stockholm format consists of a header, a multiple sequence alignment, associated metadata (features), and a footer. Header ^^^^^^ The first line of a Stockholm file must be the following header: .. code-block:: none # STOCKHOLM 1.0 Multiple Sequence Alignment ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Sequence lines consist of a sequence name, followed by whitespace, followed by the aligned sequence. For example:: seq1 ACG-T-GGT seq2 ACCGTTCG- Sequence names (``seq1``, ``seq2``) are stored in the ``TabularMSA`` ``index``. .. note:: scikit-bio currently supports reading Stockholm files where each sequence is contained on a single line. Interleaved/wrap-around Stockholm files are not supported. When writing, each sequence will be placed on its own line. .. warning:: Sequence names must be unique in the Stockholm file. Likewise, when writing from a ``TabularMSA``, ``index`` must be unique. Metadata ^^^^^^^^ Stockholm files support storing arbitrary metadata (features) about the MSA. All metadata described in the following sections are optional and may appear in any order. Metadata "mark-up" lines begin with either ``#=GF``, ``#=GS``, ``#=GR``, or ``#=GC``, and each line describes a single feature of the alignment. .. note:: Stockholm format supports generic features. [1]_ and [2]_ provide a list of common features output by Pfam/Rfam. scikit-bio does not require that these features are present. These features are processed in the same way as any arbitrary feature would be, as a simple key-value pair of strings. When writing, feature names, feature data, and sequence names are converted to type ``str``. .. note:: When writing a Stockholm file, scikit-bio will place the metadata in the format's recommended order: - GF: Above the alignment - GS: Above the alignment (after GF) - GR: Below corresponding sequence - GC: Below the alignment GF metadata +++++++++++ Data relating to the multiple sequence alignment as a whole, such as authors or number of sequences in the alignment. Starts with ``#=GF`` followed by a feature name and data relating to the feature. Typically comes first in a Stockholm file. For example (taken from [2]_): .. code-block:: none #=GF DE CBS domain Where ``DE`` is the feature name and ``CBS Domain`` is the feature data. GF metadata is stored in the ``TabularMSA`` ``metadata`` dictionary. .. note:: When reading, duplicate GF feature names will have their values concatenated in the order they appear in the file. Concatenation will also add a space between lines if one isn't already there in order to avoid joining words together. When writing, each GF feature will be placed on its own line, regardless of length. .. note:: Trees labelled with ``NH``/``TN`` are handled differently than other GF features. When reading a Stockholm file with these features, the reader follows the rules described in [2]_. Trees split over multiple lines will have their values concatenated. Unlike other GF features, trees will never have a space added when they are concatenated. A single tree without an identifier will be stored as:: metadata = { 'NH': 'tree in NHX format' } A single tree with an identifier will be stored as:: metadata = { 'NH': { 'tree-id': 'tree in NHX format' } } Multiple trees (which must have identifiers) will be stored as:: metadata = { 'NH': { 'tree-id-1': 'tree in NHX format', 'tree-id-2': 'tree in NHX format' } } .. note:: References labelled with ``RN``/``RM``/``RT``/``RA``/``RL``/``RC`` are handled differently than other GF features. When reading a Stockholm file with these features, the reader populates a list of dictionaries, where each dictionary represents a single reference. The list contains references in the order they appear in the file, regardless of the value provided for ``RN``. If a reference does not include all possible reference tags (e.g. ``RC`` is missing), the dictionary will only contain the reference tags present for that reference. When writing, the writer adds a reference number (``RN``) line before writing each reference, for example: .. code-block:: none #=GF RN [1] #=GF RA NAME ... #=GF RN [2] ... References will be stored as:: metadata = { 'RN': [{ 'RM': 'reference medline', 'RT': 'reference title', 'RA': 'reference author', 'RL': 'reference location', 'RC': 'reference comment' }, { 'RM': 'reference medline', ... }] } GS metadata +++++++++++ Data relating to a specific sequence in the multiple sequence alignment. Starts with ``#=GS`` followed by the sequence name followed by a feature name and data relating to the feature. Typically comes after GF metadata in a Stockholm file. For example (taken from [2]_): .. code-block:: none #=GS O83071/259-312 AC O83071 Where ``O83071/259-312`` is the sequence name, ``AC`` is the feature name, and ``083071`` is the feature data. GS metadata is stored in the sequence-specific ``metadata`` dictionary. .. note:: When reading, duplicate GS feature names will have their values concatenated in the order they appear in the file. Concatenation will also add a space between lines if one isn't already there in order to avoid joining words together. When writing, each GS feature will be placed on its own line, regardless of length. GR metadata +++++++++++ Data relating to the columns of a specific sequence in a multiple sequence alignment. Starts with ``#=GR`` followed by the sequence name followed by a feature name and data relating to the feature, one character per column. Typically comes after the sequence line it relates to. For example (taken from [2]_): .. code-block:: none #=GR O31698/18-71 SS CCCHHHHHHHHHHHHHHH..EEEEEEEE....EEEEEEEEHHH Where ``O31698/18-71`` is the sequence name, ``SS`` is the feature name, and ``CCCHHHHHHHHHHHHHHH..EEEEEEEE....EEEEEEEEHHH`` is the feature data. GR metadata is stored in sequence-specific ``positional_metadata``. .. note:: Duplicate GR feature names attributed to a single sequence are disallowed. GC metadata +++++++++++ Data relating to the columns of the multiple sequence alignment as a whole. Starts with ``#=GC`` followed by a feature name and data relating to the feature, one character per column. Typically comes at the end of the multiple sequence alignment. For example (taken from [2]_): .. code-block:: none #=GC SS_cons CCCCCHHHHHHHHHHHHH..EEEEEEEE....EEEEEEEEEEH Where ``SS_cons`` is the feature name and ``CCCCCHHHHHHHHHHHHH..EEEEEEEE....EEEEEEEEEEH`` is the feature data. GC metadata is stored in ``TabularMSA`` ``positional_metadata``. .. note:: Duplicate GC feature names are disallowed. Footer ^^^^^^ The final line of a Stockholm file must be the following footer:: // .. note:: scikit-bio currently supports reading a Stockholm file containing a single MSA. If the file contains more than one MSA, only the first MSA will be read into a ``TabularMSA``. Format Parameters ----------------- The only supported format parameter is ``constructor``, which specifies the type of in-memory sequence object to read each aligned sequence into. This must be a subclass of ``GrammaredSequence`` (e.g., ``DNA``, ``RNA``, ``Protein``) and is a required format parameter. For example, if you know that the Stockholm file you're reading contains DNA sequences, you would pass ``constructor=DNA`` to the reader call. Examples -------- Suppose we have a Stockholm file containing an MSA of protein sequences (modified from [2]_): >>> import skbio.io >>> from io import StringIO >>> from skbio import Protein, TabularMSA >>> fs = '\\n'.join([ ... '# STOCKHOLM 1.0', ... '#=GF CC CBS domains are small intracellular modules mostly' ... ' found', ... '#=GF CC in 2 or four copies within a protein.', ... '#=GS O83071/192-246 AC O83071', ... '#=GS O31698/88-139 OS Bacillus subtilis', ... 'O83071/192-246 MTCRAQLIAVPRASSLAE..AIACAQKM....RVSRV', ... '#=GR O83071/192-246 SA 999887756453524252..55152525....36463', ... 'O83071/259-312 MQHVSAPVFVFECTRLAY..VQHKLRAH....SRAVA', ... 'O31698/18-71 MIEADKVAHVQVGNNLEH..ALLVLTKT....GYTAI', ... 'O31698/88-139 EVMLTDIPRLHINDPIMK..GFGMVINN......GFV', ... 'O31699/88-139 EVMLTDIPRLHINDPIMK..GFGMVINN......GFV', ... '#=GR O31699/88-139 AS ________________*____________________', ... '#=GR O31699/88-139 IN ____________1______________2_________', ... '#=GC SS_cons CCCCCHHHHHHHHHHHHH..EEEEEEEE....EEEEE', ... '//' ... ]) >>> fh = StringIO(fs) >>> msa = TabularMSA.read(fh, constructor=Protein) >>> msa # doctest: +NORMALIZE_WHITESPACE TabularMSA[Protein] ---------------------------------------------------------------------- Metadata: 'CC': 'CBS domains are small intracellular modules mostly found in 2 or four copies within a protein.' Positional metadata: 'SS_cons': <dtype: object> Stats: sequence count: 5 position count: 37 ---------------------------------------------------------------------- MTCRAQLIAVPRASSLAE..AIACAQKM....RVSRV MQHVSAPVFVFECTRLAY..VQHKLRAH....SRAVA MIEADKVAHVQVGNNLEH..ALLVLTKT....GYTAI EVMLTDIPRLHINDPIMK..GFGMVINN......GFV EVMLTDIPRLHINDPIMK..GFGMVINN......GFV The sequence names are stored in the ``index``: >>> msa.index Index(['O83071/192-246', 'O83071/259-312', 'O31698/18-71', 'O31698/88-139', 'O31699/88-139'], dtype='object') The ``TabularMSA`` has GF metadata stored in its ``metadata`` dictionary: >>> msa.metadata OrderedDict([('CC', 'CBS domains are small intracellular modules mostly found \ in 2 or four copies within a protein.')]) GC metadata is stored in the ``TabularMSA`` ``positional_metadata``: >>> msa.positional_metadata # doctest: +ELLIPSIS SS_cons 0 C 1 C 2 C 3 C 4 C 5 H 6 H 7 H 8 H 9 H ... GS metadata is stored in the sequence-specific ``metadata`` dictionary: >>> msa[0].metadata OrderedDict([('AC', 'O83071')]) GR metadata is stored in sequence-specific ``positional_metadata``: >>> msa[4].positional_metadata # doctest: +ELLIPSIS AS IN 0 _ _ 1 _ _ 2 _ _ 3 _ _ 4 _ _ 5 _ _ 6 _ _ 7 _ _ 8 _ _ 9 _ _ ... Let's write this ``TabularMSA`` in Stockholm format: >>> fh = StringIO() >>> _ = msa.write(fh, format='stockholm') >>> print(fh.getvalue()) # STOCKHOLM 1.0 #=GF CC CBS domains are small intracellular modules mostly found in 2 or four \ copies within a protein. #=GS O83071/192-246 AC O83071 #=GS O31698/88-139 OS Bacillus subtilis O83071/192-246 MTCRAQLIAVPRASSLAE..AIACAQKM....RVSRV #=GR O83071/192-246 SA 999887756453524252..55152525....36463 O83071/259-312 MQHVSAPVFVFECTRLAY..VQHKLRAH....SRAVA O31698/18-71 MIEADKVAHVQVGNNLEH..ALLVLTKT....GYTAI O31698/88-139 EVMLTDIPRLHINDPIMK..GFGMVINN......GFV O31699/88-139 EVMLTDIPRLHINDPIMK..GFGMVINN......GFV #=GR O31699/88-139 AS ________________*____________________ #=GR O31699/88-139 IN ____________1______________2_________ #=GC SS_cons CCCCCHHHHHHHHHHHHH..EEEEEEEE....EEEEE // <BLANKLINE> >>> fh.close() References ========== .. [1] https://en.wikipedia.org/wiki/Stockholm_format .. [2] http://sonnhammer.sbc.su.se/Stockholm.html """
""" This module implements helper functions and classes that can be used to define reducers in the same fashion of redux ones, but using decorators instead of anonymous functions. Things you **should never do** inside a reducer: * Mutate its arguments; * Perform side effects like API calls and routing transitions; * Call **non-pure** functions. **Given the same arguments, it should calculate the next state and return it. No surprises. No side effects. No API calls. No mutations. Just a calculation.** Create a reducer ================ A reducer is a function that looks like this: .. code:: python def dummy(prev, action): next = prev if action.type == ActionType.DUMMY_ACTION_TYPE: # Do something return next In order to decrease the amount of required boilerplate ``revived`` makes use of a lot of python goodies, especially **decorators**. While every function can be used as ``reducer`` (as long as it takes the proper parameters), the easiest way to create a ``reducer`` that handles a specific type of ``actions`` is to use the :any:`revived.reducer.reducer` decorator. .. code:: python @reducer(ActionType.DUMMY_ACTION_TYPE) def dummy(prev, action): next = prev # Do something return next Combine reducers ================ You can naively combine several ``reducers`` in this way: .. code:: python def dummy(prev, action): next = prev if action.type == ActionType.DUMMY_ACTION_TYPE1: # Do something return next elif action.type == ActionType.DUMMY_ACTION_TYPE2: # Do something different return next else: return next but this is going to make your ``reducer`` function huge and barely readable. :any:`revived.reducer` contains utility functions that allows you to create much more readable ``reducers``. Reducers can (*and should*) be combined. You can easily do this combination using :any:`revived.reducer.combine_reducers`. The following example will produce a ``combined reducer`` where both the ``reducers`` will handle the whole subtree passed to it: exactly the same result of the previous snippet of code! .. code:: python @reducer(ActionType.DUMMY_ACTION_TYPE1) def dummy1(prev, action): next = prev # Do something return next @reducer(ActionType.DUMMY_ACTION_TYPE2) def dummy2(prev, action): next = prev # Do something return next combined_reducer = combine_reducers(dummy1, dummy2) **Note**: a ``combined reducer`` is a ``reducer`` and can be combined again with other reducers allowing you to creare every structure you will ever need in your app. Pass a subtree of the state --------------------------- If you want it is possible to pass to a reducer only a subtree of the state passed to the ``combined reducer``. To do this you should use keyword arguments in this way: .. code:: python @reducer(ActionType.DUMMY_ACTION_TYPE1) def dummy1(prev, action): next = prev # Do something return next @reducer(ActionType.DUMMY_ACTION_TYPE2) def dummy2(prev, action): next = prev # Do something return next combined_reducer = combine_reducers(dummy1, dummy_subtree=dummy2) In this example ``dummy1`` will receive the whole subtree passed to the ``combined_reducer`` while ``dummy2`` will only receive the ``dummy_subtree`` subtree. Create a reducer module ======================= A ``reducer module`` is an utility object that behave exactly like a single ``reducer``, but permits to register more ``reducers`` into it. You will use it to define a bunch of ``reducers`` that are all handling the same subtree of the ``state``. Note that this is *only a helper construct*, because the following snippet of code: .. code:: python mod = Module() @mod.reducer(ActionType.DUMMY_ACTION_TYPE1) def dummy1(prev, action): next = prev # Do something return next @mod.reducer(ActionType.DUMMY_ACTION_TYPE2) def dummy2(prev, action): next = prev # Do something return next has exactly the same result of: .. code:: python @reducer(ActionType.DUMMY_ACTION_TYPE1) def dummy1(prev, action): next = prev # Do something return next @reducer(ActionType.DUMMY_ACTION_TYPE2) def dummy2(prev, action): next = prev # Do something return next module_reducer = combine_reducers(dummy1, dummy2) And of course **you can combine** a ``reducer module`` with other ``reducers`` and ``reducer modules``. """
# import time # # from getresults.tests.base_selenium_test import BaseSeleniumTest # # # class TestReceiveSelenium(BaseSeleniumTest): # # def test_open_receive(self): # '''Asserts user can open receive sample window''' # self.login() # self.assertTrue('Receive', self.browser.title) # self.browser.save_screenshot('getresults_receive/screenshots/receive.png') # # def test_open_receive_sample_modal(self): # '''Asserts user can open receive sample window''' # self.login() # time.sleep(1) # receive = self.browser.find_element_by_name("topbar_receive") # receive.click() # time.sleep(1) # self.assertTrue('Receive', self.browser.title) # sample_button = self.browser.find_element_by_name("submit_button") # sample_button.click() # time.sleep(1) # self.browser.save_screenshot('getresults_receive/screenshots/receive_sample.png') # # def test_open_receive_batch_modal(self): # '''Asserts user can open receive sample window''' # self.login() # time.sleep(1) # receive = self.browser.find_element_by_name("topbar_receive") # receive.click() # time.sleep(1) # self.assertTrue('Receive', self.browser.title) # sample_button = self.browser.find_element_by_name("receive_batch") # sample_button.click() # time.sleep(1) # self.browser.save_screenshot('getresults_receive/screenshots/receive_batch.png') # # def test_open_batch_preset_form(self): # '''Asserts user can open the batch preset form''' # self.login() # time.sleep(1) # self.browser.get(self.live_server_url + '/receive/') # time.sleep(1) # batch_preset_button = self.browser.find_element_by_id("receive_batch_button") # batch_preset_button.click() # time.sleep(1) # self.switch_to_new_window('Batch Preset Form', 'batchModalLabel') # # def test_submit_batch_preset_form_with_only_itemcount_populated(self): # '''Asserts user can open the batch preset form and submit it with all defaults populated''' # self.login() # time.sleep(1) # self.browser.get(self.live_server_url + '/receive/') # time.sleep(1) # batch_preset_button = self.browser.find_element_by_id("receive_batch_button") # batch_preset_button.click() # time.sleep(1) # self.switch_to_new_window('Batch Preset Form', 'batchModalLabel') # itemcount_input = self.browser.find_element_by_id("item_count_input_id") # itemcount_input.send_keys(10) # batch_preset_submit = self.browser.find_element_by_id("submit_batch_preset") # batch_preset_submit.click() # number_rows = self.browser.find_elements_by_name("patient_name") # self.assertEqual(len(number_rows), 10) # # def test_submit_batch_preset_form_with_all_defaults_populated(self): # '''Asserts user can open the batch preset form and submit it with only item count''' # self.login() # time.sleep(1) # self.browser.get(self.live_server_url + '/receive/') # time.sleep(1) # batch_preset_button = self.browser.find_element_by_id("receive_batch_button") # batch_preset_button.click() # time.sleep(1) # self.switch_to_new_window('Batch Preset Form', 'batchModalLabel') # itemcount_input = self.browser.find_element_by_id("item_count_input_id") # itemcount_input.send_keys(5) # sampletype_input = self.browser.find_element_by_id("specimen_type_input_id") # sampletype_input.send_keys('BF') # sitecode_input = self.browser.find_element_by_id("site_code_input_id") # sitecode_input.send_keys('14') # protocol_input = self.browser.find_element_by_id("protocol_number_input_id") # protocol_input.send_keys('066') # batch_preset_submit = self.browser.find_element_by_id("submit_batch_preset") # batch_preset_submit.click() # time.sleep(1) # receive_specimen_type_name = self.browser.find_elements_by_name("specimen_type_name")[0] # self.assertEqual(receive_specimen_type_name.get_attribute('value'), 'BF') # receive_site_code_name = self.browser.find_elements_by_name("site_code_name")[0] # self.assertEqual(receive_site_code_name.get_attribute('value'), '14') # receive_protocol_no_name = self.browser.find_elements_by_name("protocol_no_name")[0] # self.assertEqual(receive_protocol_no_name.get_attribute('value'), '066') # # def test_user_batch_filter(self): # self.login() # time.sleep(1) # self.browser.find_element_by_name("topbar_receive").click() # time.sleep(1) # self.browser.find_element_by_id('receive_batch_button').click() # time.sleep(1) # self.switch_to_new_window('Batch Preset Form', 'batchModalLabel') # self.browser.find_element_by_id('item_count_input_id').send_keys(1) # time.sleep(1) # self.browser.find_element_by_id("submit_batch_preset").click() # time.sleep(1) # self.browser.find_element_by_name("topbar_receive").click() # self.browser.find_element_by_name('view_my_batches').click() # time.sleep(1) # self.assertIn('receive_user_batches', self.browser.current_url) # table = self.browser.find_element_by_class_name('table-responsive') # rows = table.find_elements_by_tag_name('th') # self.assertTrue(any(row.text == 'Batch Identifier' for row in rows)) # self.browser.save_screenshot('getresults_receive/screenshots/receive_user_batch.png')
""" This module contains generic generator functions for traversing tree (and DAG) structures. It is agnostic to the underlying data structure and implementation of the tree object. It does this through dependency injection of the tree's accessor functions: get_parents and get_children. The following depth-first traversal methods are implemented: * Pre-order: Parent yielded before children; child with multiple parents is yielded when first encountered. Example use cases (when DAGs are *not* supported): 1. User access. If computing a user's access to a node relies on the user's access to the node's parents, access to the parent has to be computed before access to the child can be determined. To support access chains, a user's access on a node is actually an accumulation of accesses down from the root node through the ancestor chain to the actual node. 2. Field value percolated down. If a value for a field is dependent on a combination of the child's and the parent's value, the parent's value should be computed before that of the child's. Similar to "User access", the value would be percolated down through the entire ancestor chain. Example: Start Date is max(node's start date, start date of each ancestor) This takes the most restrictive value. 3. Depth. When computing the depth of a tree, since a child's depth value is 1 + the parent's depth value, the parent's value should be computed before the child's. 4. Fast Subtree Deletion. If the tree is to be pruned during traversal, an entire subtree can be deleted, without traversing the children, as soon as the parent is determined to be deleted. * Topological: Parent yielded before children; child with multiple parents yielded only after all its parents are visited. Example use cases (when DAGs *are* supported): 1. User access. Similar to pre-order, except a user's access is now determined by taking a *union* of the percolated access value from each of the node's parents combined with its own access. 2. Field value percolated down. Similar to pre-order, except the value for a node is calculated from the array of percolated values from each of its parents combined with its own. Example: Start Date is max(node's start date, min(max(ancestry of each parent)) This takes the most permissive from all ancestry chains. 3. Depth. Similar to pre-order, except the depth of a node will be 1 + the minimum (or the maximum depending on semantics) of the depth of all its parents. 4. Deletion. Deletion of subtrees are not as fast as they are for pre-order since a node can be accessed through multiple parents. * Post-order: Children yielded before its parents. Example use cases: 1. Counting. When each node wants to count the number of nodes within its sub-structure, the count for each child has to be calculated before its parents, since a parent's value depends on its children. 2. Map function (when order doesn't matter). If a function needs to be evaluated for each node in a DAG and the order that the nodes are iterated doesn't matter, then use post-order since it is faster than topological for DAGs. 3. Field value percolated up. If a value for a field is based on the value from it's children, the children's values need to be computed before their parents. Example: Minimum Due Date of all nodes within the sub-structure. Note: In-order traversal is not implemented as of yet. We can do so if/when needed. Optimization once DAGs are not supported: Supporting Directed Acyclic Graphs (DAGs) requires us to use topological sort, which has the following negative performance implications: * For a simple tree, we can immediately skip over traversing descendants, once it is determined that a parent is not to be yielded (based on the return value from the 'filter_func' function). However, since we support DAGs, we cannot simply skip over descendants since they may still be accessible through a different ancestry chain and need to be revisited once all their parents are visited. * For topological sort, we need the get_parents accessor function in order to determine whether all of a node's parents have been visited. This means the underlying implementation of the graph needs to have an efficient way to get a node's parents, perhaps with back pointers to each node's parents. This requires additional storage space, which could be eliminated if DAGs are not supported. """
""" =============== Array Internals =============== Internal organization of numpy arrays ===================================== It helps to understand a bit about how numpy arrays are handled under the covers to help understand numpy better. This section will not go into great detail. Those wishing to understand the full details are referred to Travis Oliphant's book "Guide to Numpy". Numpy arrays consist of two major components, the raw array data (from now on, referred to as the data buffer), and the information about the raw array data. The data buffer is typically what people think of as arrays in C or Fortran, a contiguous (and fixed) block of memory containing fixed sized data items. Numpy also contains a significant set of data that describes how to interpret the data in the data buffer. This extra information contains (among other things): 1) The basic data element's size in bytes 2) The start of the data within the data buffer (an offset relative to the beginning of the data buffer). 3) The number of dimensions and the size of each dimension 4) The separation between elements for each dimension (the 'stride'). This does not have to be a multiple of the element size 5) The byte order of the data (which may not be the native byte order) 6) Whether the buffer is read-only 7) Information (via the dtype object) about the interpretation of the basic data element. The basic data element may be as simple as a int or a float, or it may be a compound object (e.g., struct-like), a fixed character field, or Python object pointers. 8) Whether the array is to interpreted as C-order or Fortran-order. This arrangement allow for very flexible use of arrays. One thing that it allows is simple changes of the metadata to change the interpretation of the array buffer. Changing the byteorder of the array is a simple change involving no rearrangement of the data. The shape of the array can be changed very easily without changing anything in the data buffer or any data copying at all Among other things that are made possible is one can create a new array metadata object that uses the same data buffer to create a new view of that data buffer that has a different interpretation of the buffer (e.g., different shape, offset, byte order, strides, etc) but shares the same data bytes. Many operations in numpy do just this such as slices. Other operations, such as transpose, don't move data elements around in the array, but rather change the information about the shape and strides so that the indexing of the array changes, but the data in the doesn't move. Typically these new versions of the array metadata but the same data buffer are new 'views' into the data buffer. There is a different ndarray object, but it uses the same data buffer. This is why it is necessary to force copies through use of the .copy() method if one really wants to make a new and independent copy of the data buffer. New views into arrays mean the the object reference counts for the data buffer increase. Simply doing away with the original array object will not remove the data buffer if other views of it still exist. Multidimensional Array Indexing Order Issues ============================================ What is the right way to index multi-dimensional arrays? Before you jump to conclusions about the one and true way to index multi-dimensional arrays, it pays to understand why this is a confusing issue. This section will try to explain in detail how numpy indexing works and why we adopt the convention we do for images, and when it may be appropriate to adopt other conventions. The first thing to understand is that there are two conflicting conventions for indexing 2-dimensional arrays. Matrix notation uses the first index to indicate which row is being selected and the second index to indicate which column is selected. This is opposite the geometrically oriented-convention for images where people generally think the first index represents x position (i.e., column) and the second represents y position (i.e., row). This alone is the source of much confusion; matrix-oriented users and image-oriented users expect two different things with regard to indexing. The second issue to understand is how indices correspond to the order the array is stored in memory. In Fortran the first index is the most rapidly varying index when moving through the elements of a two dimensional array as it is stored in memory. If you adopt the matrix convention for indexing, then this means the matrix is stored one column at a time (since the first index moves to the next row as it changes). Thus Fortran is considered a Column-major language. C has just the opposite convention. In C, the last index changes most rapidly as one moves through the array as stored in memory. Thus C is a Row-major language. The matrix is stored by rows. Note that in both cases it presumes that the matrix convention for indexing is being used, i.e., for both Fortran and C, the first index is the row. Note this convention implies that the indexing convention is invariant and that the data order changes to keep that so. But that's not the only way to look at it. Suppose one has large two-dimensional arrays (images or matrices) stored in data files. Suppose the data are stored by rows rather than by columns. If we are to preserve our index convention (whether matrix or image) that means that depending on the language we use, we may be forced to reorder the data if it is read into memory to preserve our indexing convention. For example if we read row-ordered data into memory without reordering, it will match the matrix indexing convention for C, but not for Fortran. Conversely, it will match the image indexing convention for Fortran, but not for C. For C, if one is using data stored in row order, and one wants to preserve the image index convention, the data must be reordered when reading into memory. In the end, which you do for Fortran or C depends on which is more important, not reordering data or preserving the indexing convention. For large images, reordering data is potentially expensive, and often the indexing convention is inverted to avoid that. The situation with numpy makes this issue yet more complicated. The internal machinery of numpy arrays is flexible enough to accept any ordering of indices. One can simply reorder indices by manipulating the internal stride information for arrays without reordering the data at all. Numpy will know how to map the new index order to the data without moving the data. So if this is true, why not choose the index order that matches what you most expect? In particular, why not define row-ordered images to use the image convention? (This is sometimes referred to as the Fortran convention vs the C convention, thus the 'C' and 'FORTRAN' order options for array ordering in numpy.) The drawback of doing this is potential performance penalties. It's common to access the data sequentially, either implicitly in array operations or explicitly by looping over rows of an image. When that is done, then the data will be accessed in non-optimal order. As the first index is incremented, what is actually happening is that elements spaced far apart in memory are being sequentially accessed, with usually poor memory access speeds. For example, for a two dimensional image 'im' defined so that im[0, 10] represents the value at x=0, y=10. To be consistent with usual Python behavior then im[0] would represent a column at x=0. Yet that data would be spread over the whole array since the data are stored in row order. Despite the flexibility of numpy's indexing, it can't really paper over the fact basic operations are rendered inefficient because of data order or that getting contiguous subarrays is still awkward (e.g., im[:,0] for the first row, vs im[0]), thus one can't use an idiom such as for row in im; for col in im does work, but doesn't yield contiguous column data. As it turns out, numpy is smart enough when dealing with ufuncs to determine which index is the most rapidly varying one in memory and uses that for the innermost loop. Thus for ufuncs there is no large intrinsic advantage to either approach in most cases. On the other hand, use of .flat with an FORTRAN ordered array will lead to non-optimal memory access as adjacent elements in the flattened array (iterator, actually) are not contiguous in memory. Indeed, the fact is that Python indexing on lists and other sequences naturally leads to an outside-to inside ordering (the first index gets the largest grouping, the next the next largest, and the last gets the smallest element). Since image data are normally stored by rows, this corresponds to position within rows being the last item indexed. If you do want to use Fortran ordering realize that there are two approaches to consider: 1) accept that the first index is just not the most rapidly changing in memory and have all your I/O routines reorder your data when going from memory to disk or visa versa, or use numpy's mechanism for mapping the first index to the most rapidly varying data. We recommend the former if possible. The disadvantage of the latter is that many of numpy's functions will yield arrays without Fortran ordering unless you are careful to use the 'order' keyword. Doing this would be highly inconvenient. Otherwise we recommend simply learning to reverse the usual order of indices when accessing elements of an array. Granted, it goes against the grain, but it is more in line with Python semantics and the natural order of the data. """
""" Discrete Fourier Transform (:mod:`numpy.fft`) ============================================= .. currentmodule:: numpy.fft Standard FFTs ------------- .. autosummary:: :toctree: generated/ fft Discrete Fourier transform. ifft Inverse discrete Fourier transform. fft2 Discrete Fourier transform in two dimensions. ifft2 Inverse discrete Fourier transform in two dimensions. fftn Discrete Fourier transform in N-dimensions. ifftn Inverse discrete Fourier transform in N dimensions. Real FFTs --------- .. autosummary:: :toctree: generated/ rfft Real discrete Fourier transform. irfft Inverse real discrete Fourier transform. rfft2 Real discrete Fourier transform in two dimensions. irfft2 Inverse real discrete Fourier transform in two dimensions. rfftn Real discrete Fourier transform in N dimensions. irfftn Inverse real discrete Fourier transform in N dimensions. Hermitian FFTs -------------- .. autosummary:: :toctree: generated/ hfft Hermitian discrete Fourier transform. ihfft Inverse Hermitian discrete Fourier transform. Helper routines --------------- .. autosummary:: :toctree: generated/ fftfreq Discrete Fourier Transform sample frequencies. fftshift Shift zero-frequency component to center of spectrum. ifftshift Inverse of fftshift. Background information ---------------------- Fourier analysis is fundamentally a method for expressing a function as a sum of periodic components, and for recovering the signal from those components. When both the function and its Fourier transform are replaced with discretized counterparts, it is called the discrete Fourier transform (DFT). The DFT has become a mainstay of numerical computing in part because of a very fast algorithm for computing it, called the Fast Fourier Transform (FFT), which was known to Gauss (1805) and was brought to light in its current form by Cooley and Tukey [CT]_. Press et al. [NR]_ provide an accessible introduction to Fourier analysis and its applications. Because the discrete Fourier transform separates its input into components that contribute at discrete frequencies, it has a great number of applications in digital signal processing, e.g., for filtering, and in this context the discretized input to the transform is customarily referred to as a *signal*, which exists in the *time domain*. The output is called a *spectrum* or *transform* and exists in the *frequency domain*. There are many ways to define the DFT, varying in the sign of the exponent, normalization, etc. In this implementation, the DFT is defined as .. math:: A_k = \\sum_{m=0}^{n-1} a_m \\exp\\left\\{-2\\pi i{mk \\over n}\\right\\} \\qquad k = 0,\\ldots,n-1. The DFT is in general defined for complex inputs and outputs, and a single-frequency component at linear frequency :math:`f` is represented by a complex exponential :math:`a_m = \\exp\\{2\\pi i\\,f m\\Delta t\\}`, where :math:`\\Delta t` is the sampling interval. The values in the result follow so-called "standard" order: If ``A = fft(a, n)``, then ``A[0]`` contains the zero-frequency term (the mean of the signal), which is always purely real for real inputs. Then ``A[1:n/2]`` contains the positive-frequency terms, and ``A[n/2+1:]`` contains the negative-frequency terms, in order of decreasingly negative frequency. For an even number of input points, ``A[n/2]`` represents both positive and negative Nyquist frequency, and is also purely real for real input. For an odd number of input points, ``A[(n-1)/2]`` contains the largest positive frequency, while ``A[(n+1)/2]`` contains the largest negative frequency. The routine ``np.fft.fftfreq(A)`` returns an array giving the frequencies of corresponding elements in the output. The routine ``np.fft.fftshift(A)`` shifts transforms and their frequencies to put the zero-frequency components in the middle, and ``np.fft.ifftshift(A)`` undoes that shift. When the input `a` is a time-domain signal and ``A = fft(a)``, ``np.abs(A)`` is its amplitude spectrum and ``np.abs(A)**2`` is its power spectrum. The phase spectrum is obtained by ``np.angle(A)``. The inverse DFT is defined as .. math:: a_m = \\frac{1}{n}\\sum_{k=0}^{n-1}A_k\\exp\\left\\{2\\pi i{mk\\over n}\\right\\} \\qquad n = 0,\\ldots,n-1. It differs from the forward transform by the sign of the exponential argument and the normalization by :math:`1/n`. Real and Hermitian transforms ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ When the input is purely real, its transform is Hermitian, i.e., the component at frequency :math:`f_k` is the complex conjugate of the component at frequency :math:`-f_k`, which means that for real inputs there is no information in the negative frequency components that is not already available from the positive frequency components. The family of `rfft` functions is designed to operate on real inputs, and exploits this symmetry by computing only the positive frequency components, up to and including the Nyquist frequency. Thus, ``n`` input points produce ``n/2+1`` complex output points. The inverses of this family assumes the same symmetry of its input, and for an output of ``n`` points uses ``n/2+1`` input points. Correspondingly, when the spectrum is purely real, the signal is Hermitian. The `hfft` family of functions exploits this symmetry by using ``n/2+1`` complex points in the input (time) domain for ``n`` real points in the frequency domain. In higher dimensions, FFTs are used, e.g., for image analysis and filtering. The computational efficiency of the FFT means that it can also be a faster way to compute large convolutions, using the property that a convolution in the time domain is equivalent to a point-by-point multiplication in the frequency domain. In two dimensions, the DFT is defined as .. math:: A_{kl} = \\sum_{m=0}^{M-1} \\sum_{n=0}^{N-1} a_{mn}\\exp\\left\\{-2\\pi i \\left({mk\\over M}+{nl\\over N}\\right)\\right\\} \\qquad k = 0, \\ldots, N-1;\\quad l = 0, \\ldots, M-1, which extends in the obvious way to higher dimensions, and the inverses in higher dimensions also extend in the same way. References ^^^^^^^^^^ .. [CT] NAME NAME and NAME Tukey, 1965, "An algorithm for the machine calculation of complex Fourier series," *Math. Comput.* 19: 297-301. .. [NR] NAME NAME NAME and NAME 2007, *Numerical Recipes: The Art of Scientific Computing*, ch. 12-13. Cambridge Univ. Press, Cambridge, UK. Examples ^^^^^^^^ For examples, see the various functions. """
""" Writing Plugins --------------- nose supports plugins for test collection, selection, observation and reporting. There are two basic rules for plugins: * Plugin classes should subclass :class:`nose.plugins.Plugin`. * Plugins may implement any of the methods described in the class :doc:`IPluginInterface <interface>` in nose.plugins.base. Please note that this class is for documentary purposes only; plugins may not subclass IPluginInterface. Hello World =========== Here's a basic plugin. It doesn't do much so read on for more ideas or dive into the :doc:`IPluginInterface <interface>` to see all available hooks. .. code-block:: python import logging import os from nose.plugins import Plugin log = logging.getLogger('nose.plugins.helloworld') class HelloWorld(Plugin): name = 'helloworld' def options(self, parser, env=os.environ): super(HelloWorld, self).options(parser, env=env) def configure(self, options, conf): super(HelloWorld, self).configure(options, conf) if not self.enabled: return def finalize(self, result): log.info('Hello pluginized world!') Registering =========== .. Note:: Important note: the following applies only to the default plugin manager. Other plugin managers may use different means to locate and load plugins. For nose to find a plugin, it must be part of a package that uses setuptools_, and the plugin must be included in the entry points defined in the setup.py for the package: .. code-block:: python setup(name='Some plugin', # ... entry_points = { 'nose.plugins.0.10': [ 'someplugin = someplugin:SomePlugin' ] }, # ... ) Once the package is installed with install or develop, nose will be able to load the plugin. .. _setuptools: http://peak.telecommunity.com/DevCenter/setuptools Registering a plugin without setuptools ======================================= It is currently possible to register a plugin programmatically by creating a custom nose runner like this : .. code-block:: python import nose from yourplugin import YourPlugin if __name__ == '__main__': nose.main(addplugins=[YourPlugin()]) Defining options ================ All plugins must implement the methods ``options(self, parser, env)`` and ``configure(self, options, conf)``. Subclasses of nose.plugins.Plugin that want the standard options should call the superclass methods. nose uses optparse.OptionParser from the standard library to parse arguments. A plugin's ``options()`` method receives a parser instance. It's good form for a plugin to use that instance only to add additional arguments that take only long arguments (--like-this). Most of nose's built-in arguments get their default value from an environment variable. A plugin's ``configure()`` method receives the parsed ``OptionParser`` options object, as well as the current config object. Plugins should configure their behavior based on the user-selected settings, and may raise exceptions if the configured behavior is nonsensical. Logging ======= nose uses the logging classes from the standard library. To enable users to view debug messages easily, plugins should use ``logging.getLogger()`` to acquire a logger in the ``nose.plugins`` namespace. Recipes ======= * Writing a plugin that monitors or controls test result output Implement any or all of ``addError``, ``addFailure``, etc., to monitor test results. If you also want to monitor output, implement ``setOutputStream`` and keep a reference to the output stream. If you want to prevent the builtin ``TextTestResult`` output, implement ``setOutputSteam`` and *return a dummy stream*. The default output will go to the dummy stream, while you send your desired output to the real stream. Example: `examples/html_plugin/htmlplug.py`_ * Writing a plugin that handles exceptions Subclass :doc:`ErrorClassPlugin <errorclasses>`. Examples: :doc:`nose.plugins.deprecated <deprecated>`, :doc:`nose.plugins.skip <skip>` * Writing a plugin that adds detail to error reports Implement ``formatError`` and/or ``formatFailure``. The error tuple you return (error class, error message, traceback) will replace the original error tuple. Examples: :doc:`nose.plugins.capture <capture>`, :doc:`nose.plugins.failuredetail <failuredetail>` * Writing a plugin that loads tests from files other than python modules Implement ``wantFile`` and ``loadTestsFromFile``. In ``wantFile``, return True for files that you want to examine for tests. In ``loadTestsFromFile``, for those files, return an iterable containing TestCases (or yield them as you find them; ``loadTestsFromFile`` may also be a generator). Example: :doc:`nose.plugins.doctests <doctests>` * Writing a plugin that prints a report Implement ``begin`` if you need to perform setup before testing begins. Implement ``report`` and output your report to the provided stream. Examples: :doc:`nose.plugins.cover <cover>`, :doc:`nose.plugins.prof <prof>` * Writing a plugin that selects or rejects tests Implement any or all ``want*`` methods. Return False to reject the test candidate, True to accept it -- which means that the test candidate will pass through the rest of the system, so you must be prepared to load tests from it if tests can't be loaded by the core loader or another plugin -- and None if you don't care. Examples: :doc:`nose.plugins.attrib <attrib>`, :doc:`nose.plugins.doctests <doctests>`, :doc:`nose.plugins.testid <testid>` More Examples ============= See any builtin plugin or example plugin in the examples_ directory in the nose source distribution. There is a list of third-party plugins `on jottit`_. .. _examples/html_plugin/htmlplug.py: http://python-nose.googlecode.com/svn/trunk/examples/html_plugin/htmlplug.py .. _examples: http://python-nose.googlecode.com/svn/trunk/examples .. _on jottit: http://nose-plugins.jottit.com/ """
""" TestCmd.py: a testing framework for commands and scripts. The TestCmd module provides a framework for portable automated testing of executable commands and scripts (in any language, not just Python), especially commands and scripts that require file system interaction. In addition to running tests and evaluating conditions, the TestCmd module manages and cleans up one or more temporary workspace directories, and provides methods for creating files and directories in those workspace directories from in-line data, here-documents), allowing tests to be completely self-contained. A TestCmd environment object is created via the usual invocation: import TestCmd test = TestCmd.TestCmd() There are a bunch of keyword arguments available at instantiation: test = TestCmd.TestCmd(description = 'string', program = 'program_or_script_to_test', interpreter = 'script_interpreter', workdir = 'prefix', subdir = 'subdir', verbose = Boolean, match = default_match_function, diff = default_diff_function, combine = Boolean) There are a bunch of methods that let you do different things: test.verbose_set(1) test.description_set('string') test.program_set('program_or_script_to_test') test.interpreter_set('script_interpreter') test.interpreter_set(['script_interpreter', 'arg']) test.workdir_set('prefix') test.workdir_set('') test.workpath('file') test.workpath('subdir', 'file') test.subdir('subdir', ...) test.rmdir('subdir', ...) test.write('file', "contents\n") test.write(['subdir', 'file'], "contents\n") test.read('file') test.read(['subdir', 'file']) test.read('file', mode) test.read(['subdir', 'file'], mode) test.writable('dir', 1) test.writable('dir', None) test.preserve(condition, ...) test.cleanup(condition) test.command_args(program = 'program_or_script_to_run', interpreter = 'script_interpreter', arguments = 'arguments to pass to program') test.run(program = 'program_or_script_to_run', interpreter = 'script_interpreter', arguments = 'arguments to pass to program', chdir = 'directory_to_chdir_to', stdin = 'input to feed to the program\n') universal_newlines = True) p = test.start(program = 'program_or_script_to_run', interpreter = 'script_interpreter', arguments = 'arguments to pass to program', universal_newlines = None) test.finish(self, p) test.pass_test() test.pass_test(condition) test.pass_test(condition, function) test.fail_test() test.fail_test(condition) test.fail_test(condition, function) test.fail_test(condition, function, skip) test.no_result() test.no_result(condition) test.no_result(condition, function) test.no_result(condition, function, skip) test.stdout() test.stdout(run) test.stderr() test.stderr(run) test.symlink(target, link) test.banner(string) test.banner(string, width) test.diff(actual, expected) test.match(actual, expected) test.match_exact("actual 1\nactual 2\n", "expected 1\nexpected 2\n") test.match_exact(["actual 1\n", "actual 2\n"], ["expected 1\n", "expected 2\n"]) test.match_re("actual 1\nactual 2\n", regex_string) test.match_re(["actual 1\n", "actual 2\n"], list_of_regexes) test.match_re_dotall("actual 1\nactual 2\n", regex_string) test.match_re_dotall(["actual 1\n", "actual 2\n"], list_of_regexes) test.tempdir() test.tempdir('temporary-directory') test.sleep() test.sleep(seconds) test.where_is('foo') test.where_is('foo', 'PATH1:PATH2') test.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4') test.unlink('file') test.unlink('subdir', 'file') The TestCmd module provides pass_test(), fail_test(), and no_result() unbound functions that report test results for use with the Aegis change management system. These methods terminate the test immediately, reporting PASSED, FAILED, or NO RESULT respectively, and exiting with status 0 (success), 1 or 2 respectively. This allows for a distinction between an actual failed test and a test that could not be properly evaluated because of an external condition (such as a full file system or incorrect permissions). import TestCmd TestCmd.pass_test() TestCmd.pass_test(condition) TestCmd.pass_test(condition, function) TestCmd.fail_test() TestCmd.fail_test(condition) TestCmd.fail_test(condition, function) TestCmd.fail_test(condition, function, skip) TestCmd.no_result() TestCmd.no_result(condition) TestCmd.no_result(condition, function) TestCmd.no_result(condition, function, skip) The TestCmd module also provides unbound functions that handle matching in the same way as the match_*() methods described above. import TestCmd test = TestCmd.TestCmd(match = TestCmd.match_exact) test = TestCmd.TestCmd(match = TestCmd.match_re) test = TestCmd.TestCmd(match = TestCmd.match_re_dotall) The TestCmd module provides unbound functions that can be used for the "diff" argument to TestCmd.TestCmd instantiation: import TestCmd test = TestCmd.TestCmd(match = TestCmd.match_re, diff = TestCmd.diff_re) test = TestCmd.TestCmd(diff = TestCmd.simple_diff) The "diff" argument can also be used with standard difflib functions: import difflib test = TestCmd.TestCmd(diff = difflib.context_diff) test = TestCmd.TestCmd(diff = difflib.unified_diff) Lastly, the where_is() method also exists in an unbound function version. import TestCmd TestCmd.where_is('foo') TestCmd.where_is('foo', 'PATH1:PATH2') TestCmd.where_is('foo', 'PATH1;PATH2', '.suffix3;.suffix4') """
# -*- encoding: utf-8 -*- ############################################################################## # # Copyright (c) 2009 Veritos - NAME - www.veritos.nl # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsability of assessing all potential # consequences resulting from its eventual inadequacies and bugs. # End users who are looking for a ready-to-use solution with commercial # garantees and support are strongly adviced to contract a Free Software # Service Company like Veritos. # # This program is Free Software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # ############################################################################## # # Deze module werkt in OpenERP 5.0.0 (en waarschijnlijk hoger). # Deze module werkt niet in OpenERP versie 4 en lager. # # Status 1.0 - getest op OpenERP 5.0.3 # # Versie IP_ADDRESS # account.account.type # Basis gelegd voor alle account type # # account.account.template # Basis gelegd met alle benodigde grootboekrekeningen welke via een menu- # structuur gelinkt zijn aan rubrieken 1 t/m 9. # De grootboekrekeningen gelinkt aan de account.account.type # Deze links moeten nog eens goed nagelopen worden. # # account.chart.template # Basis gelegd voor het koppelen van rekeningen aan debiteuren, crediteuren, # bank, inkoop en verkoop boeken en de BTW configuratie. # # Versie IP_ADDRESS # account.tax.code.template # Basis gelegd voor de BTW configuratie (structuur) # Heb als basis het BTW aangifte formulier gebruikt. Of dit werkt? # # account.tax.template # De BTW rekeningen aangemaakt en deze gekoppeld aan de betreffende # grootboekrekeningen # # Versie IP_ADDRESS # Opschonen van de code en verwijderen van niet gebruikte componenten. # Versie IP_ADDRESS # Aanpassen a_expense van 3000 -> 7000 # record id='btw_code_5b' op negatieve waarde gezet # Versie IP_ADDRESS # BTW rekeningen hebben typeaanduiding gekregen t.b.v. purchase of sale # Versie IP_ADDRESS # Opschonen van module. # Versie IP_ADDRESS # Opschonen van module. # Versie IP_ADDRESS # Foutje in l10n_nl_wizard.xml gecorrigeerd waardoor de module niet volledig installeerde. # Versie IP_ADDRESS # Account Receivable en Payable goed gedefinieerd. # Versie IP_ADDRESS # Alle user_type_xxx velden goed gedefinieerd. # Specifieke bouw en garage gerelateerde grootboeken verwijderd om een standaard module te creeeren. # Deze module kan dan als basis worden gebruikt voor specifieke doelgroep modules te creeeren. # Versie IP_ADDRESS # Correctie van rekening 7010 (stond dubbel met 7014 waardoor installatie verkeerd ging) # versie IP_ADDRESS # Correctie op diverse rekening types van user_type_asset -> user_type_liability en user_type_equity # versie IP_ADDRESS # Kleine correctie op BTW te vorderen hoog, id was hetzelfde voor beide, waardoor hoog werd overschreven door # overig. Verduidelijking van omschrijvingen in belastingcodes t.b.v. aangifte overzicht. # versie IP_ADDRESS # BTW omschrijvingen aangepast, zodat rapporten er beter uitzien. 2a en 5b e.d. verwijderd en enkele omschrijvingen toegevoegd. # versie IP_ADDRESS - Switch to English # Added properties_stock_xxx accounts for correct stock valuation, changed 7000-accounts from type cash to type expense # Changed naming of 7020 and 7030 to Kostprijs omzet xxxx
"""Generic socket server classes. This module tries to capture the various aspects of defining a server: For socket-based servers: - address family: - AF_INET{,6}: IP (Internet Protocol) sockets (default) - AF_UNIX: Unix domain sockets - others, e.g. AF_DECNET are conceivable (see <socket.h> - socket type: - SOCK_STREAM (reliable stream, e.g. TCP) - SOCK_DGRAM (datagrams, e.g. UDP) For request-based servers (including socket-based): - client address verification before further looking at the request (This is actually a hook for any processing that needs to look at the request before anything else, e.g. logging) - how to handle multiple requests: - synchronous (one request is handled at a time) - forking (each request is handled by a new process) - threading (each request is handled by a new thread) The classes in this module favor the server type that is simplest to write: a synchronous TCP/IP server. This is bad class design, but save some typing. (There's also the issue that a deep class hierarchy slows down method lookups.) There are five classes in an inheritance diagram, four of which represent synchronous servers of four types: +------------+ | BaseServer | +------------+ | v +-----------+ +------------------+ | TCPServer |------->| UnixStreamServer | +-----------+ +------------------+ | v +-----------+ +--------------------+ | UDPServer |------->| UnixDatagramServer | +-----------+ +--------------------+ Note that UnixDatagramServer derives from UDPServer, not from UnixStreamServer -- the only difference between an IP and a Unix stream server is the address family, which is simply repeated in both unix server classes. Forking and threading versions of each type of server can be created using the ForkingMixIn and ThreadingMixIn mix-in classes. For instance, a threading UDP server class is created as follows: class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass The Mix-in class must come first, since it overrides a method defined in UDPServer! Setting the various member variables also changes the behavior of the underlying server mechanism. To implement a service, you must derive a class from BaseRequestHandler and redefine its handle() method. You can then run various versions of the service by combining one of the server classes with your request handler class. The request handler class must be different for datagram or stream services. This can be hidden by using the request handler subclasses StreamRequestHandler or DatagramRequestHandler. Of course, you still have to use your head! For instance, it makes no sense to use a forking server if the service contains state in memory that can be modified by requests (since the modifications in the child process would never reach the initial state kept in the parent process and passed to each child). In this case, you can use a threading server, but you will probably have to use locks to avoid two requests that come in nearly simultaneous to apply conflicting changes to the server state. On the other hand, if you are building e.g. an HTTP server, where all data is stored externally (e.g. in the file system), a synchronous class will essentially render the service "deaf" while one request is being handled -- which may be for a very long time if a client is slow to read all the data it has requested. Here a threading or forking server is appropriate. In some cases, it may be appropriate to process part of a request synchronously, but to finish processing in a forked child depending on the request data. This can be implemented by using a synchronous server and doing an explicit fork in the request handler class handle() method. Another approach to handling multiple simultaneous requests in an environment that supports neither threads nor fork (or where these are too expensive or inappropriate for the service) is to maintain an explicit table of partially finished requests and to use select() to decide which request to work on next (or whether to handle a new incoming request). This is particularly important for stream services where each client can potentially be connected for a long time (if threads or subprocesses cannot be used). Future work: - Standard classes for Sun RPC (which uses either UDP or TCP) - Standard mix-in classes to implement various authentication and encryption schemes - Standard framework for select-based multiplexing XXX Open problems: - What to do with out-of-band data? BaseServer: - split generic "request" functionality out into BaseServer class. Copyright (C) 2000 NAME <EMAIL> example: read entries from a SQL database (requires overriding get_request() to return a table entry from the database). entry is processed by a RequestHandlerClass. """
"""Generic socket server classes. This module tries to capture the various aspects of defining a server: For socket-based servers: - address family: - AF_INET{,6}: IP (Internet Protocol) sockets (default) - AF_UNIX: Unix domain sockets - others, e.g. AF_DECNET are conceivable (see <socket.h> - socket type: - SOCK_STREAM (reliable stream, e.g. TCP) - SOCK_DGRAM (datagrams, e.g. UDP) For request-based servers (including socket-based): - client address verification before further looking at the request (This is actually a hook for any processing that needs to look at the request before anything else, e.g. logging) - how to handle multiple requests: - synchronous (one request is handled at a time) - forking (each request is handled by a new process) - threading (each request is handled by a new thread) The classes in this module favor the server type that is simplest to write: a synchronous TCP/IP server. This is bad class design, but save some typing. (There's also the issue that a deep class hierarchy slows down method lookups.) There are five classes in an inheritance diagram, four of which represent synchronous servers of four types: +------------+ | BaseServer | +------------+ | v +-----------+ +------------------+ | TCPServer |------->| UnixStreamServer | +-----------+ +------------------+ | v +-----------+ +--------------------+ | UDPServer |------->| UnixDatagramServer | +-----------+ +--------------------+ Note that UnixDatagramServer derives from UDPServer, not from UnixStreamServer -- the only difference between an IP and a Unix stream server is the address family, which is simply repeated in both unix server classes. Forking and threading versions of each type of server can be created using the ForkingMixIn and ThreadingMixIn mix-in classes. For instance, a threading UDP server class is created as follows: class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass The Mix-in class must come first, since it overrides a method defined in UDPServer! Setting the various member variables also changes the behavior of the underlying server mechanism. To implement a service, you must derive a class from BaseRequestHandler and redefine its handle() method. You can then run various versions of the service by combining one of the server classes with your request handler class. The request handler class must be different for datagram or stream services. This can be hidden by using the request handler subclasses StreamRequestHandler or DatagramRequestHandler. Of course, you still have to use your head! For instance, it makes no sense to use a forking server if the service contains state in memory that can be modified by requests (since the modifications in the child process would never reach the initial state kept in the parent process and passed to each child). In this case, you can use a threading server, but you will probably have to use locks to avoid two requests that come in nearly simultaneous to apply conflicting changes to the server state. On the other hand, if you are building e.g. an HTTP server, where all data is stored externally (e.g. in the file system), a synchronous class will essentially render the service "deaf" while one request is being handled -- which may be for a very long time if a client is slow to read all the data it has requested. Here a threading or forking server is appropriate. In some cases, it may be appropriate to process part of a request synchronously, but to finish processing in a forked child depending on the request data. This can be implemented by using a synchronous server and doing an explicit fork in the request handler class handle() method. Another approach to handling multiple simultaneous requests in an environment that supports neither threads nor fork (or where these are too expensive or inappropriate for the service) is to maintain an explicit table of partially finished requests and to use select() to decide which request to work on next (or whether to handle a new incoming request). This is particularly important for stream services where each client can potentially be connected for a long time (if threads or subprocesses cannot be used). Future work: - Standard classes for Sun RPC (which uses either UDP or TCP) - Standard mix-in classes to implement various authentication and encryption schemes - Standard framework for select-based multiplexing XXX Open problems: - What to do with out-of-band data? BaseServer: - split generic "request" functionality out into BaseServer class. Copyright (C) 2000 NAME <EMAIL> example: read entries from a SQL database (requires overriding get_request() to return a table entry from the database). entry is processed by a RequestHandlerClass. """
""" # ggame The simple cross-platform sprite and game platform for Brython Server (Pygame, Tkinter to follow?). Ggame stands for a couple of things: "good game" (of course!) and also "git game" or "github game" because it is designed to operate with [Brython Server](http://runpython.com) in concert with Github as a backend file store. Ggame is **not** intended to be a full-featured gaming API, with every bell and whistle. Ggame is designed primarily as a tool for teaching computer programming, recognizing that the ability to create engaging and interactive games is a powerful motivator for many progamming students. Accordingly, any functional or performance enhancements that *can* be reasonably implemented by the user are left as an exercise. ## Functionality Goals The ggame library is intended to be trivially easy to use. For example: from ggame import App, ImageAsset, Sprite # Create a displayed object at 100,100 using an image asset Sprite(ImageAsset("ggame/bunny.png"), (100,100)) # Create the app, with a 500x500 pixel stage app = App(500,500) # Run the app app.run() ## Overview There are three major components to the `ggame` system: Assets, Sprites and the App. ### Assets Asset objects (i.e. `ggame.ImageAsset`, etc.) typically represent separate files that are provided by the "art department". These might be background images, user interface images, or images that represent objects in the game. In addition, `ggame.SoundAsset` is used to represent sound files (`.wav` or `.mp3` format) that can be played in the game. Ggame also extends the asset concept to include graphics that are generated dynamically at run-time, such as geometrical objects, e.g. rectangles, lines, etc. ### Sprites All of the visual aspects of the game are represented by instances of `ggame.Sprite` or subclasses of it. ### App Every ggame application must create a single instance of the `ggame.App` class (or a sub-class of it). Creating an instance of the `ggame.App` class will initiate creation of a pop-up window on your browser. Executing the app's `run` method will begin the process of refreshing the visual assets on the screen. ### Events No game is complete without a player and players produce events. Your code handles user input by registering to receive keyboard and mouse events using `ggame.App.listenKeyEvent` and `ggame.App.listenMouseEvent` methods. ## Execution Environment Ggame is designed to be executed in a web browser using [Brython](http://brython.info/), [Pixi.js](http://www.pixijs.com/) and [Buzz](http://buzz.jaysalvat.com/). The easiest way to do this is by executing from [runpython](http://runpython.com), with source code residing on [github](http://github.com). When using [runpython](http://runpython.com), you will have to configure your browser to allow popup windows. To use Ggame in your own application, you will minimally need to create a folder called `ggame` in your project. Within `ggame`, copy the `ggame.py`, `sysdeps.py` and `__init__.py` files from the [ggame project](https://github.com/BrythonServer/ggame). ### Include Ggame as a Git Subtree From the same directory as your own python sources (note: you must have an existing git repository with committed files in order for the following to work properly), execute the following terminal commands: git remote add -f ggame https://github.com/BrythonServer/ggame.git git merge -s ours --no-commit ggame/master mkdir ggame git read-tree --prefix=ggame/ -u ggame/master git commit -m "Merge ggame project as our subdirectory" If you want to pull in updates from ggame in the future: git pull -s subtree ggame master You can see an example of how a ggame subtree is used by examining the [Brython Server Spacewar](https://github.com/BrythonServer/Spacewar) repo on Github. ## Geometry When referring to screen coordinates, note that the x-axis of the computer screen is *horizontal* with the zero position on the left hand side of the screen. The y-axis is *vertical* with the zero position at the **top** of the screen. Increasing positive y-coordinates correspond to the downward direction on the computer screen. Note that this is **different** from the way you may have learned about x and y coordinates in math class! """
### Rename this file to chat/settings.py ### 3 hashtag in this file tells you want to do, while single hastag is required to uncomment ######################################################################################################################## ############################################# START REQUIRED SECTION ################################################### ### Uncomment a SINGLE import from 3 below # from chat.settings_docker import * # If you run pychat inside of docker container uncomment this # from chat.settings_local import * # If you run development server on your local machine uncomment this one # from chat.settings_prod import * # if you run this in production without docker uncomment this ### Prevent host header attacks in emails ### this will used to sent emails with magic link, replce to your ip/domain , notice no trailing slash! # SERVER_ADDRESS = 'https://IP_ADDRESS:8080' ### Replace with your django secret key, use the command bellow to audogenerate it ### bash download_content.sh generate_secret_key # SECRET_KEY = '**************************************************' ############################################# END REQUIRED SECTION ##################################################### ######################################################################################################################## ######################################################################################################################## ##################################### EVERYTHING BELOW IS OPTIONAL ##################################################### ### Every email (like magic link will be marked with this lable) # FROM_EMAIL = 'pychat' ### Uncomment this setting if you don't need user location info to be shown for all. You may also want to disable FLAGS in production.json inside frontend # SHOW_COUNTRY_CODE = false ### Replace with your timezone. You can find list of timezones here https://en.wikipedia.org/wiki/List_of_tz_database_time_zones # TIME_ZONE = 'Europe/Kiev' ### this this emails settings will be used to send emails. E.g. when user restores password via email. ### Comment them out if you don't want to setup # ADMINS = [('YourName', 'EMAIL'), ] # EMAIL_USE_TLS = True # EMAIL_HOST = 'localhost' # EMAIL_PORT = 25 # EMAIL_HOST_USER = '' # EMAIL_HOST_PASSWORD = '' # SERVER_EMAIL = 'EMAIL' # EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' ### Gmail smpt (from account) settings example: #EMAIL_USE_TLS = True #EMAIL_HOST = 'smtp.gmail.com' # For gmail settings example #EMAIL_PORT = '587' # google smpt port #EMAIL_HOST_USER = 'EMAIL' #EMAIL_HOST_PASSWORD = 'yourgmailpassword' #SERVER_EMAIL = 'EMAIL' #EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend' ### Pychat also supports https://developers.google.com/web/fundamentals/push-notifications/ firebase notifications, like in facebook. ### They will fire even user doesn't have opened tab. That can be turned on/off by used in his/her profile with checkbox `Notifications`. ### The implementation is similar like https://github.com/GoogleChrome/samples/tree/gh-pages/push-messaging-and-notifications. ### 1. Create a project on the Firebase Developer Console: https://console.firebase.google.com/ ### 2. Go to Settings (the cog near the top left corner), click the Cloud Messaging Tab: https://console.firebase.google.com/u/1/project/pychat-org/settings/cloudmessaging/ ### 3. Put `<Your Cloud Messaging API Key ...>` to `FIREBASE_API_KEY` below. ### 4. Create `chat/static/manifest.json` with content like https://github.com/GoogleChrome/samples/blob/gh-pages/push-messaging-and-notifications/manifest.sample.json: ### ### { ### "name": "Pychat Push Notifications", ### "short_name": "PyPush", ### "start_url": "/", ### "display": "standalone", ### "gcm_sender_id": "<Your Sender ID from https://console.firebase.google.com>" ### } # FIREBASE_API_KEY = '***********:********************************************************************************************************************************************' #### If you want to use giphy images that appears if user types "/giphy example". ### To get those -sign up in https://developers.giphy.com/, create a new app and replaced with its key. ### you can use mine, so w/e
#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) 2015-2015: Alignak team, see AUTHORS.txt file for contributors # # This file is part of Alignak. # # Alignak is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Alignak is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Alignak. If not, see <http://www.gnu.org/licenses/>. # # # This file incorporates work covered by the following copyright and # permission notice: # # Copyright (C) 2009-2014: # NAME EMAIL NAME EMAIL NAME EMAIL aviau, EMAIL NAME EMAIL NAME EMAIL NAME EMAIL NAME EMAIL NAME EMAIL NAME EMAIL NAME EMAIL NAME EMAIL NAME EMAILymotion.com # This file is part of Shinken. # # Shinken is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Shinken is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with Shinken. If not, see <http://www.gnu.org/licenses/>. # Calendar date # ------------- # '(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) / (\d+) ([0-9:, -]+)' # => len = 8 => CALENDAR_DATE # # '(\d{4})-(\d{2})-(\d{2}) / (\d+) ([0-9:, -]+)' # => len = 5 => CALENDAR_DATE # # '(\d{4})-(\d{2})-(\d{2}) - (\d{4})-(\d{2})-(\d{2}) ([0-9:, -]+)' # => len = 7 => CALENDAR_DATE # # '(\d{4})-(\d{2})-(\d{2}) ([0-9:, -]+)' # => len = 4 => CALENDAR_DATE # # Month week day # -------------- # '([a-z]*) (\d+) ([a-z]*) - ([a-z]*) (\d+) ([a-z]*) / (\d+) ([0-9:, -]+)' # => len = 8 => MONTH WEEK DAY # e.g.: wednesday 1 january - thursday 2 july / 3 # # '([a-z]*) (\d+) - ([a-z]*) (\d+) / (\d+) ([0-9:, -]+)' => len = 6 # e.g.: february 1 - march 15 / 3 => MONTH DATE # e.g.: monday 2 - thusday 3 / 2 => WEEK DAY # e.g.: day 2 - day 6 / 3 => MONTH DAY # # '([a-z]*) (\d+) - (\d+) / (\d+) ([0-9:, -]+)' => len = 6 # e.g.: february 1 - 15 / 3 => MONTH DATE # e.g.: thursday 2 - 4 => WEEK DAY # e.g.: day 1 - 4 => MONTH DAY # # '([a-z]*) (\d+) ([a-z]*) - ([a-z]*) (\d+) ([a-z]*) ([0-9:, -]+)' => len = 7 # e.g.: wednesday 1 january - thursday 2 july => MONTH WEEK DAY # # '([a-z]*) (\d+) - (\d+) ([0-9:, -]+)' => len = 7 # e.g.: thursday 2 - 4 => WEEK DAY # e.g.: february 1 - 15 / 3 => MONTH DATE # e.g.: day 1 - 4 => MONTH DAY # # '([a-z]*) (\d+) - ([a-z]*) (\d+) ([0-9:, -]+)' => len = 5 # e.g.: february 1 - march 15 => MONTH DATE # e.g.: monday 2 - thusday 3 => WEEK DAY # e.g.: day 2 - day 6 => MONTH DAY # # '([a-z]*) (\d+) ([0-9:, -]+)' => len = 3 # e.g.: february 3 => MONTH DATE # e.g.: thursday 2 => WEEK DAY # e.g.: day 3 => MONTH DAY # # '([a-z]*) (\d+) ([a-z]*) ([0-9:, -]+)' => len = 4 # e.g.: thusday 3 february => MONTH WEEK DAY # # '([a-z]*) ([0-9:, -]+)' => len = 6 # e.g.: thusday => normal values # # Types: CALENDAR_DATE # MONTH WEEK DAY # WEEK DAY # MONTH DATE # MONTH DAY #
#!/usr/bin/env python # Copyright (c) 2013 - 2015 ARM Limited # All rights reserved # # The license below extends only to copyright in the software and shall # not be construed as granting a license to any other intellectual # property including but not limited to intellectual property relating # to a hardware implementation of the functionality of the software # licensed hereunder. You may use the software subject to the license # terms below provided that you ensure that this notice is replicated # unmodified and in its entirety in all distributions of the software, # modified or unmodified, in source code or in binary form. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer; # redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution; # neither the name of the copyright holders nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Copyright 2008 Google Inc. All rights reserved. # http://code.google.com/p/protobuf/ # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are # met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above # copyright notice, this list of conditions and the following disclaimer # in the documentation and/or other materials provided with the # distribution. # * Neither the name of Google Inc. nor the names of its # contributors may be used to endorse or promote products derived from # this software without specific prior written permission. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # Authors: NAME # # This script is used to dump protobuf traces of the instruction dependency # graph to ASCII format. # # The ASCII trace format uses one line per instruction with the format # instruction sequence number, (optional) pc, (optional) weight, type # (optional) flags, (optional) phys addr, (optional) size, comp delay, # (repeated) order dependencies comma-separated, and (repeated) register # dependencies comma-separated. # # examples: # seq_num,[pc],[weight,]type,[p_addr,size,flags,]comp_delay:[rob_dep]: # [reg_dep] # 1,35652,1,COMP,8500:: # 2,35656,1,COMP,0:,1: # 3,35660,1,LOAD,1748752,4,74,500:,2: # 4,35660,1,COMP,0:,3: # 5,35664,1,COMP,3000::,4 # 6,35666,1,STORE,1748752,4,74,1000:,3:,4,5 # 7,35666,1,COMP,3000::,4 # 8,35670,1,STORE,1748748,4,74,0:,6,3:,7 # 9,35670,1,COMP,500::,7
""" Perform Levenberg-Marquardt least-squares minimization, based on MINPACK-1. AUTHORS The original version of this software, called LMFIT, was written in FORTRAN as part of the MINPACK-1 package by XXX. NAME converted the FORTRAN code to IDL. The information for the IDL version is: NAME NASA/GSFC Code 662, Greenbelt, MD 20770 EMAIL UPDATED VERSIONs can be found on my WEB PAGE: http://cow.physics.wisc.edu/~craigm/idl/idl.html NAME created this Python version from Craig's IDL version. NAME, University of Chicago Building 434A, Argonne National Laboratory 9700 South Cass Avenue, Argonne, IL 60439 EMAIL Updated versions can be found at http://cars.uchicago.edu/software NAME converted the Mark's Python version from Numeric to numpy NAME, University of Cambridge, Institute of Astronomy, Madingley road, CB3 0HA, Cambridge, UK EMAIL Updated versions can be found at http://code.google.com/p/astrolibpy/source/browse/trunk/ DESCRIPTION MPFIT uses the Levenberg-Marquardt technique to solve the least-squares problem. In its typical use, MPFIT will be used to fit a user-supplied function (the "model") to user-supplied data points (the "data") by adjusting a set of parameters. MPFIT is based upon MINPACK-1 (LMDIF.F) by More' and collaborators. For example, a researcher may think that a set of observed data points is best modelled with a Gaussian curve. A Gaussian curve is parameterized by its mean, standard deviation and normalization. MPFIT will, within certain constraints, find the set of parameters which best fits the data. The fit is "best" in the least-squares sense; that is, the sum of the weighted squared differences between the model and data is minimized. The Levenberg-Marquardt technique is a particular strategy for iteratively searching for the best fit. This particular implementation is drawn from MINPACK-1 (see NETLIB), and is much faster and more accurate than the version provided in the Scientific Python package in Scientific.Functions.LeastSquares. This version allows upper and lower bounding constraints to be placed on each parameter, or the parameter can be held fixed. The user-supplied Python function should return an array of weighted deviations between model and data. In a typical scientific problem the residuals should be weighted so that each deviate has a gaussian sigma of 1.0. If X represents values of the independent variable, Y represents a measurement for each value of X, and ERR represents the error in the measurements, then the deviates could be calculated as follows: DEVIATES = (Y - F(X)) / ERR where F is the analytical function representing the model. You are recommended to use the convenience functions MPFITFUN and MPFITEXPR, which are driver functions that calculate the deviates for you. If ERR are the 1-sigma uncertainties in Y, then TOTAL( DEVIATES^2 ) will be the total chi-squared value. MPFIT will minimize the chi-square value. The values of X, Y and ERR are passed through MPFIT to the user-supplied function via the FUNCTKW keyword. Simple constraints can be placed on parameter values by using the PARINFO keyword to MPFIT. See below for a description of this keyword. MPFIT does not perform more general optimization tasks. See TNMIN instead. MPFIT is customized, based on MINPACK-1, to the least-squares minimization problem. USER FUNCTION The user must define a function which returns the appropriate values as specified above. The function should return the weighted deviations between the model and the data. It should also return a status flag and an optional partial derivative array. For applications which use finite-difference derivatives -- the default -- the user function should be declared in the following way: def myfunct(p, fjac=None, x=None, y=None, err=None) # Parameter values are passed in "p" # If fjac==None then partial derivatives should not be # computed. It will always be None if MPFIT is called with default # flag. model = F(x, p) # Non-negative status value means MPFIT should continue, negative means # stop the calculation. status = 0 return([status, (y-model)/err] See below for applications with analytical derivatives. The keyword parameters X, Y, and ERR in the example above are suggestive but not required. Any parameters can be passed to MYFUNCT by using the functkw keyword to MPFIT. Use MPFITFUN and MPFITEXPR if you need ideas on how to do that. The function *must* accept a parameter list, P. In general there are no restrictions on the number of dimensions in X, Y or ERR. However the deviates *must* be returned in a one-dimensional Numeric array of type Float. User functions may also indicate a fatal error condition using the status return described above. If status is set to a number between -15 and -1 then MPFIT will stop the calculation and return to the caller. ANALYTIC DERIVATIVES In the search for the best-fit solution, MPFIT by default calculates derivatives numerically via a finite difference approximation. The user-supplied function need not calculate the derivatives explicitly. However, if you desire to compute them analytically, then the AUTODERIVATIVE=0 keyword must be passed to MPFIT. As a practical matter, it is often sufficient and even faster to allow MPFIT to calculate the derivatives numerically, and so AUTODERIVATIVE=0 is not necessary. If AUTODERIVATIVE=0 is used then the user function must check the parameter FJAC, and if FJAC!=None then return the partial derivative array in the return list. def myfunct(p, fjac=None, x=None, y=None, err=None) # Parameter values are passed in "p" # If FJAC!=None then partial derivatives must be comptuer. # FJAC contains an array of len(p), where each entry # is 1 if that parameter is free and 0 if it is fixed. model = F(x, p) Non-negative status value means MPFIT should continue, negative means # stop the calculation. status = 0 if (dojac): pderiv = zeros([len(x), len(p)], Float) for j in range(len(p)): pderiv[:,j] = FGRAD(x, p, j) else: pderiv = None return([status, (y-model)/err, pderiv] where FGRAD(x, p, i) is a user function which must compute the derivative of the model with respect to parameter P[i] at X. When finite differencing is used for computing derivatives (ie, when AUTODERIVATIVE=1), or when MPFIT needs only the errors but not the derivatives the parameter FJAC=None. Derivatives should be returned in the PDERIV array. PDERIV should be an m x n array, where m is the number of data points and n is the number of parameters. dp[i,j] is the derivative at the ith point with respect to the jth parameter. The derivatives with respect to fixed parameters are ignored; zero is an appropriate value to insert for those derivatives. Upon input to the user function, FJAC is set to a vector with the same length as P, with a value of 1 for a parameter which is free, and a value of zero for a parameter which is fixed (and hence no derivative needs to be calculated). If the data is higher than one dimensional, then the *last* dimension should be the parameter dimension. Example: fitting a 50x50 image, "dp" should be 50x50xNPAR. CONSTRAINING PARAMETER VALUES WITH THE PARINFO KEYWORD The behavior of MPFIT can be modified with respect to each parameter to be fitted. A parameter value can be fixed; simple boundary constraints can be imposed; limitations on the parameter changes can be imposed; properties of the automatic derivative can be modified; and parameters can be tied to one another. These properties are governed by the PARINFO structure, which is passed as a keyword parameter to MPFIT. PARINFO should be a list of dictionaries, one list entry for each parameter. Each parameter is associated with one element of the array, in numerical order. The dictionary can have the following keys (none are required, keys are case insensitive): 'value' - the starting parameter value (but see the START_PARAMS parameter for more information). 'fixed' - a boolean value, whether the parameter is to be held fixed or not. Fixed parameters are not varied by MPFIT, but are passed on to MYFUNCT for evaluation. 'limited' - a two-element boolean array. If the first/second element is set, then the parameter is bounded on the lower/upper side. A parameter can be bounded on both sides. Both LIMITED and LIMITS must be given together. 'limits' - a two-element float array. Gives the parameter limits on the lower and upper sides, respectively. Zero, one or two of these values can be set, depending on the values of LIMITED. Both LIMITED and LIMITS must be given together. 'parname' - a string, giving the name of the parameter. The fitting code of MPFIT does not use this tag in any way. However, the default iterfunct will print the parameter name if available. 'step' - the step size to be used in calculating the numerical derivatives. If set to zero, then the step size is computed automatically. Ignored when AUTODERIVATIVE=0. 'mpside' - the sidedness of the finite difference when computing numerical derivatives. This field can take four values: 0 - one-sided derivative computed automatically 1 - one-sided derivative (f(x+h) - f(x) )/h -1 - one-sided derivative (f(x) - f(x-h))/h 2 - two-sided derivative (f(x+h) - f(x-h))/(2*h) Where H is the STEP parameter described above. The "automatic" one-sided derivative method will chose a direction for the finite difference which does not violate any constraints. The other methods do not perform this check. The two-sided method is in principle more precise, but requires twice as many function evaluations. Default: 0. 'mpmaxstep' - the maximum change to be made in the parameter value. During the fitting process, the parameter will never be changed by more than this value in one iteration. A value of 0 indicates no maximum. Default: 0. 'tied' - a string expression which "ties" the parameter to other free or fixed parameters. Any expression involving constants and the parameter array P are permitted. Example: if parameter 2 is always to be twice parameter 1 then use the following: parinfo(2).tied = '2 * p(1)'. Since they are totally constrained, tied parameters are considered to be fixed; no errors are computed for them. [ NOTE: the PARNAME can't be used in expressions. ] 'mpprint' - if set to 1, then the default iterfunct will print the parameter value. If set to 0, the parameter value will not be printed. This tag can be used to selectively print only a few parameter values out of many. Default: 1 (all parameters printed) Future modifications to the PARINFO structure, if any, will involve adding dictionary tags beginning with the two letters "MP". Therefore programmers are urged to avoid using tags starting with the same letters; otherwise they are free to include their own fields within the PARINFO structure, and they will be ignored. PARINFO Example: parinfo = [{'value':0., 'fixed':0, 'limited':[0,0], 'limits':[0.,0.]} for i in range(5)] parinfo[0]['fixed'] = 1 parinfo[4]['limited'][0] = 1 parinfo[4]['limits'][0] = 50. values = [5.7, 2.2, 500., 1.5, 2000.] for i in range(5): parinfo[i]['value']=values[i] A total of 5 parameters, with starting values of 5.7, 2.2, 500, 1.5, and 2000 are given. The first parameter is fixed at a value of 5.7, and the last parameter is constrained to be above 50. EXAMPLE import mpfit import numpy.oldnumeric as Numeric x = arange(100, float) p0 = [5.7, 2.2, 500., 1.5, 2000.] y = ( p[0] + p[1]*[x] + p[2]*[x**2] + p[3]*sqrt(x) + p[4]*log(x)) fa = {'x':x, 'y':y, 'err':err} m = mpfit('myfunct', p0, functkw=fa) print 'status = ', m.status if (m.status <= 0): print 'error message = ', m.errmsg print 'parameters = ', m.params Minimizes sum of squares of MYFUNCT. MYFUNCT is called with the X, Y, and ERR keyword parameters that are given by FUNCTKW. The results can be obtained from the returned object m. THEORY OF OPERATION There are many specific strategies for function minimization. One very popular technique is to use function gradient information to realize the local structure of the function. Near a local minimum the function value can be taylor expanded about x0 as follows: f(x) = f(x0) + f'(x0) . (x-x0) + (1/2) (x-x0) . f''(x0) . (x-x0) ----- --------------- ------------------------------- (1) Order 0th 1st 2nd Here f'(x) is the gradient vector of f at x, and f''(x) is the Hessian matrix of second derivatives of f at x. The vector x is the set of function parameters, not the measured data vector. One can find the minimum of f, f(xm) using Newton's method, and arrives at the following linear equation: f''(x0) . (xm-x0) = - f'(x0) (2) If an inverse can be found for f''(x0) then one can solve for (xm-x0), the step vector from the current position x0 to the new projected minimum. Here the problem has been linearized (ie, the gradient information is known to first order). f''(x0) is symmetric n x n matrix, and should be positive definite. The Levenberg - Marquardt technique is a variation on this theme. It adds an additional diagonal term to the equation which may aid the convergence properties: (f''(x0) + nu I) . (xm-x0) = -f'(x0) (2a) where I is the identity matrix. When nu is large, the overall matrix is diagonally dominant, and the iterations follow steepest descent. When nu is small, the iterations are quadratically convergent. In principle, if f''(x0) and f'(x0) are known then xm-x0 can be determined. However the Hessian matrix is often difficult or impossible to compute. The gradient f'(x0) may be easier to compute, if even by finite difference techniques. So-called quasi-Newton techniques attempt to successively estimate f''(x0) by building up gradient information as the iterations proceed. In the least squares problem there are further simplifications which assist in solving eqn (2). The function to be minimized is a sum of squares: f = Sum(hi^2) (3) where hi is the ith residual out of m residuals as described above. This can be substituted back into eqn (2) after computing the derivatives: f' = 2 Sum(hi hi') f'' = 2 Sum(hi' hj') + 2 Sum(hi hi'') (4) If one assumes that the parameters are already close enough to a minimum, then one typically finds that the second term in f'' is negligible [or, in any case, is too difficult to compute]. Thus, equation (2) can be solved, at least approximately, using only gradient information. In matrix notation, the combination of eqns (2) and (4) becomes: hT' . h' . dx = - hT' . h (5) Where h is the residual vector (length m), hT is its transpose, h' is the Jacobian matrix (dimensions n x m), and dx is (xm-x0). The user function supplies the residual vector h, and in some cases h' when it is not found by finite differences (see MPFIT_FDJAC2, which finds h and hT'). Even if dx is not the best absolute step to take, it does provide a good estimate of the best *direction*, so often a line minimization will occur along the dx vector direction. The method of solution employed by MINPACK is to form the Q . R factorization of h', where Q is an orthogonal matrix such that QT . Q = I, and R is upper right triangular. Using h' = Q . R and the ortogonality of Q, eqn (5) becomes (RT . QT) . (Q . R) . dx = - (RT . QT) . h RT . R . dx = - RT . QT . h (6) R . dx = - QT . h where the last statement follows because R is upper triangular. Here, R, QT and h are known so this is a matter of solving for dx. The routine MPFIT_QRFAC provides the QR factorization of h, with pivoting, and MPFIT_QRSOLV provides the solution for dx. REFERENCES MINPACK-1, NAME available from netlib (www.netlib.org). "Optimization Software Guide," NAME and NAME SIAM, *Frontiers in Applied Mathematics*, Number 14. More', NAME "The Levenberg-Marquardt Algorithm: Implementation and Theory," in *Numerical Analysis*, ed. NAME G. A., Lecture Notes in Mathematics 630, Springer-Verlag, 1977. MODIFICATION HISTORY Translated from MINPACK-1 in FORTRAN, Apr-Jul 1998, CM Copyright (C) 1997-2002, NAME This software is provided as is without any warranty whatsoever. Permission to use, copy, modify, and distribute modified or unmodified copies is granted, provided this copyright and disclaimer are included unchanged. Translated from MPFIT (NAME's IDL package) to Python, August, 2002. NAME Converted from Numeric to numpy (NAME, July 2008) """
""" It's somewhat of a fool's errand to introduce a Python ORM in 2013, with `SQLAlchemy`_ ascendant (`Django's ORM`_ not-withstanding). And yet here we are. SQLAlchemy is mature and robust and full-featured. This makes it complex, difficult to learn, and kind of scary. The ORM we introduce here is simpler: it targets PostgreSQL only, it depends on raw SQL (it has no object model for schema definition nor one for query construction), and it never updates your database for you. You are in full, direct control of your application's database usage. .. _SQLAlchemy: http://www.sqlalchemy.org/ .. _Django's ORM: http://www.djangobook.com/en/2.0/chapter05.html The fundamental technique we employ, introduced by `Michael NAME at PyOhio 2013`_, is to write SQL queries that typecast results to table types, and then use a :py:mod:`psycopg2` :py:class:`~psycopg2.extra.CompositeCaster` to map these to Python objects. This means we get to define our schema in SQL, and we get to write our queries in SQL, and we get to explicitly indicate in our SQL queries how Python should map the results to objects, and then we can write Python objects that contain only business logic and not schema definitions. .. _Michael NAME at PyOhio 2013: https://www.youtube.com/watch?v=Wz1_GYc4GmU#t=25m06s Introducing Table Types ----------------------- Every table in PostgreSQL has a type associated with it, which is the column definition for that table. These are composite types just like any other composite type in PostgreSQL, meaning we can use them to cast query results. When we do, we get a single field that contains our query result, nested one level:: test=# CREATE TABLE foo (bar text, baz int); CREATE TABLE test=# INSERT INTO foo VALUES ('blam', 42); INSERT 0 1 test=# INSERT INTO foo VALUES ('whit', 537); INSERT 0 1 test=# SELECT * FROM foo; +------+-----+ | bar | baz | +------+-----+ | blam | 42 | | whit | 537 | +------+-----+ (2 rows) test=# SELECT foo.*::foo FROM foo; +------------+ | foo | +------------+ | (blam,42) | | (whit,537) | +------------+ (2 rows) test=# The same thing works for views:: test=# CREATE VIEW bar AS SELECT bar FROM foo; CREATE VIEW test=# SELECT * FROM bar; +------+ | bar | +------+ | blam | | whit | +------+ (2 rows) test=# SELECT bar.*::bar FROM bar; +--------+ | bar | +--------+ | (blam) | | (whit) | +--------+ (2 rows) test=# :py:mod:`psycopg2` provides a :py:func:`~psycopg2.extras.register_composite` function that lets us map PostgreSQL composite types to Python objects. This includes table and view types, and that is the basis for :py:mod:`postgres.orm`. We map based on types, not tables. .. _orm-tutorial: ORM Tutorial ------------ First, write a Python class that subclasses :py:class:`~postgres.orm.Model`:: >>> from postgres.orm import Model >>> class Foo(Model): ... typname = "foo" ... Your model must have a :py:attr:`typname` attribute, which is the name of the PostgreSQL type for which this class is an object mapping. (``typname``, spelled without an "e," is the name of the relevant column in the ``pg_type`` table in your database.) Second, register your model with your :py:class:`~postgres.Postgres` instance: >>> db.register_model(Foo) That will plug your model into the :py:mod:`psycopg2` composite casting machinery, and you'll now get instances of your model back from :py:meth:`~postgres.Postgres.one` and :py:meth:`~postgres.Postgres.all` when you cast to the relevant type in your query. If your query returns more than one column, you'll need to dereference the column containing the model just as with any other query: >>> rec = db.one("SELECT foo.*::foo, bar.* " ... "FROM foo JOIN bar ON foo.bar = bar.bar " ... "ORDER BY foo.bar LIMIT 1") >>> rec.foo.bar 'blam' >>> rec.bar 'blam' And as usual, if your query only returns one column, then :py:meth:`~postgres.Postgres.one` and :py:meth:`~postgres.Postgres.all` will do the dereferencing for you: >>> foo = db.one("SELECT foo.*::foo FROM foo WHERE bar='blam'") >>> foo.bar 'blam' >>> [foo.bar for foo in db.all("SELECT foo.*::foo FROM foo")] ['blam', 'whit'] To update your database, add a method to your model: >>> db.unregister_model(Foo) >>> class Foo(Model): ... ... typname = "foo" ... ... def update_baz(self, baz): ... self.db.run( "UPDATE foo SET baz=%s WHERE bar=%s" ... , (baz, self.bar) ... ) ... self.set_attributes(baz=baz) ... >>> db.register_model(Foo) Then use that method to update the database: >>> db.one("SELECT baz FROM foo WHERE bar='blam'") 42 >>> foo = db.one("SELECT foo.*::foo FROM foo WHERE bar='blam'") >>> foo.update_baz(90210) >>> foo.baz 90210 >>> db.one("SELECT baz FROM foo WHERE bar='blam'") 90210 We never update your database for you. We also never sync your objects for you: note the use of the :py:meth:`~postgres.orm.Model.set_attributes` method to sync our instance after modifying the database. The Model Base Class -------------------- """
#!/usr/bin/env python # (c) 2013, NAME <EMAIL> # # This file is part of Ansible. # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # # # Author: NAME <EMAIL> # # Description: # This module queries local or remote Docker daemons and generates # inventory information. # # This plugin does not support targeting of specific hosts using the --host # flag. Instead, it queries the Docker API for each container, running # or not, and returns this data all once. # # The plugin returns the following custom attributes on Docker containers: # docker_args # docker_config # docker_created # docker_driver # docker_exec_driver # docker_host_config # docker_hostname_path # docker_hosts_path # docker_id # docker_image # docker_name # docker_network_settings # docker_path # docker_resolv_conf_path # docker_state # docker_volumes # docker_volumes_rw # # Requirements: # The docker-py module: https://github.com/dotcloud/docker-py # # Notes: # A config file can be used to configure this inventory module, and there # are several environment variables that can be set to modify the behavior # of the plugin at runtime: # DOCKER_CONFIG_FILE # DOCKER_HOST # DOCKER_VERSION # DOCKER_TIMEOUT # DOCKER_PRIVATE_SSH_PORT # DOCKER_DEFAULT_IP # # Environment Variables: # environment variable: DOCKER_CONFIG_FILE # description: # - A path to a Docker inventory hosts/defaults file in YAML format # - A sample file has been provided, colocated with the inventory # file called 'docker.yml' # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_HOST # description: # - The socket on which to connect to a Docker daemon API # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_VERSION # description: # - Version of the Docker API to use # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_TIMEOUT # description: # - Timeout in seconds for connections to Docker daemon API # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_PRIVATE_SSH_PORT # description: # - The private port (container port) on which SSH is listening # for connections # default: 22 # required: false # environment variable: DOCKER_DEFAULT_IP # description: # - This environment variable overrides the container SSH connection # IP address (aka, 'ansible_ssh_host') # # This option allows one to override the ansible_ssh_host whenever # Docker has exercised its default behavior of binding private ports # to all interfaces of the Docker host. This behavior, when dealing # with remote Docker hosts, does not allow Ansible to determine # a proper host IP address on which to connect via SSH to containers. # By default, this inventory module assumes all IP_ADDRESS-exposed # ports to be bound to localhost:<port>. To override this # behavior, for example, to bind a container's SSH port to the public # interface of its host, one must manually set this IP. # # It is preferable to begin to launch Docker containers with # ports exposed on publicly accessible IP addresses, particularly # if the containers are to be targeted by Ansible for remote # configuration, not accessible via localhost SSH connections. # # Docker containers can be explicitly exposed on IP addresses by # a) starting the daemon with the --ip argument # b) running containers with the -P/--publish ip::containerPort # argument # default: IP_ADDRESS if port exposed on IP_ADDRESS by Docker # required: false # # Examples: # Use the config file: # DOCKER_CONFIG_FILE=./docker.yml docker.py --list # # Connect to docker instance on localhost port 4243 # DOCKER_HOST=tcp://localhost:4243 docker.py --list # # Any container's ssh port exposed on IP_ADDRESS will mapped to # another IP address (where Ansible will attempt to connect via SSH) # DOCKER_DEFAULT_IP=IP_ADDRESS docker.py --list
#!/usr/bin/env python # (c) 2013, NAME <EMAIL> # # This file is part of Ansible. # # Ansible is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # Ansible is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see <http://www.gnu.org/licenses/>. # # # Author: NAME <EMAIL> # # Description: # This module queries local or remote Docker daemons and generates # inventory information. # # This plugin does not support targeting of specific hosts using the --host # flag. Instead, it queries the Docker API for each container, running # or not, and returns this data all once. # # The plugin returns the following custom attributes on Docker containers: # docker_args # docker_config # docker_created # docker_driver # docker_exec_driver # docker_host_config # docker_hostname_path # docker_hosts_path # docker_id # docker_image # docker_name # docker_network_settings # docker_path # docker_resolv_conf_path # docker_state # docker_volumes # docker_volumes_rw # # Requirements: # The docker-py module: https://github.com/dotcloud/docker-py # # Notes: # A config file can be used to configure this inventory module, and there # are several environment variables that can be set to modify the behavior # of the plugin at runtime: # DOCKER_CONFIG_FILE # DOCKER_HOST # DOCKER_VERSION # DOCKER_TIMEOUT # DOCKER_PRIVATE_SSH_PORT # DOCKER_DEFAULT_IP # # Environment Variables: # environment variable: DOCKER_CONFIG_FILE # description: # - A path to a Docker inventory hosts/defaults file in YAML format # - A sample file has been provided, colocated with the inventory # file called 'docker.yml' # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_HOST # description: # - The socket on which to connect to a Docker daemon API # required: false # default: Uses docker.docker.Client constructor defaults # environment variable: DOCKER_VERSION # description: # - Version of the Docker API to use # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_TIMEOUT # description: # - Timeout in seconds for connections to Docker daemon API # default: Uses docker.docker.Client constructor defaults # required: false # environment variable: DOCKER_PRIVATE_SSH_PORT # description: # - The private port (container port) on which SSH is listening # for connections # default: 22 # required: false # environment variable: DOCKER_DEFAULT_IP # description: # - This environment variable overrides the container SSH connection # IP address (aka, 'ansible_ssh_host') # # This option allows one to override the ansible_ssh_host whenever # Docker has exercised its default behavior of binding private ports # to all interfaces of the Docker host. This behavior, when dealing # with remote Docker hosts, does not allow Ansible to determine # a proper host IP address on which to connect via SSH to containers. # By default, this inventory module assumes all IP_ADDRESS-exposed # ports to be bound to localhost:<port>. To override this # behavior, for example, to bind a container's SSH port to the public # interface of its host, one must manually set this IP. # # It is preferable to begin to launch Docker containers with # ports exposed on publicly accessible IP addresses, particularly # if the containers are to be targeted by Ansible for remote # configuration, not accessible via localhost SSH connections. # # Docker containers can be explicitly exposed on IP addresses by # a) starting the daemon with the --ip argument # b) running containers with the -P/--publish ip::containerPort # argument # default: IP_ADDRESS if port exposed on IP_ADDRESS by Docker # required: false # # Examples: # Use the config file: # DOCKER_CONFIG_FILE=./docker.yml docker.py --list # # Connect to docker instance on localhost port 4243 # DOCKER_HOST=tcp://localhost:4243 docker.py --list # # Any container's ssh port exposed on IP_ADDRESS will mapped to # another IP address (where Ansible will attempt to connect via SSH) # DOCKER_DEFAULT_IP=IP_ADDRESS docker.py --list
# # A collection of utilities for ms2 (lookup tables etc..) # Rewrite in Python, January 2013, NAME $Id: ms2util.py,v 1.20 2017-01-27 13:50:28 jive_cc Exp $ # # $Log: ms2util.py,v $ # Revision 1.20 2017-01-27 13:50:28 USERNAME HV: * jplotter.py: small edits # - "not refresh(e)" => "refresh(e); if not e.plots ..." # - "e.rawplots.XXX" i.s.o. "e.plots.XXX" # * relatively big overhaul: in order to force (old) pyrap to # re-read tables from disk all table objects must call ".close()" # when they're done. # Implemented by patching the pyrap.tables.table object on the fly # with '__enter__' and '__exit__' methods (see "ms2util.opentable(...)") # such that all table access can be done in a "with ..." block: # with ms2util.opentable(...) as tbl: # tbl.getcol('DATA') # ... # and then when the with-block is left, tbl gets automagically closed # # Revision 1.19 2015-09-23 12:28:36 USERNAME HV: * NAME requested sensible requests (ones that were already in the # back of my mind too): # - option to specify the data column # - option to not reorder the spectral windows # Both options are now supported by the code and are triggered by # passing options to the "ms" command # # Revision 1.18 2015-04-29 14:34:14 USERNAME HV: * add support for retrieving the actual frequencies of the channels # # Revision 1.17 2015-02-16 12:51:07 USERNAME HV: * "getcolslice()" in combination with j2ms2 inefficient tiling scheme # results in very poor performance. So now we do the "slicing" # ourselves in Python [might change again when j2ms2 does things more # efficiently or when the casa # # Revision 1.16 2014-04-25 12:22:30 USERNAME HV: * deal with lag data correctly (number of channels/number of lags) # * there was a big problem in the polarization labelling which is now fixed # # Revision 1.15 2014-04-24 20:09:19 USERNAME HV: * indexr now uses 'SCAN_NUMBER' column for scan determination # # Revision 1.14 2014-04-14 22:08:01 USERNAME HV: * add support for accessing scan properties in time selection # # Revision 1.13 2014-04-14 14:46:05 USERNAME HV: * Uses pycasa.so for table data access waiting for pyrap to be fixed # * added "indexr" + scan-based selection option # # Revision 1.12 2014-04-10 21:14:40 USERNAME HV: * I fell for the age-old Python trick where a default argument is # initialized statically - all data sets were integrating into the # the same arrays! Nice! # * Fixed other efficiency measures: with time averaging data already # IS in numarray so no conversion needs to be done # * more improvements # # Revision 1.11 2014-04-08 23:34:12 USERNAME HV: * Minor fixes - should be better now # # Revision 1.10 2014-04-08 22:41:11 USERNAME HV: Finally! This might be release 0.1! # * python based plot iteration now has tolerable speed # (need to test on 8M row MS though) # * added quite a few plot types, simplified plotters # (plotiterators need a round of moving common functionality # into base class) # * added generic X/Y plotter # # Revision 1.9 2013-12-12 14:10:16 USERNAME HV: * another savegame. Now going with pythonic based plotiterator, # built around ms2util.reducems # # Revision 1.8 2013-08-20 18:23:50 USERNAME HV: * Another savegame # Got plotting to work! We have stuff on Screen (tm)! # Including the fance standardplot labels. # Only three plot types supported yet but the bulk of the work should # have been done I think. Then again, there's still a ton of work # to do. But good progress! # # Revision 1.7 2013-06-19 12:28:44 USERNAME HV: * making another savegame # # Revision 1.6 2013-03-31 17:17:56 USERNAME HV: * another savegame # # Revision 1.5 2013-03-09 16:59:07 USERNAME HV: * another savegame # # Revision 1.4 2013-02-19 16:53:29 USERNAME HV: * About time to commit - make sure all edits are safeguarded. # Making good progress. baselineselection, sourceselection and # timeselection working # # Revision 1.3 2013-02-11 09:40:33 USERNAME HV: * saving work done so far # - almost all mapping-functionality is in place # - some of the API functions are starting to appear # # Revision 1.2 2013-01-29 12:23:45 USERNAME HV: * time to commit - added some more basic stuff # # Revision IP_ADDRESS 2013-01-25 09:53:40 USERNAME HV: Initial import of some of the python code for the # rewrite of standardplots into python # # Revision 1.3 2003-10-29 12:35:38 USERNAME HV: Changed the way of how to open sub-tables of a MS; now using the right way rather than the JIVE way..:) # # Revision 1.2 2001/04/19 14:59:32 USERNAME HV: Added project detection+added it to the plots properties # # Revision IP_ADDRESS 2001/04/06 13:34:34 USERNAME Files, new + from jivegui/MS1
""" =============== Array Internals =============== Internal organization of numpy arrays ===================================== It helps to understand a bit about how numpy arrays are handled under the covers to help understand numpy better. This section will not go into great detail. Those wishing to understand the full details are referred to Travis Oliphant's book "Guide to NumPy". NumPy arrays consist of two major components, the raw array data (from now on, referred to as the data buffer), and the information about the raw array data. The data buffer is typically what people think of as arrays in C or Fortran, a contiguous (and fixed) block of memory containing fixed sized data items. NumPy also contains a significant set of data that describes how to interpret the data in the data buffer. This extra information contains (among other things): 1) The basic data element's size in bytes 2) The start of the data within the data buffer (an offset relative to the beginning of the data buffer). 3) The number of dimensions and the size of each dimension 4) The separation between elements for each dimension (the 'stride'). This does not have to be a multiple of the element size 5) The byte order of the data (which may not be the native byte order) 6) Whether the buffer is read-only 7) Information (via the dtype object) about the interpretation of the basic data element. The basic data element may be as simple as a int or a float, or it may be a compound object (e.g., struct-like), a fixed character field, or Python object pointers. 8) Whether the array is to interpreted as C-order or Fortran-order. This arrangement allow for very flexible use of arrays. One thing that it allows is simple changes of the metadata to change the interpretation of the array buffer. Changing the byteorder of the array is a simple change involving no rearrangement of the data. The shape of the array can be changed very easily without changing anything in the data buffer or any data copying at all Among other things that are made possible is one can create a new array metadata object that uses the same data buffer to create a new view of that data buffer that has a different interpretation of the buffer (e.g., different shape, offset, byte order, strides, etc) but shares the same data bytes. Many operations in numpy do just this such as slices. Other operations, such as transpose, don't move data elements around in the array, but rather change the information about the shape and strides so that the indexing of the array changes, but the data in the doesn't move. Typically these new versions of the array metadata but the same data buffer are new 'views' into the data buffer. There is a different ndarray object, but it uses the same data buffer. This is why it is necessary to force copies through use of the .copy() method if one really wants to make a new and independent copy of the data buffer. New views into arrays mean the object reference counts for the data buffer increase. Simply doing away with the original array object will not remove the data buffer if other views of it still exist. Multidimensional Array Indexing Order Issues ============================================ What is the right way to index multi-dimensional arrays? Before you jump to conclusions about the one and true way to index multi-dimensional arrays, it pays to understand why this is a confusing issue. This section will try to explain in detail how numpy indexing works and why we adopt the convention we do for images, and when it may be appropriate to adopt other conventions. The first thing to understand is that there are two conflicting conventions for indexing 2-dimensional arrays. Matrix notation uses the first index to indicate which row is being selected and the second index to indicate which column is selected. This is opposite the geometrically oriented-convention for images where people generally think the first index represents x position (i.e., column) and the second represents y position (i.e., row). This alone is the source of much confusion; matrix-oriented users and image-oriented users expect two different things with regard to indexing. The second issue to understand is how indices correspond to the order the array is stored in memory. In Fortran the first index is the most rapidly varying index when moving through the elements of a two dimensional array as it is stored in memory. If you adopt the matrix convention for indexing, then this means the matrix is stored one column at a time (since the first index moves to the next row as it changes). Thus Fortran is considered a Column-major language. C has just the opposite convention. In C, the last index changes most rapidly as one moves through the array as stored in memory. Thus C is a Row-major language. The matrix is stored by rows. Note that in both cases it presumes that the matrix convention for indexing is being used, i.e., for both Fortran and C, the first index is the row. Note this convention implies that the indexing convention is invariant and that the data order changes to keep that so. But that's not the only way to look at it. Suppose one has large two-dimensional arrays (images or matrices) stored in data files. Suppose the data are stored by rows rather than by columns. If we are to preserve our index convention (whether matrix or image) that means that depending on the language we use, we may be forced to reorder the data if it is read into memory to preserve our indexing convention. For example if we read row-ordered data into memory without reordering, it will match the matrix indexing convention for C, but not for Fortran. Conversely, it will match the image indexing convention for Fortran, but not for C. For C, if one is using data stored in row order, and one wants to preserve the image index convention, the data must be reordered when reading into memory. In the end, which you do for Fortran or C depends on which is more important, not reordering data or preserving the indexing convention. For large images, reordering data is potentially expensive, and often the indexing convention is inverted to avoid that. The situation with numpy makes this issue yet more complicated. The internal machinery of numpy arrays is flexible enough to accept any ordering of indices. One can simply reorder indices by manipulating the internal stride information for arrays without reordering the data at all. NumPy will know how to map the new index order to the data without moving the data. So if this is true, why not choose the index order that matches what you most expect? In particular, why not define row-ordered images to use the image convention? (This is sometimes referred to as the Fortran convention vs the C convention, thus the 'C' and 'FORTRAN' order options for array ordering in numpy.) The drawback of doing this is potential performance penalties. It's common to access the data sequentially, either implicitly in array operations or explicitly by looping over rows of an image. When that is done, then the data will be accessed in non-optimal order. As the first index is incremented, what is actually happening is that elements spaced far apart in memory are being sequentially accessed, with usually poor memory access speeds. For example, for a two dimensional image 'im' defined so that im[0, 10] represents the value at x=0, y=10. To be consistent with usual Python behavior then im[0] would represent a column at x=0. Yet that data would be spread over the whole array since the data are stored in row order. Despite the flexibility of numpy's indexing, it can't really paper over the fact basic operations are rendered inefficient because of data order or that getting contiguous subarrays is still awkward (e.g., im[:,0] for the first row, vs im[0]), thus one can't use an idiom such as for row in im; for col in im does work, but doesn't yield contiguous column data. As it turns out, numpy is smart enough when dealing with ufuncs to determine which index is the most rapidly varying one in memory and uses that for the innermost loop. Thus for ufuncs there is no large intrinsic advantage to either approach in most cases. On the other hand, use of .flat with an FORTRAN ordered array will lead to non-optimal memory access as adjacent elements in the flattened array (iterator, actually) are not contiguous in memory. Indeed, the fact is that Python indexing on lists and other sequences naturally leads to an outside-to inside ordering (the first index gets the largest grouping, the next the next largest, and the last gets the smallest element). Since image data are normally stored by rows, this corresponds to position within rows being the last item indexed. If you do want to use Fortran ordering realize that there are two approaches to consider: 1) accept that the first index is just not the most rapidly changing in memory and have all your I/O routines reorder your data when going from memory to disk or visa versa, or use numpy's mechanism for mapping the first index to the most rapidly varying data. We recommend the former if possible. The disadvantage of the latter is that many of numpy's functions will yield arrays without Fortran ordering unless you are careful to use the 'order' keyword. Doing this would be highly inconvenient. Otherwise we recommend simply learning to reverse the usual order of indices when accessing elements of an array. Granted, it goes against the grain, but it is more in line with Python semantics and the natural order of the data. """
""" # ggame The simple cross-platform sprite and game platform for Brython Server (Pygame, Tkinter to follow?). Ggame stands for a couple of things: "good game" (of course!) and also "git game" or "github game" because it is designed to operate with [Brython Server](http://runpython.com) in concert with Github as a backend file store. Ggame is **not** intended to be a full-featured gaming API, with every bell and whistle. Ggame is designed primarily as a tool for teaching computer programming, recognizing that the ability to create engaging and interactive games is a powerful motivator for many progamming students. Accordingly, any functional or performance enhancements that *can* be reasonably implemented by the user are left as an exercise. ## Functionality Goals The ggame library is intended to be trivially easy to use. For example: from ggame import App, ImageAsset, Sprite # Create a displayed object at 100,100 using an image asset Sprite(ImageAsset("ggame/bunny.png"), (100,100)) # Create the app, with a 500x500 pixel stage app = App(500,500) # Run the app app.run() ## Overview There are three major components to the `ggame` system: Assets, Sprites and the App. ### Assets Asset objects (i.e. `ggame.ImageAsset`, etc.) typically represent separate files that are provided by the "art department". These might be background images, user interface images, or images that represent objects in the game. In addition, `ggame.SoundAsset` is used to represent sound files (`.wav` or `.mp3` format) that can be played in the game. Ggame also extends the asset concept to include graphics that are generated dynamically at run-time, such as geometrical objects, e.g. rectangles, lines, etc. ### Sprites All of the visual aspects of the game are represented by instances of `ggame.Sprite` or subclasses of it. ### App Every ggame application must create a single instance of the `ggame.App` class (or a sub-class of it). Creating an instance of the `ggame.App` class will initiate creation of a pop-up window on your browser. Executing the app's `run` method will begin the process of refreshing the visual assets on the screen. ### Events No game is complete without a player and players produce events. Your code handles user input by registering to receive keyboard and mouse events using `ggame.App.listenKeyEvent` and `ggame.App.listenMouseEvent` methods. ## Execution Environment Ggame is designed to be executed in a web browser using [Brython](http://brython.info/), [Pixi.js](http://www.pixijs.com/) and [Buzz](http://buzz.jaysalvat.com/). The easiest way to do this is by executing from [runpython](http://runpython.com), with source code residing on [github](http://github.com). When using [runpython](http://runpython.com), you will have to configure your browser to allow popup windows. To use Ggame in your own application, you will minimally need to create a folder called `ggame` in your project. Within `ggame`, copy the `ggame.py`, `sysdeps.py` and `__init__.py` files from the [ggame project](https://github.com/BrythonServer/ggame). ### Include Ggame as a Git Subtree From the same directory as your own python sources (note: you must have an existing git repository with committed files in order for the following to work properly), execute the following terminal commands: git remote add -f ggame https://github.com/BrythonServer/ggame.git git merge -s ours --no-commit ggame/master mkdir ggame git read-tree --prefix=ggame/ -u ggame/master git commit -m "Merge ggame project as our subdirectory" If you want to pull in updates from ggame in the future: git pull -s subtree ggame master You can see an example of how a ggame subtree is used by examining the [Brython Server Spacewar](https://github.com/BrythonServer/Spacewar) repo on Github. ## Geometry When referring to screen coordinates, note that the x-axis of the computer screen is *horizontal* with the zero position on the left hand side of the screen. The y-axis is *vertical* with the zero position at the **top** of the screen. Increasing positive y-coordinates correspond to the downward direction on the computer screen. Note that this is **different** from the way you may have learned about x and y coordinates in math class! """
""" Define a simple format for saving numpy arrays to disk with the full information about them. The ``.npy`` format is the standard binary file format in NumPy for persisting a *single* arbitrary NumPy array on disk. The format stores all of the shape and dtype information necessary to reconstruct the array correctly even on another machine with a different architecture. The format is designed to be as simple as possible while achieving its limited goals. The ``.npz`` format is the standard format for persisting *multiple* NumPy arrays on disk. A ``.npz`` file is a zip file containing multiple ``.npy`` files, one for each array. Capabilities ------------ - Can represent all NumPy arrays including nested record arrays and object arrays. - Represents the data in its native binary form. - Supports Fortran-contiguous arrays directly. - Stores all of the necessary information to reconstruct the array including shape and dtype on a machine of a different architecture. Both little-endian and big-endian arrays are supported, and a file with little-endian numbers will yield a little-endian array on any machine reading the file. The types are described in terms of their actual sizes. For example, if a machine with a 64-bit C "long int" writes out an array with "long ints", a reading machine with 32-bit C "long ints" will yield an array with 64-bit integers. - Is straightforward to reverse engineer. Datasets often live longer than the programs that created them. A competent developer should be able to create a solution in their preferred programming language to read most ``.npy`` files that he has been given without much documentation. - Allows memory-mapping of the data. See `open_memmep`. - Can be read from a filelike stream object instead of an actual file. - Stores object arrays, i.e. arrays containing elements that are arbitrary Python objects. Files with object arrays are not to be mmapable, but can be read and written to disk. Limitations ----------- - Arbitrary subclasses of numpy.ndarray are not completely preserved. Subclasses will be accepted for writing, but only the array data will be written out. A regular numpy.ndarray object will be created upon reading the file. .. warning:: Due to limitations in the interpretation of structured dtypes, dtypes with fields with empty names will have the names replaced by 'f0', 'f1', etc. Such arrays will not round-trip through the format entirely accurately. The data is intact; only the field names will differ. We are working on a fix for this. This fix will not require a change in the file format. The arrays with such structures can still be saved and restored, and the correct dtype may be restored by using the ``loadedarray.view(correct_dtype)`` method. File extensions --------------- We recommend using the ``.npy`` and ``.npz`` extensions for files saved in this format. This is by no means a requirement; applications may wish to use these file formats but use an extension specific to the application. In the absence of an obvious alternative, however, we suggest using ``.npy`` and ``.npz``. Version numbering ----------------- The version numbering of these formats is independent of NumPy version numbering. If the format is upgraded, the code in `numpy.io` will still be able to read and write Version 1.0 files. Format Version 1.0 ------------------ The first 6 bytes are a magic string: exactly ``\\x93NUMPY``. The next 1 byte is an unsigned byte: the major version number of the file format, e.g. ``\\x01``. The next 1 byte is an unsigned byte: the minor version number of the file format, e.g. ``\\x00``. Note: the version of the file format is not tied to the version of the numpy package. The next 2 bytes form a little-endian unsigned short int: the length of the header data HEADER_LEN. The next HEADER_LEN bytes form the header data describing the array's format. It is an ASCII string which contains a Python literal expression of a dictionary. It is terminated by a newline (``\\n``) and padded with spaces (``\\x20``) to make the total length of ``magic string + 4 + HEADER_LEN`` be evenly divisible by 16 for alignment purposes. The dictionary contains three keys: "descr" : dtype.descr An object that can be passed as an argument to the `numpy.dtype` constructor to create the array's dtype. "fortran_order" : bool Whether the array data is Fortran-contiguous or not. Since Fortran-contiguous arrays are a common form of non-C-contiguity, we allow them to be written directly to disk for efficiency. "shape" : tuple of int The shape of the array. For repeatability and readability, the dictionary keys are sorted in alphabetic order. This is for convenience only. A writer SHOULD implement this if possible. A reader MUST NOT depend on this. Following the header comes the array data. If the dtype contains Python objects (i.e. ``dtype.hasobject is True``), then the data is a Python pickle of the array. Otherwise the data is the contiguous (either C- or Fortran-, depending on ``fortran_order``) bytes of the array. Consumers can figure out the number of bytes by multiplying the number of elements given by the shape (noting that ``shape=()`` means there is 1 element) by ``dtype.itemsize``. Format Version 2.0 ------------------ The version 1.0 format only allowed the array header to have a total size of 65535 bytes. This can be exceeded by structured arrays with a large number of columns. The version 2.0 format extends the header size to 4 GiB. `numpy.save` will automatically save in 2.0 format if the data requires it, else it will always use the more compatible 1.0 format. The description of the fourth element of the header therefore has become: "The next 4 bytes form a little-endian unsigned int: the length of the header data HEADER_LEN." Notes ----- The ``.npy`` format, including reasons for creating it and a comparison of alternatives, is described fully in the "npy-format" NEP. """
"""Doctest for method/function calls. We're going the use these types for extra testing >>> from UserList import UserList >>> from UserDict import UserDict We're defining four helper functions >>> def e(a,b): ... print a, b >>> def f(*a, **k): ... print a, test_support.sortdict(k) >>> def g(x, *y, **z): ... print x, y, test_support.sortdict(z) >>> def h(j=1, a=2, h=3): ... print j, a, h Argument list examples >>> f() () {} >>> f(1) (1,) {} >>> f(1, 2) (1, 2) {} >>> f(1, 2, 3) (1, 2, 3) {} >>> f(1, 2, 3, *(4, 5)) (1, 2, 3, 4, 5) {} >>> f(1, 2, 3, *[4, 5]) (1, 2, 3, 4, 5) {} >>> f(1, 2, 3, *UserList([4, 5])) (1, 2, 3, 4, 5) {} Here we add keyword arguments >>> f(1, 2, 3, **{'a':4, 'b':5}) (1, 2, 3) {'a': 4, 'b': 5} >>> f(1, 2, 3, *[4, 5], **{'a':6, 'b':7}) (1, 2, 3, 4, 5) {'a': 6, 'b': 7} >>> f(1, 2, 3, x=4, y=5, *(6, 7), **{'a':8, 'b': 9}) (1, 2, 3, 6, 7) {'a': 8, 'b': 9, 'x': 4, 'y': 5} >>> f(1, 2, 3, **UserDict(a=4, b=5)) (1, 2, 3) {'a': 4, 'b': 5} >>> f(1, 2, 3, *(4, 5), **UserDict(a=6, b=7)) (1, 2, 3, 4, 5) {'a': 6, 'b': 7} >>> f(1, 2, 3, x=4, y=5, *(6, 7), **UserDict(a=8, b=9)) (1, 2, 3, 6, 7) {'a': 8, 'b': 9, 'x': 4, 'y': 5} Examples with invalid arguments (TypeErrors). We're also testing the function names in the exception messages. Verify clearing of SF bug #733667 >>> e(c=4) Traceback (most recent call last): ... TypeError: e() got an unexpected keyword argument 'c' >>> g() Traceback (most recent call last): ... TypeError: g() takes at least 1 argument (0 given) >>> g(*()) Traceback (most recent call last): ... TypeError: g() takes at least 1 argument (0 given) >>> g(*(), **{}) Traceback (most recent call last): ... TypeError: g() takes at least 1 argument (0 given) >>> g(1) 1 () {} >>> g(1, 2) 1 (2,) {} >>> g(1, 2, 3) 1 (2, 3) {} >>> g(1, 2, 3, *(4, 5)) 1 (2, 3, 4, 5) {} >>> class Nothing: pass ... >>> g(*Nothing()) Traceback (most recent call last): ... TypeError: g() argument after * must be a sequence, not instance >>> class Nothing: ... def __len__(self): return 5 ... >>> g(*Nothing()) Traceback (most recent call last): ... TypeError: g() argument after * must be a sequence, not instance >>> class Nothing(): ... def __len__(self): return 5 ... def __getitem__(self, i): ... if i<3: return i ... else: raise IndexError(i) ... >>> g(*Nothing()) 0 (1, 2) {} >>> class Nothing: ... def __init__(self): self.c = 0 ... def __iter__(self): return self ... def next(self): ... if self.c == 4: ... raise StopIteration ... c = self.c ... self.c += 1 ... return c ... >>> g(*Nothing()) 0 (1, 2, 3) {} Make sure that the function doesn't stomp the dictionary >>> d = {'a': 1, 'b': 2, 'c': 3} >>> d2 = d.copy() >>> g(1, d=4, **d) 1 () {'a': 1, 'b': 2, 'c': 3, 'd': 4} >>> d == d2 True What about willful misconduct? >>> def saboteur(**kw): ... kw['x'] = 'm' ... return kw >>> d = {} >>> kw = saboteur(a=1, **d) >>> d {} >>> g(1, 2, 3, **{'x': 4, 'y': 5}) Traceback (most recent call last): ... TypeError: g() got multiple values for keyword argument 'x' >>> f(**{1:2}) Traceback (most recent call last): ... TypeError: f() keywords must be strings >>> h(**{'e': 2}) Traceback (most recent call last): ... TypeError: h() got an unexpected keyword argument 'e' >>> h(*h) Traceback (most recent call last): ... TypeError: h() argument after * must be a sequence, not function >>> dir(*h) Traceback (most recent call last): ... TypeError: dir() argument after * must be a sequence, not function >>> None(*h) Traceback (most recent call last): ... TypeError: NoneType object argument after * must be a sequence, \ not function >>> h(**h) Traceback (most recent call last): ... TypeError: h() argument after ** must be a mapping, not function >>> dir(**h) Traceback (most recent call last): ... TypeError: dir() argument after ** must be a mapping, not function >>> None(**h) Traceback (most recent call last): ... TypeError: NoneType object argument after ** must be a mapping, \ not function >>> dir(b=1, **{'b': 1}) Traceback (most recent call last): ... TypeError: dir() got multiple values for keyword argument 'b' Another helper function >>> def f2(*a, **b): ... return a, b >>> d = {} >>> for i in xrange(512): ... key = 'k%d' % i ... d[key] = i >>> a, b = f2(1, *(2,3), **d) >>> len(a), len(b), b == d (3, 512, True) >>> class Foo: ... def method(self, arg1, arg2): ... return arg1+arg2 >>> x = Foo() >>> Foo.method(*(x, 1, 2)) 3 >>> Foo.method(x, *(1, 2)) 3 >>> Foo.method(*(1, 2, 3)) Traceback (most recent call last): ... TypeError: unbound method method() must be called with Foo instance as \ first argument (got int instance instead) >>> Foo.method(1, *[2, 3]) Traceback (most recent call last): ... TypeError: unbound method method() must be called with Foo instance as \ first argument (got int instance instead) A PyCFunction that takes only positional parameters shoud allow an empty keyword dictionary to pass without a complaint, but raise a TypeError if te dictionary is not empty >>> try: ... silence = id(1, *{}) ... True ... except: ... False True >>> id(1, **{'foo': 1}) Traceback (most recent call last): ... TypeError: id() takes no keyword arguments """
""" ================================== Constants (:mod:`scipy.constants`) ================================== .. currentmodule:: scipy.constants Physical and mathematical constants and units. Mathematical constants ====================== ================ ================================================================= ``pi`` Pi ``golden`` Golden ratio ``golden_ratio`` Golden ratio ================ ================================================================= Physical constants ================== =========================== ================================================================= ``c`` speed of light in vacuum ``speed_of_light`` speed of light in vacuum ``mu_0`` the magnetic constant :math:`\mu_0` ``epsilon_0`` the electric constant (vacuum permittivity), :math:`\epsilon_0` ``h`` the Planck constant :math:`h` ``Planck`` the Planck constant :math:`h` ``hbar`` :math:`\hbar = h/(2\pi)` ``G`` Newtonian constant of gravitation ``gravitational_constant`` Newtonian constant of gravitation ``g`` standard acceleration of gravity ``e`` elementary charge ``elementary_charge`` elementary charge ``R`` molar gas constant ``gas_constant`` molar gas constant ``alpha`` fine-structure constant ``fine_structure`` fine-structure constant ``N_A`` Avogadro constant ``Avogadro`` Avogadro constant ``k`` Boltzmann constant ``Boltzmann`` Boltzmann constant ``sigma`` Stefan-Boltzmann constant :math:`\sigma` ``Stefan_Boltzmann`` Stefan-Boltzmann constant :math:`\sigma` ``Wien`` Wien displacement law constant ``Rydberg`` Rydberg constant ``m_e`` electron mass ``electron_mass`` electron mass ``m_p`` proton mass ``proton_mass`` proton mass ``m_n`` neutron mass ``neutron_mass`` neutron mass =========================== ================================================================= Constants database ------------------ In addition to the above variables, :mod:`scipy.constants` also contains the 2014 CODATA recommended values [CODATA2014]_ database containing more physical constants. .. autosummary:: :toctree: generated/ value -- Value in physical_constants indexed by key unit -- Unit in physical_constants indexed by key precision -- Relative precision in physical_constants indexed by key find -- Return list of physical_constant keys with a given string ConstantWarning -- Constant sought not in newest CODATA data set .. data:: physical_constants Dictionary of physical constants, of the format ``physical_constants[name] = (value, unit, uncertainty)``. Available constants: ====================================================================== ==== %(constant_names)s ====================================================================== ==== Units ===== SI prefixes ----------- ============ ================================================================= ``yotta`` :math:`10^{24}` ``zetta`` :math:`10^{21}` ``exa`` :math:`10^{18}` ``peta`` :math:`10^{15}` ``tera`` :math:`10^{12}` ``giga`` :math:`10^{9}` ``mega`` :math:`10^{6}` ``kilo`` :math:`10^{3}` ``hecto`` :math:`10^{2}` ``deka`` :math:`10^{1}` ``deci`` :math:`10^{-1}` ``centi`` :math:`10^{-2}` ``milli`` :math:`10^{-3}` ``micro`` :math:`10^{-6}` ``nano`` :math:`10^{-9}` ``pico`` :math:`10^{-12}` ``femto`` :math:`10^{-15}` ``atto`` :math:`10^{-18}` ``zepto`` :math:`10^{-21}` ============ ================================================================= Binary prefixes --------------- ============ ================================================================= ``kibi`` :math:`2^{10}` ``mebi`` :math:`2^{20}` ``gibi`` :math:`2^{30}` ``tebi`` :math:`2^{40}` ``pebi`` :math:`2^{50}` ``exbi`` :math:`2^{60}` ``zebi`` :math:`2^{70}` ``yobi`` :math:`2^{80}` ============ ================================================================= Weight ------ ================= ============================================================ ``gram`` :math:`10^{-3}` kg ``metric_ton`` :math:`10^{3}` kg ``grain`` one grain in kg ``lb`` one pound (avoirdupous) in kg ``pound`` one pound (avoirdupous) in kg ``oz`` one ounce in kg ``ounce`` one ounce in kg ``stone`` one stone in kg ``grain`` one grain in kg ``long_ton`` one long ton in kg ``short_ton`` one short ton in kg ``troy_ounce`` one Troy ounce in kg ``troy_pound`` one Troy pound in kg ``carat`` one carat in kg ``m_u`` atomic mass constant (in kg) ``u`` atomic mass constant (in kg) ``atomic_mass`` atomic mass constant (in kg) ================= ============================================================ Angle ----- ================= ============================================================ ``degree`` degree in radians ``arcmin`` arc minute in radians ``arcminute`` arc minute in radians ``arcsec`` arc second in radians ``arcsecond`` arc second in radians ================= ============================================================ Time ---- ================= ============================================================ ``minute`` one minute in seconds ``hour`` one hour in seconds ``day`` one day in seconds ``week`` one week in seconds ``year`` one year (365 days) in seconds ``Julian_year`` one Julian year (365.25 days) in seconds ================= ============================================================ Length ------ ===================== ============================================================ ``inch`` one inch in meters ``foot`` one foot in meters ``yard`` one yard in meters ``mile`` one mile in meters ``mil`` one mil in meters ``pt`` one point in meters ``point`` one point in meters ``survey_foot`` one survey foot in meters ``survey_mile`` one survey mile in meters ``nautical_mile`` one nautical mile in meters ``fermi`` one Fermi in meters ``angstrom`` one Angstrom in meters ``micron`` one micron in meters ``au`` one astronomical unit in meters ``astronomical_unit`` one astronomical unit in meters ``light_year`` one light year in meters ``parsec`` one parsec in meters ===================== ============================================================ Pressure -------- ================= ============================================================ ``atm`` standard atmosphere in pascals ``atmosphere`` standard atmosphere in pascals ``bar`` one bar in pascals ``torr`` one torr (mmHg) in pascals ``mmHg`` one torr (mmHg) in pascals ``psi`` one psi in pascals ================= ============================================================ Area ---- ================= ============================================================ ``hectare`` one hectare in square meters ``acre`` one acre in square meters ================= ============================================================ Volume ------ =================== ======================================================== ``liter`` one liter in cubic meters ``litre`` one liter in cubic meters ``gallon`` one gallon (US) in cubic meters ``gallon_US`` one gallon (US) in cubic meters ``gallon_imp`` one gallon (UK) in cubic meters ``fluid_ounce`` one fluid ounce (US) in cubic meters ``fluid_ounce_US`` one fluid ounce (US) in cubic meters ``fluid_ounce_imp`` one fluid ounce (UK) in cubic meters ``bbl`` one barrel in cubic meters ``barrel`` one barrel in cubic meters =================== ======================================================== Speed ----- ================== ========================================================== ``kmh`` kilometers per hour in meters per second ``mph`` miles per hour in meters per second ``mach`` one Mach (approx., at 15 C, 1 atm) in meters per second ``speed_of_sound`` one Mach (approx., at 15 C, 1 atm) in meters per second ``knot`` one knot in meters per second ================== ========================================================== Temperature ----------- ===================== ======================================================= ``zero_Celsius`` zero of Celsius scale in Kelvin ``degree_Fahrenheit`` one Fahrenheit (only differences) in Kelvins ===================== ======================================================= .. autosummary:: :toctree: generated/ C2K K2C F2C C2F F2K K2F Energy ------ ==================== ======================================================= ``eV`` one electron volt in Joules ``electron_volt`` one electron volt in Joules ``calorie`` one calorie (thermochemical) in Joules ``calorie_th`` one calorie (thermochemical) in Joules ``calorie_IT`` one calorie (International Steam Table calorie, 1956) in Joules ``erg`` one erg in Joules ``Btu`` one British thermal unit (International Steam Table) in Joules ``Btu_IT`` one British thermal unit (International Steam Table) in Joules ``Btu_th`` one British thermal unit (thermochemical) in Joules ``ton_TNT`` one ton of TNT in Joules ==================== ======================================================= Power ----- ==================== ======================================================= ``hp`` one horsepower in watts ``horsepower`` one horsepower in watts ==================== ======================================================= Force ----- ==================== ======================================================= ``dyn`` one dyne in newtons ``dyne`` one dyne in newtons ``lbf`` one pound force in newtons ``pound_force`` one pound force in newtons ``kgf`` one kilogram force in newtons ``kilogram_force`` one kilogram force in newtons ==================== ======================================================= Optics ------ .. autosummary:: :toctree: generated/ lambda2nu nu2lambda References ========== .. [CODATA2014] CODATA Recommended Values of the Fundamental Physical Constants 2014. http://physics.nist.gov/cuu/Constants/index.html """
""" ================================== Constants (:mod:`scipy.constants`) ================================== .. currentmodule:: scipy.constants Physical and mathematical constants and units. Mathematical constants ====================== ============ ================================================================= ``pi`` Pi ``golden`` Golden ratio ============ ================================================================= Physical constants ================== ============= ================================================================= ``c`` speed of light in vacuum ``mu_0`` the magnetic constant :math:`\mu_0` ``epsilon_0`` the electric constant (vacuum permittivity), :math:`\epsilon_0` ``h`` the Planck constant :math:`h` ``hbar`` :math:`\hbar = h/(2\pi)` ``G`` Newtonian constant of gravitation ``g`` standard acceleration of gravity ``e`` elementary charge ``R`` molar gas constant ``alpha`` fine-structure constant ``N_A`` Avogadro constant ``k`` Boltzmann constant ``sigma`` Stefan-Boltzmann constant :math:`\sigma` ``Wien`` Wien displacement law constant ``Rydberg`` Rydberg constant ``m_e`` electron mass ``m_p`` proton mass ``m_n`` neutron mass ============= ================================================================= Constants database ------------------ In addition to the above variables, :mod:`scipy.constants` also contains the 2010 CODATA recommended values [CODATA2010]_ database containing more physical constants. .. autosummary:: :toctree: generated/ value -- Value in physical_constants indexed by key unit -- Unit in physical_constants indexed by key precision -- Relative precision in physical_constants indexed by key find -- Return list of physical_constant keys with a given string ConstantWarning -- Constant sought not in newest CODATA data set .. data:: physical_constants Dictionary of physical constants, of the format ``physical_constants[name] = (value, unit, uncertainty)``. Available constants: ====================================================================== ==== %(constant_names)s ====================================================================== ==== Units ===== SI prefixes ----------- ============ ================================================================= ``yotta`` :math:`10^{24}` ``zetta`` :math:`10^{21}` ``exa`` :math:`10^{18}` ``peta`` :math:`10^{15}` ``tera`` :math:`10^{12}` ``giga`` :math:`10^{9}` ``mega`` :math:`10^{6}` ``kilo`` :math:`10^{3}` ``hecto`` :math:`10^{2}` ``deka`` :math:`10^{1}` ``deci`` :math:`10^{-1}` ``centi`` :math:`10^{-2}` ``milli`` :math:`10^{-3}` ``micro`` :math:`10^{-6}` ``nano`` :math:`10^{-9}` ``pico`` :math:`10^{-12}` ``femto`` :math:`10^{-15}` ``atto`` :math:`10^{-18}` ``zepto`` :math:`10^{-21}` ============ ================================================================= Binary prefixes --------------- ============ ================================================================= ``kibi`` :math:`2^{10}` ``mebi`` :math:`2^{20}` ``gibi`` :math:`2^{30}` ``tebi`` :math:`2^{40}` ``pebi`` :math:`2^{50}` ``exbi`` :math:`2^{60}` ``zebi`` :math:`2^{70}` ``yobi`` :math:`2^{80}` ============ ================================================================= Weight ------ ================= ============================================================ ``gram`` :math:`10^{-3}` kg ``metric_ton`` :math:`10^{3}` kg ``grain`` one grain in kg ``lb`` one pound (avoirdupous) in kg ``oz`` one ounce in kg ``stone`` one stone in kg ``grain`` one grain in kg ``long_ton`` one long ton in kg ``short_ton`` one short ton in kg ``troy_ounce`` one Troy ounce in kg ``troy_pound`` one Troy pound in kg ``carat`` one carat in kg ``m_u`` atomic mass constant (in kg) ================= ============================================================ Angle ----- ================= ============================================================ ``degree`` degree in radians ``arcmin`` arc minute in radians ``arcsec`` arc second in radians ================= ============================================================ Time ---- ================= ============================================================ ``minute`` one minute in seconds ``hour`` one hour in seconds ``day`` one day in seconds ``week`` one week in seconds ``year`` one year (365 days) in seconds ``Julian_year`` one Julian year (365.25 days) in seconds ================= ============================================================ Length ------ ================= ============================================================ ``inch`` one inch in meters ``foot`` one foot in meters ``yard`` one yard in meters ``mile`` one mile in meters ``mil`` one mil in meters ``pt`` one point in meters ``survey_foot`` one survey foot in meters ``survey_mile`` one survey mile in meters ``nautical_mile`` one nautical mile in meters ``fermi`` one Fermi in meters ``angstrom`` one Angstrom in meters ``micron`` one micron in meters ``au`` one astronomical unit in meters ``light_year`` one light year in meters ``parsec`` one parsec in meters ================= ============================================================ Pressure -------- ================= ============================================================ ``atm`` standard atmosphere in pascals ``bar`` one bar in pascals ``torr`` one torr (mmHg) in pascals ``psi`` one psi in pascals ================= ============================================================ Area ---- ================= ============================================================ ``hectare`` one hectare in square meters ``acre`` one acre in square meters ================= ============================================================ Volume ------ =================== ======================================================== ``liter`` one liter in cubic meters ``gallon`` one gallon (US) in cubic meters ``gallon_imp`` one gallon (UK) in cubic meters ``fluid_ounce`` one fluid ounce (US) in cubic meters ``fluid_ounce_imp`` one fluid ounce (UK) in cubic meters ``bbl`` one barrel in cubic meters =================== ======================================================== Speed ----- ================= ========================================================== ``kmh`` kilometers per hour in meters per second ``mph`` miles per hour in meters per second ``mach`` one Mach (approx., at 15 C, 1 atm) in meters per second ``knot`` one knot in meters per second ================= ========================================================== Temperature ----------- ===================== ======================================================= ``zero_Celsius`` zero of Celsius scale in Kelvin ``degree_Fahrenheit`` one Fahrenheit (only differences) in Kelvins ===================== ======================================================= .. autosummary:: :toctree: generated/ C2K K2C F2C C2F F2K K2F Energy ------ ==================== ======================================================= ``eV`` one electron volt in Joules ``calorie`` one calorie (thermochemical) in Joules ``calorie_IT`` one calorie (International Steam Table calorie, 1956) in Joules ``erg`` one erg in Joules ``Btu`` one British thermal unit (International Steam Table) in Joules ``Btu_th`` one British thermal unit (thermochemical) in Joules ``ton_TNT`` one ton of TNT in Joules ==================== ======================================================= Power ----- ==================== ======================================================= ``hp`` one horsepower in watts ==================== ======================================================= Force ----- ==================== ======================================================= ``dyn`` one dyne in newtons ``lbf`` one pound force in newtons ``kgf`` one kilogram force in newtons ==================== ======================================================= Optics ------ .. autosummary:: :toctree: generated/ lambda2nu nu2lambda References ========== .. [CODATA2010] CODATA Recommended Values of the Fundamental Physical Constants 2010. http://physics.nist.gov/cuu/Constants/index.html """
""" ======== Glossary ======== .. glossary:: along an axis Axes are defined for arrays with more than one dimension. A 2-dimensional array has two corresponding axes: the first running vertically downwards across rows (axis 0), and the second running horizontally across columns (axis 1). Many operation can take place along one of these axes. For example, we can sum each row of an array, in which case we operate along columns, or axis 1:: >>> x = np.arange(12).reshape((3,4)) >>> x array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> x.sum(axis=1) array([ 6, 22, 38]) array A homogeneous container of numerical elements. Each element in the array occupies a fixed amount of memory (hence homogeneous), and can be a numerical element of a single type (such as float, int or complex) or a combination (such as ``(float, int, float)``). Each array has an associated data-type (or ``dtype``), which describes the numerical type of its elements:: >>> x = np.array([1, 2, 3], float) >>> x array([ 1., 2., 3.]) >>> x.dtype # floating point number, 64 bits of memory per element dtype('float64') # More complicated data type: each array element is a combination of # and integer and a floating point number >>> np.array([(1, 2.0), (3, 4.0)], dtype=[('x', int), ('y', float)]) array([(1, 2.0), (3, 4.0)], dtype=[('x', '<i4'), ('y', '<f8')]) Fast element-wise operations, called `ufuncs`_, operate on arrays. array_like Any sequence that can be interpreted as an ndarray. This includes nested lists, tuples, scalars and existing arrays. attribute A property of an object that can be accessed using ``obj.attribute``, e.g., ``shape`` is an attribute of an array:: >>> x = np.array([1, 2, 3]) >>> x.shape (3,) BLAS `Basic Linear Algebra Subprograms <http://en.wikipedia.org/wiki/BLAS>`_ broadcast NumPy can do operations on arrays whose shapes are mismatched:: >>> x = np.array([1, 2]) >>> y = np.array([[3], [4]]) >>> x array([1, 2]) >>> y array([[3], [4]]) >>> x + y array([[4, 5], [5, 6]]) See `doc.broadcasting`_ for more information. C order See `row-major` column-major A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In column-major order, the leftmost index "varies the fastest": for example the array:: [[1, 2, 3], [4, 5, 6]] is represented in the column-major order as:: [1, 4, 2, 5, 3, 6] Column-major order is also known as the Fortran order, as the Fortran programming language uses it. decorator An operator that transforms a function. For example, a ``log`` decorator may be defined to print debugging information upon function execution:: >>> def log(f): ... def new_logging_func(*args, **kwargs): ... print("Logging call with parameters:", args, kwargs) ... return f(*args, **kwargs) ... ... return new_logging_func Now, when we define a function, we can "decorate" it using ``log``:: >>> @log ... def add(a, b): ... return a + b Calling ``add`` then yields: >>> add(1, 2) Logging call with parameters: (1, 2) {} 3 dictionary Resembling a language dictionary, which provides a mapping between words and descriptions thereof, a Python dictionary is a mapping between two objects:: >>> x = {1: 'one', 'two': [1, 2]} Here, `x` is a dictionary mapping keys to values, in this case the integer 1 to the string "one", and the string "two" to the list ``[1, 2]``. The values may be accessed using their corresponding keys:: >>> x[1] 'one' >>> x['two'] [1, 2] Note that dictionaries are not stored in any specific order. Also, most mutable (see *immutable* below) objects, such as lists, may not be used as keys. For more information on dictionaries, read the `Python tutorial <http://docs.python.org/tut>`_. Fortran order See `column-major` flattened Collapsed to a one-dimensional array. See `ndarray.flatten`_ for details. immutable An object that cannot be modified after execution is called immutable. Two common examples are strings and tuples. instance A class definition gives the blueprint for constructing an object:: >>> class House(object): ... wall_colour = 'white' Yet, we have to *build* a house before it exists:: >>> h = House() # build a house Now, ``h`` is called a ``House`` instance. An instance is therefore a specific realisation of a class. iterable A sequence that allows "walking" (iterating) over items, typically using a loop such as:: >>> x = [1, 2, 3] >>> [item**2 for item in x] [1, 4, 9] It is often used in combination with ``enumerate``:: >>> keys = ['a','b','c'] >>> for n, k in enumerate(keys): ... print("Key %d: %s" % (n, k)) ... Key 0: a Key 1: b Key 2: c list A Python container that can hold any number of objects or items. The items do not have to be of the same type, and can even be lists themselves:: >>> x = [2, 2.0, "two", [2, 2.0]] The list `x` contains 4 items, each which can be accessed individually:: >>> x[2] # the string 'two' 'two' >>> x[3] # a list, containing an integer 2 and a float 2.0 [2, 2.0] It is also possible to select more than one item at a time, using *slicing*:: >>> x[0:2] # or, equivalently, x[:2] [2, 2.0] In code, arrays are often conveniently expressed as nested lists:: >>> np.array([[1, 2], [3, 4]]) array([[1, 2], [3, 4]]) For more information, read the section on lists in the `Python tutorial <http://docs.python.org/tut>`_. For a mapping type (key-value), see *dictionary*. mask A boolean array, used to select only certain elements for an operation:: >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> mask = (x > 2) >>> mask array([False, False, False, True, True], dtype=bool) >>> x[mask] = -1 >>> x array([ 0, 1, 2, -1, -1]) masked array Array that suppressed values indicated by a mask:: >>> x = np.ma.masked_array([np.nan, 2, np.nan], [True, False, True]) >>> x masked_array(data = [-- 2.0 --], mask = [ True False True], fill_value = 1e+20) <BLANKLINE> >>> x + [1, 2, 3] masked_array(data = [-- 4.0 --], mask = [ True False True], fill_value = 1e+20) <BLANKLINE> Masked arrays are often used when operating on arrays containing missing or invalid entries. matrix A 2-dimensional ndarray that preserves its two-dimensional nature throughout operations. It has certain special operations, such as ``*`` (matrix multiplication) and ``**`` (matrix power), defined:: >>> x = np.mat([[1, 2], [3, 4]]) >>> x matrix([[1, 2], [3, 4]]) >>> x**2 matrix([[ 7, 10], [15, 22]]) method A function associated with an object. For example, each ndarray has a method called ``repeat``:: >>> x = np.array([1, 2, 3]) >>> x.repeat(2) array([1, 1, 2, 2, 3, 3]) ndarray See *array*. record array An `ndarray`_ with `structured data type`_ which has been subclassed as np.recarray and whose dtype is of type np.record, making the fields of its data type to be accessible by attribute. reference If ``a`` is a reference to ``b``, then ``(a is b) == True``. Therefore, ``a`` and ``b`` are different names for the same Python object. row-major A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In row-major order, the rightmost index "varies the fastest": for example the array:: [[1, 2, 3], [4, 5, 6]] is represented in the row-major order as:: [1, 2, 3, 4, 5, 6] Row-major order is also known as the C order, as the C programming language uses it. New NumPy arrays are by default in row-major order. self Often seen in method signatures, ``self`` refers to the instance of the associated class. For example: >>> class Paintbrush(object): ... color = 'blue' ... ... def paint(self): ... print("Painting the city %s!" % self.color) ... >>> p = Paintbrush() >>> p.color = 'red' >>> p.paint() # self refers to 'p' Painting the city red! slice Used to select only certain elements from a sequence:: >>> x = range(5) >>> x [0, 1, 2, 3, 4] >>> x[1:3] # slice from 1 to 3 (excluding 3 itself) [1, 2] >>> x[1:5:2] # slice from 1 to 5, but skipping every second element [1, 3] >>> x[::-1] # slice a sequence in reverse [4, 3, 2, 1, 0] Arrays may have more than one dimension, each which can be sliced individually:: >>> x = np.array([[1, 2], [3, 4]]) >>> x array([[1, 2], [3, 4]]) >>> x[:, 1] array([2, 4]) structured data type A data type composed of other datatypes tuple A sequence that may contain a variable number of types of any kind. A tuple is immutable, i.e., once constructed it cannot be changed. Similar to a list, it can be indexed and sliced:: >>> x = (1, 'one', [1, 2]) >>> x (1, 'one', [1, 2]) >>> x[0] 1 >>> x[:2] (1, 'one') A useful concept is "tuple unpacking", which allows variables to be assigned to the contents of a tuple:: >>> x, y = (1, 2) >>> x, y = 1, 2 This is often used when a function returns multiple values: >>> def return_many(): ... return 1, 'alpha', None >>> a, b, c = return_many() >>> a, b, c (1, 'alpha', None) >>> a 1 >>> b 'alpha' ufunc Universal function. A fast element-wise array operation. Examples include ``add``, ``sin`` and ``logical_or``. view An array that does not own its data, but refers to another array's data instead. For example, we may create a view that only shows every second element of another array:: >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> y = x[::2] >>> y array([0, 2, 4]) >>> x[0] = 3 # changing x changes y as well, since y is a view on x >>> y array([3, 2, 4]) wrapper Python is a high-level (highly abstracted, or English-like) language. This abstraction comes at a price in execution speed, and sometimes it becomes necessary to use lower level languages to do fast computations. A wrapper is code that provides a bridge between high and the low level languages, allowing, e.g., Python to execute code written in C or Fortran. Examples include ctypes, SWIG and Cython (which wraps C and C++) and f2py (which wraps Fortran). """
""" .. currentmodule:: pele.rates Rates (`pele.rates`) ==================== This module contains tools to quickly (and exactly) compute transition rates, first passage times and and commitor probabilities in a transition network. The resulting rates are exact, in the sense of Kinetic Monte Carlo, but the analysis can be orders of magnitude faster than doing a Kinetic Monte Carlo This module can also be found as an independent package at `<https://github.com/js850/kmc_rates>`_ Description of the method ------------------------- The rates are computed using the New Graph Transformation (NGT) method of described in the paper Calculating rate constants and committor probabilities for transition networks by graph transformation David NAME (2009) J. Chem. Phys., 130, 204111 `<http://dx.doi.org/10.1063/1.3133782>`_ The method uses a graph renormalization method (renormalization in the sense of renormalization group theory) to compute exact Kinetic Monte Carlo rates and first passage probabilities from a reactant group A to a product group B. Each node `u` has an attribute `tau_u` which is the waiting time at that node. Each edge `u -> v` has an associated transition probability and `P_uv`. An important feature of this algorithm is that each node has a loop edge pointing back to itself and associated probability `P_uu` which gives the self-transitio probability. In the typical case the self-transition probabilities will all be zero initially, but will take non zero values after renormalization. The transition probabilities always satisfy `sum_v P_uv = 1`. graph transformation ++++++++++++++++++++ The algorithm is most easily described if we first assume that A, and B each contain only one node (called `a`, and `b`). In the algorithm, nodes are iteratively removed from the graph until the only two remaining nodes are a and `b`. Upon removing node `x`, in order to preserve the transition times and probabilities, the properties of the neighbors of `x` are all updated. For each neighbor, `u`, of `x`, the transition times are updated according to tau_u -> tau_u + P_ux * tau_x / (1 - P_xx) Similarly, for each pair, `u` and `v`, of neighbors of `x` the transition probabilities are updated according to P_uv -> P_uv + P_ux * P_xv / (1 - P_xx) Note that the self-transition probabilities `P_uu` are also updated according to the above equation. Once the graph is reduced to only the two nodes, `a`, and `b`, the probability `P_ab` is interpreted as the commitor probability from `a` to `b`. That is, the probability that a trajectory starting at `a` will end up at `b` before returning to `a`. Similarly, the mean first passage time from `a` to `b` is simply `tau_a / P_ab`. Note that because the probabilies sum to 1 the mean first passage time can also be written `tau_a / (1-P_aa)`. The transtion rate from `a` to `b` is simply the inverse of the mean first passage time. The rates and probabilites from `b -> a` are read from the resuling graph in the same way. The above interpretations are exact in the sense that a Kinetic Monte Carlo simulation will give the same result. if B has more than one element ++++++++++++++++++++++++++++++ If there is more than one element in `B` the calculation of rates from `a -> B` is nearly as simple. Following the same procedure described above, all nodes except those in `A` or `B` are iteratively removed. The commitor probability from `a` to `B` is then the sum over the transition probabilities from `a` to `b` for each element `b` in `B`. This can also be written as 1 - P_aa The mean first passage time from `a` to `B` is given by T_aB = tau_a / (1 - P_aa) if A has more than one element ++++++++++++++++++++++++++++++ In this, the most general case, when both A and B have more than one element, the transition rate from `A` to `B` must be computed as an average over the inverse mean first passage time for each element `a` in `A`. That is k_AB = average( 1 / T_aB ) The computation is done in two phases. In the first phase the intermediate nodes (those not in `A` or in `B`) are all removed from the graph. In the second phase we first make a backup copy of the graph. Then for each node `a` in `A` we remove from the graph all nodes in `A` (except `a`). This allows us to compute commitor probabilities and mean first passage times (`T_aB`) from `a` to `B` as described in the preceding section. If the nodes `a` are not all equally likely to be occupied, then the above average can be a weighted average where each node is weighted according to its equilibrium occupation probabilities. The rates `B -> A` can be computed in a similar manner .. autosummary:: :toctree: generated/ GraphReduction """
# # tested on | Windows native | Linux cross-compilation # ------------------------+-------------------+--------------------------- # MSVS C++ 2010 Express | WORKS | n/a # Mingw-w64 | WORKS | WORKS # Mingw-w32 | WORKS | WORKS # MinGW | WORKS | untested # ##### # Notes about MSVS C++ : # # - MSVC2010-Express compiles to 32bits only. # ##### # Notes about Mingw-w64 and Mingw-w32 under Windows : # # - both can be installed using the official installer : # http://mingw-w64.sourceforge.net/download.php#mingw-builds # # - if you want to compile both 32bits and 64bits, don't forget to # run the installer twice to install them both. # # - install them into a path that does not contain spaces # ( example : "C:/Mingw-w32", "C:/Mingw-w64" ) # # - if you want to compile faster using the "-j" option, don't forget # to install the appropriate version of the Pywin32 python extension # available from : http://sourceforge.net/projects/pywin32/files/ # # - before running scons, you must add into the environment path # the path to the "/bin" directory of the Mingw version you want # to use : # # set PATH=C:/Mingw-w32/bin;%PATH% # # - then, scons should be able to detect gcc. # - Mingw-w32 only compiles 32bits. # - Mingw-w64 only compiles 64bits. # # - it is possible to add them both at the same time into the PATH env, # if you also define the MINGW32_PREFIX and MINGW64_PREFIX environment # variables. # For instance, you could store that set of commands into a .bat script # that you would run just before scons : # # set PATH=C:\mingw-w32\bin;%PATH% # set PATH=C:\mingw-w64\bin;%PATH% # set MINGW32_PREFIX=C:\mingw-w32\bin\ # set MINGW64_PREFIX=C:\mingw-w64\bin\ # ##### # Notes about Mingw, Mingw-w64 and Mingw-w32 under Linux : # # - default toolchain prefixes are : # "i586-mingw32msvc-" for MinGW # "i686-w64-mingw32-" for Mingw-w32 # "x86_64-w64-mingw32-" for Mingw-w64 # # - if both MinGW and Mingw-w32 are installed on your system # Mingw-w32 should take the priority over MinGW. # # - it is possible to manually override prefixes by defining # the MINGW32_PREFIX and MINGW64_PREFIX environment variables. # ##### # Notes about Mingw under Windows : # # - this is the MinGW version from http://mingw.org/ # - install it into a path that does not contain spaces # ( example : "C:/MinGW" ) # - several DirectX headers might be missing. You can copy them into # the C:/MinGW/include" directory from this page : # https://code.google.com/p/mingw-lib/source/browse/trunk/working/avcodec_to_widget_5/directx_include/ # - before running scons, add the path to the "/bin" directory : # set PATH=C:/MinGW/bin;%PATH% # - scons should be able to detect gcc. # ##### # TODO : # # - finish to cleanup this script to remove all the remains of previous hacks and workarounds # - make it work with the Windows7 SDK that is supposed to enable 64bits compilation for MSVC2010-Express # - confirm it works well with other Visual Studio versions. # - update the wiki about the pywin32 extension required for the "-j" option under Windows. # - update the wiki to document MINGW32_PREFIX and MINGW64_PREFIX #
""" Basic functions used by several sub-packages and useful to have in the main name-space. Type Handling ------------- ================ =================== iscomplexobj Test for complex object, scalar result isrealobj Test for real object, scalar result iscomplex Test for complex elements, array result isreal Test for real elements, array result imag Imaginary part real Real part real_if_close Turns complex number with tiny imaginary part to real isneginf Tests for negative infinity, array result isposinf Tests for positive infinity, array result isnan Tests for nans, array result isinf Tests for infinity, array result isfinite Tests for finite numbers, array result isscalar True if argument is a scalar nan_to_num Replaces NaN's with 0 and infinities with large numbers cast Dictionary of functions to force cast to each type common_type Determine the minimum common type code for a group of arrays mintypecode Return minimal allowed common typecode. ================ =================== Index Tricks ------------ ================ =================== mgrid Method which allows easy construction of N-d 'mesh-grids' ``r_`` Append and construct arrays: turns slice objects into ranges and concatenates them, for 2d arrays appends rows. index_exp Konrad Hinsen's index_expression class instance which can be useful for building complicated slicing syntax. ================ =================== Useful Functions ---------------- ================ =================== select Extension of where to multiple conditions and choices extract Extract 1d array from flattened array according to mask insert Insert 1d array of values into Nd array according to mask linspace Evenly spaced samples in linear space logspace Evenly spaced samples in logarithmic space fix Round x to nearest integer towards zero mod Modulo mod(x,y) = x % y except keeps sign of y amax Array maximum along axis amin Array minimum along axis ptp Array max-min along axis cumsum Cumulative sum along axis prod Product of elements along axis cumprod Cumluative product along axis diff Discrete differences along axis angle Returns angle of complex argument unwrap Unwrap phase along given axis (1-d algorithm) sort_complex Sort a complex-array (based on real, then imaginary) trim_zeros Trim the leading and trailing zeros from 1D array. vectorize A class that wraps a Python function taking scalar arguments into a generalized function which can handle arrays of arguments using the broadcast rules of numerix Python. ================ =================== Shape Manipulation ------------------ ================ =================== squeeze Return a with length-one dimensions removed. atleast_1d Force arrays to be > 1D atleast_2d Force arrays to be > 2D atleast_3d Force arrays to be > 3D vstack Stack arrays vertically (row on row) hstack Stack arrays horizontally (column on column) column_stack Stack 1D arrays as columns into 2D array dstack Stack arrays depthwise (along third dimension) split Divide array into a list of sub-arrays hsplit Split into columns vsplit Split into rows dsplit Split along third dimension ================ =================== Matrix (2D Array) Manipulations ------------------------------- ================ =================== fliplr 2D array with columns flipped flipud 2D array with rows flipped rot90 Rotate a 2D array a multiple of 90 degrees eye Return a 2D array with ones down a given diagonal diag Construct a 2D array from a vector, or return a given diagonal from a 2D array. mat Construct a Matrix bmat Build a Matrix from blocks ================ =================== Polynomials ----------- ================ =================== poly1d A one-dimensional polynomial class poly Return polynomial coefficients from roots roots Find roots of polynomial given coefficients polyint Integrate polynomial polyder Differentiate polynomial polyadd Add polynomials polysub Substract polynomials polymul Multiply polynomials polydiv Divide polynomials polyval Evaluate polynomial at given argument ================ =================== Import Tricks ------------- ================ =================== ppimport Postpone module import until trying to use it ppimport_attr Postpone module import until trying to use its attribute ppresolve Import postponed module and return it. ================ =================== Machine Arithmetics ------------------- ================ =================== machar_single Single precision floating point arithmetic parameters machar_double Double precision floating point arithmetic parameters ================ =================== Threading Tricks ---------------- ================ =================== ParallelExec Execute commands in parallel thread. ================ =================== 1D Array Set Operations ----------------------- Set operations for 1D numeric arrays based on sort() function. ================ =================== ediff1d Array difference (auxiliary function). unique Unique elements of an array. intersect1d Intersection of 1D arrays with unique elements. setxor1d Set exclusive-or of 1D arrays with unique elements. in1d Test whether elements in a 1D array are also present in another array. union1d Union of 1D arrays with unique elements. setdiff1d Set difference of 1D arrays with unique elements. ================ =================== """
"""Stuff to parse AIFF-C and AIFF files. Unless explicitly stated otherwise, the description below is true both for AIFF-C files and AIFF files. An AIFF-C file has the following structure. +-----------------+ | FORM | +-----------------+ | <size> | +----+------------+ | | AIFC | | +------------+ | | <chunks> | | | . | | | . | | | . | +----+------------+ An AIFF file has the string "AIFF" instead of "AIFC". A chunk consists of an identifier (4 bytes) followed by a size (4 bytes, big endian order), followed by the data. The size field does not include the size of the 8 byte header. The following chunk types are recognized. FVER <version number of AIFF-C defining document> (AIFF-C only). MARK <# of markers> (2 bytes) list of markers: <marker ID> (2 bytes, must be > 0) <position> (4 bytes) <marker name> ("pstring") COMM <# of channels> (2 bytes) <# of sound frames> (4 bytes) <size of the samples> (2 bytes) <sampling frequency> (10 bytes, IEEE 80-bit extended floating point) in AIFF-C files only: <compression type> (4 bytes) <human-readable version of compression type> ("pstring") SSND <offset> (4 bytes, not used by this program) <blocksize> (4 bytes, not used by this program) <sound data> A pstring consists of 1 byte length, a string of characters, and 0 or 1 byte pad to make the total length even. Usage. Reading AIFF files: f = aifc.open(file, 'r') where file is either the name of a file or an open file pointer. The open file pointer must have methods read(), seek(), and close(). In some types of audio files, if the setpos() method is not used, the seek() method is not necessary. This returns an instance of a class with the following public methods: getnchannels() -- returns number of audio channels (1 for mono, 2 for stereo) getsampwidth() -- returns sample width in bytes getframerate() -- returns sampling frequency getnframes() -- returns number of audio frames getcomptype() -- returns compression type ('NONE' for AIFF files) getcompname() -- returns human-readable version of compression type ('not compressed' for AIFF files) getparams() -- returns a tuple consisting of all of the above in the above order getmarkers() -- get the list of marks in the audio file or None if there are no marks getmark(id) -- get mark with the specified id (raises an error if the mark does not exist) readframes(n) -- returns at most n frames of audio rewind() -- rewind to the beginning of the audio stream setpos(pos) -- seek to the specified position tell() -- return the current position close() -- close the instance (make it unusable) The position returned by tell(), the position given to setpos() and the position of marks are all compatible and have nothing to do with the actual position in the file. The close() method is called automatically when the class instance is destroyed. Writing AIFF files: f = aifc.open(file, 'w') where file is either the name of a file or an open file pointer. The open file pointer must have methods write(), tell(), seek(), and close(). This returns an instance of a class with the following public methods: aiff() -- create an AIFF file (AIFF-C default) aifc() -- create an AIFF-C file setnchannels(n) -- set the number of channels setsampwidth(n) -- set the sample width setframerate(n) -- set the frame rate setnframes(n) -- set the number of frames setcomptype(type, name) -- set the compression type and the human-readable compression type setparams(tuple) -- set all parameters at once setmark(id, pos, name) -- add specified mark to the list of marks tell() -- return current position in output file (useful in combination with setmark()) writeframesraw(data) -- write audio frames without pathing up the file header writeframes(data) -- write audio frames and patch up the file header close() -- patch up the file header and close the output file You should set the parameters before the first writeframesraw or writeframes. The total number of frames does not need to be set, but when it is set to the correct value, the header does not have to be patched up. It is best to first set all parameters, perhaps possibly the compression type, and then write audio frames using writeframesraw. When all frames have been written, either call writeframes('') or close() to patch up the sizes in the header. Marks can be added anytime. If there are any marks, ypu must call close() after all frames have been written. The close() method is called automatically when the class instance is destroyed. When a file is opened with the extension '.aiff', an AIFF file is written, otherwise an AIFF-C file is written. This default can be changed by calling aiff() or aifc() before the first writeframes or writeframesraw. """
"""Drag-and-drop support for Tkinter. This is very preliminary. I currently only support dnd *within* one application, between different windows (or within the same window). I an trying to make this as generic as possible -- not dependent on the use of a particular widget or icon type, etc. I also hope that this will work with Pmw. To enable an object to be dragged, you must create an event binding for it that starts the drag-and-drop process. Typically, you should bind <ButtonPress> to a callback function that you write. The function should call Tkdnd.dnd_start(source, event), where 'source' is the object to be dragged, and 'event' is the event that invoked the call (the argument to your callback function). Even though this is a class instantiation, the returned instance should not be stored -- it will be kept alive automatically for the duration of the drag-and-drop. When a drag-and-drop is already in process for the Tk interpreter, the call is *ignored*; this normally averts starting multiple simultaneous dnd processes, e.g. because different button callbacks all dnd_start(). The object is *not* necessarily a widget -- it can be any application-specific object that is meaningful to potential drag-and-drop targets. Potential drag-and-drop targets are discovered as follows. Whenever the mouse moves, and at the start and end of a drag-and-drop move, the Tk widget directly under the mouse is inspected. This is the target widget (not to be confused with the target object, yet to be determined). If there is no target widget, there is no dnd target object. If there is a target widget, and it has an attribute dnd_accept, this should be a function (or any callable object). The function is called as dnd_accept(source, event), where 'source' is the object being dragged (the object passed to dnd_start() above), and 'event' is the most recent event object (generally a <Motion> event; it can also be <ButtonPress> or <ButtonRelease>). If the dnd_accept() function returns something other than None, this is the new dnd target object. If dnd_accept() returns None, or if the target widget has no dnd_accept attribute, the target widget's parent is considered as the target widget, and the search for a target object is repeated from there. If necessary, the search is repeated all the way up to the root widget. If none of the target widgets can produce a target object, there is no target object (the target object is None). The target object thus produced, if any, is called the new target object. It is compared with the old target object (or None, if there was no old target widget). There are several cases ('source' is the source object, and 'event' is the most recent event object): - Both the old and new target objects are None. Nothing happens. - The old and new target objects are the same object. Its method dnd_motion(source, event) is called. - The old target object was None, and the new target object is not None. The new target object's method dnd_enter(source, event) is called. - The new target object is None, and the old target object is not None. The old target object's method dnd_leave(source, event) is called. - The old and new target objects differ and neither is None. The old target object's method dnd_leave(source, event), and then the new target object's method dnd_enter(source, event) is called. Once this is done, the new target object replaces the old one, and the Tk mainloop proceeds. The return value of the methods mentioned above is ignored; if they raise an exception, the normal exception handling mechanisms take over. The drag-and-drop processes can end in two ways: a final target object is selected, or no final target object is selected. When a final target object is selected, it will always have been notified of the potential drop by a call to its dnd_enter() method, as described above, and possibly one or more calls to its dnd_motion() method; its dnd_leave() method has not been called since the last call to dnd_enter(). The target is notified of the drop by a call to its method dnd_commit(source, event). If no final target object is selected, and there was an old target object, its dnd_leave(source, event) method is called to complete the dnd sequence. Finally, the source object is notified that the drag-and-drop process is over, by a call to source.dnd_end(target, event), specifying either the selected target object, or None if no target object was selected. The source object can use this to implement the commit action; this is sometimes simpler than to do it in the target's dnd_commit(). The target's dnd_commit() method could then simply be aliased to dnd_leave(). At any time during a dnd sequence, the application can cancel the sequence by calling the cancel() method on the object returned by dnd_start(). This will call dnd_leave() if a target is currently active; it will never call dnd_commit(). """
# -*- encoding: utf-8 -*- ############################################################################## # # Copyright (c) 2009 Veritos - NAME - www.veritos.nl # # WARNING: This program as such is intended to be used by professional # programmers who take the whole responsability of assessing all potential # consequences resulting from its eventual inadequacies and bugs. # End users who are looking for a ready-to-use solution with commercial # garantees and support are strongly adviced to contract a Free Software # Service Company like Veritos. # # This program is Free Software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # ############################################################################## # # Deze module werkt in OpenERP 5.0.0 (en waarschijnlijk hoger). # Deze module werkt niet in OpenERP versie 4 en lager. # # Status 1.0 - getest op OpenERP 5.0.3 # # Versie IP_ADDRESS # account.account.type # Basis gelegd voor alle account type # # account.account.template # Basis gelegd met alle benodigde grootboekrekeningen welke via een menu- # structuur gelinkt zijn aan rubrieken 1 t/m 9. # De grootboekrekeningen gelinkt aan de account.account.type # Deze links moeten nog eens goed nagelopen worden. # # account.chart.template # Basis gelegd voor het koppelen van rekeningen aan debiteuren, crediteuren, # bank, inkoop en verkoop boeken en de BTW configuratie. # # Versie IP_ADDRESS # account.tax.code.template # Basis gelegd voor de BTW configuratie (structuur) # Heb als basis het BTW aangifte formulier gebruikt. Of dit werkt? # # account.tax.template # De BTW rekeningen aangemaakt en deze gekoppeld aan de betreffende # grootboekrekeningen # # Versie IP_ADDRESS # Opschonen van de code en verwijderen van niet gebruikte componenten. # Versie IP_ADDRESS # Aanpassen a_expense van 3000 -> 7000 # record id='btw_code_5b' op negatieve waarde gezet # Versie IP_ADDRESS # BTW rekeningen hebben typeaanduiding gekregen t.b.v. purchase of sale # Versie IP_ADDRESS # Opschonen van module. # Versie IP_ADDRESS # Opschonen van module. # Versie IP_ADDRESS # Foutje in l10n_nl_wizard.xml gecorrigeerd waardoor de module niet volledig installeerde. # Versie IP_ADDRESS # Account Receivable en Payable goed gedefinieerd. # Versie IP_ADDRESS # Alle user_type_xxx velden goed gedefinieerd. # Specifieke bouw en garage gerelateerde grootboeken verwijderd om een standaard module te creeeren. # Deze module kan dan als basis worden gebruikt voor specifieke doelgroep modules te creeeren. # Versie IP_ADDRESS # Correctie van rekening 7010 (stond dubbel met 7014 waardoor installatie verkeerd ging) # versie IP_ADDRESS # Correctie op diverse rekening types van user_type_asset -> user_type_liability en user_type_equity # versie IP_ADDRESS # Kleine correctie op BTW te vorderen hoog, id was hetzelfde voor beide, waardoor hoog werd overschreven door # overig. Verduidelijking van omschrijvingen in belastingcodes t.b.v. aangifte overzicht. # versie IP_ADDRESS # BTW omschrijvingen aangepast, zodat rapporten er beter uitzien. 2a en 5b e.d. verwijderd en enkele omschrijvingen toegevoegd. # versie IP_ADDRESS - Switch to English # Added properties_stock_xxx accounts for correct stock valuation, changed 7000-accounts from type cash to type expense # Changed naming of 7020 and 7030 to Kostprijs omzet xxxx
""" # Tests for stuff in django.utils.datastructures. >>> from django.utils.datastructures import * ### MergeDict ################################################################# >>> d1 = {'chris':'cool','camri':'cute','cotton':'adorable','tulip':'snuggable', 'twoofme':'firstone'} >>> d2 = {'chris2':'cool2','camri2':'cute2','cotton2':'adorable2','tulip2':'snuggable2'} >>> d3 = {'chris3':'cool3','camri3':'cute3','cotton3':'adorable3','tulip3':'snuggable3'} >>> d4 = {'twoofme':'secondone'} >>> md = MergeDict( d1,d2,d3 ) >>> md['chris'] 'cool' >>> md['camri'] 'cute' >>> md['twoofme'] 'firstone' >>> md2 = md.copy() >>> md2['chris'] 'cool' MergeDict can merge MultiValueDicts >>> multi1 = MultiValueDict({'key1': ['value1'], 'key2': ['value2', 'value3']}) >>> multi2 = MultiValueDict({'key2': ['value4'], 'key4': ['value5', 'value6']}) >>> mm = MergeDict(multi1, multi2) # Although 'key2' appears in both dictionaries, only the first value is used. >>> mm.getlist('key2') ['value2', 'value3'] >>> mm.getlist('key4') ['value5', 'value6'] >>> mm.getlist('undefined') [] ### MultiValueDict ########################################################## >>> d = MultiValueDict({'name': ['Adrian', 'Simon'], 'position': ['Developer']}) >>> d['name'] 'Simon' >>> d.get('name') 'Simon' >>> d.getlist('name') ['Adrian', 'Simon'] >>> d['lastname'] Traceback (most recent call last): ... MultiValueDictKeyError: "Key 'lastname' not found in <MultiValueDict: {'position': ['Developer'], 'name': ['Adrian', 'Simon']}>" >>> d.get('lastname') >>> d.get('lastname', 'nonexistent') 'nonexistent' >>> d.getlist('lastname') [] >>> d.setlist('lastname', ['Holovaty', 'Willison']) >>> d.getlist('lastname') ['Holovaty', 'Willison'] ### SortedDict ################################################################# >>> d = SortedDict() >>> d['one'] = 'one' >>> d['two'] = 'two' >>> d['three'] = 'three' >>> d['one'] 'one' >>> d['two'] 'two' >>> d['three'] 'three' >>> d.keys() ['one', 'two', 'three'] >>> d.values() ['one', 'two', 'three'] >>> d['one'] = 'not one' >>> d['one'] 'not one' >>> d.keys() == d.copy().keys() True >>> d2 = d.copy() >>> d2['four'] = 'four' >>> print repr(d) {'one': 'not one', 'two': 'two', 'three': 'three'} >>> d.pop('one', 'missing') 'not one' >>> d.pop('one', 'missing') 'missing' We don't know which item will be popped in popitem(), so we'll just check that the number of keys has decreased. >>> l = len(d) >>> _ = d.popitem() >>> l - len(d) 1 Init from sequence of tuples >>> d = SortedDict(( ... (1, "one"), ... (0, "zero"), ... (2, "two"))) >>> print repr(d) {1: 'one', 0: 'zero', 2: 'two'} >>> d.clear() >>> d {} >>> d.keyOrder [] ### DotExpandedDict ############################################################ >>> d = DotExpandedDict({'person.1.firstname': ['Simon'], 'person.1.lastname': ['Willison'], 'person.2.firstname': ['Adrian'], 'person.2.lastname': ['Holovaty']}) >>> d['person']['1']['lastname'] ['Willison'] >>> d['person']['2']['lastname'] ['Holovaty'] >>> d['person']['2']['firstname'] ['Adrian'] ### ImmutableList ################################################################ >>> d = ImmutableList(range(10)) >>> d.sort() Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/var/lib/python-support/python2.5/django/utils/datastructures.py", line 359, in complain raise AttributeError, self.warning AttributeError: ImmutableList object is immutable. >>> repr(d) '(0, 1, 2, 3, 4, 5, 6, 7, 8, 9)' >>> d = ImmutableList(range(10), warning="Object is immutable!") >>> d[1] 1 >>> d[1] = 'test' Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/var/lib/python-support/python2.5/django/utils/datastructures.py", line 359, in complain raise AttributeError, self.warning AttributeError: Object is immutable! ### DictWrapper ############################################################# >>> f = lambda x: "*%s" % x >>> d = DictWrapper({'a': 'a'}, f, 'xx_') >>> "Normal: %(a)s. Modified: %(xx_a)s" % d 'Normal: a. Modified: *a' """
#!/usr/bin/python ################################################################################################### # IR Distill # # By: NAME Version: 0.4 # # Description: # IR File Distill is designed to help reduce the amount of output that has to be reviewed during # mass triage. # # Usage APPCACHE/SHIMCACHE: # 1) Gather up SYSTEM hives # 2) Run RegRipper on all system hives. Make sure to use the modified version. # Windows: find {directory with SYSTEM hives} -print -exec rip.exe -r {} -p appcompatcache ; >> appcache{date}.txt # *NIX: find {directory with SYSTEM hives} -print -exec rip.pl -r {} -p appcompatcache \; >> appcache{date}.txt # 3) grep APPCACHE appcache{date}.txt | cut -d\| -f2 | sort | uniq -c | sort -f -t\| -k2 --ignore-case > {filename}.txt # 3a) cat appcache{date}.txt | parallel --pipe grep -a "APPCAC" | | cut -d\| -f2 | sort | uniq -c | sort -f -t\| -k2 --ignore-case > {filename}.txt # 4) ir_distill --sqlite os.sqlite --file {filename}.txt --out {outputfilename} --ignorecase # 5) Review output # # Usage AMCACHE: # 1) Gather up AMCACHE hives # 2) Run RegRipper on all system hives. Make sure to use the modified version. # Windows: find {directory with AMCACHE hives} -print -exec rip.exe -r {} -p amcache3 ; >> amcache{date}.txt # *NIX: find {directory with AMCACHE hives} -print -exec rip.pl -r {} -p amcache3 \; >> amcache{date}.txt # 3) grep -a "Path:" amcache{date}.txt | cut -d\| -f1 | cut -d" " -f2- | sort | uniq -c | sort -f -t\| -k2 --ignore-case > {filename}.txt # cat amcache_051317.txt | parallel --pipe grep -a "Path:" > a # # 4) ir_distill --sqlite os.sqlite --file {filename}.txt --out {outputfilename} --ignorecase # 5) Review output # # # Pull for ecat # grep -a "|km" kmfile.txt | cut -d\| -f2 | sed 's/^/C:/g' > amcache_051317_pull.txt # cat shimcache | cut -d\# -f1 |sed 's/ *$//' | cut -d\| -f 2| sed 's/^/C:/g' > s.pull # Shimcache # sed 's/ *$//' remove the end of line blank spaces # grep -a APPCAC system_051317_applines.txt | fgrep -a -f shimcache_051317_findings.pull | cut -f2,4- | sed 's/Executed//g'|sed 's/\|$//g' | sed 's/||/|/g' > shimcache_051317_findings.newpull.csv # Amcache # grep -a "Path:" # grep -a "Path:" amcache_051317.txt | fgrep -a -f 3 | cut -f1,2 -d\| | cut -f3- -d: | sort | uniq > 4 # sed 's/Path: //g' 4 | sed 's/SHA1: 0000//g' > 5 # ./virustotal-search.py -o output ./5_hashes #Create NSRL DB #1) mv NSRLFile.txt NSRLFile.csv #2) mv NSRLProd.txt NSRLProd.csv #3) sqlite3 nsrl.db #SQLite version 3.22.0 2018-01-22 18:45:57 #Enter ".help" for usage hints. #4) sqlite> .mode csv #5) sqlite> .import NSRLFile.csv nsrl #6) sqlite> .import NSRLProd.csv prod #7) sqlite> CREATE INDEX `sha1` ON `nsrl` ( `SHA-1` COLLATE NOCASE ); #8) sqlite> CREATE INDEX `code` ON `prod` ( `ProductCode` COLLATE NOCASE ); #9) sqlite> CREATE INDEX `apptype` ON `prod` ( `ApplicationType` COLLATE NOCASE ); #10) sqlite> CREATE INDEX `OpSystemCode` ON `prod` ( `OpSystemCode` COLLATE NOCASE ); #11) sqlite> .exit #1) Remove non-ascii characters: perl -i.bak -pe 's/[^[:ascii:]]//g' NSRLFile.txt #2) Rename NSRLFile.txt to nsrl.csv # Rename NSRLProd.txt to prod.csv #3) ./test.py -f nsrl.csv -f NSRLMfg.csv -f NSRLOS.csv -f NSRLProd.csv -o ./nsrl.db #White/Review List Creation #1) echo 'SHA-1|FileName' > review.csv #2) grep AmCache amcache_2019-04-24.txt | awk -v OFS="\|" -F"\|" '{print $8, $7}' >> review.csv #3) sqlite3 review.db #4) sqlite> .mode csv #5) sqlite> .separator "\|" #6) sqlite> .import review.csv review #7) sqlite> CREATE INDEX `sha1` ON `review` ( `SHA-1` COLLATE NOCASE ); #8) sqlite> CREATE INDEX `filename` ON `review` ( `FileName` COLLATE NOCASE ); #9) sqlite> .exit #White/Review List Append to DB #1) echo 'SHA-1|FileName' > review.csv #2) Gather new items for the review/whitelist # grep AmCache amcache_2019-04-24.txt | awk -v OFS="\|" -F"\|" '{print $8, $7}' >> review.csv #3) sqlite3 review.db #4) sqlite> .mode csv #5) sqlite> .separator "\|" #6) sqlite> .import review.csv review #7) sqlite> .exit #ECAT DB Notes #Note: This is very slow compared to creating and running against a SQLite db of the table # 1) *NIX must install unixODBC and FreeTDS; make sure to install the devel for both # 2) pip install pyodbc # 3) /etc/odbc.ini contents: #[MSSQLServer] #Driver = FreeTDS #Description = Any description #Trace = No #Server = xx.xx.xx.xx #Port = 1433 #Database = ECAT$PRIMARY #ECAT SQLite Notes #Note you need to install FreeTDS, unixODBC, and create an /etc/odbc.ini #1) run dbtocsv.py --server {IP} --user {User} --pass {Password} --out {output filename} #2) sqlite3 {db name}.db #3) sqlite> .mode csv #4) sqlite> .import review.csv review #5) sqlite> CREATE INDEX `sha1` ON `review` ( `SHA-1` COLLATE NOCASE ); #6) sqlite> .exit ###################################################################################################
""" This page is in the table of contents. Some filaments contract too much and warp the extruded object. To prevent this you have to print the object in a temperature regulated chamber and/or on a temperature regulated bed. The chamber tool allows you to control the bed and chamber temperature and the holding pressure. The chamber gcodes are also described at: http://reprap.org/wiki/Mendel_User_Manual:_RepRapGCodes The chamber manual page is at: http://fabmetheus.crsndoo.com/wiki/index.php/Skeinforge_Chamber ==Operation== The default 'Activate Chamber' checkbox is on. When it is on, the functions described below will work, when it is off, nothing will be done. ==Settings== ===Bed=== The initial bed temperature is defined by 'Bed Temperature'. If the 'Bed Temperature End Change Height' is greater or equal to the 'Bed Temperature Begin Change Height' and the 'Bed Temperature Begin Change Height' is greater or equal to zero, then the temperature will be ramped toward the 'Bed Temperature End'. The ramp will start once the extruder reaches the 'Bed Temperature Begin Change Height', then the bed temperature will approach the 'Bed Temperature End' as the extruder reaches the 'Bed Temperature End Change Height', finally the bed temperature will stay at the 'Bed Temperature End' for the remainder of the build. ====Bed Temperature==== Default: 60C Defines the initial print bed temperature in Celcius by adding an M140 command. ====Bed Temperature Begin Change Height==== Default: -1 mm Defines the height of the beginning of the temperature ramp. If the 'Bed Temperature End Change Height' is less than zero, the bed temperature will remain at the initial 'Bed Temperature'. ====Bed Temperature End Change Height==== Default: -1 mm Defines the height of the end of the temperature ramp. If the 'Bed Temperature End Change Height' is less than zero or less than the 'Bed Temperature Begin Change Height', the bed temperature will remain at the initial 'Bed Temperature'. ====Bed Temperature End==== Default: 20C Defines the end bed temperature if there is a temperature ramp. ===Chamber Temperature=== Default: 30C Defines the chamber temperature in Celcius by adding an M141 command. ===Holding Force=== Default: 0 Defines the holding pressure of a mechanism, like a vacuum table or electromagnet, to hold the bed surface or object, by adding an M142 command. The holding pressure is in bars. For hardware which only has on/off holding, when the holding pressure is zero, turn off holding, when the holding pressure is greater than zero, turn on holding. ==Heated Beds== ===Bothacker=== A resistor heated aluminum plate by NAME an article at: http://bothacker.com/2009/12/18/heated-build-platform/ ===Domingo=== A heated copper build plate by Domingo: http://casainho-emcrepstrap.blogspot.com/ with articles at: http://casainho-emcrepstrap.blogspot.com/2010/01/first-time-with-pla-testing-it-also-on.html http://casainho-emcrepstrap.blogspot.com/2010/01/call-for-helpideas-to-develop-heated.html http://casainho-emcrepstrap.blogspot.com/2010/01/new-heated-build-platform.html http://casainho-emcrepstrap.blogspot.com/2010/01/no-acrylic-and-instead-kapton-tape-on.html http://casainho-emcrepstrap.blogspot.com/2010/01/problems-with-heated-build-platform-and.html http://casainho-emcrepstrap.blogspot.com/2010/01/perfect-build-platform.html http://casainho-emcrepstrap.blogspot.com/2009/12/almost-no-warp.html http://casainho-emcrepstrap.blogspot.com/2009/12/heated-base-plate.html ===Jmil=== A heated build stage by jmil, over at: http://www.hive76.org with articles at: http://www.hive76.org/handling-hot-build-surfaces http://www.hive76.org/heated-build-stage-success ===Metalab=== A heated base by the Metalab folks: http://reprap.soup.io with information at: http://reprap.soup.io/?search=heated%20base ===Nophead=== A resistor heated aluminum bed by Nophead: http://hydraraptor.blogspot.com with articles at: http://hydraraptor.blogspot.com/2010/01/will-it-stick.html http://hydraraptor.blogspot.com/2010/01/hot-metal-and-serendipity.html http://hydraraptor.blogspot.com/2010/01/new-year-new-plastic.html http://hydraraptor.blogspot.com/2010/01/hot-bed.html ===Prusajr=== A resistive wire heated plexiglass plate by prusajr: http://prusadjs.cz/ with articles at: http://prusadjs.cz/2010/01/heated-reprap-print-bed-mk2/ http://prusadjs.cz/2009/11/look-ma-no-warping-heated-reprap-print-bed/ ===Zaggo=== A resistor heated aluminum plate by Zaggo at Pleasant Software: http://pleasantsoftware.com/developer/3d/ with articles at: http://pleasantsoftware.com/developer/3d/2009/12/05/raftless/ http://pleasantsoftware.com/developer/3d/2009/11/15/living-in-times-of-warp-free-printing/ http://pleasantsoftware.com/developer/3d/2009/11/12/canned-heat/ ==Examples== The following examples chamber the file Screw Holder Bottom.stl. The examples are run in a terminal in the folder which contains Screw Holder Bottom.stl and chamber.py. > python chamber.py This brings up the chamber dialog. > python chamber.py Screw Holder Bottom.stl The chamber tool is parsing the file: Screw Holder Bottom.stl .. The chamber tool has created the file: Screw Holder Bottom_chamber.gcode """
""" ======== Glossary ======== .. glossary:: along an axis Axes are defined for arrays with more than one dimension. A 2-dimensional array has two corresponding axes: the first running vertically downwards across rows (axis 0), and the second running horizontally across columns (axis 1). Many operation can take place along one of these axes. For example, we can sum each row of an array, in which case we operate along columns, or axis 1:: >>> x = np.arange(12).reshape((3,4)) >>> x array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) >>> x.sum(axis=1) array([ 6, 22, 38]) array A homogeneous container of numerical elements. Each element in the array occupies a fixed amount of memory (hence homogeneous), and can be a numerical element of a single type (such as float, int or complex) or a combination (such as ``(float, int, float)``). Each array has an associated data-type (or ``dtype``), which describes the numerical type of its elements:: >>> x = np.array([1, 2, 3], float) >>> x array([ 1., 2., 3.]) >>> x.dtype # floating point number, 64 bits of memory per element dtype('float64') # More complicated data type: each array element is a combination of # and integer and a floating point number >>> np.array([(1, 2.0), (3, 4.0)], dtype=[('x', int), ('y', float)]) array([(1, 2.0), (3, 4.0)], dtype=[('x', '<i4'), ('y', '<f8')]) Fast element-wise operations, called `ufuncs`_, operate on arrays. array_like Any sequence that can be interpreted as an ndarray. This includes nested lists, tuples, scalars and existing arrays. attribute A property of an object that can be accessed using ``obj.attribute``, e.g., ``shape`` is an attribute of an array:: >>> x = np.array([1, 2, 3]) >>> x.shape (3,) BLAS `Basic Linear Algebra Subprograms <http://en.wikipedia.org/wiki/BLAS>`_ broadcast NumPy can do operations on arrays whose shapes are mismatched:: >>> x = np.array([1, 2]) >>> y = np.array([[3], [4]]) >>> x array([1, 2]) >>> y array([[3], [4]]) >>> x + y array([[4, 5], [5, 6]]) See `doc.broadcasting`_ for more information. C order See `row-major` column-major A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In column-major order, the leftmost index "varies the fastest": for example the array:: [[1, 2, 3], [4, 5, 6]] is represented in the column-major order as:: [1, 4, 2, 5, 3, 6] Column-major order is also known as the Fortran order, as the Fortran programming language uses it. decorator An operator that transforms a function. For example, a ``log`` decorator may be defined to print debugging information upon function execution:: >>> def log(f): ... def new_logging_func(*args, **kwargs): ... print("Logging call with parameters:", args, kwargs) ... return f(*args, **kwargs) ... ... return new_logging_func Now, when we define a function, we can "decorate" it using ``log``:: >>> @log ... def add(a, b): ... return a + b Calling ``add`` then yields: >>> add(1, 2) Logging call with parameters: (1, 2) {} 3 dictionary Resembling a language dictionary, which provides a mapping between words and descriptions thereof, a Python dictionary is a mapping between two objects:: >>> x = {1: 'one', 'two': [1, 2]} Here, `x` is a dictionary mapping keys to values, in this case the integer 1 to the string "one", and the string "two" to the list ``[1, 2]``. The values may be accessed using their corresponding keys:: >>> x[1] 'one' >>> x['two'] [1, 2] Note that dictionaries are not stored in any specific order. Also, most mutable (see *immutable* below) objects, such as lists, may not be used as keys. For more information on dictionaries, read the `Python tutorial <http://docs.python.org/tut>`_. Fortran order See `column-major` flattened Collapsed to a one-dimensional array. See `ndarray.flatten`_ for details. immutable An object that cannot be modified after execution is called immutable. Two common examples are strings and tuples. instance A class definition gives the blueprint for constructing an object:: >>> class House(object): ... wall_colour = 'white' Yet, we have to *build* a house before it exists:: >>> h = House() # build a house Now, ``h`` is called a ``House`` instance. An instance is therefore a specific realisation of a class. iterable A sequence that allows "walking" (iterating) over items, typically using a loop such as:: >>> x = [1, 2, 3] >>> [item**2 for item in x] [1, 4, 9] It is often used in combination with ``enumerate``:: >>> keys = ['a','b','c'] >>> for n, k in enumerate(keys): ... print("Key %d: %s" % (n, k)) ... Key 0: a Key 1: b Key 2: c list A Python container that can hold any number of objects or items. The items do not have to be of the same type, and can even be lists themselves:: >>> x = [2, 2.0, "two", [2, 2.0]] The list `x` contains 4 items, each which can be accessed individually:: >>> x[2] # the string 'two' 'two' >>> x[3] # a list, containing an integer 2 and a float 2.0 [2, 2.0] It is also possible to select more than one item at a time, using *slicing*:: >>> x[0:2] # or, equivalently, x[:2] [2, 2.0] In code, arrays are often conveniently expressed as nested lists:: >>> np.array([[1, 2], [3, 4]]) array([[1, 2], [3, 4]]) For more information, read the section on lists in the `Python tutorial <http://docs.python.org/tut>`_. For a mapping type (key-value), see *dictionary*. mask A boolean array, used to select only certain elements for an operation:: >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> mask = (x > 2) >>> mask array([False, False, False, True, True], dtype=bool) >>> x[mask] = -1 >>> x array([ 0, 1, 2, -1, -1]) masked array Array that suppressed values indicated by a mask:: >>> x = np.ma.masked_array([np.nan, 2, np.nan], [True, False, True]) >>> x masked_array(data = [-- 2.0 --], mask = [ True False True], fill_value = 1e+20) <BLANKLINE> >>> x + [1, 2, 3] masked_array(data = [-- 4.0 --], mask = [ True False True], fill_value = 1e+20) <BLANKLINE> Masked arrays are often used when operating on arrays containing missing or invalid entries. matrix A 2-dimensional ndarray that preserves its two-dimensional nature throughout operations. It has certain special operations, such as ``*`` (matrix multiplication) and ``**`` (matrix power), defined:: >>> x = np.mat([[1, 2], [3, 4]]) >>> x matrix([[1, 2], [3, 4]]) >>> x**2 matrix([[ 7, 10], [15, 22]]) method A function associated with an object. For example, each ndarray has a method called ``repeat``:: >>> x = np.array([1, 2, 3]) >>> x.repeat(2) array([1, 1, 2, 2, 3, 3]) ndarray See *array*. record array An `ndarray`_ with `structured data type`_ which has been subclassed as np.recarray and whose dtype is of type np.record, making the fields of its data type to be accessible by attribute. reference If ``a`` is a reference to ``b``, then ``(a is b) == True``. Therefore, ``a`` and ``b`` are different names for the same Python object. row-major A way to represent items in a N-dimensional array in the 1-dimensional computer memory. In row-major order, the rightmost index "varies the fastest": for example the array:: [[1, 2, 3], [4, 5, 6]] is represented in the row-major order as:: [1, 2, 3, 4, 5, 6] Row-major order is also known as the C order, as the C programming language uses it. New NumPy arrays are by default in row-major order. self Often seen in method signatures, ``self`` refers to the instance of the associated class. For example: >>> class Paintbrush(object): ... color = 'blue' ... ... def paint(self): ... print("Painting the city %s!" % self.color) ... >>> p = Paintbrush() >>> p.color = 'red' >>> p.paint() # self refers to 'p' Painting the city red! slice Used to select only certain elements from a sequence:: >>> x = range(5) >>> x [0, 1, 2, 3, 4] >>> x[1:3] # slice from 1 to 3 (excluding 3 itself) [1, 2] >>> x[1:5:2] # slice from 1 to 5, but skipping every second element [1, 3] >>> x[::-1] # slice a sequence in reverse [4, 3, 2, 1, 0] Arrays may have more than one dimension, each which can be sliced individually:: >>> x = np.array([[1, 2], [3, 4]]) >>> x array([[1, 2], [3, 4]]) >>> x[:, 1] array([2, 4]) structured data type A data type composed of other datatypes tuple A sequence that may contain a variable number of types of any kind. A tuple is immutable, i.e., once constructed it cannot be changed. Similar to a list, it can be indexed and sliced:: >>> x = (1, 'one', [1, 2]) >>> x (1, 'one', [1, 2]) >>> x[0] 1 >>> x[:2] (1, 'one') A useful concept is "tuple unpacking", which allows variables to be assigned to the contents of a tuple:: >>> x, y = (1, 2) >>> x, y = 1, 2 This is often used when a function returns multiple values: >>> def return_many(): ... return 1, 'alpha', None >>> a, b, c = return_many() >>> a, b, c (1, 'alpha', None) >>> a 1 >>> b 'alpha' ufunc Universal function. A fast element-wise array operation. Examples include ``add``, ``sin`` and ``logical_or``. view An array that does not own its data, but refers to another array's data instead. For example, we may create a view that only shows every second element of another array:: >>> x = np.arange(5) >>> x array([0, 1, 2, 3, 4]) >>> y = x[::2] >>> y array([0, 2, 4]) >>> x[0] = 3 # changing x changes y as well, since y is a view on x >>> y array([3, 2, 4]) wrapper Python is a high-level (highly abstracted, or English-like) language. This abstraction comes at a price in execution speed, and sometimes it becomes necessary to use lower level languages to do fast computations. A wrapper is code that provides a bridge between high and the low level languages, allowing, e.g., Python to execute code written in C or Fortran. Examples include ctypes, SWIG and Cython (which wraps C and C++) and f2py (which wraps Fortran). """
""" ============= Miscellaneous ============= IEEE 754 Floating Point Special Values -------------------------------------- Special values defined in numpy: nan, inf, NaNs can be used as a poor-man's mask (if you don't care what the original value was) Note: cannot use equality to test NaNs. E.g.: :: >>> myarr = np.array([1., 0., np.nan, 3.]) >>> np.where(myarr == np.nan) >>> np.nan == np.nan # is always False! Use special numpy functions instead. False >>> myarr[myarr == np.nan] = 0. # doesn't work >>> myarr array([ 1., 0., NaN, 3.]) >>> myarr[np.isnan(myarr)] = 0. # use this instead find >>> myarr array([ 1., 0., 0., 3.]) Other related special value functions: :: isinf(): True if value is inf isfinite(): True if not nan or inf nan_to_num(): Map nan to 0, inf to max float, -inf to min float The following corresponds to the usual functions except that nans are excluded from the results: :: nansum() nanmax() nanmin() nanargmax() nanargmin() >>> x = np.arange(10.) >>> x[3] = np.nan >>> x.sum() nan >>> np.nansum(x) 42.0 How numpy handles numerical exceptions -------------------------------------- The default is to ``'warn'`` for ``invalid``, ``divide``, and ``overflow`` and ``'ignore'`` for ``underflow``. But this can be changed, and it can be set individually for different kinds of exceptions. The different behaviors are: - 'ignore' : Take no action when the exception occurs. - 'warn' : Print a `RuntimeWarning` (via the Python `warnings` module). - 'raise' : Raise a `FloatingPointError`. - 'call' : Call a function specified using the `seterrcall` function. - 'print' : Print a warning directly to ``stdout``. - 'log' : Record error in a Log object specified by `seterrcall`. These behaviors can be set for all kinds of errors or specific ones: - all : apply to all numeric exceptions - invalid : when NaNs are generated - divide : divide by zero (for integers as well!) - overflow : floating point overflows - underflow : floating point underflows Note that integer divide-by-zero is handled by the same machinery. These behaviors are set on a per-thread basis. Examples -------- :: >>> oldsettings = np.seterr(all='warn') >>> np.zeros(5,dtype=np.float32)/0. invalid value encountered in divide >>> j = np.seterr(under='ignore') >>> np.array([1.e-100])**10 >>> j = np.seterr(invalid='raise') >>> np.sqrt(np.array([-1.])) FloatingPointError: invalid value encountered in sqrt >>> def errorhandler(errstr, errflag): ... print "saw stupid error!" >>> np.seterrcall(errorhandler) <function err_handler at 0x...> >>> j = np.seterr(all='call') >>> np.zeros(5, dtype=np.int32)/0 FloatingPointError: invalid value encountered in divide saw stupid error! >>> j = np.seterr(**oldsettings) # restore previous ... # error-handling settings Interfacing to C ---------------- Only a survey of the choices. Little detail on how each works. 1) Bare metal, wrap your own C-code manually. - Plusses: - Efficient - No dependencies on other tools - Minuses: - Lots of learning overhead: - need to learn basics of Python C API - need to learn basics of numpy C API - need to learn how to handle reference counting and love it. - Reference counting often difficult to get right. - getting it wrong leads to memory leaks, and worse, segfaults - API will change for Python 3.0! 2) Cython - Plusses: - avoid learning C API's - no dealing with reference counting - can code in pseudo python and generate C code - can also interface to existing C code - should shield you from changes to Python C api - has become the de-facto standard within the scientific Python community - fast indexing support for arrays - Minuses: - Can write code in non-standard form which may become obsolete - Not as flexible as manual wrapping 4) ctypes - Plusses: - part of Python standard library - good for interfacing to existing sharable libraries, particularly Windows DLLs - avoids API/reference counting issues - good numpy support: arrays have all these in their ctypes attribute: :: a.ctypes.data a.ctypes.get_strides a.ctypes.data_as a.ctypes.shape a.ctypes.get_as_parameter a.ctypes.shape_as a.ctypes.get_data a.ctypes.strides a.ctypes.get_shape a.ctypes.strides_as - Minuses: - can't use for writing code to be turned into C extensions, only a wrapper tool. 5) SWIG (automatic wrapper generator) - Plusses: - around a long time - multiple scripting language support - C++ support - Good for wrapping large (many functions) existing C libraries - Minuses: - generates lots of code between Python and the C code - can cause performance problems that are nearly impossible to optimize out - interface files can be hard to write - doesn't necessarily avoid reference counting issues or needing to know API's 7) scipy.weave - Plusses: - can turn many numpy expressions into C code - dynamic compiling and loading of generated C code - can embed pure C code in Python module and have weave extract, generate interfaces and compile, etc. - Minuses: - Future very uncertain: it's the only part of Scipy not ported to Python 3 and is effectively deprecated in favor of Cython. 8) Psyco - Plusses: - Turns pure python into efficient machine code through jit-like optimizations - very fast when it optimizes well - Minuses: - Only on intel (windows?) - Doesn't do much for numpy? Interfacing to Fortran: ----------------------- The clear choice to wrap Fortran code is `f2py <http://docs.scipy.org/doc/numpy-dev/f2py/>`_. Pyfort is an older alternative, but not supported any longer. Fwrap is a newer project that looked promising but isn't being developed any longer. Interfacing to C++: ------------------- 1) Cython 2) CXX 3) Boost.python 4) SWIG 5) SIP (used mainly in PyQT) """
"""Stuff to parse AIFF-C and AIFF files. Unless explicitly stated otherwise, the description below is true both for AIFF-C files and AIFF files. An AIFF-C file has the following structure. +-----------------+ | FORM | +-----------------+ | <size> | +----+------------+ | | AIFC | | +------------+ | | <chunks> | | | . | | | . | | | . | +----+------------+ An AIFF file has the string "AIFF" instead of "AIFC". A chunk consists of an identifier (4 bytes) followed by a size (4 bytes, big endian order), followed by the data. The size field does not include the size of the 8 byte header. The following chunk types are recognized. FVER <version number of AIFF-C defining document> (AIFF-C only). MARK <# of markers> (2 bytes) list of markers: <marker ID> (2 bytes, must be > 0) <position> (4 bytes) <marker name> ("pstring") COMM <# of channels> (2 bytes) <# of sound frames> (4 bytes) <size of the samples> (2 bytes) <sampling frequency> (10 bytes, IEEE 80-bit extended floating point) in AIFF-C files only: <compression type> (4 bytes) <human-readable version of compression type> ("pstring") SSND <offset> (4 bytes, not used by this program) <blocksize> (4 bytes, not used by this program) <sound data> A pstring consists of 1 byte length, a string of characters, and 0 or 1 byte pad to make the total length even. Usage. Reading AIFF files: f = aifc.open(file, 'r') where file is either the name of a file or an open file pointer. The open file pointer must have methods read(), seek(), and close(). In some types of audio files, if the setpos() method is not used, the seek() method is not necessary. This returns an instance of a class with the following public methods: getnchannels() -- returns number of audio channels (1 for mono, 2 for stereo) getsampwidth() -- returns sample width in bytes getframerate() -- returns sampling frequency getnframes() -- returns number of audio frames getcomptype() -- returns compression type ('NONE' for AIFF files) getcompname() -- returns human-readable version of compression type ('not compressed' for AIFF files) getparams() -- returns a namedtuple consisting of all of the above in the above order getmarkers() -- get the list of marks in the audio file or None if there are no marks getmark(id) -- get mark with the specified id (raises an error if the mark does not exist) readframes(n) -- returns at most n frames of audio rewind() -- rewind to the beginning of the audio stream setpos(pos) -- seek to the specified position tell() -- return the current position close() -- close the instance (make it unusable) The position returned by tell(), the position given to setpos() and the position of marks are all compatible and have nothing to do with the actual position in the file. The close() method is called automatically when the class instance is destroyed. Writing AIFF files: f = aifc.open(file, 'w') where file is either the name of a file or an open file pointer. The open file pointer must have methods write(), tell(), seek(), and close(). This returns an instance of a class with the following public methods: aiff() -- create an AIFF file (AIFF-C default) aifc() -- create an AIFF-C file setnchannels(n) -- set the number of channels setsampwidth(n) -- set the sample width setframerate(n) -- set the frame rate setnframes(n) -- set the number of frames setcomptype(type, name) -- set the compression type and the human-readable compression type setparams(tuple) -- set all parameters at once setmark(id, pos, name) -- add specified mark to the list of marks tell() -- return current position in output file (useful in combination with setmark()) writeframesraw(data) -- write audio frames without pathing up the file header writeframes(data) -- write audio frames and patch up the file header close() -- patch up the file header and close the output file You should set the parameters before the first writeframesraw or writeframes. The total number of frames does not need to be set, but when it is set to the correct value, the header does not have to be patched up. It is best to first set all parameters, perhaps possibly the compression type, and then write audio frames using writeframesraw. When all frames have been written, either call writeframes('') or close() to patch up the sizes in the header. Marks can be added anytime. If there are any marks, you must call close() after all frames have been written. The close() method is called automatically when the class instance is destroyed. When a file is opened with the extension '.aiff', an AIFF file is written, otherwise an AIFF-C file is written. This default can be changed by calling aiff() or aifc() before the first writeframes or writeframesraw. """
#!/usr/bin/env python # # This file is part of the pebil project. # # Copyright (c) 2010, University of California Regents # All rights reserved. # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. # # Counter for a folder # /pmaclabs/icepic/ti10_round1_icepic_large_0256/processed_trace # Executable: # AvgCacheCalc.py # # This will calculate the Average of Cache hits for a series of processed metasim files. # # # Usage: # # A number of arguments are needed. The arguments determine how to select the set of files to process # and whether to compute the average across all files or not. # # Either sysid or taskid is required # sysid - calculates a single average for all files with the same sysid # - use with --sysid option to speciy which sysid to use. # - for file icepic_large_0256_0127.sysid44, the sysid is 44 # # taskid - prints an average for each file with the same task id (ie 1 set of averages for for each sysid found) # - use with --taskid option to specify the task id # - for file icepic_large_0256_0127.sysid44, the taskid is 0127 # # # app icepic,hycom,..." # dataset large, standard..." # cpu_count 256,1024,... input will be padded with 0s to 4 digits # Optional: # dir - current dir is used if these argument is not given # As an example take the folder: # /pmaclabs/ti10/ti10_round1_icepic_large_0256/processed_trace # # # SysID mode: #mattl@trebek[21]$ ./AvgCacheCalc.py --app icepic --dataset large --cpu_count 1024 --sysid 99 --dir /pmaclabs/ti10/ti10_round1_icepic_large_1024/processed_trace/ # # # Reading files from: /pmaclabs/ti10/ti10_round1_icepic_large_1024/processed_trace/ # Averaging for all files like icepic_large_1024*.sysid99 # Number of files: 1024 # Cache 1 average %= 98.365459015 incl(98.365459015) # Cache 2 average %= 0.000974823792366 incl(98.3654743948) # Cache 3 average %= 0.0 incl(98.3654743948) # # # TaskID: # mattl@trebek[20]$ ./AvgCacheCalc.py --app icepic --dataset large --cpu_count 1024 --taskid 125 --dir /pmaclabs/ti10/ti10_round1_icepic_large_1024/processed_trace/ # # Reading files from: /pmaclabs/ti10/ti10_round1_icepic_large_1024/processed_trace/ # Averaging for all files like icepic_large_1024_0125* # Number of files: 32 # sysid0 99.5021899287 # sysid3 98.3544410843 98.4873748354 # sysid4 99.0521953314 99.0939555641 # sysid21 98.2867244765 98.496093132 # sysid22 98.8836107446 99.0731860899 99.5543906444 # sysid23 98.086753753 98.4952485239 # sysid44 98.8836107446 99.0772427056 99.5790751053 # sysid54 96.785672042 99.0781143074 # sysid64 98.3544410843 98.4789295449 98.4817196019 # sysid67 74.5078816751 # sysid68 23.7552154266 # sysid69 30.5848561276 # sysid70 33.5335710304 # sysid71 37.710498373 # sysid72 98.2910942185 98.2910942244 98.2910942244 # sysid73 98.3544410843 98.4789295449 98.49290069 # sysid74 98.3544410843 98.4789295449 98.4887431283 # sysid75 98.9182843857 99.0849451175 99.5487031836 # sysid77 98.086753753 98.4769519456 98.4956922971 # sysid78 98.9182843857 99.0849451175 99.1358601016 # sysid81 98.2910942185 98.2910942244 98.2910942244 # sysid82 98.2910942185 98.2910942244 98.2910942244 # sysid96 98.3544410843 98.4789295449 98.4928364694 # sysid97 98.3544410843 98.4789295449 98.492618417 # sysid98 98.2910942185 98.2910942244 98.2910942244 # sysid99 98.2910942185 98.2910942244 98.2910942244 # sysid100 98.3544410843 98.4789295449 98.4884141107 # sysid101 98.3544410843 98.4789295449 98.4884425654 # sysid102 98.2910942185 98.2910942244 98.2910942244 # sysid103 98.2910942185 98.2910942244 98.2910942244 # sysid104 98.086753753 98.4769519456 98.5007917366 # sysid105 98.086753753 98.4769519456 98.4966562518
""" =================== Universal Functions =================== Ufuncs are, generally speaking, mathematical functions or operations that are applied element-by-element to the contents of an array. That is, the result in each output array element only depends on the value in the corresponding input array (or arrays) and on no other array elements. Numpy comes with a large suite of ufuncs, and scipy extends that suite substantially. The simplest example is the addition operator: :: >>> np.array([0,2,3,4]) + np.array([1,1,-1,2]) array([1, 3, 2, 6]) The unfunc module lists all the available ufuncs in numpy. Documentation on the specific ufuncs may be found in those modules. This documentation is intended to address the more general aspects of unfuncs common to most of them. All of the ufuncs that make use of Python operators (e.g., +, -, etc.) have equivalent functions defined (e.g. add() for +) Type coercion ============= What happens when a binary operator (e.g., +,-,\\*,/, etc) deals with arrays of two different types? What is the type of the result? Typically, the result is the higher of the two types. For example: :: float32 + float64 -> float64 int8 + int32 -> int32 int16 + float32 -> float32 float32 + complex64 -> complex64 There are some less obvious cases generally involving mixes of types (e.g. uints, ints and floats) where equal bit sizes for each are not capable of saving all the information in a different type of equivalent bit size. Some examples are int32 vs float32 or uint32 vs int32. Generally, the result is the higher type of larger size than both (if available). So: :: int32 + float32 -> float64 uint32 + int32 -> int64 Finally, the type coercion behavior when expressions involve Python scalars is different than that seen for arrays. Since Python has a limited number of types, combining a Python int with a dtype=np.int8 array does not coerce to the higher type but instead, the type of the array prevails. So the rules for Python scalars combined with arrays is that the result will be that of the array equivalent the Python scalar if the Python scalar is of a higher 'kind' than the array (e.g., float vs. int), otherwise the resultant type will be that of the array. For example: :: Python int + int8 -> int8 Python float + int8 -> float64 ufunc methods ============= Binary ufuncs support 4 methods. **.reduce(arr)** applies the binary operator to elements of the array in sequence. For example: :: >>> np.add.reduce(np.arange(10)) # adds all elements of array 45 For multidimensional arrays, the first dimension is reduced by default: :: >>> np.add.reduce(np.arange(10).reshape(2,5)) array([ 5, 7, 9, 11, 13]) The axis keyword can be used to specify different axes to reduce: :: >>> np.add.reduce(np.arange(10).reshape(2,5),axis=1) array([10, 35]) **.accumulate(arr)** applies the binary operator and generates an an equivalently shaped array that includes the accumulated amount for each element of the array. A couple examples: :: >>> np.add.accumulate(np.arange(10)) array([ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) >>> np.multiply.accumulate(np.arange(1,9)) array([ 1, 2, 6, 24, 120, 720, 5040, 40320]) The behavior for multidimensional arrays is the same as for .reduce(), as is the use of the axis keyword). **.reduceat(arr,indices)** allows one to apply reduce to selected parts of an array. It is a difficult method to understand. See the documentation at: **.outer(arr1,arr2)** generates an outer operation on the two arrays arr1 and arr2. It will work on multidimensional arrays (the shape of the result is the concatenation of the two input shapes.: :: >>> np.multiply.outer(np.arange(3),np.arange(4)) array([[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]) Output arguments ================ All ufuncs accept an optional output array. The array must be of the expected output shape. Beware that if the type of the output array is of a different (and lower) type than the output result, the results may be silently truncated or otherwise corrupted in the downcast to the lower type. This usage is useful when one wants to avoid creating large temporary arrays and instead allows one to reuse the same array memory repeatedly (at the expense of not being able to use more convenient operator notation in expressions). Note that when the output argument is used, the ufunc still returns a reference to the result. >>> x = np.arange(2) >>> np.add(np.arange(2),np.arange(2.),x) array([0, 2]) >>> x array([0, 2]) and & or as ufuncs ================== Invariably people try to use the python 'and' and 'or' as logical operators (and quite understandably). But these operators do not behave as normal operators since Python treats these quite differently. They cannot be overloaded with array equivalents. Thus using 'and' or 'or' with an array results in an error. There are two alternatives: 1) use the ufunc functions logical_and() and logical_or(). 2) use the bitwise operators & and \\|. The drawback of these is that if the arguments to these operators are not boolean arrays, the result is likely incorrect. On the other hand, most usages of logical_and and logical_or are with boolean arrays. As long as one is careful, this is a convenient way to apply these operators. """
# from __future__ import division # # import os # from io import BytesIO # from random import choice # from uuid import uuid4 # # import numpy as np # import unittest2 # from soundfile import * # # from zounds.soundfile import AudioStream, OggVorbis, Resampler # from zounds.timeseries import SR44100 # from featureflow import \ # BaseModel, ByteStream, ByteStreamFeature, Feature, UuidProvider, \ # InMemoryDatabase, StringDelimitedKeyBuilder, PersistenceSettings # from featureflow.nmpy import NumpyFeature # # _sample_rates = (11025, 22050, 44100, 48000, 88200, 96000) # _channels = (1, 2) # _formats = ( # ('WAV', 'PCM_16'), # ('WAV', 'PCM_24'), # ('WAV', 'PCM_32'), # ('WAV', 'FLOAT'), # ('WAV', 'DOUBLE'), # # ('AIFF', 'PCM_16'), # ('AIFF', 'PCM_24'), # ('AIFF', 'PCM_32'), # ('AIFF', 'FLOAT'), # ('AIFF', 'DOUBLE'), # # ('FLAC', 'PCM_16'), # ('FLAC', 'PCM_24'), # # ('OGG', 'VORBIS') # ) # # # class FuzzTests(unittest2.TestCase): # def __init__( # self, chunksize_bytes, samplerate, fmt, subtype, channels, seconds): # # super(FuzzTests, self).__init__() # self._samplerate = samplerate # self._fmt = fmt # self._subtype = subtype # self._seconds = seconds # self._channels = channels # self._chunksize_bytes = chunksize_bytes # # def __repr__(self): # return 'FuzzTests(sr = {_samplerate}, fmt = {_fmt}, st = {_subtype}, secs = {_seconds}, ch = {_channels}, cs = {_chunksize_bytes})'.format( # **self.__dict__) # # def __str__(self): # return self.__repr__() # # def model_cls(self): # # class Settings(PersistenceSettings): # id_provider = UuidProvider() # key_builder = StringDelimitedKeyBuilder() # database = InMemoryDatabase(key_builder=key_builder) # # class Document(BaseModel, Settings): # raw = ByteStreamFeature( # ByteStream, # chunksize=self._chunksize_bytes, # store=False) # # ogg = Feature( # OggVorbis, # needs=raw, # store=True) # # pcm = NumpyFeature( # AudioStream, # needs=raw, # store=True) # # resampled = NumpyFeature( # Resampler, # samplerate=SR44100(), # needs=pcm, # store=True) # # return Document # # def runTest(self): # # TODO: Update this to use BytesIO instead of writing a file to disk # self._fn = '/tmp/' + uuid4().hex # print self # # n_samples = int(self._samplerate * self._seconds) # samples = np.sin(np.arange(0, n_samples * 440, 440) * (2 * np.pi)) # if self._channels == 2: # samples = np.repeat(samples, 2).reshape((n_samples, 2)) # # try: # with SoundFile( # self._fn, # mode='w', # samplerate=self._samplerate, # channels=self._channels, # format=self._fmt, # subtype=self._subtype) as sf: # for i in range(0, n_samples, 44100): # sf.write(samples[i: i + 44100]) # except ValueError as e: # self.fail(e) # # class HasUri(object): # def __init__(self, uri): # self.uri = uri # # model = self.model_cls() # _id = model.process(raw=HasUri(self._fn)) # doc = model(_id) # orig_samples = doc.pcm # self.assertAlmostEqual( # samples.shape[0], orig_samples.shape[0], delta=1) # # del orig_samples # resampled = doc.resampled # seconds = resampled.shape[0] / 44100 # self.assertAlmostEqual(self._seconds, seconds, delta=.025) # del resampled # ogg_bytes = doc.ogg # # # first, do the ogg conversion "by hand" to make sure I'm not missing # # something # bio = BytesIO() # with SoundFile( \ # bio, # format='OGG', # subtype='VORBIS', # mode='w', # samplerate=self._samplerate, # channels=self._channels) as ogg_sf: # for i in xrange(0, n_samples, 44100): # ogg_sf.write(samples[i: i + 44100]) # # bio.seek(0) # ogg_bytes.seek(0) # bio.seek(0) # # with SoundFile(ogg_bytes) as ogg_sf: # ogg_samples = ogg_sf.read(samples.shape[0] + 99999) # # ogg_seconds = ogg_samples.shape[0] / self._samplerate # self.assertAlmostEqual(self._seconds, ogg_seconds, delta=.025) # # def tearDown(self): # os.remove(self._fn) # # # def suite(): # suite = unittest2.TestSuite() # # for _ in xrange(50): # seconds = (np.random.random_sample() * 50) # min_size = 4 * 96000 * 5 * 2 # chunksize = min_size + (np.random.randint(0, 4 * 96000 * 25 * 2)) # samplerate = choice(_sample_rates) # fmt = choice(_formats) # channels = choice(_channels) # suite.addTest( # FuzzTests(chunksize, samplerate, fmt[0], fmt[1], channels, # seconds)) # # return suite # # # if __name__ == '__main__': # unittest2.TextTestRunner().run(suite())
#makeHTML.py version 0.8.1 September 10, 2008 NAME (defaults to paragraph), content="text" style="css style name", id="css id", attributes={named array of attributes for tag} # addAttribute(attributename="name for tag attribute", attributevalue="value for tag attribute") # addPart(code, content, style, id, attributes): adds at end # addPiece(thePart=another part object or "content text") # addPieces(pices=a list of part objects or content texts) # insertPart(code, content, style, id, attributes): inserts at start # insertPiece(thePart) # make(tab="initial tabs") # makePart(code, content, style, id, attributes): returns a part object # __len__: parts support the len() function; return number of pieces directly contained #snippet(code (defaults to "em"), content, posttext="text that comes directly after tag", pretext="text that comes directly before tag", style, id, attributes) # #head(title="text for title of page") #body(title="text for main headline", style, id, attributes) #page(pieces, style, id, attributes) #styleSheet(sheet="url of stylesheet", media="relevance of style sheet") # #headline(content="text content" (required), level="numerical level", style, id, attributes) # #table(rows=list of data for rows, style, thStyle="css style for table headers", tdStyle="css style for table cells", # trStyle="css style for table rows", tdBlankStyle="css style for blank cells", firstRowHeader=1--if first row is a header row, # firstColumnHeader=1--if first column is a header column, id, attributes) # addRow(rowList=[list of cells or data], celltype="th or td", cellclass="css style of cells", attributes, style) # addRows(rows=[list of list of cells or data], celltype, cellclass, attributes) # columnCount() #tableByColumn(columns=[list of columns], style, thStyle, tdStyle, trStyle, tdBlankStyle, firstRowHeader, firstColumnHeader, id, attributes) # addColumn(columnList=[list of column data or cells], celltype, cellclass, attributes) # addColumns(columns=[list of list of columns or column data], celltype, cellclass, attributes) #tableColumn(column=[list of data or cells for column], celltype, cellclass, firstRowHeader, thStyle, tdBlankStyle, attributes) # addCell(cell="cell or cell content", celltype, cellclass, id, attributes) # addCells(column="list of cells or cell contents", celltype, cellclass, attributes) #tableRow(celltype, row=[list of cells or cell data], style, cellclass, firstColumnHeader, thStyle, id, attributes) # addCell(cell="cell or cell content", celltype, cellclass, colspan="numerical span of cell vertically", rowspan="numerical span of cell horizontally") # addCells(cells=[list of cells or cell content]) # columnCount() # #linkedList(links=[list of items of the form [url, name]], outer="outer html tag", inner="inner html tag", style="outer css style", # iclass="inner css style", id, attributes) # addLink(link=[url, name]) # addLinks(links) #simpleList(items=[list of text items], outer, inner, defaultname="text for marking default entry", default="text of default entry", # style, iclass, id, attributes) # addItem(item="text of item") # addItems(items) # #image(src="url of image", alt="alternate text for image", align="alignment", style, id, attributes) #link(content, url, posttext, pretext, style, id, attributes) # #form(submitText="text of submit button", pieces, method="submit method", action="form action", submitName="name for submit button", submitAction="javascript for submission" # headline="headline text", headlineLevel (defaults to 2), style, attributes, id) #input(type="type of form input", name="name for input", value="default value for input", size="size for input", maxlength="maximum characters accepted", # style, id, attributes) #select(name, items, default, style, iclass, id, attributes #textinput(name, text, value, size, maxlength, style, id, attributes, type, tableRow=true if this should be a tr row, otherwise it is a paragraph) #basic parts
# -*- encoding: utf-8 -*- # back ported from CPython 3 # A. HISTORY OF THE SOFTWARE # ========================== # # Python was created in the early 1990s by NAME at Stichting # Mathematisch Centrum (CWI, see http://www.cwi.nl) in the Netherlands # as a successor of a language called ABC. NAME remains Python's # principal author, although it includes many contributions from others. # # In 1995, NAME continued his work on Python at the Corporation for # National Research Initiatives (CNRI, see http://www.cnri.reston.va.us) # in Reston, Virginia where he released several versions of the # software. # # In May 2000, NAME and the Python core development team moved to # BeOpen.com to form the BeOpen PythonLabs team. In October of the same # year, the PythonLabs team moved to Digital Creations (now Zope # Corporation, see http://www.zope.com). In 2001, the Python Software # Foundation (PSF, see http://www.python.org/psf/) was formed, a # non-profit organization created specifically to own Python-related # Intellectual Property. Zope Corporation is a sponsoring member of # the PSF. # # All Python releases are Open Source (see http://www.opensource.org for # the Open Source Definition). Historically, most, but not all, Python # releases have also been GPL-compatible; the table below summarizes # the various releases. # # Release Derived Year Owner GPL- # from compatible? (1) # # 0.9.0 thru 1.2 1991-1995 CWI yes # 1.3 thru 1.5.2 1.2 1995-1999 CNRI yes # 1.6 1.5.2 2000 CNRI no # 2.0 1.6 2000 BeOpen.com no # 1.6.1 1.6 2001 CNRI yes (2) # 2.1 2.0+1.6.1 2001 PSF no # 2.0.1 2.0+1.6.1 2001 PSF yes # 2.1.1 2.1+2.0.1 2001 PSF yes # 2.2 2.1.1 2001 PSF yes # 2.1.2 2.1.1 2002 PSF yes # 2.1.3 2.1.2 2002 PSF yes # 2.2.1 2.2 2002 PSF yes # 2.2.2 2.2.1 2002 PSF yes # 2.2.3 2.2.2 2003 PSF yes # 2.3 2.2.2 2002-2003 PSF yes # 2.3.1 2.3 2002-2003 PSF yes # 2.3.2 2.3.1 2002-2003 PSF yes # 2.3.3 2.3.2 2002-2003 PSF yes # 2.3.4 2.3.3 2004 PSF yes # 2.3.5 2.3.4 2005 PSF yes # 2.4 2.3 2004 PSF yes # 2.4.1 2.4 2005 PSF yes # 2.4.2 2.4.1 2005 PSF yes # 2.4.3 2.4.2 2006 PSF yes # 2.4.4 2.4.3 2006 PSF yes # 2.5 2.4 2006 PSF yes # 2.5.1 2.5 2007 PSF yes # 2.5.2 2.5.1 2008 PSF yes # 2.5.3 2.5.2 2008 PSF yes # 2.6 2.5 2008 PSF yes # 2.6.1 2.6 2008 PSF yes # 2.6.2 2.6.1 2009 PSF yes # 2.6.3 2.6.2 2009 PSF yes # 2.6.4 2.6.3 2009 PSF yes # 2.6.5 2.6.4 2010 PSF yes # 2.7 2.6 2010 PSF yes # # Footnotes: # # (1) GPL-compatible doesn't mean that we're distributing Python under # the GPL. All Python licenses, unlike the GPL, let you distribute # a modified version without making your changes open source. The # GPL-compatible licenses make it possible to combine Python with # other software that is released under the GPL; the others don't. # # (2) According to NAME 1.6.1 is not GPL-compatible, # because its license has a choice of law clause. According to # CNRI, however, Stallman's lawyer has told CNRI's lawyer that 1.6.1 # is "not incompatible" with the GPL. # # Thanks to the many outside volunteers who have worked under NAME's # direction to make these releases possible. # # # B. TERMS AND CONDITIONS FOR ACCESSING OR OTHERWISE USING PYTHON # =============================================================== # # PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 # -------------------------------------------- # # 1. This LICENSE AGREEMENT is between the Python Software Foundation # ("PSF"), and the Individual or Organization ("Licensee") accessing and # otherwise using this software ("Python") in source or binary form and # its associated documentation. # # 2. Subject to the terms and conditions of this License Agreement, PSF hereby # grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, # analyze, test, perform and/or display publicly, prepare derivative works, # distribute, and otherwise use Python alone or in any derivative version, # provided, however, that PSF's License Agreement and PSF's notice of copyright, # i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012, 2013 Python Software Foundation; All Rights Reserved" are retained # in Python alone or in any derivative version prepared by Licensee. # # 3. In the event Licensee prepares a derivative work that is based on # or incorporates Python or any part thereof, and wants to make # the derivative work available to others as provided herein, then # Licensee hereby agrees to include in any such work a brief summary of # the changes made to Python. # # 4. PSF is making Python available to Licensee on an "AS IS" # basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR # IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND # DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS # FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT # INFRINGE ANY THIRD PARTY RIGHTS. # # 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON # FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS # A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, # OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. # # 6. This License Agreement will automatically terminate upon a material # breach of its terms and conditions. # # 7. Nothing in this License Agreement shall be deemed to create any # relationship of agency, partnership, or joint venture between PSF and # Licensee. This License Agreement does not grant permission to use PSF # trademarks or trade name in a trademark sense to endorse or promote # products or services of Licensee, or any third party. # # 8. By copying, installing or otherwise using Python, Licensee # agrees to be bound by the terms and conditions of this License # Agreement. # # # BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0 # ------------------------------------------- # # BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1 # # 1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an # office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the # Individual or Organization ("Licensee") accessing and otherwise using # this software in source or binary form and its associated # documentation ("the Software"). # # 2. Subject to the terms and conditions of this BeOpen Python License # Agreement, BeOpen hereby grants Licensee a non-exclusive, # royalty-free, world-wide license to reproduce, analyze, test, perform # and/or display publicly, prepare derivative works, distribute, and # otherwise use the Software alone or in any derivative version, # provided, however, that the BeOpen Python License is retained in the # Software, alone or in any derivative version prepared by Licensee. # # 3. BeOpen is making the Software available to Licensee on an "AS IS" # basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR # IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND # DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS # FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT # INFRINGE ANY THIRD PARTY RIGHTS. # # 4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE # SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS # AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY # DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. # # 5. This License Agreement will automatically terminate upon a material # breach of its terms and conditions. # # 6. This License Agreement shall be governed by and interpreted in all # respects by the law of the State of California, excluding conflict of # law provisions. Nothing in this License Agreement shall be deemed to # create any relationship of agency, partnership, or joint venture # between BeOpen and Licensee. This License Agreement does not grant # permission to use BeOpen trademarks or trade names in a trademark # sense to endorse or promote products or services of Licensee, or any # third party. As an exception, the "BeOpen Python" logos available at # http://www.pythonlabs.com/logos.html may be used according to the # permissions granted on that web page. # # 7. By copying, installing or otherwise using the software, Licensee # agrees to be bound by the terms and conditions of this License # Agreement. # # # CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1 # --------------------------------------- # # 1. This LICENSE AGREEMENT is between the Corporation for National # Research Initiatives, having an office at 1895 Preston White Drive, # Reston, VA 20191 ("CNRI"), and the Individual or Organization # ("Licensee") accessing and otherwise using Python 1.6.1 software in # source or binary form and its associated documentation. # # 2. Subject to the terms and conditions of this License Agreement, CNRI # hereby grants Licensee a nonexclusive, royalty-free, world-wide # license to reproduce, analyze, test, perform and/or display publicly, # prepare derivative works, distribute, and otherwise use Python 1.6.1 # alone or in any derivative version, provided, however, that CNRI's # License Agreement and CNRI's notice of copyright, i.e., "Copyright (c) # 1995-2001 Corporation for National Research Initiatives; All Rights # Reserved" are retained in Python 1.6.1 alone or in any derivative # version prepared by Licensee. Alternately, in lieu of CNRI's License # Agreement, Licensee may substitute the following text (omitting the # quotes): "Python 1.6.1 is made available subject to the terms and # conditions in CNRI's License Agreement. This Agreement together with # Python 1.6.1 may be located on the Internet using the following # unique, persistent identifier (known as a handle): 1895.22/1013. This # Agreement may also be obtained from a proxy server on the Internet # using the following URL: http://hdl.handle.net/1895.22/1013". # # 3. In the event Licensee prepares a derivative work that is based on # or incorporates Python 1.6.1 or any part thereof, and wants to make # the derivative work available to others as provided herein, then # Licensee hereby agrees to include in any such work a brief summary of # the changes made to Python 1.6.1. # # 4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS" # basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR # IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND # DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS # FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT # INFRINGE ANY THIRD PARTY RIGHTS. # # 5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON # 1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS # A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1, # OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. # # 6. This License Agreement will automatically terminate upon a material # breach of its terms and conditions. # # 7. This License Agreement shall be governed by the federal # intellectual property law of the United States, including without # limitation the federal copyright law, and, to the extent such # U.S. federal law does not apply, by the law of the Commonwealth of # Virginia, excluding Virginia's conflict of law provisions. # Notwithstanding the foregoing, with regard to derivative works based # on Python 1.6.1 that incorporate non-separable material that was # previously distributed under the GNU General Public License (GPL), the # law of the Commonwealth of Virginia shall govern this License # Agreement only as to issues arising under or with respect to # Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this # License Agreement shall be deemed to create any relationship of # agency, partnership, or joint venture between CNRI and Licensee. This # License Agreement does not grant permission to use CNRI trademarks or # trade name in a trademark sense to endorse or promote products or # services of Licensee, or any third party. # # 8. By clicking on the "ACCEPT" button where indicated, or by copying, # installing or otherwise using Python 1.6.1, Licensee agrees to be # bound by the terms and conditions of this License Agreement. # # ACCEPT # # # CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2 # -------------------------------------------------- # # Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam, # The Netherlands. All rights reserved. # # Permission to use, copy, modify, and distribute this software and its # documentation for any purpose and without fee is hereby granted, # provided that the above copyright notice appear in all copies and that # both that copyright notice and this permission notice appear in # supporting documentation, and that the name of Stichting Mathematisch # Centrum or CWI not be used in advertising or publicity pertaining to # distribution of the software without specific, written prior # permission. # # STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO # THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND # FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE # FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT # OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# REQUIRES: python-psutil # llvm.org/PR33944 # UNSUPPORTED: system-windows # FIXME: This test is fragile because it relies on time which can # be affected by system performance. In particular we are currently # assuming that `short.py` can be successfully executed within 2 # seconds of wallclock time. # Test per test timeout using external shell # RUN: not %{lit} \ # RUN: %{inputs}/shtest-timeout/infinite_loop.py \ # RUN: %{inputs}/shtest-timeout/short.py \ # RUN: -j 1 -v --debug --timeout 2 --param external=1 > %t.extsh.out 2> %t.extsh.err # RUN: FileCheck --check-prefix=CHECK-OUT-COMMON < %t.extsh.out %s # RUN: FileCheck --check-prefix=CHECK-EXTSH-ERR < %t.extsh.err %s # # CHECK-EXTSH-ERR: Using external shell # Test per test timeout using internal shell # RUN: not %{lit} \ # RUN: %{inputs}/shtest-timeout/infinite_loop.py \ # RUN: %{inputs}/shtest-timeout/short.py \ # RUN: -j 1 -v --debug --timeout 2 --param external=0 > %t.intsh.out 2> %t.intsh.err # RUN: FileCheck --check-prefix=CHECK-OUT-COMMON < %t.intsh.out %s # RUN: FileCheck --check-prefix=CHECK-INTSH-OUT < %t.intsh.out %s # RUN: FileCheck --check-prefix=CHECK-INTSH-ERR < %t.intsh.err %s # CHECK-INTSH-OUT: TIMEOUT: per_test_timeout :: infinite_loop.py # CHECK-INTSH-OUT: command output: # CHECK-INTSH-OUT: command reached timeout: True # CHECK-INTSH-ERR: Using internal shell # Test per test timeout set via a config file rather than on the command line # RUN: not %{lit} \ # RUN: %{inputs}/shtest-timeout/infinite_loop.py \ # RUN: %{inputs}/shtest-timeout/short.py \ # RUN: -j 1 -v --debug --param external=0 \ # RUN: --param set_timeout=2 > %t.cfgset.out 2> %t.cfgset.err # RUN: FileCheck --check-prefix=CHECK-OUT-COMMON < %t.cfgset.out %s # RUN: FileCheck --check-prefix=CHECK-CFGSET-ERR < %t.cfgset.err %s # # CHECK-CFGSET-ERR: Using internal shell # CHECK-OUT-COMMON: TIMEOUT: per_test_timeout :: infinite_loop.py # CHECK-OUT-COMMON: Timeout: Reached timeout of 2 seconds # CHECK-OUT-COMMON: Command {{([0-9]+ )?}}Output # CHECK-OUT-COMMON: PASS: per_test_timeout :: short.py # CHECK-OUT-COMMON: Expected Passes{{ *}}: 1 # CHECK-OUT-COMMON: Individual Timeouts{{ *}}: 1 # Test per test timeout via a config file and on the command line. # The value set on the command line should override the config file. # RUN: not %{lit} \ # RUN: %{inputs}/shtest-timeout/infinite_loop.py \ # RUN: %{inputs}/shtest-timeout/short.py \ # RUN: -j 1 -v --debug --param external=0 \ # RUN: --param set_timeout=1 --timeout=2 > %t.cmdover.out 2> %t.cmdover.err # RUN: FileCheck --check-prefix=CHECK-CMDLINE-OVERRIDE-OUT < %t.cmdover.out %s # RUN: FileCheck --check-prefix=CHECK-CMDLINE-OVERRIDE-ERR < %t.cmdover.err %s # CHECK-CMDLINE-OVERRIDE-ERR: Forcing timeout to be 2 seconds # CHECK-CMDLINE-OVERRIDE-OUT: TIMEOUT: per_test_timeout :: infinite_loop.py # CHECK-CMDLINE-OVERRIDE-OUT: Timeout: Reached timeout of 2 seconds # CHECK-CMDLINE-OVERRIDE-OUT: Command {{([0-9]+ )?}}Output # CHECK-CMDLINE-OVERRIDE-OUT: PASS: per_test_timeout :: short.py # CHECK-CMDLINE-OVERRIDE-OUT: Expected Passes{{ *}}: 1 # CHECK-CMDLINE-OVERRIDE-OUT: Individual Timeouts{{ *}}: 1
""" GraphPath package. Modules: ======== * expr: the GraphPath language steps and operators * entail: the inference machinery: RuleBase and Sandbox * redadapt: apply GraphPath expressions to Redland RDF framework * libadapt: apply GraphPath expressions to rdflib RDF framework * util: (package) support for and testing of graphpath Example ======= .. code-block:: pycon >>> from graphpath.util.anyrdf import Population, Namespace, uriref >>> from graphpath.expr import Class >>> from graphpath.expr import HasNo >>> from graphpath.expr import Map >>> from graphpath.expr import Node >>> from graphpath.expr import Nodes >>> from graphpath.expr import Property >>> from graphpath.expr import Self >>> from graphpath.expr import Subject >>> from graphpath.entail import RuleBase >>> ex = Namespace("#") >>> samples = Population() >>> rules = RuleBase() >>> def add(set, prop, *values): ... for member in set: ... for value in values: ... samples.add(member, prop, value) >>> girls = set([ex.pauline, ex.annette, ex.lisa, ex.julie, ex.nalda, ... ex.lillian, ex.rene]) >>> boys = set([ex.arnold, ex.john, ex.jack, ex.george]) >>> child_of_nalda_john = set( ... [ex.arnold, ex.pauline, ex.annette, ex.lisa, ex.julie]) ... >>> child_of_lil_geo = set([ex.nalda]) >>> child_of_rene_jack = set([ex.john]) >>> nalda_john = set([ex.john, ex.nalda]) >>> grandparents = set([ex.rene, ex.jack, ex.lillian, ex.george]) >>> add(girls, samples.rdf_type, ex.Female) >>> add(boys, samples.rdf_type, ex.Male) >>> add(child_of_nalda_john, ex.parent, *nalda_john) >>> add(child_of_lil_geo, ex.parent, ex.lillian, ex.george) >>> add(child_of_rene_jack, ex.parent, ex.rene, ex.jack) >>> for person in girls | boys: ... samples.add(person, ex.name, uriref(person)[1:]) ... samples.add(person, ex.initial, uriref(person)[1]) ... samples.add(ex.bindi, samples.rdf_type, ex.Dog) ... samples.add(ex.annette, ex.pet, ex.bindi) ... relation = set([(uriref(person)[1], uriref(person)[1:]) ... for person in child_of_nalda_john]) ... >>> rules[Class(ex.Person)] = Class(ex.Male) | Class(ex.Female) >>> rules[Property(ex.child)] = ~Property(ex.parent) >>> rules[Property(ex.hasMother)] = Property(ex.parent)[Class(ex.Female)] >>> rules[Property(ex.descendant)] = Property( ... ex.child) | Property( ... ex.descendant) / Property(ex.descendant) ... >>> rules[Property(ex.family)] = Self() | Property( ... ex.child) / Property(ex.family) | Property( ... ex.parent) / Property(ex.family) >>> print("population:") population: >>> print("-----------") ----------- >>> for subject in samples: ... print(subject) ... for predicate, value in samples[subject]: ... print(" has %s of %s" % ( ... predicate, repr(value))) #doctest: +SKIP #julie has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #parent of '#nalda' has #parent of '#john' has #name of 'julie' has #initial of 'j' #pauline has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #parent of '#nalda' has #parent of '#john' has #name of 'pauline' has #initial of 'p' #john has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Male' has #parent of '#rene' has #parent of '#jack' has #name of 'john' has #initial of 'j' #lillian has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #name of 'lillian' has #initial of 'l' #lisa has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #parent of '#nalda' has #parent of '#john' has #name of 'lisa' has #initial of 'l' #arnold has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Male' has #parent of '#nalda' has #parent of '#john' has #name of 'arnold' has #initial of 'a' #george has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Male' has #name of 'george' has #initial of 'g' #rene has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #name of 'rene' has #initial of 'r' #nalda has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #parent of '#lillian' has #parent of '#george' has #name of 'nalda' has #initial of 'n' #bindi has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Dog' #annette has #pet of '#bindi' has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Female' has #parent of '#nalda' has #parent of '#john' has #name of 'annette' has #initial of 'a' #jack has http://www.w3.org/1999/02/22-rdf-syntax-ns#type of '#Male' has #name of 'jack' has #initial of 'j' >>> print("rules:") rules: >>> print("------") ------ >>> for rule in rules: ... print("%s = %s" % (rule, rules[rule])) #doctest: +SKIP Class('#Person') = (Class('#Male')|Class('#Female')) Property('#family') = ((Any() | Property('#child') / Property('#family') ) | Property('#parent') / Property('#family')) Property('#child') = (~Property('#parent')) Property('#hasMother') = Property('#parent')[Class('#Female')] Property('#descendant') = (Property('#child' ) | Property('#descendant') / Property('#descendant')) """
""" =================== Universal Functions =================== Ufuncs are, generally speaking, mathematical functions or operations that are applied element-by-element to the contents of an array. That is, the result in each output array element only depends on the value in the corresponding input array (or arrays) and on no other array elements. Numpy comes with a large suite of ufuncs, and scipy extends that suite substantially. The simplest example is the addition operator: :: >>> np.array([0,2,3,4]) + np.array([1,1,-1,2]) array([1, 3, 2, 6]) The unfunc module lists all the available ufuncs in numpy. Documentation on the specific ufuncs may be found in those modules. This documentation is intended to address the more general aspects of unfuncs common to most of them. All of the ufuncs that make use of Python operators (e.g., +, -, etc.) have equivalent functions defined (e.g. add() for +) Type coercion ============= What happens when a binary operator (e.g., +,-,\\*,/, etc) deals with arrays of two different types? What is the type of the result? Typically, the result is the higher of the two types. For example: :: float32 + float64 -> float64 int8 + int32 -> int32 int16 + float32 -> float32 float32 + complex64 -> complex64 There are some less obvious cases generally involving mixes of types (e.g. uints, ints and floats) where equal bit sizes for each are not capable of saving all the information in a different type of equivalent bit size. Some examples are int32 vs float32 or uint32 vs int32. Generally, the result is the higher type of larger size than both (if available). So: :: int32 + float32 -> float64 uint32 + int32 -> int64 Finally, the type coercion behavior when expressions involve Python scalars is different than that seen for arrays. Since Python has a limited number of types, combining a Python int with a dtype=np.int8 array does not coerce to the higher type but instead, the type of the array prevails. So the rules for Python scalars combined with arrays is that the result will be that of the array equivalent the Python scalar if the Python scalar is of a higher 'kind' than the array (e.g., float vs. int), otherwise the resultant type will be that of the array. For example: :: Python int + int8 -> int8 Python float + int8 -> float64 ufunc methods ============= Binary ufuncs support 4 methods. **.reduce(arr)** applies the binary operator to elements of the array in sequence. For example: :: >>> np.add.reduce(np.arange(10)) # adds all elements of array 45 For multidimensional arrays, the first dimension is reduced by default: :: >>> np.add.reduce(np.arange(10).reshape(2,5)) array([ 5, 7, 9, 11, 13]) The axis keyword can be used to specify different axes to reduce: :: >>> np.add.reduce(np.arange(10).reshape(2,5),axis=1) array([10, 35]) **.accumulate(arr)** applies the binary operator and generates an an equivalently shaped array that includes the accumulated amount for each element of the array. A couple examples: :: >>> np.add.accumulate(np.arange(10)) array([ 0, 1, 3, 6, 10, 15, 21, 28, 36, 45]) >>> np.multiply.accumulate(np.arange(1,9)) array([ 1, 2, 6, 24, 120, 720, 5040, 40320]) The behavior for multidimensional arrays is the same as for .reduce(), as is the use of the axis keyword). **.reduceat(arr,indices)** allows one to apply reduce to selected parts of an array. It is a difficult method to understand. See the documentation at: **.outer(arr1,arr2)** generates an outer operation on the two arrays arr1 and arr2. It will work on multidimensional arrays (the shape of the result is the concatenation of the two input shapes.: :: >>> np.multiply.outer(np.arange(3),np.arange(4)) array([[0, 0, 0, 0], [0, 1, 2, 3], [0, 2, 4, 6]]) Output arguments ================ All ufuncs accept an optional output array. The array must be of the expected output shape. Beware that if the type of the output array is of a different (and lower) type than the output result, the results may be silently truncated or otherwise corrupted in the downcast to the lower type. This usage is useful when one wants to avoid creating large temporary arrays and instead allows one to reuse the same array memory repeatedly (at the expense of not being able to use more convenient operator notation in expressions). Note that when the output argument is used, the ufunc still returns a reference to the result. >>> x = np.arange(2) >>> np.add(np.arange(2),np.arange(2.),x) array([0, 2]) >>> x array([0, 2]) and & or as ufuncs ================== Invariably people try to use the python 'and' and 'or' as logical operators (and quite understandably). But these operators do not behave as normal operators since Python treats these quite differently. They cannot be overloaded with array equivalents. Thus using 'and' or 'or' with an array results in an error. There are two alternatives: 1) use the ufunc functions logical_and() and logical_or(). 2) use the bitwise operators & and \\|. The drawback of these is that if the arguments to these operators are not boolean arrays, the result is likely incorrect. On the other hand, most usages of logical_and and logical_or are with boolean arrays. As long as one is careful, this is a convenient way to apply these operators. """
""" =============== Array Internals =============== Internal organization of numpy arrays ===================================== It helps to understand a bit about how numpy arrays are handled under the covers to help understand numpy better. This section will not go into great detail. Those wishing to understand the full details are referred to Travis Oliphant's book "Guide to Numpy". Numpy arrays consist of two major components, the raw array data (from now on, referred to as the data buffer), and the information about the raw array data. The data buffer is typically what people think of as arrays in C or Fortran, a contiguous (and fixed) block of memory containing fixed sized data items. Numpy also contains a significant set of data that describes how to interpret the data in the data buffer. This extra information contains (among other things): 1) The basic data element's size in bytes 2) The start of the data within the data buffer (an offset relative to the beginning of the data buffer). 3) The number of dimensions and the size of each dimension 4) The separation between elements for each dimension (the 'stride'). This does not have to be a multiple of the element size 5) The byte order of the data (which may not be the native byte order) 6) Whether the buffer is read-only 7) Information (via the dtype object) about the interpretation of the basic data element. The basic data element may be as simple as a int or a float, or it may be a compound object (e.g., struct-like), a fixed character field, or Python object pointers. 8) Whether the array is to interpreted as C-order or Fortran-order. This arrangement allow for very flexible use of arrays. One thing that it allows is simple changes of the metadata to change the interpretation of the array buffer. Changing the byteorder of the array is a simple change involving no rearrangement of the data. The shape of the array can be changed very easily without changing anything in the data buffer or any data copying at all Among other things that are made possible is one can create a new array metadata object that uses the same data buffer to create a new view of that data buffer that has a different interpretation of the buffer (e.g., different shape, offset, byte order, strides, etc) but shares the same data bytes. Many operations in numpy do just this such as slices. Other operations, such as transpose, don't move data elements around in the array, but rather change the information about the shape and strides so that the indexing of the array changes, but the data in the doesn't move. Typically these new versions of the array metadata but the same data buffer are new 'views' into the data buffer. There is a different ndarray object, but it uses the same data buffer. This is why it is necessary to force copies through use of the .copy() method if one really wants to make a new and independent copy of the data buffer. New views into arrays mean the the object reference counts for the data buffer increase. Simply doing away with the original array object will not remove the data buffer if other views of it still exist. Multidimensional Array Indexing Order Issues ============================================ What is the right way to index multi-dimensional arrays? Before you jump to conclusions about the one and true way to index multi-dimensional arrays, it pays to understand why this is a confusing issue. This section will try to explain in detail how numpy indexing works and why we adopt the convention we do for images, and when it may be appropriate to adopt other conventions. The first thing to understand is that there are two conflicting conventions for indexing 2-dimensional arrays. Matrix notation uses the first index to indicate which row is being selected and the second index to indicate which column is selected. This is opposite the geometrically oriented-convention for images where people generally think the first index represents x position (i.e., column) and the second represents y position (i.e., row). This alone is the source of much confusion; matrix-oriented users and image-oriented users expect two different things with regard to indexing. The second issue to understand is how indices correspond to the order the array is stored in memory. In Fortran the first index is the most rapidly varying index when moving through the elements of a two dimensional array as it is stored in memory. If you adopt the matrix convention for indexing, then this means the matrix is stored one column at a time (since the first index moves to the next row as it changes). Thus Fortran is considered a Column-major language. C has just the opposite convention. In C, the last index changes most rapidly as one moves through the array as stored in memory. Thus C is a Row-major language. The matrix is stored by rows. Note that in both cases it presumes that the matrix convention for indexing is being used, i.e., for both Fortran and C, the first index is the row. Note this convention implies that the indexing convention is invariant and that the data order changes to keep that so. But that's not the only way to look at it. Suppose one has large two-dimensional arrays (images or matrices) stored in data files. Suppose the data are stored by rows rather than by columns. If we are to preserve our index convention (whether matrix or image) that means that depending on the language we use, we may be forced to reorder the data if it is read into memory to preserve our indexing convention. For example if we read row-ordered data into memory without reordering, it will match the matrix indexing convention for C, but not for Fortran. Conversely, it will match the image indexing convention for Fortran, but not for C. For C, if one is using data stored in row order, and one wants to preserve the image index convention, the data must be reordered when reading into memory. In the end, which you do for Fortran or C depends on which is more important, not reordering data or preserving the indexing convention. For large images, reordering data is potentially expensive, and often the indexing convention is inverted to avoid that. The situation with numpy makes this issue yet more complicated. The internal machinery of numpy arrays is flexible enough to accept any ordering of indices. One can simply reorder indices by manipulating the internal stride information for arrays without reordering the data at all. Numpy will know how to map the new index order to the data without moving the data. So if this is true, why not choose the index order that matches what you most expect? In particular, why not define row-ordered images to use the image convention? (This is sometimes referred to as the Fortran convention vs the C convention, thus the 'C' and 'FORTRAN' order options for array ordering in numpy.) The drawback of doing this is potential performance penalties. It's common to access the data sequentially, either implicitly in array operations or explicitly by looping over rows of an image. When that is done, then the data will be accessed in non-optimal order. As the first index is incremented, what is actually happening is that elements spaced far apart in memory are being sequentially accessed, with usually poor memory access speeds. For example, for a two dimensional image 'im' defined so that im[0, 10] represents the value at x=0, y=10. To be consistent with usual Python behavior then im[0] would represent a column at x=0. Yet that data would be spread over the whole array since the data are stored in row order. Despite the flexibility of numpy's indexing, it can't really paper over the fact basic operations are rendered inefficient because of data order or that getting contiguous subarrays is still awkward (e.g., im[:,0] for the first row, vs im[0]), thus one can't use an idiom such as for row in im; for col in im does work, but doesn't yield contiguous column data. As it turns out, numpy is smart enough when dealing with ufuncs to determine which index is the most rapidly varying one in memory and uses that for the innermost loop. Thus for ufuncs there is no large intrinsic advantage to either approach in most cases. On the other hand, use of .flat with an FORTRAN ordered array will lead to non-optimal memory access as adjacent elements in the flattened array (iterator, actually) are not contiguous in memory. Indeed, the fact is that Python indexing on lists and other sequences naturally leads to an outside-to inside ordering (the first index gets the largest grouping, the next the next largest, and the last gets the smallest element). Since image data are normally stored by rows, this corresponds to position within rows being the last item indexed. If you do want to use Fortran ordering realize that there are two approaches to consider: 1) accept that the first index is just not the most rapidly changing in memory and have all your I/O routines reorder your data when going from memory to disk or visa versa, or use numpy's mechanism for mapping the first index to the most rapidly varying data. We recommend the former if possible. The disadvantage of the latter is that many of numpy's functions will yield arrays without Fortran ordering unless you are careful to use the 'order' keyword. Doing this would be highly inconvenient. Otherwise we recommend simply learning to reverse the usual order of indices when accessing elements of an array. Granted, it goes against the grain, but it is more in line with Python semantics and the natural order of the data. """
""" Numerical python functions written for compatability with matlab(TM) commands with the same names. Matlab(TM) compatible functions ------------------------------- :func:`cohere` Coherence (normalized cross spectral density) :func:`csd` Cross spectral density uing Welch's average periodogram :func:`detrend` Remove the mean or best fit line from an array :func:`find` Return the indices where some condition is true; numpy.nonzero is similar but more general. :func:`griddata` interpolate irregularly distributed data to a regular grid. :func:`prctile` find the percentiles of a sequence :func:`prepca` Principal Component Analysis :func:`psd` Power spectral density uing Welch's average periodogram :func:`rk4` A 4th order runge kutta integrator for 1D or ND systems :func:`specgram` Spectrogram (power spectral density over segments of time) Miscellaneous functions ------------------------- Functions that don't exist in matlab(TM), but are useful anyway: :meth:`cohere_pairs` Coherence over all pairs. This is not a matlab function, but we compute coherence a lot in my lab, and we compute it for a lot of pairs. This function is optimized to do this efficiently by caching the direct FFTs. :meth:`rk4` A 4th order Runge-Kutta ODE integrator in case you ever find yourself stranded without scipy (and the far superior scipy.integrate tools) record array helper functions ------------------------------- A collection of helper methods for numpyrecord arrays .. _htmlonly:: See :ref:`misc-examples-index` :meth:`rec2txt` pretty print a record array :meth:`rec2csv` store record array in CSV file :meth:`csv2rec` import record array from CSV file with type inspection :meth:`rec_append_fields` adds field(s)/array(s) to record array :meth:`rec_drop_fields` drop fields from record array :meth:`rec_join` join two record arrays on sequence of fields :meth:`rec_groupby` summarize data by groups (similar to SQL GROUP BY) :meth:`rec_summarize` helper code to filter rec array fields into new fields For the rec viewer functions(e rec2csv), there are a bunch of Format objects you can pass into the functions that will do things like color negative values red, set percent formatting and scaling, etc. Example usage:: r = csv2rec('somefile.csv', checkrows=0) formatd = dict( weight = FormatFloat(2), change = FormatPercent(2), cost = FormatThousands(2), ) rec2excel(r, 'test.xls', formatd=formatd) rec2csv(r, 'test.csv', formatd=formatd) scroll = rec2gtk(r, formatd=formatd) win = gtk.Window() win.set_size_request(600,800) win.add(scroll) win.show_all() gtk.main() Deprecated functions --------------------- The following are deprecated; please import directly from numpy (with care--function signatures may differ): :meth:`conv` convolution (numpy.convolve) :meth:`corrcoef` The matrix of correlation coefficients :meth:`hist` Histogram (numpy.histogram) :meth:`linspace` Linear spaced array from min to max :meth:`load` load ASCII file - use numpy.loadtxt :meth:`meshgrid` Make a 2D grid from 2 1 arrays (numpy.meshgrid) :meth:`polyfit` least squares best polynomial fit of x to y (numpy.polyfit) :meth:`polyval` evaluate a vector for a vector of polynomial coeffs (numpy.polyval) :meth:`save` save ASCII file - use numpy.savetxt :meth:`trapz` trapeziodal integration (trapz(x,y) -> numpy.trapz(y,x)) :meth:`vander` the Vandermonde matrix (numpy.vander) """
""" Simple config ============= Although CherryPy uses the :mod:`Python logging module <logging>`, it does so behind the scenes so that simple logging is simple, but complicated logging is still possible. "Simple" logging means that you can log to the screen (i.e. console/stdout) or to a file, and that you can easily have separate error and access log files. Here are the simplified logging settings. You use these by adding lines to your config file or dict. You should set these at either the global level or per application (see next), but generally not both. * ``log.screen``: Set this to True to have both "error" and "access" messages printed to stdout. * ``log.access_file``: Set this to an absolute filename where you want "access" messages written. * ``log.error_file``: Set this to an absolute filename where you want "error" messages written. Many events are automatically logged; to log your own application events, call :func:`cherrypy.log`. Architecture ============ Separate scopes --------------- CherryPy provides log managers at both the global and application layers. This means you can have one set of logging rules for your entire site, and another set of rules specific to each application. The global log manager is found at :func:`cherrypy.log`, and the log manager for each application is found at :attr:`app.log<cherrypy._cptree.Application.log>`. If you're inside a request, the latter is reachable from ``cherrypy.request.app.log``; if you're outside a request, you'll have to obtain a reference to the ``app``: either the return value of :func:`tree.mount()<cherrypy._cptree.Tree.mount>` or, if you used :func:`quickstart()<cherrypy.quickstart>` instead, via ``cherrypy.tree.apps['/']``. By default, the global logs are named "cherrypy.error" and "cherrypy.access", and the application logs are named "cherrypy.error.2378745" and "cherrypy.access.2378745" (the number is the id of the Application object). This means that the application logs "bubble up" to the site logs, so if your application has no log handlers, the site-level handlers will still log the messages. Errors vs. Access ----------------- Each log manager handles both "access" messages (one per HTTP request) and "error" messages (everything else). Note that the "error" log is not just for errors! The format of access messages is highly formalized, but the error log isn't--it receives messages from a variety of sources (including full error tracebacks, if enabled). If you are logging the access log and error log to the same source, then there is a possibility that a specially crafted error message may replicate an access log message as described in CWE-117. In this case it is the application developer's responsibility to manually escape data before using CherryPy's log() functionality, or they may create an application that is vulnerable to CWE-117. This would be achieved by using a custom handler escape any special characters, and attached as described below. Custom Handlers =============== The simple settings above work by manipulating Python's standard :mod:`logging` module. So when you need something more complex, the full power of the standard module is yours to exploit. You can borrow or create custom handlers, formats, filters, and much more. Here's an example that skips the standard FileHandler and uses a RotatingFileHandler instead: :: #python log = app.log # Remove the default FileHandlers if present. log.error_file = "" log.access_file = "" maxBytes = getattr(log, "rot_maxBytes", 10000000) backupCount = getattr(log, "rot_backupCount", 1000) # Make a new RotatingFileHandler for the error log. fname = getattr(log, "rot_error_file", "error.log") h = handlers.RotatingFileHandler(fname, 'a', maxBytes, backupCount) h.setLevel(DEBUG) h.setFormatter(_cplogging.logfmt) log.error_log.addHandler(h) # Make a new RotatingFileHandler for the access log. fname = getattr(log, "rot_access_file", "access.log") h = handlers.RotatingFileHandler(fname, 'a', maxBytes, backupCount) h.setLevel(DEBUG) h.setFormatter(_cplogging.logfmt) log.access_log.addHandler(h) The ``rot_*`` attributes are pulled straight from the application log object. Since "log.*" config entries simply set attributes on the log object, you can add custom attributes to your heart's content. Note that these handlers are used ''instead'' of the default, simple handlers outlined above (so don't set the "log.error_file" config entry, for example). """
#!/usr/bin/env python # CoNLL 2017 UD Parsing evaluation script. # # Compatible with Python 2.7 and 3.2+, can be used either as a module # or a standalone executable. # # Copyright 2017 Institute of Formal and Applied Linguistics (UFAL), # Faculty of Mathematics and Physics, Charles University, Czech Republic. # # Changelog: # - [02 Jan 2017] Version 0.9: Initial release # - [25 Jan 2017] Version 0.9.1: Fix bug in LCS alignment computation # - [10 Mar 2017] Version 1.0: Add documentation and test # Compare HEADs correctly using aligned words # Allow evaluation with errorneous spaces in forms # Compare forms in LCS case insensitively # Detect cycles and multiple root nodes # Compute AlignedAccuracy # Command line usage # ------------------ # conll17_ud_eval.py [-v] [-w weights_file] gold_conllu_file system_conllu_file # # - if no -v is given, only the CoNLL17 UD Shared Task evaluation LAS metrics # is printed # - if -v is given, several metrics are printed (as precision, recall, F1 score, # and in case the metric is computed on aligned words also accuracy on these): # - Tokens: how well do the gold tokens match system tokens # - Sentences: how well do the gold sentences match system sentences # - Words: how well can the gold words be aligned to system words # - UPOS: using aligned words, how well does UPOS match # - XPOS: using aligned words, how well does XPOS match # - Feats: using aligned words, how well does FEATS match # - AllTags: using aligned words, how well does UPOS+XPOS+FEATS match # - Lemmas: using aligned words, how well does LEMMA match # - UAS: using aligned words, how well does HEAD match # - LAS: using aligned words, how well does HEAD+DEPREL(ignoring subtypes) match # - if weights_file is given (with lines containing deprel-weight pairs), # one more metric is shown: # - WeightedLAS: as LAS, but each deprel (ignoring subtypes) has different weight # API usage # --------- # - load_conllu(file) # - loads CoNLL-U file from given file object to an internal representation # - the file object should return str on both Python 2 and Python 3 # - raises UDError exception if the given file cannot be loaded # - evaluate(gold_ud, system_ud) # - evaluate the given gold and system CoNLL-U files (loaded with load_conllu) # - raises UDError if the concatenated tokens of gold and system file do not match # - returns a dictionary with the metrics described above, each metrics having # three fields: precision, recall and f1 # Description of token matching # ----------------------------- # In order to match tokens of gold file and system file, we consider the text # resulting from concatenation of gold tokens and text resulting from # concatenation of system tokens. These texts should match -- if they do not, # the evaluation fails. # # If the texts do match, every token is represented as a range in this original # text, and tokens are equal only if their range is the same. # Description of word matching # ---------------------------- # When matching words of gold file and system file, we first match the tokens. # The words which are also tokens are matched as tokens, but words in multi-word # tokens have to be handled differently. # # To handle multi-word tokens, we start by finding "multi-word spans". # Multi-word span is a span in the original text such that # - it contains at least one multi-word token # - all multi-word tokens in the span (considering both gold and system ones) # are completely inside the span (i.e., they do not "stick out") # - the multi-word span is as small as possible # # For every multi-word span, we align the gold and system words completely # inside this span using LCS on their FORMs. The words not intersecting # (even partially) any multi-word span are then aligned as tokens.
#----------------------------------------------------------------------------- # eveapi - EVE Online API access # # Copyright (c)2007-2014 NAME "Entity" NAME <EMAIL> # # 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 # #----------------------------------------------------------------------------- # # Version: 1.3.2 - 29 August 2015 # - Added Python 3 support # # Version: 1.3.1 - 02 November 2014 # - Fix problem with strings ending in spaces (this is not supposed to happen, # but apparently tiancity thinks it is ok to bypass constraints) # # Version: 1.3.0 - 27 May 2014 # - Added set_user_agent() module-level function to set the User-Agent header # to be used for any requests by the library. If this function is not used, # a warning will be thrown for every API request. # # Version: 1.2.9 - 14 September 2013 # - Updated error handling: Raise an AuthenticationError in case # the API returns HTTP Status Code 403 - Forbidden # # Version: 1.2.8 - 9 August 2013 # - the XML value cast function (_autocast) can now be changed globally to a # custom one using the set_cast_func(func) module-level function. # # Version: 1.2.7 - 3 September 2012 # - Added get() method to Row object. # # Version: 1.2.6 - 29 August 2012 # - Added finer error handling + added setup.py to allow distributing eveapi # through pypi. # # Version: 1.2.5 - 1 August 2012 # - Row objects now have __hasattr__ and __contains__ methods # # Version: 1.2.4 - 12 April 2012 # - API version of XML response now available as _meta.version # # Version: 1.2.3 - 10 April 2012 # - fix for tags of the form <tag attr=bla ... /> # # Version: 1.2.2 - 27 February 2012 # - fix for the workaround in 1.2.1. # # Version: 1.2.1 - 23 February 2012 # - added workaround for row tags missing attributes that were defined # in their rowset (this should fix ContractItems) # # Version: 1.2.0 - 18 February 2012 # - fix handling of empty XML tags. # - improved proxy support a bit. # # Version: 1.1.9 - 2 September 2011 # - added workaround for row tags with attributes that were not defined # in their rowset (this should fix AssetList) # # Version: 1.1.8 - 1 September 2011 # - fix for inconsistent columns attribute in rowsets. # # Version: 1.1.7 - 1 September 2011 # - auth() method updated to work with the new authentication scheme. # # Version: 1.1.6 - 27 May 2011 # - Now supports composite keys for IndexRowsets. # - Fixed calls not working if a path was specified in the root url. # # Version: 1.1.5 - 27 Januari 2011 # - Now supports (and defaults to) HTTPS. Non-SSL proxies will still work by # explicitly specifying http:// in the url. # # Version: 1.1.4 - 1 December 2010 # - Empty explicit CDATA tags are now properly handled. # - _autocast now receives the name of the variable it's trying to typecast, # enabling custom/future casting functions to make smarter decisions. # # Version: 1.1.3 - 6 November 2010 # - Added support for anonymous CDATA inside row tags. This makes the body of # mails in the rows of char/MailBodies available through the .data attribute. # # Version: 1.1.2 - 2 July 2010 # - Fixed __str__ on row objects to work properly with unicode strings. # # Version: 1.1.1 - 10 Januari 2010 # - Fixed bug that causes nested tags to not appear in rows of rowsets created # from normal Elements. This should fix the corp.MemberSecurity method, # which now returns all data for members. [jehed] # # Version: 1.1.0 - 15 Januari 2009 # - Added Select() method to Rowset class. Using it avoids the creation of # temporary row instances, speeding up iteration considerably. # - Added ParseXML() function, which can be passed arbitrary API XML file or # string objects. # - Added support for proxy servers. A proxy can be specified globally or # per api connection instance. [suggestion by USERNAME - Some minor refactoring. # - Fixed deprecation warning when using Python 2.6. # # Version: 1.0.7 - 14 November 2008 # - Added workaround for rowsets that are missing the (required!) columns # attribute. If missing, it will use the columns found in the first row. # Note that this is will still break when expecting columns, if the rowset # is empty. [Flux/Entity] # # Version: 1.0.6 - 18 July 2008 # - Enabled expat text buffering to avoid content breaking up. [BigWhale] # # Version: 1.0.5 - 03 February 2008 # - Added workaround to make broken XML responses (like the "row:name" bug in # eve/CharacterID) work as intended. # - Bogus datestamps before the epoch in XML responses are now set to 0 to # avoid breaking certain date/time functions. [Anathema Matou] # # Version: 1.0.4 - 23 December 2007 # - Changed _autocast() to use timegm() instead of mktime(). [Invisible Hand] # - Fixed missing attributes of elements inside rows. [Elandra NAME Version: 1.0.3 - 13 December 2007 # - Fixed keyless columns bugging out the parser (in CorporationSheet for ex.) # # Version: 1.0.2 - 12 December 2007 # - Fixed parser not working with indented XML. # # Version: 1.0.1 # - Some micro optimizations # # Version: 1.0 # - Initial release # # Requirements: # Python 2.6+ or Python 3.3+ # #-----------------------------------------------------------------------------
"""Stuff to parse AIFF-C and AIFF files. Unless explicitly stated otherwise, the description below is true both for AIFF-C files and AIFF files. An AIFF-C file has the following structure. +-----------------+ | FORM | +-----------------+ | <size> | +----+------------+ | | AIFC | | +------------+ | | <chunks> | | | . | | | . | | | . | +----+------------+ An AIFF file has the string "AIFF" instead of "AIFC". A chunk consists of an identifier (4 bytes) followed by a size (4 bytes, big endian order), followed by the data. The size field does not include the size of the 8 byte header. The following chunk types are recognized. FVER <version number of AIFF-C defining document> (AIFF-C only). MARK <# of markers> (2 bytes) list of markers: <marker ID> (2 bytes, must be > 0) <position> (4 bytes) <marker name> ("pstring") COMM <# of channels> (2 bytes) <# of sound frames> (4 bytes) <size of the samples> (2 bytes) <sampling frequency> (10 bytes, IEEE 80-bit extended floating point) in AIFF-C files only: <compression type> (4 bytes) <human-readable version of compression type> ("pstring") SSND <offset> (4 bytes, not used by this program) <blocksize> (4 bytes, not used by this program) <sound data> A pstring consists of 1 byte length, a string of characters, and 0 or 1 byte pad to make the total length even. Usage. Reading AIFF files: f = aifc.open(file, 'r') where file is either the name of a file or an open file pointer. The open file pointer must have methods read(), seek(), and close(). In some types of audio files, if the setpos() method is not used, the seek() method is not necessary. This returns an instance of a class with the following public methods: getnchannels() -- returns number of audio channels (1 for mono, 2 for stereo) getsampwidth() -- returns sample width in bytes getframerate() -- returns sampling frequency getnframes() -- returns number of audio frames getcomptype() -- returns compression type ('NONE' for AIFF files) getcompname() -- returns human-readable version of compression type ('not compressed' for AIFF files) getparams() -- returns a tuple consisting of all of the above in the above order getmarkers() -- get the list of marks in the audio file or None if there are no marks getmark(id) -- get mark with the specified id (raises an error if the mark does not exist) readframes(n) -- returns at most n frames of audio rewind() -- rewind to the beginning of the audio stream setpos(pos) -- seek to the specified position tell() -- return the current position close() -- close the instance (make it unusable) The position returned by tell(), the position given to setpos() and the position of marks are all compatible and have nothing to do with the actual position in the file. The close() method is called automatically when the class instance is destroyed. Writing AIFF files: f = aifc.open(file, 'w') where file is either the name of a file or an open file pointer. The open file pointer must have methods write(), tell(), seek(), and close(). This returns an instance of a class with the following public methods: aiff() -- create an AIFF file (AIFF-C default) aifc() -- create an AIFF-C file setnchannels(n) -- set the number of channels setsampwidth(n) -- set the sample width setframerate(n) -- set the frame rate setnframes(n) -- set the number of frames setcomptype(type, name) -- set the compression type and the human-readable compression type setparams(tuple) -- set all parameters at once setmark(id, pos, name) -- add specified mark to the list of marks tell() -- return current position in output file (useful in combination with setmark()) writeframesraw(data) -- write audio frames without pathing up the file header writeframes(data) -- write audio frames and patch up the file header close() -- patch up the file header and close the output file You should set the parameters before the first writeframesraw or writeframes. The total number of frames does not need to be set, but when it is set to the correct value, the header does not have to be patched up. It is best to first set all parameters, perhaps possibly the compression type, and then write audio frames using writeframesraw. When all frames have been written, either call writeframes('') or close() to patch up the sizes in the header. Marks can be added anytime. If there are any marks, ypu must call close() after all frames have been written. The close() method is called automatically when the class instance is destroyed. When a file is opened with the extension '.aiff', an AIFF file is written, otherwise an AIFF-C file is written. This default can be changed by calling aiff() or aifc() before the first writeframes or writeframesraw. """
# This code is part of Ansible, but is an independent component. # This particular file snippet, and this file snippet only, is BSD licensed. # Modules you write using this snippet, which is embedded dynamically by Ansible # still belong to the author of the module, and may assign their own license # to the complete work. # # Copyright (c), NAME <EMAIL>, 2012-2013 # Copyright (c), NAME <EMAIL>, 2015 # All rights reserved. # # Redistribution and use in source and binary forms, with or without modification, # are permitted provided that the following conditions are met: # # * Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # * Redistributions in binary form must reproduce the above copyright notice, # this list of conditions and the following disclaimer in the documentation # and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. # IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. # # The match_hostname function and supporting code is under the terms and # conditions of the Python Software Foundation License. They were taken from # the Python3 standard library and adapted for use in Python2. See comments in the # source for which code precisely is under this License. PSF License text # follows: # # PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2 # -------------------------------------------- # # 1. This LICENSE AGREEMENT is between the Python Software Foundation # ("PSF"), and the Individual or Organization ("Licensee") accessing and # otherwise using this software ("Python") in source or binary form and # its associated documentation. # # 2. Subject to the terms and conditions of this License Agreement, PSF hereby # grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, # analyze, test, perform and/or display publicly, prepare derivative works, # distribute, and otherwise use Python alone or in any derivative version, # provided, however, that PSF's License Agreement and PSF's notice of copyright, # i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, # 2011, 2012, 2013, 2014 Python Software Foundation; All Rights Reserved" are # retained in Python alone or in any derivative version prepared by Licensee. # # 3. In the event Licensee prepares a derivative work that is based on # or incorporates Python or any part thereof, and wants to make # the derivative work available to others as provided herein, then # Licensee hereby agrees to include in any such work a brief summary of # the changes made to Python. # # 4. PSF is making Python available to Licensee on an "AS IS" # basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR # IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND # DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS # FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT # INFRINGE ANY THIRD PARTY RIGHTS. # # 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON # FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS # A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON, # OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. # # 6. This License Agreement will automatically terminate upon a material # breach of its terms and conditions. # # 7. Nothing in this License Agreement shall be deemed to create any # relationship of agency, partnership, or joint venture between PSF and # Licensee. This License Agreement does not grant permission to use PSF # trademarks or trade name in a trademark sense to endorse or promote # products or services of Licensee, or any third party. # # 8. By copying, installing or otherwise using Python, Licensee # agrees to be bound by the terms and conditions of this License # Agreement.
# # XML-RPC CLIENT LIBRARY # $Id$ # # an XML-RPC client interface for Python. # # the marshalling and response parser code can also be used to # implement XML-RPC servers. # # Notes: # this version is designed to work with Python 2.1 or newer. # # History: # 1999-01-14 fl Created # 1999-01-15 fl Changed dateTime to use localtime # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service # 1999-01-19 fl Fixed array data element (from Skip Montanaro) # 1999-01-21 fl Fixed dateTime constructor, etc. # 1999-02-02 fl Added fault handling, handle empty sequences, etc. # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro) # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8) # 2000-11-28 fl Changed boolean to check the truth value of its argument # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1) # 2001-03-28 fl Make sure response tuple is a singleton # 2001-03-29 fl Don't require empty params element (from NAME 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2) # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from NAME 2001-09-03 fl Allow Transport subclass to override getparser # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup) # 2001-10-01 fl Remove containers from memo cache when done with them # 2001-10-01 fl Use faster escape method (80% dumps speedup) # 2001-10-02 fl More dumps microtuning # 2001-10-04 fl Make sure import expat gets a parser (from NAME 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems) # 2001-11-12 fl Use repr() to marshal doubles (from NAME 2002-03-17 fl Avoid buffered read when possible (from NAME 2002-04-07 fl Added pythondoc comments # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers # 2002-05-15 fl Added error constants (from NAME 2002-06-27 fl Merged with Python CVS version # 2002-10-22 fl Added basic authentication (based on code from NAME 2003-01-22 sm Add support for the bool type # 2003-02-27 gvr Remove apply calls # 2003-04-24 sm Use cStringIO if available # 2003-04-25 ak Add support for nil # 2003-06-15 gn Add support for time.struct_time # 2003-07-12 gp Correct marshalling of Faults # 2003-10-31 mvl Add multicall support # 2004-08-20 mvl Bump minimum supported Python version to 2.1 # # Copyright (c) 1999-2002 by Secret Labs AB. # Copyright (c) 1999-2002 by NAME EMAIL http://www.pythonware.com # # -------------------------------------------------------------------- # The XML-RPC client interface is # # Copyright (c) 1999-2002 by Secret Labs AB # Copyright (c) 1999-2002 by NAME By obtaining, using, and/or copying this software and/or its # associated documentation, you agree that you have read, understood, # and will comply with the following terms and conditions: # # Permission to use, copy, modify, and distribute this software and # its associated documentation for any purpose and without fee is # hereby granted, provided that the above copyright notice appears in # all copies, and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of # Secret Labs AB or the author not be used in advertising or publicity # pertaining to distribution of the software without specific, written # prior permission. # # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. # --------------------------------------------------------------------
# # =============================================================================== # # Copyright 2014 NAME # # # Licensed under the Apache License, Version 2.0 (the "License"); # # you may not use this file except in compliance with the License. # # You may obtain a copy of the License at # # # # http://www.apache.org/licenses/LICENSE-2.0 # # # # Unless required by applicable law or agreed to in writing, software # # distributed under the License is distributed on an "AS IS" BASIS, # # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # # See the License for the specific language governing permissions and # # limitations under the License. # # =============================================================================== # from pychron.core.ui import set_qt # # set_qt() # # # ============= enthought library imports ======================= # from traitsui.menu import ToolBar, Action # from enable.component_editor import ComponentEditor # from traits.api import HasTraits, Instance, Dict, List # from traitsui.api import View, UItem # # # ============= standard library imports ======================== # # ============= local library imports ========================== # from pychron.loggable import Loggable # from pychron.canvas.canvas2D.extraction_line_canvas2D import ExtractionLineCanvas2D # # # def diff_states(s1, s2): # """ # return list of new states # """ # diffs = {} # for k, v in s1: # if s1[k] != s2[k]: # diffs[k] = s1[k] # return diffs # # # class ValveState(HasTraits): # __valves = Dict # # def set_state(self, k, v): # self.__valves[k] = v # # def diff(self, s1): # return diff_states(self, s1) # # def __iter__(self): # return self.__valves.iteritems() # # def __getitem__(self, item): # return self.__valves[item] # # def get_states(self): # return self.__valves.copy() # # def set_states(self, v): # self.__valves = v # # def __repr__(self): # return ','.join(['{}={}'.format(k, 'open' if v else 'close') # for k, v in self.__valves.iteritems()]) # # # class ValveProgrammer(Loggable): # canvas = Instance(ExtractionLineCanvas2D) # previous_state = Instance(ValveState) # current_state = Instance(ValveState) # states = List # # def assemble(self): # for si in self.states: # print si # # def save_state(self): # self.debug('save state') # self.states.append(self.previous_state) # # vd = self.current_state.get_states() # self.previous_state.set_states(vd) # # def clear_state(self): # self.debug('clear state') # # #extraction_line_canvas protocol # def set_selected_explanation_item(self, v): # pass # # def open_valve(self, v, *args, **kw): # self.current_state.set_state(v, True) # print self.current_state.diff(self.previous_state) # return True, True # # def close_valve(self, v, *args, **kw): # self.current_state.set_state(v, False) # print self.current_state.diff(self.previous_state) # return True, True # # def setup(self): # self.canvas.load_canvas_file('canvas.xml') # self.previous_state = ValveState() # self.current_state = ValveState() # # self.save_state() # for vi in self.canvas.iter_valves(): # self.previous_state.set_state(vi.name, False) # self.current_state.set_state(vi.name, False) # # def traits_view(self): # v = View(UItem('canvas', editor=ComponentEditor()), # resizable=True, # toolbar=ToolBar(Action(name='Save State', # action='save_state'), # Action(name='Assemble', # action='assemble'), # ), # width=500) # return v # # def _canvas_default(self): # return ExtractionLineCanvas2D(manager=self) # # # if __name__ == '__main__': # v = ValveProgrammer() # v.setup() # v.configure_traits() # # # ============= EOF ============================================= #
""" ============ Array basics ============ Array types and conversions between types ========================================= Numpy supports a much greater variety of numerical types than Python does. This section shows which are available, and how to modify an array's data-type. ========== ========================================================= Data type Description ========== ========================================================= bool Boolean (True or False) stored as a byte int Platform integer (normally either ``int32`` or ``int64``) int8 Byte (-128 to 127) int16 Integer (-32768 to 32767) int32 Integer (-2147483648 to 2147483647) int64 Integer (9223372036854775808 to 9223372036854775807) uint8 Unsigned integer (0 to 255) uint16 Unsigned integer (0 to 65535) uint32 Unsigned integer (0 to 4294967295) uint64 Unsigned integer (0 to 18446744073709551615) float Shorthand for ``float64``. float32 Single precision float: sign bit, 8 bits exponent, 23 bits mantissa float64 Double precision float: sign bit, 11 bits exponent, 52 bits mantissa complex Shorthand for ``complex128``. complex64 Complex number, represented by two 32-bit floats (real and imaginary components) complex128 Complex number, represented by two 64-bit floats (real and imaginary components) ========== ========================================================= Numpy numerical types are instances of ``dtype`` (data-type) objects, each having unique characteristics. Once you have imported NumPy using :: >>> import numpy as np the dtypes are available as ``np.bool``, ``np.float32``, etc. Advanced types, not listed in the table above, are explored in section :ref:`structured_arrays`. There are 5 basic numerical types representing booleans (bool), integers (int), unsigned integers (uint) floating point (float) and complex. Those with numbers in their name indicate the bitsize of the type (i.e. how many bits are needed to represent a single value in memory). Some types, such as ``int`` and ``intp``, have differing bitsizes, dependent on the platforms (e.g. 32-bit vs. 64-bit machines). This should be taken into account when interfacing with low-level code (such as C or Fortran) where the raw memory is addressed. Data-types can be used as functions to convert python numbers to array scalars (see the array scalar section for an explanation), python sequences of numbers to arrays of that type, or as arguments to the dtype keyword that many numpy functions or methods accept. Some examples:: >>> import numpy as np >>> x = np.float32(1.0) >>> x 1.0 >>> y = np.int_([1,2,4]) >>> y array([1, 2, 4]) >>> z = np.arange(3, dtype=np.uint8) >>> z array([0, 1, 2], dtype=uint8) Array types can also be referred to by character codes, mostly to retain backward compatibility with older packages such as Numeric. Some documentation may still refer to these, for example:: >>> np.array([1, 2, 3], dtype='f') array([ 1., 2., 3.], dtype=float32) We recommend using dtype objects instead. To convert the type of an array, use the .astype() method (preferred) or the type itself as a function. For example: :: >>> z.astype(float) #doctest: +NORMALIZE_WHITESPACE array([ 0., 1., 2.]) >>> np.int8(z) array([0, 1, 2], dtype=int8) Note that, above, we use the *Python* float object as a dtype. NumPy knows that ``int`` refers to ``np.int``, ``bool`` means ``np.bool`` and that ``float`` is ``np.float``. The other data-types do not have Python equivalents. To determine the type of an array, look at the dtype attribute:: >>> z.dtype dtype('uint8') dtype objects also contain information about the type, such as its bit-width and its byte-order. The data type can also be used indirectly to query properties of the type, such as whether it is an integer:: >>> d = np.dtype(int) >>> d dtype('int32') >>> np.issubdtype(d, int) True >>> np.issubdtype(d, float) False Array Scalars ============= Numpy generally returns elements of arrays as array scalars (a scalar with an associated dtype). Array scalars differ from Python scalars, but for the most part they can be used interchangeably (the primary exception is for versions of Python older than v2.x, where integer array scalars cannot act as indices for lists and tuples). There are some exceptions, such as when code requires very specific attributes of a scalar or when it checks specifically whether a value is a Python scalar. Generally, problems are easily fixed by explicitly converting array scalars to Python scalars, using the corresponding Python type function (e.g., ``int``, ``float``, ``complex``, ``str``, ``unicode``). The primary advantage of using array scalars is that they preserve the array type (Python may not have a matching scalar type available, e.g. ``int16``). Therefore, the use of array scalars ensures identical behaviour between arrays and scalars, irrespective of whether the value is inside an array or not. NumPy scalars also have many of the same methods arrays do. """
""" Basic functions used by several sub-packages and useful to have in the main name-space. Type Handling ------------- ================ =================== iscomplexobj Test for complex object, scalar result isrealobj Test for real object, scalar result iscomplex Test for complex elements, array result isreal Test for real elements, array result imag Imaginary part real Real part real_if_close Turns complex number with tiny imaginary part to real isneginf Tests for negative infinity, array result isposinf Tests for positive infinity, array result isnan Tests for nans, array result isinf Tests for infinity, array result isfinite Tests for finite numbers, array result isscalar True if argument is a scalar nan_to_num Replaces NaN's with 0 and infinities with large numbers cast Dictionary of functions to force cast to each type common_type Determine the minimum common type code for a group of arrays mintypecode Return minimal allowed common typecode. ================ =================== Index Tricks ------------ ================ =================== mgrid Method which allows easy construction of N-d 'mesh-grids' ``r_`` Append and construct arrays: turns slice objects into ranges and concatenates them, for 2d arrays appends rows. index_exp Konrad Hinsen's index_expression class instance which can be useful for building complicated slicing syntax. ================ =================== Useful Functions ---------------- ================ =================== select Extension of where to multiple conditions and choices extract Extract 1d array from flattened array according to mask insert Insert 1d array of values into Nd array according to mask linspace Evenly spaced samples in linear space logspace Evenly spaced samples in logarithmic space fix Round x to nearest integer towards zero mod Modulo mod(x,y) = x % y except keeps sign of y amax Array maximum along axis amin Array minimum along axis ptp Array max-min along axis cumsum Cumulative sum along axis prod Product of elements along axis cumprod Cumluative product along axis diff Discrete differences along axis angle Returns angle of complex argument unwrap Unwrap phase along given axis (1-d algorithm) sort_complex Sort a complex-array (based on real, then imaginary) trim_zeros Trim the leading and trailing zeros from 1D array. vectorize A class that wraps a Python function taking scalar arguments into a generalized function which can handle arrays of arguments using the broadcast rules of numerix Python. ================ =================== Shape Manipulation ------------------ ================ =================== squeeze Return a with length-one dimensions removed. atleast_1d Force arrays to be > 1D atleast_2d Force arrays to be > 2D atleast_3d Force arrays to be > 3D vstack Stack arrays vertically (row on row) hstack Stack arrays horizontally (column on column) column_stack Stack 1D arrays as columns into 2D array dstack Stack arrays depthwise (along third dimension) split Divide array into a list of sub-arrays hsplit Split into columns vsplit Split into rows dsplit Split along third dimension ================ =================== Matrix (2D Array) Manipulations ------------------------------- ================ =================== fliplr 2D array with columns flipped flipud 2D array with rows flipped rot90 Rotate a 2D array a multiple of 90 degrees eye Return a 2D array with ones down a given diagonal diag Construct a 2D array from a vector, or return a given diagonal from a 2D array. mat Construct a Matrix bmat Build a Matrix from blocks ================ =================== Polynomials ----------- ================ =================== poly1d A one-dimensional polynomial class poly Return polynomial coefficients from roots roots Find roots of polynomial given coefficients polyint Integrate polynomial polyder Differentiate polynomial polyadd Add polynomials polysub Substract polynomials polymul Multiply polynomials polydiv Divide polynomials polyval Evaluate polynomial at given argument ================ =================== Import Tricks ------------- ================ =================== ppimport Postpone module import until trying to use it ppimport_attr Postpone module import until trying to use its attribute ppresolve Import postponed module and return it. ================ =================== Machine Arithmetics ------------------- ================ =================== machar_single Single precision floating point arithmetic parameters machar_double Double precision floating point arithmetic parameters ================ =================== Threading Tricks ---------------- ================ =================== ParallelExec Execute commands in parallel thread. ================ =================== 1D Array Set Operations ----------------------- Set operations for 1D numeric arrays based on sort() function. ================ =================== ediff1d Array difference (auxiliary function). unique Unique elements of an array. intersect1d Intersection of 1D arrays with unique elements. setxor1d Set exclusive-or of 1D arrays with unique elements. in1d Test whether elements in a 1D array are also present in another array. union1d Union of 1D arrays with unique elements. setdiff1d Set difference of 1D arrays with unique elements. ================ =================== """
"""Configuration file parser. A configuration file consists of sections, lead by a "[section]" header, and followed by "name: value" entries, with continuations and such in the style of RFC 822. Intrinsic defaults can be specified by passing them into the ConfigParser constructor as a dictionary. class: ConfigParser -- responsible for parsing a list of configuration files, and managing the parsed database. methods: __init__(defaults=None, dict_type=_default_dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True): Create the parser. When `defaults' is given, it is initialized into the dictionary or intrinsic defaults. The keys must be strings, the values must be appropriate for %()s string interpolation. When `dict_type' is given, it will be used to create the dictionary objects for the list of sections, for the options within a section, and for the default values. When `delimiters' is given, it will be used as the set of substrings that divide keys from values. When `comment_prefixes' is given, it will be used as the set of substrings that prefix comments in empty lines. Comments can be indented. When `inline_comment_prefixes' is given, it will be used as the set of substrings that prefix comments in non-empty lines. When `strict` is True, the parser won't allow for any section or option duplicates while reading from a single source (file, string or dictionary). Default is True. When `empty_lines_in_values' is False (default: True), each empty line marks the end of an option. Otherwise, internal empty lines of a multiline option are kept as part of the value. When `allow_no_value' is True (default: False), options without values are accepted; the value presented for these is None. sections() Return all the configuration section names, sans DEFAULT. has_section(section) Return whether the given section exists. has_option(section, option) Return whether the given option exists in the given section. options(section) Return list of configuration options for the named section. read(filenames, encoding=None) Read and parse the list of named configuration files, given by name. A single filename is also allowed. Non-existing files are ignored. Return list of successfully read files. read_file(f, filename=None) Read and parse one configuration file, given as a file object. The filename defaults to f.name; it is only used in error messages (if f has no `name' attribute, the string `<???>' is used). read_string(string) Read configuration from a given string. read_dict(dictionary) Read configuration from a dictionary. Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order. Values are automatically converted to strings. get(section, option, raw=False, vars=None, fallback=_UNSET) Return a string value for the named option. All % interpolations are expanded in the return values, based on the defaults passed into the constructor and the DEFAULT section. Additional substitutions may be provided using the `vars' argument, which must be a dictionary whose contents override any pre-existing defaults. If `option' is a key in `vars', the value from `vars' is used. getint(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to an integer. getfloat(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to a float. getboolean(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to a boolean (currently case insensitively defined as 0, false, no, off for False, and 1, true, yes, on for True). Returns False or True. items(section=_UNSET, raw=False, vars=None) If section is given, return a list of tuples with (name, value) for each option in the section. Otherwise, return a list of tuples with (section_name, section_proxy) for each section, including DEFAULTSECT. remove_section(section) Remove the given file section and all its options. remove_option(section, option) Remove the given option from the given section. set(section, option, value) Set the given option. write(fp, space_around_delimiters=True) Write the configuration state in .ini format. If `space_around_delimiters' is True (the default), delimiters between keys and values are surrounded by spaces. """
# # XML-RPC CLIENT LIBRARY # $Id$ # # an XML-RPC client interface for Python. # # the marshalling and response parser code can also be used to # implement XML-RPC servers. # # Notes: # this version is designed to work with Python 2.1 or newer. # # History: # 1999-01-14 fl Created # 1999-01-15 fl Changed dateTime to use localtime # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service # 1999-01-19 fl Fixed array data element (from Skip Montanaro) # 1999-01-21 fl Fixed dateTime constructor, etc. # 1999-02-02 fl Added fault handling, handle empty sequences, etc. # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro) # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8) # 2000-11-28 fl Changed boolean to check the truth value of its argument # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1) # 2001-03-28 fl Make sure response tuple is a singleton # 2001-03-29 fl Don't require empty params element (from NAME 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2) # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from NAME 2001-09-03 fl Allow Transport subclass to override getparser # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup) # 2001-10-01 fl Remove containers from memo cache when done with them # 2001-10-01 fl Use faster escape method (80% dumps speedup) # 2001-10-02 fl More dumps microtuning # 2001-10-04 fl Make sure import expat gets a parser (from NAME 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems) # 2001-11-12 fl Use repr() to marshal doubles (from NAME 2002-03-17 fl Avoid buffered read when possible (from NAME 2002-04-07 fl Added pythondoc comments # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers # 2002-05-15 fl Added error constants (from NAME 2002-06-27 fl Merged with Python CVS version # 2002-10-22 fl Added basic authentication (based on code from NAME 2003-01-22 sm Add support for the bool type # 2003-02-27 gvr Remove apply calls # 2003-04-24 sm Use cStringIO if available # 2003-04-25 ak Add support for nil # 2003-06-15 gn Add support for time.struct_time # 2003-07-12 gp Correct marshalling of Faults # 2003-10-31 mvl Add multicall support # 2004-08-20 mvl Bump minimum supported Python version to 2.1 # # Copyright (c) 1999-2002 by Secret Labs AB. # Copyright (c) 1999-2002 by NAME EMAIL http://www.pythonware.com # # -------------------------------------------------------------------- # The XML-RPC client interface is # # Copyright (c) 1999-2002 by Secret Labs AB # Copyright (c) 1999-2002 by NAME By obtaining, using, and/or copying this software and/or its # associated documentation, you agree that you have read, understood, # and will comply with the following terms and conditions: # # Permission to use, copy, modify, and distribute this software and # its associated documentation for any purpose and without fee is # hereby granted, provided that the above copyright notice appears in # all copies, and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of # Secret Labs AB or the author not be used in advertising or publicity # pertaining to distribution of the software without specific, written # prior permission. # # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. # -------------------------------------------------------------------- # # things to look into some day: # TODO: sort out True/False/boolean issues for Python 2.3
""" Block device listing - Command ``lsblk`` ======================================== Module for processing output of the ``lsblk`` command. Different information is provided by the ``lsblk`` command depending upon the options. Parsers included here are: LSBlock ------- The ``LSBlock`` class parses output of the ``lsblk`` command with no options. LSBlockPairs ------------ The ``LSBlockPairs`` class parses output of the ``lsblk -P -o column_names`` command. These classes based on ``BlockDevices`` which implements all of the functionality except the parsing of command specific information. Information is stored in the attribute ``self.rows`` which is a ``list`` of ``BlockDevice`` objects. Each ``BlockDevice`` object provides the functionality for one row of data from the command output. Data in a ``BlockDevice`` object is accessible by multiple methods. For example the NAME field can be accessed in the follow three ways:: lsblk_info.rows[0].data['NAME'] lsblk_info.rows[0].NAME lsblk_info.rows[0].name lsblk_info.rows[0].get('NAME') Sample output of the ``lsblk`` command looks like:: NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT vda 252:0 0 9G 0 disk |-vda1 252:1 0 500M 0 part /boot `-vda2 252:2 0 8.5G 0 part |-rhel-root 253:0 0 7.6G 0 lvm / |-rhel-swap 253:1 0 924M 0 lvm [SWAP] sda 8:0 0 500G 0 disk `-sda1 8:1 0 500G 0 part /data Note the hierarchy demonstrated in the name column. For instance ``vda1`` and ``vda2`` are children of ``vda``. Likewise, ``rhel-root`` and ``rhel-swap`` are children of ``vda2``. This relationship is demonstrated in the ``PARENT_NAMES`` key, which is only present if the row is a *child* row. For example ``PARENT_NAMES`` value for ``rhel-root`` will be ``['vda', 'vda2']`` meaning that ``vda2`` is the immediate parent and ``vda`` is parent of ``vda2``. Also note that column names that are not valid Python property names been changed. For example ``MAJ:MIN`` has been changed to ``MAJ_MIN``. Examples: >>> lsblk_info = shared[LSBlock] >>> lsblk_info <insights.parsers.lsblk.LSBlock object at 0x7f1f6a422d50> >>> lsblk_info.rows [disk:vda, part:vda1(/boot), part:vda2, lvm:rhel-root(/), lvm:rhel-swap([SWAP]), disk:sda, part:sda1(/data)] >>> lsblk_info.rows[0] disk:vda >>> lsblk_info.rows[0].data {'READ_ONLY': False, 'NAME': 'vda', 'REMOVABLE': False, 'MAJ_MIN': '252:0', 'TYPE': 'disk', 'SIZE': '9G'} >>> lsblk_info.rows[0].data['NAME'] 'vda' >>> lsblk_info.rows[0].NAME 'vda' >>> lsblk_info.rows[0].name 'vda' >>> lsblk_info.rows[0].data['MAJ_MIN'] '252:0' >>> lsblk_info.rows[0].MAJ_MIN '252:0' >>> lsblk_info.rows[0].maj_min '252:0' >>> lsblk_info.rows[0].removable False >>> lsblk_info.rows[0].read_only False >>> lsblk_info.rows[2].data {'READ_ONLY': False, 'PARENT_NAMES': ['vda'], 'NAME': 'vda2', 'REMOVABLE': False, 'MAJ_MIN': '252:2', 'TYPE': 'part', 'SIZE': '8.5G'} >>> lsblk_info.rows[2].parent_names ['vda'] >>> lsblk_info.rows[3].parent_names ['vda', 'vda2'] >>> lsblk_info.device_data['vda'] # Access devices by name 'disk:vda' """
# Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. ########################################################################################### # Implementation of the stochastic depth algorithm described in the paper # # NAME et al. "Deep networks with stochastic depth." arXiv preprint arXiv:1603.09382 (2016). # # Reference torch implementation can be found at https://github.com/yueatsprograms/Stochastic_Depth # # There are some differences in the implementation: # - A BN->ReLU->Conv is used for skip connection when input and output shapes are different, # as oppose to a padding layer. # - The residual block is different: we use BN->ReLU->Conv->BN->ReLU->Conv, as oppose to # Conv->BN->ReLU->Conv->BN (->ReLU also applied to skip connection). # - We did not try to match with the same initialization, learning rate scheduling, etc. # #-------------------------------------------------------------------------------- # A sample from the running log (We achieved ~9.4% error after 500 epochs, some # more careful tuning of the hyper parameters and maybe also the arch is needed # to achieve the reported numbers in the paper): # # INFO:root:Epoch[80] Batch [50] Speed: 1020.95 samples/sec Train-accuracy=0.910080 # INFO:root:Epoch[80] Batch [100] Speed: 1013.41 samples/sec Train-accuracy=0.912031 # INFO:root:Epoch[80] Batch [150] Speed: 1035.48 samples/sec Train-accuracy=0.913438 # INFO:root:Epoch[80] Batch [200] Speed: 1045.00 samples/sec Train-accuracy=0.907344 # INFO:root:Epoch[80] Batch [250] Speed: 1055.32 samples/sec Train-accuracy=0.905937 # INFO:root:Epoch[80] Batch [300] Speed: 1071.71 samples/sec Train-accuracy=0.912500 # INFO:root:Epoch[80] Batch [350] Speed: 1033.73 samples/sec Train-accuracy=0.910937 # INFO:root:Epoch[80] Train-accuracy=0.919922 # INFO:root:Epoch[80] Time cost=48.348 # INFO:root:Saved checkpoint to "sd-110-0081.params" # INFO:root:Epoch[80] Validation-accuracy=0.880142 # ... # INFO:root:Epoch[115] Batch [50] Speed: 1037.04 samples/sec Train-accuracy=0.937040 # INFO:root:Epoch[115] Batch [100] Speed: 1041.12 samples/sec Train-accuracy=0.934219 # INFO:root:Epoch[115] Batch [150] Speed: 1036.02 samples/sec Train-accuracy=0.933125 # INFO:root:Epoch[115] Batch [200] Speed: 1057.49 samples/sec Train-accuracy=0.938125 # INFO:root:Epoch[115] Batch [250] Speed: 1060.56 samples/sec Train-accuracy=0.933438 # INFO:root:Epoch[115] Batch [300] Speed: 1046.25 samples/sec Train-accuracy=0.935625 # INFO:root:Epoch[115] Batch [350] Speed: 1043.83 samples/sec Train-accuracy=0.927188 # INFO:root:Epoch[115] Train-accuracy=0.938477 # INFO:root:Epoch[115] Time cost=47.815 # INFO:root:Saved checkpoint to "sd-110-0116.params" # INFO:root:Epoch[115] Validation-accuracy=0.884415 # ... # INFO:root:Saved checkpoint to "sd-110-0499.params" # INFO:root:Epoch[498] Validation-accuracy=0.908554 # INFO:root:Epoch[499] Batch [50] Speed: 1068.28 samples/sec Train-accuracy=0.991422 # INFO:root:Epoch[499] Batch [100] Speed: 1053.10 samples/sec Train-accuracy=0.991094 # INFO:root:Epoch[499] Batch [150] Speed: 1042.89 samples/sec Train-accuracy=0.995156 # INFO:root:Epoch[499] Batch [200] Speed: 1066.22 samples/sec Train-accuracy=0.991406 # INFO:root:Epoch[499] Batch [250] Speed: 1050.56 samples/sec Train-accuracy=0.990781 # INFO:root:Epoch[499] Batch [300] Speed: 1032.02 samples/sec Train-accuracy=0.992500 # INFO:root:Epoch[499] Batch [350] Speed: 1062.16 samples/sec Train-accuracy=0.992969 # INFO:root:Epoch[499] Train-accuracy=0.994141 # INFO:root:Epoch[499] Time cost=47.401 # INFO:root:Saved checkpoint to "sd-110-0500.params" # INFO:root:Epoch[499] Validation-accuracy=0.906050 # ###########################################################################################
# # XML-RPC CLIENT LIBRARY # $Id$ # # an XML-RPC client interface for Python. # # the marshalling and response parser code can also be used to # implement XML-RPC servers. # # Notes: # this version is designed to work with Python 2.1 or newer. # # History: # 1999-01-14 fl Created # 1999-01-15 fl Changed dateTime to use localtime # 1999-01-16 fl Added Binary/base64 element, default to RPC2 service # 1999-01-19 fl Fixed array data element (from Skip Montanaro) # 1999-01-21 fl Fixed dateTime constructor, etc. # 1999-02-02 fl Added fault handling, handle empty sequences, etc. # 1999-02-10 fl Fixed problem with empty responses (from Skip Montanaro) # 1999-06-20 fl Speed improvements, pluggable parsers/transports (0.9.8) # 2000-11-28 fl Changed boolean to check the truth value of its argument # 2001-02-24 fl Added encoding/Unicode/SafeTransport patches # 2001-02-26 fl Added compare support to wrappers (0.9.9/1.0b1) # 2001-03-28 fl Make sure response tuple is a singleton # 2001-03-29 fl Don't require empty params element (from NAME 2001-06-10 fl Folded in _xmlrpclib accelerator support (1.0b2) # 2001-08-20 fl Base xmlrpclib.Error on built-in Exception (from NAME 2001-09-03 fl Allow Transport subclass to override getparser # 2001-09-10 fl Lazy import of urllib, cgi, xmllib (20x import speedup) # 2001-10-01 fl Remove containers from memo cache when done with them # 2001-10-01 fl Use faster escape method (80% dumps speedup) # 2001-10-02 fl More dumps microtuning # 2001-10-04 fl Make sure import expat gets a parser (from NAME 2001-10-10 sm Allow long ints to be passed as ints if they don't overflow # 2001-10-17 sm Test for int and long overflow (allows use on 64-bit systems) # 2001-11-12 fl Use repr() to marshal doubles (from NAME 2002-03-17 fl Avoid buffered read when possible (from NAME 2002-04-07 fl Added pythondoc comments # 2002-04-16 fl Added __str__ methods to datetime/binary wrappers # 2002-05-15 fl Added error constants (from NAME 2002-06-27 fl Merged with Python CVS version # 2002-10-22 fl Added basic authentication (based on code from NAME 2003-01-22 sm Add support for the bool type # 2003-02-27 gvr Remove apply calls # 2003-04-24 sm Use cStringIO if available # 2003-04-25 ak Add support for nil # 2003-06-15 gn Add support for time.struct_time # 2003-07-12 gp Correct marshalling of Faults # 2003-10-31 mvl Add multicall support # 2004-08-20 mvl Bump minimum supported Python version to 2.1 # 2014-12-02 ch/doko Add workaround for gzip bomb vulnerability # # Copyright (c) 1999-2002 by Secret Labs AB. # Copyright (c) 1999-2002 by NAME Lundh. # # EMAIL http://www.pythonware.com # # -------------------------------------------------------------------- # The XML-RPC client interface is # # Copyright (c) 1999-2002 by Secret Labs AB # Copyright (c) 1999-2002 by NAME Lundh # # By obtaining, using, and/or copying this software and/or its # associated documentation, you agree that you have read, understood, # and will comply with the following terms and conditions: # # Permission to use, copy, modify, and distribute this software and # its associated documentation for any purpose and without fee is # hereby granted, provided that the above copyright notice appears in # all copies, and that both that copyright notice and this permission # notice appear in supporting documentation, and that the name of # Secret Labs AB or the author not be used in advertising or publicity # pertaining to distribution of the software without specific, written # prior permission. # # SECRET LABS AB AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD # TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANT- # ABILITY AND FITNESS. IN NO EVENT SHALL SECRET LABS AB OR THE AUTHOR # BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY # DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS # ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE # OF THIS SOFTWARE. # -------------------------------------------------------------------- # # things to look into some day: # TODO: sort out True/False/boolean issues for Python 2.3
""" Define a simple format for saving numpy arrays to disk with the full information about them. The ``.npy`` format is the standard binary file format in NumPy for persisting a *single* arbitrary NumPy array on disk. The format stores all of the shape and dtype information necessary to reconstruct the array correctly even on another machine with a different architecture. The format is designed to be as simple as possible while achieving its limited goals. The ``.npz`` format is the standard format for persisting *multiple* NumPy arrays on disk. A ``.npz`` file is a zip file containing multiple ``.npy`` files, one for each array. Capabilities ------------ - Can represent all NumPy arrays including nested record arrays and object arrays. - Represents the data in its native binary form. - Supports Fortran-contiguous arrays directly. - Stores all of the necessary information to reconstruct the array including shape and dtype on a machine of a different architecture. Both little-endian and big-endian arrays are supported, and a file with little-endian numbers will yield a little-endian array on any machine reading the file. The types are described in terms of their actual sizes. For example, if a machine with a 64-bit C "long int" writes out an array with "long ints", a reading machine with 32-bit C "long ints" will yield an array with 64-bit integers. - Is straightforward to reverse engineer. Datasets often live longer than the programs that created them. A competent developer should be able to create a solution in their preferred programming language to read most ``.npy`` files that he has been given without much documentation. - Allows memory-mapping of the data. See `open_memmep`. - Can be read from a filelike stream object instead of an actual file. - Stores object arrays, i.e. arrays containing elements that are arbitrary Python objects. Files with object arrays are not to be mmapable, but can be read and written to disk. Limitations ----------- - Arbitrary subclasses of numpy.ndarray are not completely preserved. Subclasses will be accepted for writing, but only the array data will be written out. A regular numpy.ndarray object will be created upon reading the file. .. warning:: Due to limitations in the interpretation of structured dtypes, dtypes with fields with empty names will have the names replaced by 'f0', 'f1', etc. Such arrays will not round-trip through the format entirely accurately. The data is intact; only the field names will differ. We are working on a fix for this. This fix will not require a change in the file format. The arrays with such structures can still be saved and restored, and the correct dtype may be restored by using the ``loadedarray.view(correct_dtype)`` method. File extensions --------------- We recommend using the ``.npy`` and ``.npz`` extensions for files saved in this format. This is by no means a requirement; applications may wish to use these file formats but use an extension specific to the application. In the absence of an obvious alternative, however, we suggest using ``.npy`` and ``.npz``. Version numbering ----------------- The version numbering of these formats is independent of NumPy version numbering. If the format is upgraded, the code in `numpy.io` will still be able to read and write Version 1.0 files. Format Version 1.0 ------------------ The first 6 bytes are a magic string: exactly ``\\x93NUMPY``. The next 1 byte is an unsigned byte: the major version number of the file format, e.g. ``\\x01``. The next 1 byte is an unsigned byte: the minor version number of the file format, e.g. ``\\x00``. Note: the version of the file format is not tied to the version of the numpy package. The next 2 bytes form a little-endian unsigned short int: the length of the header data HEADER_LEN. The next HEADER_LEN bytes form the header data describing the array's format. It is an ASCII string which contains a Python literal expression of a dictionary. It is terminated by a newline (``\\n``) and padded with spaces (``\\x20``) to make the total length of ``magic string + 4 + HEADER_LEN`` be evenly divisible by 16 for alignment purposes. The dictionary contains three keys: "descr" : dtype.descr An object that can be passed as an argument to the `numpy.dtype` constructor to create the array's dtype. "fortran_order" : bool Whether the array data is Fortran-contiguous or not. Since Fortran-contiguous arrays are a common form of non-C-contiguity, we allow them to be written directly to disk for efficiency. "shape" : tuple of int The shape of the array. For repeatability and readability, the dictionary keys are sorted in alphabetic order. This is for convenience only. A writer SHOULD implement this if possible. A reader MUST NOT depend on this. Following the header comes the array data. If the dtype contains Python objects (i.e. ``dtype.hasobject is True``), then the data is a Python pickle of the array. Otherwise the data is the contiguous (either C- or Fortran-, depending on ``fortran_order``) bytes of the array. Consumers can figure out the number of bytes by multiplying the number of elements given by the shape (noting that ``shape=()`` means there is 1 element) by ``dtype.itemsize``. Format Version 2.0 ------------------ The version 1.0 format only allowed the array header to have a total size of 65535 bytes. This can be exceeded by structured arrays with a large number of columns. The version 2.0 format extends the header size to 4 GiB. `numpy.save` will automatically save in 2.0 format if the data requires it, else it will always use the more compatible 1.0 format. The description of the fourth element of the header therefore has become: "The next 4 bytes form a little-endian unsigned int: the length of the header data HEADER_LEN." Notes ----- The ``.npy`` format, including reasons for creating it and a comparison of alternatives, is described fully in the "npy-format" NEP. """
"""automatically manage newlines in repository files This extension allows you to manage the type of line endings (CRLF or LF) that are used in the repository and in the local working directory. That way you can get CRLF line endings on Windows and LF on Unix/Mac, thereby letting everybody use their OS native line endings. The extension reads its configuration from a versioned ``.hgeol`` configuration file found in the root of the working copy. The ``.hgeol`` file use the same syntax as all other Mercurial configuration files. It uses two sections, ``[patterns]`` and ``[repository]``. The ``[patterns]`` section specifies how line endings should be converted between the working copy and the repository. The format is specified by a file pattern. The first match is used, so put more specific patterns first. The available line endings are ``LF``, ``CRLF``, and ``BIN``. Files with the declared format of ``CRLF`` or ``LF`` are always checked out and stored in the repository in that format and files declared to be binary (``BIN``) are left unchanged. Additionally, ``native`` is an alias for checking out in the platform's default line ending: ``LF`` on Unix (including Mac OS X) and ``CRLF`` on Windows. Note that ``BIN`` (do nothing to line endings) is Mercurial's default behaviour; it is only needed if you need to override a later, more general pattern. The optional ``[repository]`` section specifies the line endings to use for files stored in the repository. It has a single setting, ``native``, which determines the storage line endings for files declared as ``native`` in the ``[patterns]`` section. It can be set to ``LF`` or ``CRLF``. The default is ``LF``. For example, this means that on Windows, files configured as ``native`` (``CRLF`` by default) will be converted to ``LF`` when stored in the repository. Files declared as ``LF``, ``CRLF``, or ``BIN`` in the ``[patterns]`` section are always stored as-is in the repository. Example versioned ``.hgeol`` file:: [patterns] **.py = native **.vcproj = CRLF **.txt = native Makefile = LF **.jpg = BIN [repository] native = LF .. note:: The rules will first apply when files are touched in the working copy, e.g. by updating to null and back to tip to touch all files. The extension uses an optional ``[eol]`` section read from both the normal Mercurial configuration files and the ``.hgeol`` file, with the latter overriding the former. You can use that section to control the overall behavior. There are three settings: - ``eol.native`` (default ``os.linesep``) can be set to ``LF`` or ``CRLF`` to override the default interpretation of ``native`` for checkout. This can be used with :hg:`archive` on Unix, say, to generate an archive where files have line endings for Windows. - ``eol.only-consistent`` (default True) can be set to False to make the extension convert files with inconsistent EOLs. Inconsistent means that there is both ``CRLF`` and ``LF`` present in the file. Such files are normally not touched under the assumption that they have mixed EOLs on purpose. - ``eol.fix-trailing-newline`` (default False) can be set to True to ensure that converted files end with a EOL character (either ``\\n`` or ``\\r\\n`` as per the configured patterns). The extension provides ``cleverencode:`` and ``cleverdecode:`` filters like the deprecated win32text extension does. This means that you can disable win32text and enable eol and your filters will still work. You only need to these filters until you have prepared a ``.hgeol`` file. The ``win32text.forbid*`` hooks provided by the win32text extension have been unified into a single hook named ``eol.checkheadshook``. The hook will lookup the expected line endings from the ``.hgeol`` file, which means you must migrate to a ``.hgeol`` file first before using the hook. ``eol.checkheadshook`` only checks heads, intermediate invalid revisions will be pushed. To forbid them completely, use the ``eol.checkallhook`` hook. These hooks are best used as ``pretxnchangegroup`` hooks. See :hg:`help patterns` for more information about the glob patterns used. """
""" (This script is independent from lfc_dfc_copy) This script is used to migrate the content of the LFC DB to the DFC DB when used with Stored procedure and Foreign keys. It won't work with the other schema. It is the central component of the migration. * Please read the doc of each method in this script, there are important informations. * You need to have a "clean" LFC db. That is, the LFC does not enforce consistency, and for example a file can belong to a user which is not in the DB. This will not work in the DFC. Hence, you must make sure you have no inconsistencies what so ever in the LFC. * This script assumes that you already created the DFC DB, with the schema. * While performing the migration, the LFC must be in read-only. I am speaking here about the LFC service, not only in the DIRAC service. There should be *zero* insertion in the LFC or the DFC dbs while running this script. Read further the migration explanations for more details. * This script must be executed with a user that can execute the DIRAC method getUsernameForDN and getGroupsWithVOMSAttribute. * The script is doing 2 consistency checks at the end. One checks real inconsistencies within the DFC (see 'databaseIntegrityCheck'), while the second one compares the amount of entities in the LFC with respect to the DFC (see 'compareNumbers'). Please pay attention to the doc of these methods. * A final step is to be done once the migration is over. You need to call the procedure 'ps_rebuild_directory_usage'. Indeed, during the migration, the storage usage is not updated. So if you are happy with the report of the consistency checks, go for it. * I strongly recommend to do a snapshot of your LFC DB to try the migration script multiple times before hand The global idea of the migration is as follow: * Put the LFC service in read-only mode (it doesn't harm, while write do...) * use this script to copy the data * Put again the LFC service in read-write, and set the LFC Write in the CS * The DFC should be put in Read-Write, so LFC and DFC will be in sync, but we read only from the DFC. When after few weeks, you are sure that the migration was successful, get rid of the LFC. Having 2 master catalogs is not a good idea... As for the migration itself. Here are some tips and recommendations. * While it is possible to keep all the system running, we STRONGLY recommend to have a deep downtime. * Declare ahead of time the DFC DB and services in the CS. * One day before, start draining the system (avoid new jobs submission and so on). * Just before starting the migration: - Stop the FTSAgent and the RequestExecutingAgent. - Set the LFC service in read only - go for the deep downtime, stop all the agents basically. (Caution, don't stop the ReqManager service, it is important to have it !) * Perform the migration: - run this script - if happy with the result, rebuild the storage usage * Restarting phase: - Mark the LFC in Read only in the CS - Declare the DFC as Read-Write catalog and Master. Also, it should be the first master catalog. - start the DFC services - Hotfix the ReqManager (see bellow) - restart *all* the services that interact with the DMS, so that they pick up the new configuration - you can restart all the agents If the migration is done this way: - the read action are never perturbed - the synchronous writes (with script) will fail - the jobs that are still running during the migration and that will attempt a write will end up creating a Request. A hotfix in the ReqManager is necessary though. During the migration, some RMS Requests might have been created, that concerns registration for the master catalog. For the jobs running during the migration, the master catalog was only the DFC, however you want that when these Requests are executed, they are also done in the DFC. The best for that is to hotfix the ReqManager, so that if an operation is targeted at the LFC, it will be modified to be targeted on both the LFC and the DFC. Providing you called your LFC 'LcgFileCatalogCombined', the fix is to be put in the Catalog setter of RequestManagementSystem/Client/Operation.py and would look something like: if value == "LcgFileCatalogCombined": value = "FileCatalog,LcgFileCatalogCombined" Note that for jobs that already have the new configuration, they will create 2 operations, one targeted at the DFC, the other one at the LFC. But with this fix, you will end up with one targeted at the DFC, the other one target at the LFC and the DFC. However, it should do no harm. But remember it when debugging... Anyway, this is only useful for Requests that were created during or before the downtime, or by job started with the old configuration. So a relatively limited amount of time... GOOD LUCK ! """
"""Test module for the noddy examples Noddy 1: >>> import noddy >>> n1 = noddy.Noddy() >>> n2 = noddy.Noddy() >>> del n1 >>> del n2 Noddy 2 >>> import noddy2 >>> n1 = noddy2.Noddy('jim', 'fulton', 42) >>> n1.first 'jim' >>> n1.last 'NAME n1.number 42 >>> n1.name() 'jim NAME n1.first = 'will' >>> n1.name() 'will NAME n1.last = 'NAME n1.name() 'will NAME del n1.first >>> n1.name() Traceback (most recent call last): ... AttributeError: first >>> n1.first Traceback (most recent call last): ... AttributeError: first >>> n1.first = 'drew' >>> n1.first 'drew' >>> del n1.number Traceback (most recent call last): ... TypeError: can't delete numeric/char attribute >>> n1.number=2 >>> n1.number 2 >>> n1.first = 42 >>> n1.name() '42 NAME n2 = noddy2.Noddy() >>> n2.name() ' ' >>> n2.first '' >>> n2.last '' >>> del n2.first >>> n2.first Traceback (most recent call last): ... AttributeError: first >>> n2.first Traceback (most recent call last): ... AttributeError: first >>> n2.name() Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: first >>> n2.number 0 >>> n3 = noddy2.Noddy('jim', 'fulton', 'waaa') Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: an integer is required >>> del n1 >>> del n2 Noddy 3 >>> import noddy3 >>> n1 = noddy3.Noddy('jim', 'fulton', 42) >>> n1 = noddy3.Noddy('jim', 'fulton', 42) >>> n1.name() 'jim NAME del n1.first Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: Cannot delete the first attribute >>> n1.first = 42 Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: The first attribute value must be a string >>> n1.first = 'will' >>> n1.name() 'will NAME n2 = noddy3.Noddy() >>> n2 = noddy3.Noddy() >>> n2 = noddy3.Noddy() >>> n3 = noddy3.Noddy('jim', 'fulton', 'waaa') Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: an integer is required >>> del n1 >>> del n2 Noddy 4 >>> import noddy4 >>> n1 = noddy4.Noddy('jim', 'fulton', 42) >>> n1.first 'jim' >>> n1.last 'NAME n1.number 42 >>> n1.name() 'jim NAME n1.first = 'will' >>> n1.name() 'will NAME n1.last = 'NAME n1.name() 'will NAME del n1.first >>> n1.name() Traceback (most recent call last): ... AttributeError: first >>> n1.first Traceback (most recent call last): ... AttributeError: first >>> n1.first = 'drew' >>> n1.first 'drew' >>> del n1.number Traceback (most recent call last): ... TypeError: can't delete numeric/char attribute >>> n1.number=2 >>> n1.number 2 >>> n1.first = 42 >>> n1.name() '42 NAME n2 = noddy4.Noddy() >>> n2 = noddy4.Noddy() >>> n2 = noddy4.Noddy() >>> n2 = noddy4.Noddy() >>> n2.name() ' ' >>> n2.first '' >>> n2.last '' >>> del n2.first >>> n2.first Traceback (most recent call last): ... AttributeError: first >>> n2.first Traceback (most recent call last): ... AttributeError: first >>> n2.name() Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: first >>> n2.number 0 >>> n3 = noddy4.Noddy('jim', 'fulton', 'waaa') Traceback (most recent call last): File "<stdin>", line 1, in ? TypeError: an integer is required Test cyclic gc(?) >>> import gc >>> gc.disable() >>> x = [] >>> l = [x] >>> n2.first = l >>> n2.first [[]] >>> l.append(n2) >>> del l >>> del n1 >>> del n2 >>> sys.getrefcount(x) 3 >>> ignore = gc.collect() >>> sys.getrefcount(x) 2 >>> gc.enable() """
#!/usr/bin/env python # --------------------------------------------------------- # Filename: multilineMAX7219.py # --------------------------------------------------------- # multilineMAX7219 library - functions for driving n * m # daisy-chained MAX7219 8x8 LED matrices boards # # v1.0 # NAME 2014 # --------------------------------------------------------- # improved and extended version of USERNAME MAX7219array # ( https://github.com/JonA1961/MAX7219array ) # --------------------------------------------------------- # Controls a linear array of MAX7219 LED Display Drivers, # each of which is driving an 8x8 LED matrix. # # Terminology used in this script: # - matrix: one of the MAX7219 boards incl 8x8 LED display # - array: a 'daisy-chained' multiline display of such matrices # # Wiring up the array of MAX7219 controller boards: # - Each board's Vcc & GND pins connected to power (not from # the Raspberry Pi as the current requirement would be too # high). Note that the common GND also needs to be connected # to the Pi's GND pin # - Each board's CS & CLK pins to be connected to the corresponding # SPI GPIO pins (CE0=Pin24 & SCLK=Pin23) on the RPi # - The right-most board's DIN pins to be connected to the # MOSI (=Pin19) SPI GPIO pin on the RPi # - Each subsequent board's DIN pin to be connected to the DOUT # pin on the board to its right as shown below: # # ...-+ +----+ +----+ +----+ # | | | | | | | # DOUT- | DOUT- | DOUT- | DOUT- # | | | | | | | | | | | # -DIN- | -DIN- | -DIN- | -DIN- # | | | | | | | # +----+ +----+ +----+ +---> RPi SPI.MOSI # # Numbering used by this library: # - The number of horizontal matrices (amount of matrix modules in one row) # - The number of vertical matrices (amount of matrix modules in one column) # in the MATRIX_WIDTH and MATRIX_HEIGHT variables below # - Matrices are numbered from 0 (left bottom) to MATRIX_HEIGHT*MATRIX_WIDTH-1 (right top) # while the following matrix is the one above. If it is the uppermost matrix, the # following matrix is the one in the column right next to it (bottom): # e.g. 4x3 matrices: # 2 5 8 11 # 1 4 7 10 # 0 3 6 9 # - gfx_ (graphics-based) functions use an x,y coordinate system # to address individual LEDs: # x=0 (left-hand column) to x=8*MATRIX_WIDTH-1 (right-hand column) # y=0 (bottom row) to y=8*MATRIX_HEIGHT-1 (top row) # --------------------------------------------------------- # The main use for this script is as an imported library: # 1. In the main script, import the library using eg: # import multilineMAX7219.py as LEDMatrix # 2. Also import the fonts with: # from multilineMAX7219_fonts import CP437_FONT, SINCLAIRS_FONT, LCD_FONT, TINY_FONT # 3. To facilitate calling the library functions, # import the following pre-defined parameters: # from multilineMAX7219 import DIR_L, DIR_R, DIR_U, DIR_D # from multilineMAX7219 import DIR_LU, DIR_RU, DIR_LD, DIR_RD # from multilineMAX7219 import DISSOLVE, GFX_ON, GFX_OFF, GFX_INVERT # 4. The main script can then use the library functions using eg: # LEDMatrix.scroll_message_horiz(["This is line 1", "Sample Text"]) # # This script can also be executed directly as a shorthand way of running # a 'marquee' display. Enter the following at the command line to use # this functionality: # python multilineMAX7219.py message [repeats [speed [direction [font]]]]" # Or for more information on this usage, see the help text at the end of this # script, or alternatively, enter the following at the command line: # python multilineMAX7219.py # --------------------------------------------------------- # Based on and extended from the MAX7219array module by USERNAME (see https://github.com/JonA1961/MAX7219array ) # --------------------------------------------------------- # Requires: # - python-dev & py-spidev modules, see install instructions # at www.100randomtasks.com/simple-spi-on-raspberry-pi # - MAX7219fonts.py file containing font bitmaps # - User should also set MATRIX_HEIGHT and MATRIX_WIDTH variables below # to the appropriate value for the setup in use. Failure to do # this will prevent the library functions working properly # --------------------------------------------------------- # The functions from spidev used in this library are: # xfer() : send bytes deasserting CS/CE after every byte # xfer2() : send bytes only de-asserting CS/CE at end # --------------------------------------------------------- # The variables MATRIX_HEIGHT and MATRIX_WIDTH, defined in the # multilineMAX7219.py library script, should always be set to be # consistent with the actual hardware setup in use. # # --------------------------------------------------------- # See further documentation of each library function below # Also see multilineMAX7219_demo.py script for examples of use # MAX7219 datasheet gives full details of operation of the # LED driver chip # ---------------------------------------------------------
{ 'name': 'Web', 'category': 'Hidden', 'version': 'IP_ADDRESS', 'description': """ OpenERP Web core module. ======================== This module provides the core of the OpenERP Web Client. """, 'depends': [], 'auto_install': True, 'post_load': 'wsgi_postload', 'js' : [ "static/src/fixbind.js", "static/lib/datejs/globalization/en-US.js", "static/lib/datejs/core.js", "static/lib/datejs/parser.js", "static/lib/datejs/sugarpak.js", "static/lib/datejs/extras.js", "static/lib/jquery/jquery-1.8.3.js", "static/lib/jquery.MD5/jquery.md5.js", "static/lib/jquery.form/jquery.form.js", "static/lib/jquery.validate/jquery.validate.js", "static/lib/jquery.ba-bbq/jquery.ba-bbq.js", "static/lib/spinjs/spin.js", "static/lib/jquery.autosize/jquery.autosize.js", "static/lib/jquery.blockUI/jquery.blockUI.js", "static/lib/jquery.placeholder/jquery.placeholder.js", "static/lib/jquery.ui/js/jquery-ui-1.9.1.custom.js", "static/lib/jquery.ui.timepicker/js/jquery-ui-timepicker-addon.js", "static/lib/jquery.ui.notify/js/jquery.notify.js", "static/lib/jquery.deferred-queue/jquery.deferred-queue.js", "static/lib/jquery.scrollTo/jquery.scrollTo-min.js", "static/lib/jquery.tipsy/jquery.tipsy.js", "static/lib/jquery.textext/jquery.textext.js", "static/lib/jquery.timeago/jquery.timeago.js", "static/lib/qweb/qweb2.js", "static/lib/underscore/underscore.js", "static/lib/underscore/underscore.string.js", "static/lib/backbone/backbone.js", "static/lib/cleditor/jquery.cleditor.js", "static/lib/py.js/lib/py.js", "static/src/js/boot.js", "static/src/js/testing.js", "static/src/js/pyeval.js", "static/src/js/corelib.js", "static/src/js/coresetup.js", "static/src/js/dates.js", "static/src/js/formats.js", "static/src/js/chrome.js", "static/src/js/views.js", "static/src/js/data.js", "static/src/js/data_export.js", "static/src/js/search.js", "static/src/js/view_form.js", "static/src/js/view_list.js", "static/src/js/view_list_editable.js", "static/src/js/view_tree.js", ], 'css' : [ "static/lib/jquery.ui.bootstrap/css/custom-theme/jquery-ui-1.9.0.custom.css", "static/lib/jquery.ui.timepicker/css/jquery-ui-timepicker-addon.css", "static/lib/jquery.ui.notify/css/ui.notify.css", "static/lib/jquery.tipsy/tipsy.css", "static/lib/jquery.textext/jquery.textext.css", "static/src/css/base.css", "static/src/css/data_export.css", "static/lib/cleditor/jquery.cleditor.css", ], 'qweb' : [ "static/src/xml/*.xml", ], 'test': [ "static/test/testing.js", "static/test/class.js", "static/test/registry.js", "static/test/form.js", "static/test/data.js", "static/test/list-utils.js", "static/test/formats.js", "static/test/rpc.js", "static/test/evals.js", "static/test/search.js", "static/test/Widget.js", "static/test/list.js", "static/test/list-editable.js", "static/test/mutex.js" ], 'bootstrap': True, }
# Check the basic discovery process, including a sub-suite. # # RUN: %{lit} %{inputs}/discovery \ # RUN: -j 1 --debug --show-tests --show-suites \ # RUN: -v > %t.out 2> %t.err # RUN: FileCheck --check-prefix=CHECK-BASIC-OUT < %t.out %s # RUN: FileCheck --check-prefix=CHECK-BASIC-ERR < %t.err %s # # CHECK-BASIC-ERR: loading suite config '{{.*}}/discovery/lit.cfg' # CHECK-BASIC-ERR: loading local config '{{.*}}/discovery/subdir/lit.local.cfg' # CHECK-BASIC-ERR: loading suite config '{{.*}}/discovery/subsuite/lit.cfg' # # CHECK-BASIC-OUT: -- Test Suites -- # CHECK-BASIC-OUT: sub-suite - 2 tests # CHECK-BASIC-OUT: Source Root: {{.*/discovery/subsuite$}} # CHECK-BASIC-OUT: Exec Root : {{.*/discovery/subsuite$}} # CHECK-BASIC-OUT: top-level-suite - 3 tests # CHECK-BASIC-OUT: Source Root: {{.*/discovery$}} # CHECK-BASIC-OUT: Exec Root : {{.*/discovery$}} # # CHECK-BASIC-OUT: -- Available Tests -- # CHECK-BASIC-OUT: sub-suite :: test-one # CHECK-BASIC-OUT: sub-suite :: test-two # CHECK-BASIC-OUT: top-level-suite :: subdir/test-three # CHECK-BASIC-OUT: top-level-suite :: test-one # CHECK-BASIC-OUT: top-level-suite :: test-two # Check discovery when exact test names are given. # # RUN: %{lit} \ # RUN: %{inputs}/discovery/subdir/test-three.py \ # RUN: %{inputs}/discovery/subsuite/test-one.txt \ # RUN: -j 1 --show-tests --show-suites -v > %t.out # RUN: FileCheck --check-prefix=CHECK-EXACT-TEST < %t.out %s # # CHECK-EXACT-TEST: -- Available Tests -- # CHECK-EXACT-TEST: sub-suite :: test-one # CHECK-EXACT-TEST: top-level-suite :: subdir/test-three # Check discovery when using an exec path. # # RUN: %{lit} %{inputs}/exec-discovery \ # RUN: -j 1 --debug --show-tests --show-suites \ # RUN: -v > %t.out 2> %t.err # RUN: FileCheck --check-prefix=CHECK-ASEXEC-OUT < %t.out %s # RUN: FileCheck --check-prefix=CHECK-ASEXEC-ERR < %t.err %s # # CHECK-ASEXEC-ERR: loading suite config '{{.*}}/exec-discovery/lit.site.cfg' # CHECK-ASEXEC-ERR: load_config from '{{.*}}/discovery/lit.cfg' # CHECK-ASEXEC-ERR: loaded config '{{.*}}/discovery/lit.cfg' # CHECK-ASEXEC-ERR: loaded config '{{.*}}/exec-discovery/lit.site.cfg' # CHECK-ASEXEC-ERR: loading local config '{{.*}}/discovery/subdir/lit.local.cfg' # CHECK-ASEXEC-ERR: loading suite config '{{.*}}/discovery/subsuite/lit.cfg' # # CHECK-ASEXEC-OUT: -- Test Suites -- # CHECK-ASEXEC-OUT: sub-suite - 2 tests # CHECK-ASEXEC-OUT: Source Root: {{.*/discovery/subsuite$}} # CHECK-ASEXEC-OUT: Exec Root : {{.*/discovery/subsuite$}} # CHECK-ASEXEC-OUT: top-level-suite - 3 tests # CHECK-ASEXEC-OUT: Source Root: {{.*/discovery$}} # CHECK-ASEXEC-OUT: Exec Root : {{.*/exec-discovery$}} # # CHECK-ASEXEC-OUT: -- Available Tests -- # CHECK-ASEXEC-OUT: sub-suite :: test-one # CHECK-ASEXEC-OUT: sub-suite :: test-two # CHECK-ASEXEC-OUT: top-level-suite :: subdir/test-three # CHECK-ASEXEC-OUT: top-level-suite :: test-one # CHECK-ASEXEC-OUT: top-level-suite :: test-two # Check discovery when exact test names are given. # # FIXME: Note that using a path into a subsuite doesn't work correctly here. # # RUN: %{lit} \ # RUN: %{inputs}/exec-discovery/subdir/test-three.py \ # RUN: -j 1 --show-tests --show-suites -v > %t.out # RUN: FileCheck --check-prefix=CHECK-ASEXEC-EXACT-TEST < %t.out %s # # CHECK-ASEXEC-EXACT-TEST: -- Available Tests -- # CHECK-ASEXEC-EXACT-TEST: top-level-suite :: subdir/test-three # Check that we don't recurse infinitely when loading an site specific test # suite located inside the test source root. # # RUN: %{lit} \ # RUN: %{inputs}/exec-discovery-in-tree/obj/ \ # RUN: -j 1 --show-tests --show-suites -v > %t.out # RUN: FileCheck --check-prefix=CHECK-ASEXEC-INTREE < %t.out %s # # CHECK-ASEXEC-INTREE: exec-discovery-in-tree-suite - 1 tests # CHECK-ASEXEC-INTREE-NEXT: Source Root: {{.*/exec-discovery-in-tree$}} # CHECK-ASEXEC-INTREE-NEXT: Exec Root : {{.*/exec-discovery-in-tree/obj$}} # CHECK-ASEXEC-INTREE-NEXT: -- Available Tests -- # CHECK-ASEXEC-INTREE-NEXT: exec-discovery-in-tree-suite :: test-one
""" ===================================== Sparse matrices (:mod:`scipy.sparse`) ===================================== .. currentmodule:: scipy.sparse SciPy 2-D sparse matrix package for numeric data. Contents ======== Sparse matrix classes --------------------- .. autosummary:: :toctree: generated/ bsr_matrix - Block Sparse Row matrix coo_matrix - A sparse matrix in COOrdinate format csc_matrix - Compressed Sparse Column matrix csr_matrix - Compressed Sparse Row matrix dia_matrix - Sparse matrix with DIAgonal storage dok_matrix - Dictionary Of Keys based sparse matrix lil_matrix - Row-based list of lists sparse matrix spmatrix - Sparse matrix base class Functions --------- Building sparse matrices: .. autosummary:: :toctree: generated/ eye - Sparse MxN matrix whose k-th diagonal is all ones identity - Identity matrix in sparse format kron - kronecker product of two sparse matrices kronsum - kronecker sum of sparse matrices diags - Return a sparse matrix from diagonals spdiags - Return a sparse matrix from diagonals block_diag - Build a block diagonal sparse matrix tril - Lower triangular portion of a matrix in sparse format triu - Upper triangular portion of a matrix in sparse format bmat - Build a sparse matrix from sparse sub-blocks hstack - Stack sparse matrices horizontally (column wise) vstack - Stack sparse matrices vertically (row wise) rand - Random values in a given shape random - Random values in a given shape Save and load sparse matrices: .. autosummary:: :toctree: generated/ save_npz - Save a sparse matrix to a file using ``.npz`` format. load_npz - Load a sparse matrix from a file using ``.npz`` format. Sparse matrix tools: .. autosummary:: :toctree: generated/ find Identifying sparse matrices: .. autosummary:: :toctree: generated/ issparse isspmatrix isspmatrix_csc isspmatrix_csr isspmatrix_bsr isspmatrix_lil isspmatrix_dok isspmatrix_coo isspmatrix_dia Submodules ---------- .. autosummary:: csgraph - Compressed sparse graph routines linalg - sparse linear algebra routines Exceptions ---------- .. autosummary:: :toctree: generated/ SparseEfficiencyWarning SparseWarning Usage information ================= There are seven available sparse matrix types: 1. csc_matrix: Compressed Sparse Column format 2. csr_matrix: Compressed Sparse Row format 3. bsr_matrix: Block Sparse Row format 4. lil_matrix: List of Lists format 5. dok_matrix: Dictionary of Keys format 6. coo_matrix: COOrdinate format (aka IJV, triplet format) 7. dia_matrix: DIAgonal format To construct a matrix efficiently, use either dok_matrix or lil_matrix. The lil_matrix class supports basic slicing and fancy indexing with a similar syntax to NumPy arrays. As illustrated below, the COO format may also be used to efficiently construct matrices. Despite their similarity to NumPy arrays, it is **strongly discouraged** to use NumPy functions directly on these matrices because NumPy may not properly convert them for computations, leading to unexpected (and incorrect) results. If you do want to apply a NumPy function to these matrices, first check if SciPy has its own implementation for the given sparse matrix class, or **convert the sparse matrix to a NumPy array** (e.g., using the `toarray()` method of the class) first before applying the method. To perform manipulations such as multiplication or inversion, first convert the matrix to either CSC or CSR format. The lil_matrix format is row-based, so conversion to CSR is efficient, whereas conversion to CSC is less so. All conversions among the CSR, CSC, and COO formats are efficient, linear-time operations. Matrix vector product --------------------- To do a vector product between a sparse matrix and a vector simply use the matrix `dot` method, as described in its docstring: >>> import numpy as np >>> from scipy.sparse import csr_matrix >>> A = csr_matrix([[1, 2, 0], [0, 0, 3], [4, 0, 5]]) >>> v = np.array([1, 0, -1]) >>> A.dot(v) array([ 1, -3, -1], dtype=int64) .. warning:: As of NumPy 1.7, `np.dot` is not aware of sparse matrices, therefore using it will result on unexpected results or errors. The corresponding dense array should be obtained first instead: >>> np.dot(A.toarray(), v) array([ 1, -3, -1], dtype=int64) but then all the performance advantages would be lost. The CSR format is specially suitable for fast matrix vector products. Example 1 --------- Construct a 1000x1000 lil_matrix and add some values to it: >>> from scipy.sparse import lil_matrix >>> from scipy.sparse.linalg import spsolve >>> from numpy.linalg import solve, norm >>> from numpy.random import rand >>> A = lil_matrix((1000, 1000)) >>> A[0, :100] = rand(100) >>> A[1, 100:200] = A[0, :100] >>> A.setdiag(rand(1000)) Now convert it to CSR format and solve A x = b for x: >>> A = A.tocsr() >>> b = rand(1000) >>> x = spsolve(A, b) Convert it to a dense matrix and solve, and check that the result is the same: >>> x_ = solve(A.toarray(), b) Now we can compute norm of the error with: >>> err = norm(x-x_) >>> err < 1e-10 True It should be small :) Example 2 --------- Construct a matrix in COO format: >>> from scipy import sparse >>> from numpy import array >>> I = array([0,3,1,0]) >>> J = array([0,3,1,2]) >>> V = array([4,5,7,9]) >>> A = sparse.coo_matrix((V,(I,J)),shape=(4,4)) Notice that the indices do not need to be sorted. Duplicate (i,j) entries are summed when converting to CSR or CSC. >>> I = array([0,0,1,3,1,0,0]) >>> J = array([0,2,1,3,1,0,0]) >>> V = array([1,1,1,1,1,1,1]) >>> B = sparse.coo_matrix((V,(I,J)),shape=(4,4)).tocsr() This is useful for constructing finite-element stiffness and mass matrices. Further details --------------- CSR column indices are not necessarily sorted. Likewise for CSC row indices. Use the .sorted_indices() and .sort_indices() methods when sorted indices are required (e.g., when passing data to other libraries). """
""" ================= Structured Arrays ================= Introduction ============ NumPy provides powerful capabilities to create arrays of structured datatype. These arrays permit one to manipulate the data by named fields. A simple example will show what is meant.: :: >>> x = np.array([(1,2.,'Hello'), (2,3.,"World")], ... dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'S10')]) >>> x array([(1, 2.0, 'Hello'), (2, 3.0, 'World')], dtype=[('foo', '>i4'), ('bar', '>f4'), ('baz', '|S10')]) Here we have created a one-dimensional array of length 2. Each element of this array is a structure that contains three items, a 32-bit integer, a 32-bit float, and a string of length 10 or less. If we index this array at the second position we get the second structure: :: >>> x[1] (2,3.,"World") Conveniently, one can access any field of the array by indexing using the string that names that field. :: >>> y = x['bar'] >>> y array([ 2., 3.], dtype=float32) >>> y[:] = 2*y >>> y array([ 4., 6.], dtype=float32) >>> x array([(1, 4.0, 'Hello'), (2, 6.0, 'World')], dtype=[('foo', '>i4'), ('bar', '>f4'), ('baz', '|S10')]) In these examples, y is a simple float array consisting of the 2nd field in the structured type. But, rather than being a copy of the data in the structured array, it is a view, i.e., it shares exactly the same memory locations. Thus, when we updated this array by doubling its values, the structured array shows the corresponding values as doubled as well. Likewise, if one changes the structured array, the field view also changes: :: >>> x[1] = (-1,-1.,"Master") >>> x array([(1, 4.0, 'Hello'), (-1, -1.0, 'Master')], dtype=[('foo', '>i4'), ('bar', '>f4'), ('baz', '|S10')]) >>> y array([ 4., -1.], dtype=float32) Defining Structured Arrays ========================== One defines a structured array through the dtype object. There are **several** alternative ways to define the fields of a record. Some of these variants provide backward compatibility with Numeric, numarray, or another module, and should not be used except for such purposes. These will be so noted. One specifies record structure in one of four alternative ways, using an argument (as supplied to a dtype function keyword or a dtype object constructor itself). This argument must be one of the following: 1) string, 2) tuple, 3) list, or 4) dictionary. Each of these is briefly described below. 1) String argument. In this case, the constructor expects a comma-separated list of type specifiers, optionally with extra shape information. The fields are given the default names 'f0', 'f1', 'f2' and so on. The type specifiers can take 4 different forms: :: a) b1, i1, i2, i4, i8, u1, u2, u4, u8, f2, f4, f8, c8, c16, a<n> (representing bytes, ints, unsigned ints, floats, complex and fixed length strings of specified byte lengths) b) int8,...,uint8,...,float16, float32, float64, complex64, complex128 (this time with bit sizes) c) older Numeric/numarray type specifications (e.g. Float32). Don't use these in new code! d) Single character type specifiers (e.g H for unsigned short ints). Avoid using these unless you must. Details can be found in the NumPy book These different styles can be mixed within the same string (but why would you want to do that?). Furthermore, each type specifier can be prefixed with a repetition number, or a shape. In these cases an array element is created, i.e., an array within a record. That array is still referred to as a single field. An example: :: >>> x = np.zeros(3, dtype='3int8, float32, (2,3)float64') >>> x array([([0, 0, 0], 0.0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), ([0, 0, 0], 0.0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), ([0, 0, 0], 0.0, [[0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])], dtype=[('f0', '|i1', 3), ('f1', '>f4'), ('f2', '>f8', (2, 3))]) By using strings to define the record structure, it precludes being able to name the fields in the original definition. The names can be changed as shown later, however. 2) Tuple argument: The only relevant tuple case that applies to record structures is when a structure is mapped to an existing data type. This is done by pairing in a tuple, the existing data type with a matching dtype definition (using any of the variants being described here). As an example (using a definition using a list, so see 3) for further details): :: >>> x = np.zeros(3, dtype=('i4',[('r','u1'), ('g','u1'), ('b','u1'), ('a','u1')])) >>> x array([0, 0, 0]) >>> x['r'] array([0, 0, 0], dtype=uint8) In this case, an array is produced that looks and acts like a simple int32 array, but also has definitions for fields that use only one byte of the int32 (a bit like Fortran equivalencing). 3) List argument: In this case the record structure is defined with a list of tuples. Each tuple has 2 or 3 elements specifying: 1) The name of the field ('' is permitted), 2) the type of the field, and 3) the shape (optional). For example:: >>> x = np.zeros(3, dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))]) >>> x array([(0.0, 0.0, [[0.0, 0.0], [0.0, 0.0]]), (0.0, 0.0, [[0.0, 0.0], [0.0, 0.0]]), (0.0, 0.0, [[0.0, 0.0], [0.0, 0.0]])], dtype=[('x', '>f4'), ('y', '>f4'), ('value', '>f4', (2, 2))]) 4) Dictionary argument: two different forms are permitted. The first consists of a dictionary with two required keys ('names' and 'formats'), each having an equal sized list of values. The format list contains any type/shape specifier allowed in other contexts. The names must be strings. There are two optional keys: 'offsets' and 'titles'. Each must be a correspondingly matching list to the required two where offsets contain integer offsets for each field, and titles are objects containing metadata for each field (these do not have to be strings), where the value of None is permitted. As an example: :: >>> x = np.zeros(3, dtype={'names':['col1', 'col2'], 'formats':['i4','f4']}) >>> x array([(0, 0.0), (0, 0.0), (0, 0.0)], dtype=[('col1', '>i4'), ('col2', '>f4')]) The other dictionary form permitted is a dictionary of name keys with tuple values specifying type, offset, and an optional title. :: >>> x = np.zeros(3, dtype={'col1':('i1',0,'title 1'), 'col2':('f4',1,'title 2')}) >>> x array([(0, 0.0), (0, 0.0), (0, 0.0)], dtype=[(('title 1', 'col1'), '|i1'), (('title 2', 'col2'), '>f4')]) Accessing and modifying field names =================================== The field names are an attribute of the dtype object defining the structure. For the last example: :: >>> x.dtype.names ('col1', 'col2') >>> x.dtype.names = ('x', 'y') >>> x array([(0, 0.0), (0, 0.0), (0, 0.0)], dtype=[(('title 1', 'x'), '|i1'), (('title 2', 'y'), '>f4')]) >>> x.dtype.names = ('x', 'y', 'z') # wrong number of names <type 'exceptions.ValueError'>: must replace all names at once with a sequence of length 2 Accessing field titles ==================================== The field titles provide a standard place to put associated info for fields. They do not have to be strings. :: >>> x.dtype.fields['x'][2] 'title 1' Accessing multiple fields at once ==================================== You can access multiple fields at once using a list of field names: :: >>> x = np.array([(1.5,2.5,(1.0,2.0)),(3.,4.,(4.,5.)),(1.,3.,(2.,6.))], dtype=[('x','f4'),('y',np.float32),('value','f4',(2,2))]) Notice that `x` is created with a list of tuples. :: >>> x[['x','y']] array([(1.5, 2.5), (3.0, 4.0), (1.0, 3.0)], dtype=[('x', '<f4'), ('y', '<f4')]) >>> x[['x','value']] array([(1.5, [[1.0, 2.0], [1.0, 2.0]]), (3.0, [[4.0, 5.0], [4.0, 5.0]]), (1.0, [[2.0, 6.0], [2.0, 6.0]])], dtype=[('x', '<f4'), ('value', '<f4', (2, 2))]) The fields are returned in the order they are asked for.:: >>> x[['y','x']] array([(2.5, 1.5), (4.0, 3.0), (3.0, 1.0)], dtype=[('y', '<f4'), ('x', '<f4')]) Filling structured arrays ========================= Structured arrays can be filled by field or row by row. :: >>> arr = np.zeros((5,), dtype=[('var1','f8'),('var2','f8')]) >>> arr['var1'] = np.arange(5) If you fill it in row by row, it takes a take a tuple (but not a list or array!):: >>> arr[0] = (10,20) >>> arr array([(10.0, 20.0), (1.0, 0.0), (2.0, 0.0), (3.0, 0.0), (4.0, 0.0)], dtype=[('var1', '<f8'), ('var2', '<f8')]) Record Arrays ============= For convenience, numpy provides "record arrays" which allow one to access fields of structured arrays by attribute rather than by index. Record arrays are structured arrays wrapped using a subclass of ndarray, :class:`numpy.recarray`, which allows field access by attribute on the array object, and record arrays also use a special datatype, :class:`numpy.record`, which allows field access by attribute on the individual elements of the array. The simplest way to create a record array is with :func:`numpy.rec.array`: :: >>> recordarr = np.rec.array([(1,2.,'Hello'),(2,3.,"World")], ... dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'S10')]) >>> recordarr.bar array([ 2., 3.], dtype=float32) >>> recordarr[1:2] rec.array([(2, 3.0, 'World')], dtype=[('foo', '<i4'), ('bar', '<f4'), ('baz', 'S10')]) >>> recordarr[1:2].foo array([2], dtype=int32) >>> recordarr.foo[1:2] array([2], dtype=int32) >>> recordarr[1].baz 'World' numpy.rec.array can convert a wide variety of arguments into record arrays, including normal structured arrays: :: >>> arr = array([(1,2.,'Hello'),(2,3.,"World")], ... dtype=[('foo', 'i4'), ('bar', 'f4'), ('baz', 'S10')]) >>> recordarr = np.rec.array(arr) The numpy.rec module provides a number of other convenience functions for creating record arrays, see :ref:`record array creation routines <routines.array-creation.rec>`. A record array representation of a structured array can be obtained using the appropriate :ref:`view`: :: >>> arr = np.array([(1,2.,'Hello'),(2,3.,"World")], ... dtype=[('foo', 'i4'),('bar', 'f4'), ('baz', 'a10')]) >>> recordarr = arr.view(dtype=dtype((np.record, arr.dtype)), ... type=np.recarray) For convenience, viewing an ndarray as type `np.recarray` will automatically convert to `np.record` datatype, so the dtype can be left out of the view: :: >>> recordarr = arr.view(np.recarray) >>> recordarr.dtype dtype((numpy.record, [('foo', '<i4'), ('bar', '<f4'), ('baz', 'S10')])) To get back to a plain ndarray both the dtype and type must be reset. The following view does so, taking into account the unusual case that the recordarr was not a structured type: :: >>> arr2 = recordarr.view(recordarr.dtype.fields or recordarr.dtype, np.ndarray) Record array fields accessed by index or by attribute are returned as a record array if the field has a structured type but as a plain ndarray otherwise. :: >>> recordarr = np.rec.array([('Hello', (1,2)),("World", (3,4))], ... dtype=[('foo', 'S6'),('bar', [('A', int), ('B', int)])]) >>> type(recordarr.foo) <type 'numpy.ndarray'> >>> type(recordarr.bar) <class 'numpy.core.records.recarray'> Note that if a field has the same name as an ndarray attribute, the ndarray attribute takes precedence. Such fields will be inaccessible by attribute but may still be accessed by index. """
"""Configuration file parser. A configuration file consists of sections, lead by a "[section]" header, and followed by "name: value" entries, with continuations and such in the style of RFC 822. Intrinsic defaults can be specified by passing them into the ConfigParser constructor as a dictionary. class: ConfigParser -- responsible for parsing a list of configuration files, and managing the parsed database. methods: __init__(defaults=None, dict_type=_default_dict, allow_no_value=False, delimiters=('=', ':'), comment_prefixes=('#', ';'), inline_comment_prefixes=None, strict=True, empty_lines_in_values=True): Create the parser. When `defaults' is given, it is initialized into the dictionary or intrinsic defaults. The keys must be strings, the values must be appropriate for %()s string interpolation. When `dict_type' is given, it will be used to create the dictionary objects for the list of sections, for the options within a section, and for the default values. When `delimiters' is given, it will be used as the set of substrings that divide keys from values. When `comment_prefixes' is given, it will be used as the set of substrings that prefix comments in empty lines. Comments can be indented. When `inline_comment_prefixes' is given, it will be used as the set of substrings that prefix comments in non-empty lines. When `strict` is True, the parser won't allow for any section or option duplicates while reading from a single source (file, string or dictionary). Default is True. When `empty_lines_in_values' is False (default: True), each empty line marks the end of an option. Otherwise, internal empty lines of a multiline option are kept as part of the value. When `allow_no_value' is True (default: False), options without values are accepted; the value presented for these is None. sections() Return all the configuration section names, sans DEFAULT. has_section(section) Return whether the given section exists. has_option(section, option) Return whether the given option exists in the given section. options(section) Return list of configuration options for the named section. read(filenames, encoding=None) Read and parse the list of named configuration files, given by name. A single filename is also allowed. Non-existing files are ignored. Return list of successfully read files. read_file(f, filename=None) Read and parse one configuration file, given as a file object. The filename defaults to f.name; it is only used in error messages (if f has no `name' attribute, the string `<???>' is used). read_string(string) Read configuration from a given string. read_dict(dictionary) Read configuration from a dictionary. Keys are section names, values are dictionaries with keys and values that should be present in the section. If the used dictionary type preserves order, sections and their keys will be added in order. Values are automatically converted to strings. get(section, option, raw=False, vars=None, fallback=_UNSET) Return a string value for the named option. All % interpolations are expanded in the return values, based on the defaults passed into the constructor and the DEFAULT section. Additional substitutions may be provided using the `vars' argument, which must be a dictionary whose contents override any pre-existing defaults. If `option' is a key in `vars', the value from `vars' is used. getint(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to an integer. getfloat(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to a float. getboolean(section, options, raw=False, vars=None, fallback=_UNSET) Like get(), but convert value to a boolean (currently case insensitively defined as 0, false, no, off for False, and 1, true, yes, on for True). Returns False or True. items(section=_UNSET, raw=False, vars=None) If section is given, return a list of tuples with (name, value) for each option in the section. Otherwise, return a list of tuples with (section_name, section_proxy) for each section, including DEFAULTSECT. remove_section(section) Remove the given file section and all its options. remove_option(section, option) Remove the given option from the given section. set(section, option, value) Set the given option. write(fp, space_around_delimiters=True) Write the configuration state in .ini format. If `space_around_delimiters' is True (the default), delimiters between keys and values are surrounded by spaces. """
""" Objects for dealing with Chebyshev series. This module provides a number of objects (mostly functions) useful for dealing with Chebyshev series, including a `Chebyshev` class that encapsulates the usual arithmetic operations. (General information on how this module represents and works with such polynomials is in the docstring for its "parent" sub-package, `numpy.polynomial`). Constants --------- - `chebdomain` -- Chebyshev series default domain, [-1,1]. - `chebzero` -- (Coefficients of the) Chebyshev series that evaluates identically to 0. - `chebone` -- (Coefficients of the) Chebyshev series that evaluates identically to 1. - `chebx` -- (Coefficients of the) Chebyshev series for the identity map, ``f(x) = x``. Arithmetic ---------- - `chebadd` -- add two Chebyshev series. - `chebsub` -- subtract one Chebyshev series from another. - `chebmul` -- multiply two Chebyshev series. - `chebdiv` -- divide one Chebyshev series by another. - `chebpow` -- raise a Chebyshev series to an positive integer power - `chebval` -- evaluate a Chebyshev series at given points. - `chebval2d` -- evaluate a 2D Chebyshev series at given points. - `chebval3d` -- evaluate a 3D Chebyshev series at given points. - `chebgrid2d` -- evaluate a 2D Chebyshev series on a Cartesian product. - `chebgrid3d` -- evaluate a 3D Chebyshev series on a Cartesian product. Calculus -------- - `chebder` -- differentiate a Chebyshev series. - `chebint` -- integrate a Chebyshev series. Misc Functions -------------- - `chebfromroots` -- create a Chebyshev series with specified roots. - `chebroots` -- find the roots of a Chebyshev series. - `chebvander` -- Vandermonde-like matrix for Chebyshev polynomials. - `chebvander2d` -- Vandermonde-like matrix for 2D power series. - `chebvander3d` -- Vandermonde-like matrix for 3D power series. - `chebgauss` -- Gauss-Chebyshev quadrature, points and weights. - `chebweight` -- Chebyshev weight function. - `chebcompanion` -- symmetrized companion matrix in Chebyshev form. - `chebfit` -- least-squares fit returning a Chebyshev series. - `chebpts1` -- Chebyshev points of the first kind. - `chebpts2` -- Chebyshev points of the second kind. - `chebtrim` -- trim leading coefficients from a Chebyshev series. - `chebline` -- Chebyshev series representing given straight line. - `cheb2poly` -- convert a Chebyshev series to a polynomial. - `poly2cheb` -- convert a polynomial to a Chebyshev series. Classes ------- - `Chebyshev` -- A Chebyshev series class. See also -------- `numpy.polynomial` Notes ----- The implementations of multiplication, division, integration, and differentiation use the algebraic identities [1]_: .. math :: T_n(x) = \\frac{z^n + z^{-n}}{2} \\\\ z\\frac{dx}{dz} = \\frac{z - z^{-1}}{2}. where .. math :: x = \\frac{z + z^{-1}}{2}. These identities allow a Chebyshev series to be expressed as a finite, symmetric Laurent series. In this module, this sort of Laurent series is referred to as a "z-series." References ---------- .. [1] NAME et al., "Combinatorial Trigonometry with Chebyshev Polynomials," *Journal of Statistical Planning and Inference 14*, 2008 (preprint: http://www.math.hmc.edu/~benjamin/papers/CombTrig.pdf, pg. 4) """
# The following CSI codes supported by xcode are not tested. # Query ReGIS/Sixel attributes: CSI ? Pi ; Pa ; P vS # Initiate highlight mouse tracking: CSI Ps ; Ps ; Ps ; Ps ; Ps T # Media Copy (MC): CSI Pm i # Media Copy (MC, DEC-specific): CSI ? Pm i # Character Attributes (SGR): CSI Pm m # Disable modifiers: CSI > Ps n # Set pointer mode: CSI > Ps p # Load LEDs (DECLL): CSI Ps q # Set cursor style (DECSCUSR): CIS Ps SP q # Select character protection attribute (DECSCA): CSI Ps " q [This is already tested by DECSED and DECSEL] # Window manipulation: CSI Ps; Ps; Ps t # Reverse Attributes in Rectangular Area (DECRARA): CSI Pt ; Pl ; Pb ; Pr ; Ps $ t # Set warning bell volume (DECSWBV): CSI Ps SP t # Set margin-bell volume (DECSMBV): CSI Ps SP u # Enable Filter Rectangle (DECEFR): CSI Pt ; Pl ; Pb ; Pr ' w # Request Terminal Parameters (DECREQTPARM): CSI Ps x # Select Attribute Change Extent (DECSACE): CSI Ps * x # Request Checksum of Rectangular Area (DECRQCRA): CSI Pi ; Pg ; Pt ; Pl ; Pb ; Pr * y # Select Locator Events (DECSLE): CSI Pm ' { # Request Locator Position (DECRQLP): CSI PS ' | # ESC SP L Set ANSI conformance level 1 (dpANS X3.134.1). # ESC SP M Set ANSI conformance level 2 (dpANS X3.134.1). # ESC SP N Set ANSI conformance level 3 (dpANS X3.134.1). # In xterm, all these do is fiddle with character sets, which are not testable. # ESC # 3 DEC double-height line, top half (DECDHL). # ESC # 4 DEC double-height line, bottom half (DECDHL). # ESC # 5 DEC single-width line (DECSWL). # ESC # 6 DEC double-width line (DECDWL). # Double-width affects display only and is generally not introspectable. Wrap # doesn't work so there's no way to tell where the cursor is visually. # ESC % @ Select default character set. That is ISO 8859-1 (ISO 2022). # ESC % G Select UTF-8 character set (ISO 2022). # ESC ( C Designate G0 Character Set (ISO 2022, VT100). # ESC ) C Designate G1 Character Set (ISO 2022, VT100). # ESC * C Designate G2 Character Set (ISO 2022, VT220). # ESC + C Designate G3 Character Set (ISO 2022, VT220). # ESC - C Designate G1 Character Set (VT300). # ESC . C Designate G2 Character Set (VT300). # ESC / C Designate G3 Character Set (VT300). # Character set stuff is not introspectable. # Shift in (SI): ^O # Shift out (SO): ^N # Space (SP): 0x20 # Tab (TAB): 0x09 [tested in HTS] # ESC = Application Keypad (DECKPAM). # ESC > Normal Keypad (DECKPNM). # ESC F Cursor to lower left corner of screen. This is enabled by the # hpLowerleftBugCompat resource. (Not worth testing as it's off by # default, and silly regardless) # ESC l Memory Lock (per HP terminals). Locks memory above the cursor. # ESC m Memory Unlock (per HP terminals). # ESC n Invoke the G2 Character Set as GL (LS2). # ESC o Invoke the G3 Character Set as GL (LS3). # ESC | Invoke the G3 Character Set as GR (LS3R). # ESC } Invoke the G2 Character Set as GR (LS2R). # ESC ~ Invoke the G1 Character Set as GR (LS1R). # DCS + p Pt ST Set Termcap/Terminfo Data # DCS + q Pt ST Request Termcap/Terminfo String # The following OSC commands are tested in xterm_winops and don't have their own test: # Ps = 0 -> Change Icon Name and Window Title to Pt. # Ps = 1 -> Change Icon Name to Pt. # Ps = 2 -> Change Window Title to Pt. # This test is too ill-defined and X-specific, and is not tested: # Ps = 3 -> Set X property on top-level window. Pt should be # in the form "prop=value", or just "prop" to delete the prop- # erty # No introspection for whether special color are enabled/disabled: # Ps = 6 ; c; f -> Enable/disable Special Color Number c. The # second parameter tells xterm to enable the corresponding color # mode if nonzero, disable it if zero. # Off by default, obvious security issues: # Ps = 4 6 -> Change Log File to Pt. (This is normally dis- # abled by a compile-time option). # No introspection for fonts: # Ps = 5 0 -> Set Font to Pt. # No-op: # Ps = 5 1 -> reserved for Emacs shell.