示例#1
0
def create_site():
    """
    Create dummy site.
    Uses the same technique from test_sites
    (Test_Sites.test_read_from_file
    """
    # create dummy CSV file - this is bridges data, but sites should handle anything
    lat = [-35.352085]
    lon = [149.236994]
    clsf = ['HWB17']
    cat = ['BRIDGE']
    skew = [0]
    span = [2]
    cls = ['E']
    attribute_keys = ['BID', 'STRUCTURE_CLASSIFICATION']

    dummy_csv_data = ['BID,LONGITUDE,LATITUDE,STRUCTURE_CLASSIFICATION,'
                      'STRUCTURE_CATEGORY,SKEW,SPAN,SITE_CLASS',
                      '2,%.6f,%.6f,%s,%s,%s,%s,%s'
                          % (lon[0], lat[0], clsf[0], cat[0], skew[0], span[0], cls[0])]

    (handle, filename) = tempfile.mkstemp('.csv', 'test_sites_')
    os.close(handle)

    f = open(filename, 'wb')
    f.write('\n'.join(dummy_csv_data))
    f.close()

    # now read file - pass attribute_conversion as **kwargs data
    sites = Sites.from_csv(filename, BID=int, STRUCTURE_CLASSIFICATION=str)
    
    return sites, filename
示例#2
0
def create_site():
    """
    Create dummy site.
    Uses the same technique from test_sites
    (Test_Sites.test_read_from_file
    """
    # create dummy CSV file - this is bridges data, but sites should handle anything
    lat = [-35.352085]
    lon = [149.236994]
    clsf = ['HWB17']
    cat = ['BRIDGE']
    skew = [0]
    span = [2]
    cls = ['E']
    attribute_keys = ['BID', 'STRUCTURE_CLASSIFICATION']

    dummy_csv_data = [
        'BID,LONGITUDE,LATITUDE,STRUCTURE_CLASSIFICATION,'
        'STRUCTURE_CATEGORY,SKEW,SPAN,SITE_CLASS',
        '2,%.6f,%.6f,%s,%s,%s,%s,%s' %
        (lon[0], lat[0], clsf[0], cat[0], skew[0], span[0], cls[0])
    ]

    (handle, filename) = tempfile.mkstemp('.csv', 'test_sites_')
    os.close(handle)

    f = open(filename, 'wb')
    f.write('\n'.join(dummy_csv_data))
    f.close()

    # now read file - pass attribute_conversion as **kwargs data
    sites = Sites.from_csv(filename, BID=int, STRUCTURE_CLASSIFICATION=str)

    return sites, filename
示例#3
0
    def test_read_from_file_Vs30(self):
        """Test reading Sites data from file taking into account Vs30 data.
        1. If VS30 is present and requested, it should be an attribute
        2. If VS30 is not present and requested, it should not be an attribute
        """

        raw_csv_no_vs30 = """BID,LATITUDE,LONGITUDE
2,-6.4125,110.837502
3,-6.4125,110.845833 
4,-6.4125,110.854164"""

        raw_csv_vs30 = """BID,LATITUDE,LONGITUDE,VS30
2,-6.4125,110.837502,666
3,-6.4125,110.845833,560
4,-6.4125,110.854164,560"""

        (handle, filename_vs30) = tempfile.mkstemp('.csv', 'test_sites_')
        os.close(handle)
        f = open(filename_vs30, 'wb')
        f.write(raw_csv_vs30)
        f.close()
        
        (handle, filename_no_vs30) = tempfile.mkstemp('.csv', 'test_sites_')
        os.close(handle)
        f = open(filename_no_vs30, 'wb')
        f.write(raw_csv_no_vs30)
        f.close()
        
        expected_vs30 = [666,560,560]
        
        # Test 1.
        sites = Sites.from_csv(filename_vs30, VS30=float)
        self.failUnless('Vs30' in sites.attributes)
        self.failUnless(np.all(sites.attributes['Vs30'] == expected_vs30))
        
        # Test 2.
        sites = Sites.from_csv(filename_no_vs30, VS30=float)
        self.failUnless('Vs30' not in sites.attributes)

        # get rid of test data files
        os.remove(filename_vs30)
        os.remove(filename_no_vs30)
