Exemplo n.º 1
0
    def test_TC5(self):
        data = {
            'a': {
                'a1': 1,
                'a2': 2
            },
            'b': {
                'b1': {
                    'b11': 1,
                    'b12': 2
                }
            },
            'c': {
                'd': 4
            }
        }
        data_before = copy.deepcopy(data)

        data['a']['a2'] = 7
        del (data['b'])

        try_result = {'a': {'a2': 7}, 'b': {'b1': {'b11': 1, 'b12': 2}}}
        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 2
0
    def test_TC12(self):
        data = {'a': 1, 'b': 2}
        data_before = copy.deepcopy(data)

        try_result = {}

        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 3
0
    def test_TC13(self):
        data = {}
        data_before = copy.deepcopy(data)

        data['a'] = {'a1': {'a2': 3}}

        try_result = {'a': {'a1': {'a2': 3}}}

        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 4
0
    def test_TC4(self):
        data = {'a': 1, 'b': {'b1': 2}, 'c': {'c1': {'c2': 3, 'c3': 5}}}
        data_before = copy.deepcopy(data)

        data['c']['c1']['c4'] = {'c5': 3}

        try_result = {'c': {'c1': {'c4': {'c5': 3}}}}

        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 5
0
def diff(config):
    """
    This argument will run DYC on DIFF patch only
    """
    diff = Diff(config.plain)
    uncommitted = diff.uncommitted
    paths = [idx.get('path') for idx in uncommitted]
    if len(uncommitted):
        dyc = DYC(config.plain)
        dyc.prepare(files=paths)
        dyc.process_methods(diff_only=True, changes=uncommitted)
Exemplo n.º 6
0
def mem():
    form = ReciteForm()
    if form.validate_on_submit():
        b = Bible()
        actual = b.get_verse(request.args.get("book").lower(), request.args.get("chapter"), request.args.get("verse"), "esv")
        typed = form.text.data

        d = Diff(actual, typed)
        html = d.generate_html()
        return html
    return render_template('mem.html', form=form, book=request.args.get("book"), chapter=request.args.get("chapter"), verse=request.args.get("verse"))
Exemplo n.º 7
0
 def diff(self, **kwargs):
     """
     Compile a difference list of files between src and dst directories
     """
     if self.__validate():
         # TODO: filter kwargs
         self.diffstngs.update(kwargs)
         self.origdiff = Diff(self.src, self.dst, **self.diffstngs)
         self.trimdiff = self.origdiff.copy()
         self.__hasrundiff = True
         self.__diffcurrent = True
Exemplo n.º 8
0
    def test_TC3(self):
        data = {'a': 1, 'b': 2, 'c': {'c1': 3, 'c2': 5}}
        data_before = copy.deepcopy(data)

        data['a'] = 5
        data['c']['c2'] = 9

        try_result = {'a': 5, 'c': {'c2': 9}}

        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 9
