1. Eric Parent
  2. Utilities

Commits

Eric Parent  committed a71b150

Minor refactoring of source code

  • Participants
  • Parent commits 577695e
  • Branches master

Comments (0)

Files changed (4)

File dict_to_xml.py

View file
  • Ignore whitespace
 Dependencies
 ------------
 
-- None
+- NumPy
 
 
 Author: Eric Parent <eric@eparent.info>
 
-
 Copyright (c) 2013 Eric Parent
 
 License: The MIT License (MIT)
 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
-
 """
 # ----------------------------------------
 # Standard libraries
     """This class converts a dictionary to XML."""
 
     def __init__(self, structure):
-        self.doc     = Document()
+        self.doc = Document()
         if len(structure) == 1:
-            rootName    = str(structure.keys()[0])
-            self.root   = self.doc.createElement(rootName)
+            rootName = str(structure.keys()[0])
+            self.root = self.doc.createElement(rootName)
 
             self.doc.appendChild(self.root)
             self.build(self.root, structure[rootName])
 
         elif type(structure) == list:
             grandFather = father.parentNode
-            tagName     = father.tagName
+            tagName = father.tagName
             grandFather.removeChild(father)
             for l in structure:
                 tag = self.doc.createElement(tagName)
                 grandFather.appendChild(tag)
 
         else:
-            data    = str(structure)
-            tag     = self.doc.createTextNode(data)
+            data = str(structure)
+            tag = self.doc.createTextNode(data)
             father.appendChild(tag)
 
     def display(self):
         print self.doc.toprettyxml(indent="  ")
 
 
-
-
 def main():
     example = {'sibbling':
                {'couple':
-                {'mother':'mom',
-                 'father':'dad',
-                 'children':[{'child':'foo'},
-                             {'child':'bar'}]},
+                {'mother': 'mom',
+                 'father': 'dad',
+                 'children': [{'child':'foo'},
+                              {'child':'bar'}]},
             }
            }
 
     try:
         import numpy as np
         width = 10
-        example = {'drift': {'sid': {'Blue': [np.arange(10, 10 + width), np.arange(44, 44 + width)],
-                                     'Red': [np.arange(7, 7 + width), np.arange(22, 22 + width)],
-                                 },
-                             'cubenames': ["123456789s0", "123456987s0"],
-                         },
+        example = {'drift':
+                   {'sid':
+                    {'Blue': [np.arange(10, 10 + width),
+                              np.arange(44, 44 + width)],
+                     'Red': [np.arange(7, 7 + width),
+                             np.arange(22, 22 + width)],
+                 },
+                    'cubenames': ["123456789s0", "123456987s0"],
+                },
                }
     except ImportError:
         print "The NumPy module is not available on this system."

File save_image.py

  • Ignore whitespace
-import numpy as np
-import scipy
-import scipy.ndimage as nd
-import tables as tb
-
-from fmgr import hypercube
-
-
-# load data_undistort from the peek/H5 file.
-
-#peek = tb.openFile(r'C:\Users\Public\Documents\data_vault\bugs\misaligned_HI\peek\006201200500s0.h5', mode='r')
-
-_path = r"C:\Users\Public\Documents\data_vault\bugs\misaligned_HI\post\006201200500s0.h5"
-peek = hypercube.Hypercube(abs_path=_path, mode='r')
-
-wood_mask = peek.select_mask_array()[:]
-
-undistort_indices = peek.select_undistort_indices()[:]
-
-image = peek.getH5().getNode("/working/data_undistort")[:]
-img = np.where(wood_mask > 0, image, 0)
-scipy.misc.imsave("C:/Users/eparent/Desktop/corrected.png", img.transpose())
-
-
-#
-# Saving the RGB image
-#
-rgb = np.dstack((np.where(wood > 0, image[0], 0),
-                 np.where(wood > 0, image[1], 0),
-                 np.where(wood > 0, image[2], 0)))
-
-scipy.misc.imsave("C:/Users/eparent/Desktop/corrected_RGB.png", rgb.transpose())

File stitcher.py

View file
  • Ignore whitespace
 #!/usr/bin/env python
-#
-# copyrights : 2012, Photonic Knowledge
-#
-
+# -*- coding: latin-1 -*-
 """
 INSTRUCTIONS:
 
  - As a result, you'll have a file "merged.xlsx" created with the
    content of all the scanned Excel files merged, tab by tab.
 
+
+Dependencies
+------------
+
+- openpyxl
+
+
+Author: Eric Parent <eric@eparent.info>
+
+Copyright (c) 2013 Eric Parent
+
+License: The MIT License (MIT)
+
+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.
+
 """
 
 # -----------------------------
         work_dir = args['directory']
         print "work_dir: ", work_dir
         sys.exit(merge(**args))
-

File transformations.py

View file
  • Ignore whitespace
-# -*- coding: utf-8 -*-
-'''This module holds a few functions to enable with the affine
+#!/usr/bin/env python
+# -*- coding: latin-1 -*-
+"""This module holds a few functions to enable with the affine
 transformations of 2D images.
 
-Created on 2012-06-13
+Dependencies
+------------
 
-@author: <mailto:eparent@photonicknowledge.com>
-@copyright 2012 Photonic Knowledge Inc.
+- Numpy
 
-'''
+- SciPy
 
+
+Author: Eric Parent <eric@eparent.info>
+
+Copyright (c) 2012 Eric Parent
+
+License: The MIT License (MIT)
+
+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.
+
+"""
 # --------------------
 # Standard libraries
 #--------------------
     """Inverts the coordinates of the points so the X and Y axis are
     inverted.
 
-    Arguments:
+    Arguments
+    ---------
+
     - points: a list of points to be inverted
 
     """
     """Returns the parts of the affine transformation matrix that are
     to be used in the transformation.
 
-    Arguments:
-    ----------
+    Arguments
+    ---------
 
     - matrix: the matrix that holds all the affine transformation
       information
     """Applying the affine transformation described by M to the image
     'img' and returning a new image
 
-    Arguments:
+    Arguments
+    ---------
+
     - img: the image on which to apply the transformation
+
     - matrix: the matrix of the affine transformation to be applied
 
     NOTE:
 def transform_single_point(matrix, point):
     """Applies an affine transformation to a single point.
 
-    Arguments:
-    ----------
+    Arguments
+    ---------
 
     - matrix: the affine transformation matrix
 
     ----------
 
     - matrix: the affine transformation matrix to be used
+
     - points: a list of triplets being the mask_pts in the source
       image