示例#4
0
    def test_read_from_file_Vs30(self):
        """Test reading Sites data from file taking into account Vs30 data.
        1. If VS30 is present and requested, it should be an attribute
        2. If VS30 is not present and requested, it should not be an attribute
        """

        raw_csv_no_vs30 = """BID,LATITUDE,LONGITUDE
2,-6.4125,110.837502
3,-6.4125,110.845833 
4,-6.4125,110.854164"""

        raw_csv_vs30 = """BID,LATITUDE,LONGITUDE,VS30
2,-6.4125,110.837502,666
3,-6.4125,110.845833,560
4,-6.4125,110.854164,560"""

        (handle, filename_vs30) = tempfile.mkstemp(".csv", "test_sites_")
        os.close(handle)
        f = open(filename_vs30, "wb")
        f.write(raw_csv_vs30)
        f.close()

        (handle, filename_no_vs30) = tempfile.mkstemp(".csv", "test_sites_")
        os.close(handle)
        f = open(filename_no_vs30, "wb")
        f.write(raw_csv_no_vs30)
        f.close()

        expected_vs30 = [666, 560, 560]

        # Test 1.
        sites = Sites.from_csv(filename_vs30, VS30=float)
        self.failUnless("Vs30" in sites.attributes)
        self.failUnless(np.all(sites.attributes["Vs30"] == expected_vs30))

        # Test 2.
        sites = Sites.from_csv(filename_no_vs30, VS30=float)
        self.failUnless("Vs30" not in sites.attributes)

        # get rid of test data files
        os.remove(filename_vs30)
        os.remove(filename_no_vs30)
示例#5
0
    def test_read_from_file(self):
        """Test reading Sites data from a file."""

        # create dummy CSV file - this is bridges data, but sites should handle anything
        lat = [-35.352085, -35.348677, -35.336884, -35.345209,
               -35.340859, -35.301472, -35.293012, -35.320122]
        lon = [149.236994, 149.239383, 149.241625, 149.205986,
               149.163037, 149.141364, 149.126767, 149.063810]
        clsf = ['HWB17', 'HWB17', 'HWB17', 'HWB22',
                 'HWB3', 'HWB17', 'HWB10', 'HWB28']
        cat = ['BRIDGE', 'BRIDGE', 'BRIDGE', 'BRIDGE',
               'BRIDGE', 'BRIDGE', 'BRIDGE', 'BRIDGE']
        skew = [0, 32, 20, 4, 0, 0, 12, 0]
        span = [2, 3, 6, 2, 1, 1, 3, 3]
        cls = ['E', 'F', 'G', 'D', 'E', 'F', 'G', 'C']
        attribute_keys = ['BID', 'STRUCTURE_CLASSIFICATION']

        dummy_csv_data = ['BID,LONGITUDE,LATITUDE,STRUCTURE_CLASSIFICATION,'
                          'STRUCTURE_CATEGORY,SKEW,SPAN,SITE_CLASS',
                          '2,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[0], lat[0], clsf[0], cat[0], skew[0], span[0], cls[0]),
                          '3,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[1], lat[1], clsf[1], cat[1], skew[1], span[1], cls[1]),
                          '4,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[2], lat[2], clsf[2], cat[2], skew[2], span[2], cls[2]),
                          '5,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[3], lat[3], clsf[3], cat[3], skew[3], span[3], cls[3]),
                          '6,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[4], lat[4], clsf[4], cat[4], skew[4], span[4], cls[4]),
                          '7,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[5], lat[5], clsf[5], cat[5], skew[5], span[5], cls[5]),
                          '8,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[6], lat[6], clsf[6], cat[6], skew[6], span[6], cls[6]),
                          '9,%.6f,%.6f,%s,%s,%s,%s,%s'
                              % (lon[7], lat[7], clsf[7], cat[7], skew[7], span[7], cls[7])]

        (handle, filename) = tempfile.mkstemp('.csv', 'test_sites_')
        os.close(handle)

        f = open(filename, 'wb')
        f.write('\n'.join(dummy_csv_data))
        f.close()

        # now read file - pass attribute_conversion as **kwargs data
        sites = Sites.from_csv(filename, BID=int, STRUCTURE_CLASSIFICATION=str)

        # make sure we have required attributes, and only those attributes
        self.failUnless(hasattr(sites, 'longitude'))
        self.failUnless(np.all(sites.longitude == lon))
        self.failUnless(hasattr(sites, 'latitude'))
        self.failUnless(np.all(sites.latitude == lat))

        self.failUnless(len(sites.attributes) == len(attribute_keys))
        for key in sites.attributes:
            if key not in attribute_keys:
                self.fail("Found unexpected .attribute key '%s'" % key)

        # repeat above test, pass attributes a dict
        attr_dict = {'BID': int, 'STRUCTURE_CATEGORY': str, 'SKEW': float,
                     'SPAN': int, 'SITE_CLASS': str}
        attribute_keys = ['BID', 'STRUCTURE_CATEGORY', 'SKEW', 'SPAN', 'SITE_CLASS']
        sites = Sites.from_csv(filename, **attr_dict)

        # make sure we have required attributes, and only those attributes
        self.failUnless(hasattr(sites, 'longitude'))
        self.failUnless(np.all(sites.longitude == lon))
        self.failUnless(hasattr(sites, 'latitude'))
        self.failUnless(np.all(sites.latitude == lat))

        self.failUnless(len(sites.attributes) == len(attribute_keys))
        for key in sites.attributes:
            if key not in attribute_keys:
                self.fail("Found unexpected .attribute key '%s'" % key)

        # get rid of test data file 
        os.remove(filename)