0
 def main(self, file1path, file2path):
     xlsPre = xlrd.open_workbook(file1path.__str__())
     xlsSuf = xlrd.open_workbook(file2path.__str__())
     #存储tabel转换为list后的结果,按照行的格式,形如[(sheetname,[sheetPre],[sheetSuf]),]
     sheets = []
     #存储diff后的结果,形如[(表名,改动情况,行的diff,列的diff)],-1:删除,0:未改动,1:新增,2:改动
     #增删改的结构为,[(表的增删改,行的改动,列的改动,单元格的改动)]
     #行列的改动的结构为,[(增删,行号),]
     #单元格的改动的结构为,[(行号,列号),]
     diffrst = []
     sheetnamesPre = xlsPre.sheet_names()
     sheetnamesSuf = xlsSuf.sheet_names()
     # print u"There are %s sheets."%(len(sheetnamesSuf))
     diffmain = Diff()
     for sheetname in sheetnamesPre:
         if sheetname in sheetnamesSuf:
             # print u"Start processing: ",sheetname
             rowsPre = self.sheet2ListByRow(xlsPre.sheet_by_name(sheetname))
             rowsSuf = self.sheet2ListByRow(xlsSuf.sheet_by_name(sheetname))
             sheets.append((sheetname, rowsPre, rowsSuf))
             if rowsPre == rowsSuf:
                 diffrst.append((sheetname, 0, rowsPre, rowsSuf))
             else:
                 # print u"old sheet has %s rows. " % len(rowsPre), u"new sheet has %s rows" % len(rowsSuf)
                 diffrows = diffmain.diff_main(rowsPre, rowsSuf, True)
                 # print u"finish rows diff"
                 colsPre = self.sheet2ListByCol(
                     xlsPre.sheet_by_name(sheetname))
                 colsSuf = self.sheet2ListByCol(
                     xlsSuf.sheet_by_name(sheetname))
                 # print u"old sheet has %s columns. " % len(colsSuf), u"new sheet has %s columns" % len(colsSuf)
                 diffcols = diffmain.diff_main(colsPre, colsSuf, True)
                 # print u"finish columns diff"
                 #diffmeg=self.diffMerge(diffrows,diffcols)
                 diffrst.append((sheetname, 2, diffrows, diffcols))
         else:
             # print u"Start processing: ", sheetname
             rowsPre = self.sheet2ListByRow(xlsPre.sheet_by_name(sheetname))
             sheets.append((sheetname, rowsPre, []))
             diffrst.append((sheetname, -1, rowsPre, []))
     for sheetname in sheetnamesSuf:
         if sheetname not in sheetnamesPre:
             # print u"Start processing: ", sheetname
             rowsPre = self.sheet2ListByRow(xlsSuf.sheet_by_name(sheetname))
             sheets.append((sheetname, [], rowsPre))
             diffrst.append((sheetname, 1, [], rowsPre))
     diffmerge = self.diffMerge(diffrst)
     tables = self.makeTable(sheets, diffmerge)
     return tables
Exemplo n.º 10
0
    def test_TC1(self):
        '''
        Text example
        '''
        data = {'a': {'a1': 1, 'a2': 2}, 'b': {'b1': {'b11': 1, 'b12': 2}}}

        data_before = copy.deepcopy(data)

        data['a']['a1'] = 3
        data['b']['b1']['b11'] = 5

        try_result = {'a': {'a1': 3}, 'b': {'b1': {'b11': 5}}}
        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 11
0
 def parseDiff(self, diffLines):
     diff = Diff(diffLines[0])
     expectedOpType = self.OP_TYPE_DELETE
     if self.isDiffOpTypeAppend(diff.getOpType()):
         expectedOpType = self.OP_TYPE_APPEND
     for lineNo in range(1, len(diffLines)):
         line = diffLines[lineNo]
         if self.isDiffLineDelete(
                 line) and expectedOpType == self.OP_TYPE_DELETE:
             diff.addDelete(line)
         elif self.isDiffLineBreak(
                 line) and diff.getOpType() == self.OP_TYPE_CHANGE:
             expectedOpType = self.OP_TYPE_APPEND
         elif self.isDiffLineAppend(
                 line) and expectedOpType == self.OP_TYPE_APPEND:
             diff.addAppend(line)
         else:
             #TODO: Implement custom errors
             raise ValueError
     return diff
Exemplo n.º 12
0
    def test_TC6(self):
        data = {
            'a': {
                'a1': 1,
                'a2': 3
            },
            'b': {
                'b1': 5,
                'b2': {
                    'b3': {
                        'b4': 5
                    }
                }
            }
        }
        data_before = copy.deepcopy(data)

        data['a']['a2'] = 7
        del (data['b']['b2'])

        try_result = {'a': {'a2': 7}, 'b': {'b2': {'b3': {'b4': 5}}}}
        result = Diff().diff_two_dict(data_before, data, {})

        self.assertEqual(try_result, result)
Exemplo n.º 13
0
import numpy as np
import pandas as pd

from diff import Diff

if __name__ == '__main__':
    df1 = pd.DataFrame({
        'x': [None, 2, np.NaN, 3, np.Inf],
        'y': ['', 2, np.NaN, None, '1']
    })

    df2 = pd.DataFrame({'x': [1, 2, 3, 4], 'y': ['a', 'b', 'c', 'd']})

    diff = Diff()
    diff(df1, df2)
Exemplo n.º 14
0
def main(diff_file, output_file, ignore_files):

    d = Diff(diff_file, ignore_files.split(","))
    d.export(output_file)
