<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 from numpy import *
 import unittest
 import scipy.optimize as opt
+import copy as cp
 
 class SasData(object):
     &quot;&quot;&quot;A data object for holding 1-d Q versus I SAS data.
@@ -85,7 +86,69 @@ class SasData(object):
         for j in range(len(self)):
             out.i[j] = self.i[j] * other
 	return out
-#definition of the Guinier model for a sphere with a flat background
+
+    #########
+    #
+    # SasTrim Routines for Trimming and Masking SasData
+    #
+    #########
+
+    def make_mask(data_to_mask, mask_ranges):
+        &quot;&quot;&quot;Generates a mask list of 0's and 1's to remove data in mask_ranges
+
+        Takes a SasData object and creates a list with a 1 to 1 mapping with
+        SasData.q containing only zeros and ones based on the q-values in
+        mask_ranges. Mask_ranges takes the form of a list of length N of
+        lists of length two containing data to exclude. May expand in the future
+        to allow both positive and negative mask generation.
+        &quot;&quot;&quot;
+
+    # need to make an assertion that mask ranges is a N x 2 set of lists
+    # not immediately sure how to do this at the moment
+
+    # make a copy of the q list because we are going to change it
+        mask = cp.deepcopy(data_to_mask.q)
+
+        for j in range(len(mask)):
+
+            #for each pair of values in mask_ranges
+            for low, high in mask_ranges
+
+                # check whether q values are within mask_ranges
+                if mask[j] &gt;= low and q_mask[j] &lt;= high:
+                    mask[j] = 0
+                    break
+                else:
+                    mask[j] = 1
+
+        self.mask_list = mask
+
+    def mask(self):
+        &quot;&quot;&quot;Applies a pre-calculated mask to a SasData object.
+
+        Takes the pre-calculated mask from make_mask and creates a new
+        SasData object with the masked data points (those corresponding
+        to zeros in the mask) removed. The new object is then placed in
+        self.masked. In principle this should allow nested masking operations.
+        Whether this is a good idea remains to be seen.
+        &quot;&quot;&quot;
+
+        assert type(self.mask) is list
+        assert len(self.mask) != 0
+
+        q_masked = extract(self.mask, self.q)
+        i_masked = extract(self.mask, self.i)
+
+        self.masked = SasData(q_masked, i_masked)
+        return self.masked
+
+
+###################################################
+#
+# Definition of data fitting models
+#
+###################################################
+
 def guinier(q,param):
     &quot;&quot;&quot;Function that returns a Guinier model
 
@@ -121,6 +184,12 @@ def fit_guinier(data):
 
     return least_squares_fit
 
+########################################
+#
+# Unit tests
+#
+########################################
+
 class TestSasData(unittest.TestCase):
 
     def setUp(self):</diff>
      <filename>sas.py</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ff96dbf62a635e6e7d06319afbb77d2bc0f4e4dc</id>
    </parent>
  </parents>
  <author>
    <name>Cameron Neylon</name>
    <email>cameron.neylon@stfc.ac.uk</email>
  </author>
  <url>http://github.com/cameronneylon/sas/commit/1cf7f651cbcede5b536cc04341dbdcc6b5f88109</url>
  <id>1cf7f651cbcede5b536cc04341dbdcc6b5f88109</id>
  <committed-date>2009-03-03T23:57:14-08:00</committed-date>
  <authored-date>2009-03-03T23:57:14-08:00</authored-date>
  <message>added sastrim routines as methods of SasData- still need to write tests for these</message>
  <tree>2ba6a3f487b200f139f1351d52d4a32a335e3f77</tree>
  <committer>
    <name>Cameron Neylon</name>
    <email>cameron.neylon@stfc.ac.uk</email>
  </committer>
</commit>
