예제 #1
0
    def _get_fn_data(self):
        ralpha       = units.convert( self.ralpha, degree, radian )
        ralpha_range = units.convert( self.ralpha_range, degree, radian )
        salpha       = units.convert( self.salpha, degree, radian )

        r_min = ralpha - ralpha_range / 2.
        r_max = ralpha + ralpha_range / 2.

        if r_min < 0:  s_min = r_min + Pi
        else:          s_min = r_min
        if r_max > Pi: s_max = r_max - Pi
        else:          s_max = r_max
        
        step_size = salpha
        rinteg = self.res_integ
        if s_min < s_max:
            self.single_interval = True
            return ([0.0, s_min-(step_size), s_min,
                    s_max, s_max+(step_size), Pi], 
                    [ 0.0, 0.0, rinteg, rinteg, 0.0, 0.0 ] )
        else:
            self.single_interval = False
            return ([0.0, s_max, s_max+(step_size),
                    s_min-(step_size), s_min, Pi],
                    [ rinteg, rinteg, 0.0, 0.0, rinteg, rinteg ])
    def setUp(self):
        unittest.TestCase.setUp(self)

        # Put unit adapters on either side of a masking adapter to see if they
        # cooperate. Store meters in the raw context, push fathoms through the
        # mask, and expose feet to the outside world.
        self.units = units = { 'in':meters, 'mid':fathom, 'out':feet }

        # Set up data for the contexts
        depth = Log(linspace(0.0, 100.0, 11), units=units['in'])
        lith = array(['sand']*len(depth), dtype=object)

        # Create the contexts
        self.context = PassThruContext( ReductionContext( NumericContext() ) )
        self.raw_context = self.context.context_base

        # Add data (before creating the adapters)
        self.context.update(depth=depth, lith=lith)

        # (This simplifies creating UnitConversionAdapters)
        def always(value):
            class C(dict):
                def get(self, key, default=None):
                    return value
                def __repr__(self):
                    return '{*:%r}' % value
            return C()

        # Layer multiple adapters
        self.mask = (15.0 < depth) & (depth < 55.0)
        self.convert_out = lambda x: convert(x, units['in'], units['out'])
        self.convert_in = lambda x: convert(x, units['out'], units['in'])
        self.context.get_reduction_context(OpenContext).context_filter = \
            MaskFilter( mask = self.mask )
예제 #3
0
파일: Cfx.py 프로젝트: jenshnielsen/hemelb
def CfxCentreLineSnapshot(filename):
    """Factory function wrapping a CFX snapshot.
    
    Load the data with:
    >>> snap = CfxSnapshot(filename)

    Fields are constructed from the header line.
    
        
    """
    (__raw_row, fieldUnits) = parseHeader(filename, AllData=True)
    __raw_row = [('id', int),] + __raw_row
    fieldUnits['id'] = 1
    
                 # ('position', float, (3,)),
                 # ('strain_rate', float),
                 # ('speed', float),
                 # ('velocity', float, (3,)),
                 # ('wall_shear', float, (4,))]

    __readable_row = np.dtype(__raw_row[1:])
    row = np.dtype(__raw_row)
    
    noindex = np.genfromtxt(filename, skip_header=findStart(filename, AllData=True)+2,
                           delimiter=',',
                           dtype=__readable_row).view(np.recarray)
    index = np.recarray(shape=noindex.shape, dtype=row)
    index.id = np.arange(len(noindex))
    for el in __raw_row[1:]:
        key = el[0]
        index.__setattr__(key, U.convert(noindex.__getattribute__(key), fieldUnits[key], hlbUnits[key]))
        continue
    
    return index
예제 #4
0
파일: Cfx.py 프로젝트: nicholasw-gc/hemelb
def CfxCentreLineSnapshot(filename):
    """Factory function wrapping a CFX snapshot.
    
    Load the data with:
    >>> snap = CfxSnapshot(filename)

    Fields are constructed from the header line.
    
        
    """
    (__raw_row, fieldUnits) = parseHeader(filename, AllData=True)
    __raw_row = [
        ('id', int),
    ] + __raw_row
    fieldUnits['id'] = 1

    # ('position', float, (3,)),
    # ('strain_rate', float),
    # ('speed', float),
    # ('velocity', float, (3,)),
    # ('wall_shear', float, (4,))]

    __readable_row = np.dtype(__raw_row[1:])
    row = np.dtype(__raw_row)

    noindex = np.genfromtxt(filename,
                            skip_header=findStart(filename, AllData=True) + 2,
                            delimiter=',',
                            dtype=__readable_row).view(np.recarray)
    index = np.recarray(shape=noindex.shape, dtype=row)
    index.id = np.arange(len(noindex))
    for el in __raw_row[1:]:
        key = el[0]
        index.__setattr__(
            key,
            U.convert(noindex.__getattribute__(key), fieldUnits[key],
                      hlbUnits[key]))
        continue

    return index