Exemplo n.º 15
0
    def judge(self, sub):

        lang = sub.lang
        mem_policy = True if (jcnf.POLICY[lang] == 'ALL'
                              or jcnf.POLICY[lang] == 'MEM') else False

        page_size = resource.getpagesize()

        case_cnt = min(len(sub.case_lim), sub.case_cnt)
        sub.case_done = 0
        case_id = 0

        for case_id in range(case_cnt):
            sub.case_res.append({
                'res': jcnf.JUDGE_RES['init'],
                'time': 0,
                'mem': 0,
            })

        exec_cmd = jcnf.EXEC_CMD[lang]
        exec_param = jcnf.EXEC_PARAM[lang]
        if lang == 'java':
            mem_lim = 0
            for case_id in xrange(case_cnt):
                mem_lim = max(mem_lim, sub.case_lim[case_id]['mem'])
            exec_param.insert(1, '-Xmx' + str(mem_lim / 1024 + 1) + 'm')

        for case_id in xrange(case_cnt):
            lim = sub.case_lim[case_id]
            res = sub.case_res[case_id]
            exec_pid = os.fork()

            if exec_pid == 0:
                for rk, rv in jcnf.EXEC_RLIM[lang].items():
                    resource.setrlimit(rk, rv)

                try:
                    exec_i = open(jcnf.getCasePathI(sub.pid, case_id), 'r')
                    exec_o = open(jcnf.getExecPathO(), 'w')
                except:
                    #sys.stderr.write('file read error')
                    raise Exception('cannot handle input or output file')

                lim['time'] = max(lim['time'], jcnf.EXEC_MIN_TL[lang])
                lim['time'] = int(lim['time'] * jcnf.EXEC_TL_RATIO[lang])
                if lang == 'java':
                    lim['time'] *= 3
                rlimt = (lim['time'] - 1) // 1000 + 2
                resource.setrlimit(resource.RLIMIT_CPU, (rlimt, rlimt))

                rlimm = jcnf.EXEC_MAX_MEM
                if mem_policy:  # java uses virtual machine
                    resource.setrlimit(resource.RLIMIT_AS, (rlimm, rlimm))

                os.dup2(exec_i.fileno(), 0)
                os.dup2(exec_o.fileno(), 1)

                #TOTO: ptrace
                pt_ret = cptrace.ptrace(cptrace.PTRACE_TRACEME, 0)
                if (pt_ret == -1):
                    #sys.stderr.write('warning: ptrace error')
                    raise Exception('child process cannot be ptraced')
                    if exec_i:
                        exec_i.close()
                    if exec_o:
                        exec_o.close()
                    os._exit(1)

                os.execvp(exec_cmd, exec_param)

                sys.stderr.write('warning: something wrong')
                if exec_i:
                    exec_i.close()
                if exec_o:
                    exec_o.close()

                os._exit(1)

            else:
                stat_info_file = str(exec_pid).join(['/proc/', '/statm'])
                res['mem'] = 0
                res['time'] = 0
                t_prev = jclk()
                eax_prev = 142857
                insyscall = False

                def killProc():
                    try:
                        os.kill(exec_pid, signal.SIGKILL)
                    except OSError:
                        pass
                    else:
                        res['res'] = jcnf.JUDGE_RES['re']

                threading.Timer((lim['time'] - 1) // 1000 + 10,
                                killProc).start()
                try:
                    while res['res'] == jcnf.JUDGE_RES['init']:
                        #while True:
                        exec_status = os.wait4(exec_pid, 0)
                        if res['res'] != jcnf.JUDGE_RES['init']:
                            break
                        t_now = jclk()
                        res['time'] += t_now - t_prev
                        t_prev = t_now
                        DEBUG_CNT = 0
                        #res['mem'] = exec_status[2].ru_minflt-360
                        res['mem'] = exec_status[2].ru_maxrss

                        if os.WIFSIGNALED(exec_status[1]):
                            #strange exited     or tle?
                            if res['time'] * 1000 > lim['time']:
                                res['res'] = jcnf.JUDGE_RES['tle']
                                break
                        elif os.WIFEXITED(exec_status[1]):
                            #normally exited    , ok
                            break
                        elif os.WIFSTOPPED(exec_status[1]):
                            #sigtrap by ptra    ce
                            exec_sig = os.WSTOPSIG(exec_status[1])
                            if exec_sig != signal.SIGTRAP:
                                res['res'] = jcnf.JUDGE_RES['re']
                                #print exec_status[0], exec_status[1], 'hehe', exec_sig
                                cptrace.ptrace(cptrace.PTRACE_KILL, exec_pid)
                                #strange exited?
                                break
                            eax_now = cptrace.ptrace(
                                cptrace.PTRACE_PEEKUSER, exec_pid,
                                4 * cptrace.ORIG_EAX
                            )  #when used in 64bit system, it should be 8*xxxx, so it is recommended to make it a const in conf

                            if jcnf.POLICY[lang] == 'ALL':
                                if jcnf.SYSCALL[eax_now][
                                        0] == 0:  #prohibited syscall
                                    res['res'] = jcnf.JUDGE_RES['re']
                                    cptrace.ptrace(
                                        cptrace.PTRACE_KILL, exec_pid
                                    )  #deprecated! should be implemented in another way
                                    break
                            else:
                                #TODO extend implementation
                                pass

                            if eax_now != eax_prev and eax_now != -1:
                                insyscall = False

                            if eax_now != -1:
                                if insyscall:
                                    DEBUG_CNT += 1
                                    #if eax_now==45 or eax_now==90 or eax_now==91:
                                    try:
                                        stat_info = open(stat_info_file, 'r')
                                        mem_now = int(
                                            stat_info.read().split(' ')[5]
                                        )  #automatically to long when exceed
                                        #res['mem'] = max(res['mem'], mem_now)
                                        stat_info.close()
                                    except:
                                        pass
                                    insyscall = False
                                else:
                                    insyscall = True

                            if mem_policy and res['mem'] > lim[
                                    'mem']:  #res['mem']*page_size>lim['mem']*1024:
                                res['res'] = jcnf.JUDGE_RES['mle']
                                cptrace.ptrace(
                                    cptrace.PTRACE_KILL, exec_pid
                                )  #deprecated! should be implemented in another way
                                break

                            if res['time'] * 1000 > lim['time']:
                                res['res'] = jcnf.JUDGE_RES['tle']
                                cptrace.ptrace(
                                    cptrace.PTRACE_KILL, exec_pid
                                )  #deprecated! should be implemented in another way
                                break
                            if eax_now != -1:
                                eax_prev = eax_now

                            t_prev = jclk()

                        else:
                            #sys.stderr.write('unknown status')
                            pass

                        #TODO: also check total time limit?
                        if res['res'] == jcnf.JUDGE_RES['tle']:
                            #TODO: write log
                            cptrace.ptrace(
                                cptrace.PTRACE_KILL, exec_pid
                            )  #deprecated! should be implemented in another way
                        else:
                            cptrace.ptrace(cptrace.PTRACE_SYSCALL, exec_pid)
                except:
                    pass
                try:
                    os.wait()
                    os.kill(exec_pid, signal.SIGKILL)
                except Exception, e:
                    if JDEBUG: print 'cannot kill', Exception, e
                    pass
                res['mem'] = int(res['mem'])
                res['time'] = int(res['time'] * 1000)

                if res['res'] == jcnf.JUDGE_RES['init']:
                    if os.WIFSIGNALED(exec_status[1]):
                        res['res'] = jcnf.JUDGE_RES['re']
                    elif os.WIFSTOPPED(exec_status[1]) and os.WSTOPSIG(
                            exec_status[1]) != signal.SIGTRAP:
                        res['res'] = jcnf.JUDGE_RES['re']

                if res['res'] == jcnf.JUDGE_RES['init']:
                    df = Diff()
                    res['res'] = df.diff(jcnf.getCasePathO(sub.pid, case_id),
                                         jcnf.getExecPathO())

                sub.case_done += 1
                #sub.mem += res['mem']
                sub.mem = max(sub.mem, res['mem'])
                sub.time += res['time']

                if res['res'] == jcnf.JUDGE_RES['init']:
                    res['res'] = jcnf.JUDGE_RES['se']

                # Need to calculate the scores of all test data, and thus we cannot break out when judging
                # if sub.block and res['res']!=jcnf.JUDGE_RES['ac']:
                #    break

                t_prev = jclk()

                sub.status = jcnf.SUB_STATUS['done']
