# Path: smtk/parsers/base_database_parser.py
# def get_float(xval):
#     """
#     Returns a float value, or none
#     """
#     if xval.strip():
#         try:
#             return float(xval)
#         except:
#             return None
#     else:
#         return None


import os
import sys
import re
import csv
import numpy as np
import h5py
import smtk.intensity_measures as ims
import smtk.sm_utils as utils
    import pickle
    import cPickle as pickle
from smtk.parsers.base_database_parser import get_float
        ims_grp = fle.create_group("IMS")
        h_grp = ims_grp.create_group("H")
        scalar_grp = h_grp.create_group("Scalar")
        # Create Scalar values
        for f_attr, imt in scalar_fields:
            dset = scalar_grp.create_dataset(imt, (1,), dtype="f")
            dset.attrs["Component"] = component
            input_units = re.search(r'\((.*?)\)', f_attr).group(1)
            if imt == "PGA":
                # Convert acceleration from reported units to cm/s/s
                dset.attrs["Units"] = "cm/s/s"
                dset[:] = utils.convert_accel_units(get_float(row[f_attr]),
                                                    input_units)
            else:
                # For other values take direct from spreadsheet
                # Units should be given in parenthesis from fieldname
                dset.attrs["Units"] = input_units
                dset[:] = get_float(row[f_attr])

        spectra_grp = h_grp.create_group("Spectra")
        rsp_grp = spectra_grp.create_group("Response")
        # Setup periods dataset
        per_dset = rsp_grp.create_dataset("Periods",
                                          (len(periods),),
                                          dtype="f")
        per_dset.attrs["High Period"] = np.max(periods)
        per_dset.attrs["Low Period"] = np.min(periods)
        per_dset.attrs["Number Periods"] = len(periods)
        per_dset[:] = periods
        # Get response spectra

# Path: smtk/parsers/base_database_parser.py
# def get_float(xval):
#     """
#     Returns a float value, or none
#     """
#     if xval.strip():
#         try:
#             return float(xval)
#         except:
#             return None
#     else:
#         return None


# Path: smtk/sm_database_builder.py
import os
import sys
import re
import csv
import numpy as np
import h5py
import smtk.intensity_measures as ims
import smtk.sm_utils as utils
    import pickle
    import cPickle as pickle
from smtk.parsers.base_database_parser import get_float

        ims_grp = fle.create_group("IMS")
        h_grp = ims_grp.create_group("H")
        scalar_grp = h_grp.create_group("Scalar")
        # Create Scalar values
        for f_attr, imt in scalar_fields:
            dset = scalar_grp.create_dataset(imt, (1,), dtype="f")
            dset.attrs["Component"] = component
            input_units = re.search(r'\((.*?)\)', f_attr).group(1)
            if imt == "PGA":
                # Convert acceleration from reported units to cm/s/s
                dset.attrs["Units"] = "cm/s/s"
                dset[:] = utils.convert_accel_units(get_float(row[f_attr]),
                                                    input_units)
            else:
                # For other values take direct from spreadsheet
                # Units should be given in parenthesis from fieldname
                dset.attrs["Units"] = input_units
                dset[:] = get_float(row[f_attr])

        spectra_grp = h_grp.create_group("Spectra")
        rsp_grp = spectra_grp.create_group("Response")
        # Setup periods dataset
        per_dset = rsp_grp.create_dataset("Periods",
                                          (len(periods),),
                                          dtype="f")
        per_dset.attrs["High Period"] = np.max(periods)
        per_dset.attrs["Low Period"] = np.min(periods)
        per_dset.attrs["Number Periods"] = len(periods)
        per_dset[:] = periods
        # Get response spectra

        spectra = np.array([get_float(row[f_attr])