예제 #1
0
def get_env(group):
    # type: (List[ReflData]) -> Columns
    """
    Extract sample environment from all fields in group into separate fields.
    """
    head = group[0]
    # Gather environment variables such as temperature and field.
    # Make sure they are all in the same units.
    columns = dict((e.name, []) for e in head.sample.environment)
    converter = dict(
        (e.name, unit.Converter(e.units)) for e in head.sample.environment)
    for data in group:
        for env_name, env_list in columns.items():
            env = data.sample.environment.get(env_name, None)
            if env is not None:
                values = converter[env_name](env.average, units=env.units)
            else:
                values = None
            env_list.append(values)

    # Drop environment variables that are not defined in every file
    columns = dict((env_name, env_list)
                   for env_name, env_list in columns.items()
                   if not any(v is None for v in env_list))
    return columns
예제 #2
0
파일: loader.py 프로젝트: e-rus/reductus
def data_as(field, units):
    """
    Return value of field in the desired units.
    """
    if field.name.split('/')[-1] == 'sourceAperture':
        return process_sourceAperture(field, units)
    else:
        converter = unit.Converter(field.attrs.get('units', ''))
        value = converter(field.value, units)
        return value
예제 #3
0
def data_as(field, units):
    """
    Return value of field in the desired units.
    """
    if field.name.split('/')[-1] == 'sourceAperture':
        return process_sourceAperture(field, units)
    else:
        units_in = field.attrs.get('units', '')
        if type(units_in) == bytes:
            units_in = units_in.decode('utf-8')
        converter = unit.Converter(units_in)
        value = converter(field.value, units)
        return value
예제 #4
0
파일: loader.py 프로젝트: e-rus/reductus
def process_sourceAperture(field, units):
    import numpy as np

    def handler(v):
        return np.float(v.split()[0])

    handle_values = np.vectorize(handler)
    value = handle_values(field.value)
    units_from = ""
    v0 = field.value[0].split()
    if len(v0) > 1:
        units_from = v0[1]
    converter = unit.Converter(units_from)
    return converter(value, units)
예제 #5
0
def data_as(group, fieldname, units, rep=1):
    """
    Return value of field in the desired units.
    """
    if fieldname not in group:
        return np.NaN
    field = group[fieldname]
    converter = unit.Converter(field.attrs.get('units', ''))
    value = converter(field.value, units)
    if rep != 1:
        if value.shape[0] == 1:
            return np.repeat(value, rep, axis=0)
        elif value.shape[0] != rep:
            raise ValueError("field %r does not match counts in %r" %
                             (field.name, field.file.filename))
        else:
            return value
    else:
        return value
예제 #6
0
def process_sourceAperture(field, units):
    import numpy as np

    def handler(v):
        if _s(v) == 'OUT':
            return v
        else:
            return np.float(v.split()[0])

    handle_values = np.vectorize(handler)
    value = handle_values(field.value)
    units_from = ""
    v0 = field.value[0].split()
    if _s(value[0]) == 'OUT':
        return value
    if len(v0) > 1:
        units_from = v0[1]
    if type(units_from) == bytes:
        units_from = units_from.decode('utf-8')
    converter = unit.Converter(units_from)
    return converter(value, units)
예제 #7
0
def data_as(group, fieldname, units, rep=None, NA=None, dtype=None):
    """
    Return value of field in the desired units.
    """
    if fieldname not in group:
        return NA
    field = group[fieldname]
    units_in = _s(field.attrs.get('units', ''))
    converter = unit.Converter(units_in)
    value = converter(field[()], units)
    if dtype is not None:
        value = np.asarray(value, dtype=dtype)
    if rep is not None:
        if np.isscalar(value) or len(value) == 1:
            return np.repeat(value, rep, axis=0)
        elif len(value) == rep:
            return value
        else:
            raise ValueError("field %r does not match counts in %r" %
                             (field.name, field.file.filename))
    else:
        return value