예제 #1
0
    def read_bpch2_data(self, data_id, save_data=False):
        """ read in bpch2 data record for a given tracer nu print 'ix', bpch2.ix[:]mber
		
        	"""
        if (data_id > self.ntracers):
            print 'tracer not found'
            return None
        if (self.read_mode == 1):
            bpdata = self.data[data_id]
            return bpdata

        bpdata = self.data[data_id]

        ix = bpdata.grid.ix
        jy = bpdata.grid.jx
        lz = bpdata.grid.lx

        tracer = bpdata.ntracer
        tau0, tau1 = bpdata.get_attr(['tau0', 'tau1'])
        category = bpdata.category
        data, dunit, ios=bpch2_rw_py.read_bpch2(self.flnm, category, tracer,\
                                        tau0,  ix,  jy, lz)

        if (ios > 0):
            print 'error in read data', ios
            return None
        elif (ios == -1):
            print 'no data found'
            return None

        if (save_data):
            bpdata.update_data(data)
            return bpdata
        else:
            return data
예제 #2
0
    def get_data(self, categorys=None, tracers=None, taus=None, tranames=None):
        """ search the records for all the data 
		
		"""
        if (self.ntracers <= 0):
            print 'tracer not found'
            return None
        sel_data = list()
        nval = 0
        array_cat = None
        array_tracer = None
        array_tau = None
        array_traname = None

        if (categorys <> None):
            array_cat = array(categorys)
            nval = size(array_cat)

        if (tracers <> None):
            array_tracer = array(tracers)
            nval = size(array_tracer)

        if (taus <> None):
            array_tau = array(taus)
            nval = size(array_tau)

        if (tranames <> None):
            array_traname = array(tranames)
            nval = size(array_traname)

        if (nval == 0):
            nval = len(self.data)
            founded = ones(nval)
            return self.data, founded

        found_data = list()
        founded = zeros(nval)

        for bpdata in self.data:
            score_cat = ones(nval)
            score_tracer = ones(nval)
            score_tau = ones(nval)
            score_traname = ones(nval)

            if (array_cat <> None):
                score_cat = where(array_cat == bpdata.category.strip(), 1, 0)
                #	print '1', score_cat
            if (array_tracer <> None):
                score_tracer = where(array_tracer == int(bpdata.ntracer), 1, 0)
                # print '2', score_tracer
            if (array_tau <> None):
                tau0, tau1 = bpdata.get_attr(['tau0', 'tau1'])
                score_tau = where(
                    logical_and(array_tau >= tau0, array_tau < tau1), 1, 0)

                # print '3', score_tau
                # print array_tau, tau0

            if (array_traname <> None):
                traname, tau1 = bpdata.get_attr(['name', 'tau1'])
                # print 'traname', traname
                score_traname = where(array_traname == traname.strip(), 1, 0)
                # print '4', score_traname

            final_score = score_cat * score_tracer * score_tau * score_traname
            founded = founded + final_score

            if (sum(final_score) > 0):
                if (bpdata.data == None):
                    # read in the required data
                    ix = bpdata.grid.ix
                    jy = bpdata.grid.jx
                    lz = bpdata.grid.lx

                    tracer = bpdata.ntracer
                    xtau0, xtau1 = bpdata.get_attr(['tau0', 'tau1'])
                    category = bpdata.category
                    data, dunit,ios=bpch2_rw_py.read_bpch2(self.flnm, category, tracer,\
                         xtau0,  ix,  jy, lz)
                    print 'IOS', ios

                    if (ios > 0):
                        print 'error in read data', ios
                        return None
                    elif (ios == -1):
                        print 'no data found'
                        return None
                    print 'after read', size(data)
                    bpdata.update_data(data)
                found_data.append(bpdata)
        return found_data, founded