selftest.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:NuGridPy 作者: NuGrid 项目源码 文件源码
def test_abu_chart(self):
        from nugridpy import utils,ppn,data_plot
        import matplotlib
        matplotlib.use('agg')
        import matplotlib.pylab as mpy
        import os

        # Perform tests within temporary directory
        with TemporaryDirectory() as tdir:
            # wget the data for a ppn run from the CADC VOspace
            n = 3
            for cycle in range(0,n):
                cycle_str = str(cycle).zfill(2)
                os.system("wget -q --content-disposition --directory '" + tdir + "' "
                          + "'http://www.canfar.phys.uvic.ca/vospace/synctrans?TARGET="\
                          + "vos%3A%2F%2Fcadc.nrc.ca%21vospace%2Fnugrid%2Fdata%2Fprojects%2Fppn%2Fexamples%2F"\
                          + "ppn_Hburn_simple%2Fiso_massf000" + cycle_str + ".DAT&DIRECTION=pullFromVoSpace&PROTOCOL"\
                          + "=ivo%3A%2F%2Fivoa.net%2Fvospace%2Fcore%23httpget'")

            # test_data_dir should point to the correct location of a set of abundances data file
            #nugrid_dir= os.path.dirname(os.path.dirname(ppn.__file__))
            #NuPPN_dir= nugrid_dir + "/NuPPN"
            #test_data_dir= NuPPN_dir + "/examples/ppn_C13_pocket/master_results"

            p=ppn.abu_vector(tdir) # TODO: this function fails to raise an exception if path is not found!
            mp=p.get('mod')
            if len(mp) == 0:
                raise IOError("Cannot locate a set of abundance data files")
            sparse=10
            cycles=mp[:1000:sparse]
            form_str='%6.1F'
            form_str1='%4.3F'

            i=0
            for cyc in cycles:
                T9  = p.get('t9',fname=cyc)
                Rho = p.get('rho',fname=cyc)
                mod = p.get('mod',fname=cyc)
                # time= p.get('agej',fname=cyc)*utils.constants.one_year
                time= p.get('agej',fname=cyc)
                mpy.close(i);mpy.figure(i);i += 1
                p.abu_chart(cyc,mass_range=[0,41],plotaxis=[-1,22,-1,22],lbound=(-6,0),show=False)
                mpy.title(str(mod)+' t='+form_str%time+'yr $T_9$='+form_str1%T9+' $\\rho$='+str(Rho))
                png_file='abu_chart_'+str(cyc).zfill(len(str(max(mp))))+'.png'
                mpy.savefig(png_file)
                self.assertTrue(os.path.exists(png_file))
                os.remove(png_file)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号