Exemplo n.º 16
0
    def ColumnModelCal(self):

        # Calculate angle between wind direction and canyon orientation (theta_S) [deg]
        theta_S = (360+abs(self.theta_can-self.ForcWindDir))%90



        # Road roughness
        z0g = 0.05
        # Roof roughness
        z0r = 0.15
        # gas constant dry air [J kg^-1 K^-1]
        r = 287.04
        rcp = r / self.Cp
        # Define explicit and implicit parts of source and sink terms
        srex_vx = numpy.zeros(self.nz)       # Explicit part of x component of horizontal wind speed [m s^-2]
        srim_vx = numpy.zeros(self.nz)       # Implicit part of x component of horizontal wind speed [s^-1]
        srex_vy = numpy.zeros(self.nz)       # Explicit part of y component of horizontal wind speed [m s^-2]
        srim_vy = numpy.zeros(self.nz)       # Implicit part of y component of horizontal wind speed [s^-1]
        srex_tke = numpy.zeros(self.nz)      # Explicit part of turbulent kinetic energy [m^2 s^-3]
        srim_tke = numpy.zeros(self.nz)      # Implicit part of turbulent kinetic energy [s^-1]
        srex_th = numpy.zeros(self.nz)       # Explicit part of potential temperature [K s^-1]
        srim_th = numpy.zeros(self.nz)       # Implicit part of potential temperature [s^-1]
        srex_qn = numpy.zeros(self.nz)       # Explicit part of specific humidity [K s^-1] ?????
        srim_qn = numpy.zeros(self.nz)       # Implicit part of specific humidity [s^-1] ?????

        srex_th_veg = numpy.zeros(self.nz)   # Explicit part of potential temperature caused by vegetation
        srex_qn_veg = numpy.zeros(self.nz)   # Explicit part of specific humidity caused by vegetation
        Tveg = numpy.zeros(self.nz)

        # Apply boundary conditions at the top of the domain using vertical diffusion model(VDM) outputs
        self.th[self.nz-1] = self.ForcTemp
        self.qn[self.nz-1] = self.ForcHum
        self.vx[0] = 0.001
        self.vy[0] = 0.001
        self.tke[0] = 0.00001

        # Calculate bulk Richardson number (Ri_b):
        # Ri_b = (g*H/((Uroof - Ustreet)^2+(Vroof - Vstreet)^2))*(Troof - Tstreet)/Tavg (equation 6, Aliabadi et al., 2018)
        delU = ((self.vx[0]-self.vx[self.nz_u+1])**2+(self.vy[0]-self.vy[self.nz_u+1])**2)
        # Denominator of the fraction must not be zero. So, a minimum value for denominator is considered
        delU = max(delU,0.1)
        #For calculation of Rib, option 1: surface temperature difference
        #delT = self.RoofTemp-self.RoadTemp
        #For calculation of Rib, option 2: air temperature difference
        delT = self.th[self.nz_u+1]-self.th[1]
        Ri_b =  ((self.g*self.hmean)/delU)*(delT/numpy.mean(self.th[0:self.nz_u]))
        # Calculate turbulent diffusion coefficient (Km) [m^2 s^-1]
        TurbDiff = CdTurb(self.nz, self.Ck, self.tke, self.dlk,self.it,Ri_b,self.var_sens)
        Km = TurbDiff.TurbCoeff()

        # Road surface temperature [K]
        ptg = self.RoadTemp
        # Wall surface temperature [K]
        ptw = self.WallTemp
        # Roof surface temperature [K]
        ptr = self.RoofTemp

        # Call "BuildingCol" to calculate sink and source terms in momentum, temperature and turbulent kinetic energy (TKE)
        #  equations which are caused by building
        BuildingCoef = BuildingCol(self.nz, self.dz, self.dt, self.vol, (1-self.VegCoverage), self.lambdap, self.lambdaf,
                                   self.hmean, self.Ck, self.Cp, self.th0, self.vx, self.vy, self.th, self.Cdrag,
                                   ptg,ptr, ptw, self.rho,self.nz_u, self.pb, self.ss,self.g,z0g,z0r,self.SensHt_HVAC,self.HVAC_street_frac,self.HVAC_atm_frac)

        # Calculate shear production [m^2 s^-3] in TKE equation. (Term II of equation 5.2, Krayenhoff 2014, PhD thesis)
        Shear_Source = Shear(self.nz, self.dz, self.vx, self.vy, Km)
        sh = Shear_Source.ShearProd()

        # Calculate buoyant production [m^2 s^-3] in TKE equation. (Term IX of equation 5.2, Krayenhoff 2014, PhD thesis)
        Buoyancy_Source = Buoyancy(self.nz, self.dz, self.th, Km, self.th0, self.prandtl, self.g)
        bu = Buoyancy_Source.BuoProd()

        # Calculate dissipation (td) [s^-1] in TKE equation. (Term VI of equation 5.2, Krayenhoff 2014, PhD thesis)
        # parameterization of dissipation is based on Nazarian's code. (https://github.com/nenazarian/MLUCM/blob/master/Column_Model/column_lkPro.f90)
        td = numpy.zeros(self.nz)
        for i in range(0, self.nz):
            if self.dls[i] != 0:
                td[i] = -self.Ceps*(math.sqrt(self.tke[i]))/self.dls[i]
            else:
                td[i] = 0
            sh[i] = sh[i]*self.sf[i]
            bu[i] = bu[i]*self.sf[i]

        # Return sink and source terms caused by buildings
        srex_vx_h, srex_vy_h, srex_tke_h, srex_th_h, srim_vx_v, srim_vy_v, srex_tke_v, srim_th_v, srex_th_v, sff,swf, ustarCol = BuildingCoef.BuildingDrag()

        # Friction velocity (Aliabadi et al, 2018)
        ustar = 0.07 * self.ForcWind + 0.12
        # Calculate pressure gradient
        C_dpdx = 5.4
        dpdx = C_dpdx*self.rho[self.nz-1]*(ustar**2)*math.cos(math.radians(theta_S))/(self.dz*self.nz)
        dpdy = C_dpdx*self.rho[self.nz-1]*(ustar**2)*math.sin(math.radians(theta_S))/(self.dz*self.nz)

        # Latent heat of vaporization [J kg^-1]
        latent = 2.45e+06
        # Latent heat of vaporization [J mol^-1](Campbell and Norman,1998)
        latent2 = 44100
        # The average surface and boundary-layer conductance for humidity for the whole leaf
        gvs = 0.330
        # Set leaf dimension of trees
        leaf_width = 0.05
        leaf_dim = 0.72 * leaf_width
        # Air pressure [Pa]
        pr = 101300
        # Total neighbourhood foliage clumping [non dimensional]
        omega = 1
        # Molar heat capacity [J mol^-1 K^-1](Campbell and Norman, 1998)
        cp_mol = 29.3
        # Drag coefficient for vegetation foliage
        cdv = 0.2
        omega_drag = 0.34

        # Calculate source and sink terms caused by trees and then calculate total source and sink terms
        for i in range(0, self.nz):

            # source/sink terms of specific humidity
            wind = numpy.sqrt(self.vx[i] ** 2 + self.vy[i] ** 2)
            # Boundary-layer conductance for vapor (p. 101 Campbell and Norman, 1998)
            gva = 1.4 * 0.147 * numpy.sqrt(wind / leaf_dim)
            # Overall vapour conductance for leaves [mol m^-2 s^-1] (equation 14.2, Campbell and Norman, 1998):
            gv = gvs * gva / (gvs + gva)
            # Conductance for heat [mol m^-2 s^-1]
            gHa = 1.4 * 0.135 * numpy.sqrt(wind / leaf_dim)
            # Since a leaf has two sides in parallel, gHa should be multiplied by 2
            gHa = gHa * 2
            # Convert potential air temperature to real temperature [K]
            # potential temperature = real temperature * (P0/P)^(R/cp)
            tair = self.th[i] / (pr / 1.e+5) ** (-rcp)
            # Convert absolute humidity to vapour pressure [Pa]
            eair = self.qn[i] * pr / 0.622
            # Saturation vapor pressure [Pa] (equation 7.5.2d, Stull 1988)
            es = 611.2 * numpy.exp(17.67 * (tair - 273.16) / (tair - 29.66))
            D = es - eair
            desdT = 0.622 * latent * es / r / (tair) ** 2
            s = desdT / pr
            # Calculate terms in transport equations caused by trees. "wt" is term in temperature equation adn "wt_drag"
            # is term in TKE and momentum equations. It is assumed there is no vegetation above average building height
            if self.dz * i > max(self.h_LAD):
                wt = 0         # [m^2 m^-3]
                wt_drag = 0    # [m^2 m^-3]
            else:
                wt = self.f_LAD(self.dz * i) * omega * (1 - self.lambdap) / self.vol[i]             # [m^2 m^-3]
                wt_drag = self.f_LAD(self.dz * i) * omega_drag * (1. - self.lambdap) / self.vol[i]  # [m^2 m^-3]

            # Stefan-Boltzmann constant [W m^-2 K^-4]
            sigma = 5.67e-8
            gam = 6.66e-4
            # Emissivity of leaves surface
            emveg = 0.95
            # Total fraction scattered by leaves: reflected & transmitted
            albv_u = 0.5
            fact = 1
            # Total radiation absorbed by leaves [W m^-2]
            Rabs = (1-albv_u)*self.S_t+self.L_t*emveg
            gr = 4 * emveg * sigma * tair ** 3 / cp_mol
            gr = gr * 2. * omega * fact
            sides = 2. * omega * fact
            gHr = gHa + gr
            gamst = gam * gHr / gv
            # Calculate temperature of vegetation [K]
            tveg_tmp = tair+gamst/(s+gamst)*((Rabs-sides*emveg*sigma*(tair**4))/gHr/cp_mol-D/pr/gamst)
            Tveg[i] = tveg_tmp

            # Calculate terms in temperature and humidity equations caused by trees.
            if self.dz * i > max(self.h_LAD):
                srex_th_veg[i] = 0
                srex_qn_veg[i] = 0
            else:
                srex_th_veg[i] = cp_mol*gHa*tveg_tmp*wt/self.Cp/self.rho[i]
                srex_qn_veg[i] = (latent2*gv*(s*(tveg_tmp-tair)+es/pr))*wt/self.rho[i]/latent

            # Calculate total explicit terms
            # Explicit term in x momentum equation [m s^-2] = fluxes from horizontal surfaces + pressure gradient
            # pressure gradient is zero, because boundary conditions are forced by vertical diffusion model
            srex_vx[i] = srex_vx_h[i]+dpdx

            # Explicit term in y momentum equation [m s^-2] = fluxes from horizontal surfaces + pressure gradient
            # pressure gradient is zero, because boundary conditions are forced by vertical diffusion model
            srex_vy[i] = srex_vy_h[i]+dpdy

            # Explicit term in TKE equation [m^2 s^-3] = terms from urban horizontal surfaces [??????] +
            # terms from walls [m^2 s^-3] + shear production [m^2 s^-3] + buoyant production [m^2 s^-3] +
            # term caused by vegetation [m^2 s^-3]
            srex_tke[i] = srex_tke_h[i] + srex_tke_v[i] + sh[i] + bu[i] + cdv*wind**3.*wt_drag

            # Explicit term in temperature equation [K s^-1] = term from urban horizontal surfaces [K s^-1] +
            # term from walls [K s^-1] + term caused by vegetation [K s^-1]
            srex_th[i] = srex_th_h[i] + srex_th_v[i] + srex_th_veg[i] #+ 4*rho_abs*kbs*(1-self.lambdap)*self.L_abs/self.rho/self.Cp/self.vol[i]

            # Explicit term in humidity equation [K s^-1] = term caused by latent heat from vegetation [K s^-1]
            srex_qn[i] = srex_qn[i] + srex_qn_veg[i]

            # Calculate total Implicit terms
            # Implicit term in x momentum equation [s^-1] = term from walls [s^-1] - term caused by vegetation [s^-1]
            srim_vx[i] = srim_vx_v[i]-cdv*wind*wt_drag

            # Implicit term in y momentum equation [s^-1] = term from walls [s^-1] - term caused by vegetation [s^-1]
            srim_vy[i] = srim_vy_v[i]-cdv*wind*wt_drag

            # Implicit term in TKE equation [s^-1] = dissipation [s^-1] - term caused by vegetation [s^-1]
            srim_tke[i] = td[i]-6.5*cdv*wind*wt_drag

            # Implicit term in temperature equation [s^-1] = term from wall [s^-1] - term caused by vegetation [s^-1]
            srim_th[i] = srim_th_v[i]-cp_mol*gHa*wt/self.Cp/self.rho[i]

            # Implicit term in humidity equation [s^-1] = term caused by latent heat from vegetation [s^-1]
            srim_qn[i] = srim_qn[i]-latent2*gv*(pr/0.622)/pr*wt/self.rho[i]/latent


        # Solve transport equations
        # Set type of boundary conditions (B.Cs):
        # Neumann boundary condition (Flux): iz = 1
        # Dirichlet boundary condition (Constant value): iz = 2
        # Sol.Solver(B.C. at the bottom of domain)
        Sol = Diff(self.nz, self.dt, self.sf, self.vol, self.dz, self.rho)
        # Solve x component of momentum equation
        A_vx = Sol.Solver21(2, 1, self.vx, srim_vx, srex_vx,Km)[0]
        RHS_vx = Sol.Solver21(2, 1, self.vx, srim_vx, srex_vx,Km)[1]
        Inv_vx = Invert(self.nz, A_vx, RHS_vx)
        self.vx = Inv_vx.Output()
        # Solve y component of momentum equation
        A_vy = Sol.Solver21(2, 1, self.vy, srim_vy, srex_vy,Km)[0]
        RHS_vy = Sol.Solver21(2, 1, self.vy, srim_vy, srex_vy,Km)[1]
        Inv_vy = Invert(self.nz, A_vy, RHS_vy)
        self.vy = Inv_vy.Output()
        # Solve TKE equation
        A_tke = Sol.Solver21(2, 1, self.tke, srim_tke, srex_tke,Km)[0]
        RHS_tke = Sol.Solver21(2, 1, self.tke, srim_tke, srex_tke,Km)[1]
        Inv_tke = Invert(self.nz, A_tke, RHS_tke)
        self.tke = Inv_tke.Output()
        # Solve temperature equation
        A_th = Sol.Solver12(1, 2, self.th, srim_th, srex_th,Km/self.prandtl)[0]
        RHS_th = Sol.Solver12(1, 2, self.th, srim_th, srex_th,Km/self.prandtl)[1]
        Inv_th = Invert(self.nz, A_th, RHS_th)
        self.th = Inv_th.Output()
        # Solve specific humidity equation
        A_qn = Sol.Solver12(1, 2, self.qn, srim_qn, srex_qn,Km/self.schmidt)[0]
        RHS_qn = Sol.Solver12(1, 2, self.qn, srim_qn, srex_qn,Km/self.schmidt)[1]
        Inv_qn = Invert(self.nz, A_qn, RHS_qn)
        self.qn = Inv_qn.Output()

        # Set a minimum value for kinetic energy which avoid trapping of heat at street level
        for i in range(0, self.nz):
            if self.tke[i] < 1e-3:
               self.tke[i] = 1e-3

        return self.vx,self.vy,self.tke,self.th,self.qn, ustarCol,Km,tveg_tmp,Ri_b,Tveg
Exemplo n.º 17
0
    proc_list = []
    for samp in allSamps:
        proc = Process(target=basicAnalyze,
                       args=(
                           samp,
                           args.species,
                           args.threads,
                           args.alignTool,
                       ))
        proc_list.append(proc)
    for p in proc_list:
        p.start()
    for p in proc_list:
        p.join()
    PlotCorrelation(allSamps, args.threads)
    Matrix(allSamps)
    try:
        Diff(len(conSamps), args.species)
        DiffTransFig()
    except:
        print('Diff error !')
    finally:
        Cluster(allSamps)
        Enrich()
    rMATS(conSamps, expSamps, args.species)
    rmats2sashimiplot(conSamps, expSamps)

    print('分析结束')
    t1 = time.time()
    print('\n' + '#' * 60)
Exemplo n.º 18
0
 def test_TC10(self):
     with self.assertRaises(TypeError):
         Diff().diff_two_dict(5, {}, {})
Exemplo n.º 19
0
    def test_TC11(self):
        try_result = {}

        result = Diff().diff_two_dict({}, {}, {})

        self.assertEqual(try_result, result)