示例#6
0
    def test_read_from_file(self):
        """Test reading Sites data from a file."""

        # create dummy CSV file - this is bridges data, but sites should handle anything
        lat = [-35.352085, -35.348677, -35.336884, -35.345209, -35.340859, -35.301472, -35.293012, -35.320122]
        lon = [149.236994, 149.239383, 149.241625, 149.205986, 149.163037, 149.141364, 149.126767, 149.063810]
        clsf = ["HWB17", "HWB17", "HWB17", "HWB22", "HWB3", "HWB17", "HWB10", "HWB28"]
        cat = ["BRIDGE", "BRIDGE", "BRIDGE", "BRIDGE", "BRIDGE", "BRIDGE", "BRIDGE", "BRIDGE"]
        skew = [0, 32, 20, 4, 0, 0, 12, 0]
        span = [2, 3, 6, 2, 1, 1, 3, 3]
        cls = ["E", "F", "G", "D", "E", "F", "G", "C"]
        attribute_keys = ["BID", "STRUCTURE_CLASSIFICATION"]

        dummy_csv_data = [
            "BID,LONGITUDE,LATITUDE,STRUCTURE_CLASSIFICATION," "STRUCTURE_CATEGORY,SKEW,SPAN,SITE_CLASS",
            "2,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[0], lat[0], clsf[0], cat[0], skew[0], span[0], cls[0]),
            "3,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[1], lat[1], clsf[1], cat[1], skew[1], span[1], cls[1]),
            "4,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[2], lat[2], clsf[2], cat[2], skew[2], span[2], cls[2]),
            "5,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[3], lat[3], clsf[3], cat[3], skew[3], span[3], cls[3]),
            "6,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[4], lat[4], clsf[4], cat[4], skew[4], span[4], cls[4]),
            "7,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[5], lat[5], clsf[5], cat[5], skew[5], span[5], cls[5]),
            "8,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[6], lat[6], clsf[6], cat[6], skew[6], span[6], cls[6]),
            "9,%.6f,%.6f,%s,%s,%s,%s,%s" % (lon[7], lat[7], clsf[7], cat[7], skew[7], span[7], cls[7]),
        ]

        (handle, filename) = tempfile.mkstemp(".csv", "test_sites_")
        os.close(handle)

        f = open(filename, "wb")
        f.write("\n".join(dummy_csv_data))
        f.close()

        # now read file - pass attribute_conversion as **kwargs data
        sites = Sites.from_csv(filename, BID=int, STRUCTURE_CLASSIFICATION=str)

        # make sure we have required attributes, and only those attributes
        self.failUnless(hasattr(sites, "longitude"))
        self.failUnless(np.all(sites.longitude == lon))
        self.failUnless(hasattr(sites, "latitude"))
        self.failUnless(np.all(sites.latitude == lat))

        self.failUnless(len(sites.attributes) == len(attribute_keys))
        for key in sites.attributes:
            if key not in attribute_keys:
                self.fail("Found unexpected .attribute key '%s'" % key)

        # repeat above test, pass attributes a dict
        attr_dict = {"BID": int, "STRUCTURE_CATEGORY": str, "SKEW": float, "SPAN": int, "SITE_CLASS": str}
        attribute_keys = ["BID", "STRUCTURE_CATEGORY", "SKEW", "SPAN", "SITE_CLASS"]
        sites = Sites.from_csv(filename, **attr_dict)

        # make sure we have required attributes, and only those attributes
        self.failUnless(hasattr(sites, "longitude"))
        self.failUnless(np.all(sites.longitude == lon))
        self.failUnless(hasattr(sites, "latitude"))
        self.failUnless(np.all(sites.latitude == lat))

        self.failUnless(len(sites.attributes) == len(attribute_keys))
        for key in sites.attributes:
            if key not in attribute_keys:
                self.fail("Found unexpected .attribute key '%s'" % key)

        # get rid of test data file
        os.remove(filename)