예제 #1
0
def test_dtopo_io():
    r"""Test IO of dtopography class"""

    test_data_path = os.path.join(testdir, "data", "alaska1964_test_data.tt3")
    test_dtopo = dtopotools.DTopography(path=test_data_path)

    temp_path = tempfile.mkdtemp()
    try:
        dtopo_paths = [os.path.join(temp_path, 'alaska1964.tt1'),
                       os.path.join(temp_path, 'alaska1964.tt3')]
                       # os.path.join(temp_path, 'alaska1964.tt2'),

        for path in dtopo_paths:
            test_dtopo.write(path)
            dtopo = dtopotools.DTopography(path=path)

            assert test_dtopo.dZ.shape == dtopo.dZ.shape, \
                   "Shape of dZ not equal for topo_type = %s." % dtopo.topo_type

            assert numpy.allclose(test_dtopo.dZ, dtopo.dZ), \
                "dZ not equal for %s" % path

    except AssertionError as e:
        test_dump_path = os.path.join(os.getcwd(), "test_dtopo_io")
        shutil.mkdir(test_dump_path)
        shutil.copy(temp_path, test_dump_path)
        raise e
    finally:
        shutil.rmtree(temp_path)
예제 #2
0
def test_dtopo_io():
    r"""Test IO of dtopography class"""

    test_data_path = os.path.join(testdir, "data", "alaska1964_test_data.tt3")
    test_dtopo = dtopotools.DTopography(path=test_data_path)

    temp_path = tempfile.mkdtemp()
    try:
        dtopo_paths = [
            os.path.join(temp_path, 'alaska1964.tt1'),
            os.path.join(temp_path, 'alaska1964.tt3')
        ]
        # os.path.join(temp_path, 'alaska1964.tt2'),

        for path in dtopo_paths:
            test_dtopo.write(path)
            dtopo = dtopotools.DTopography(path=path)

            assert test_dtopo.dZ.shape == dtopo.dZ.shape, \
                   "Shape of dZ not equal for topo_type = %s." % dtopo.topo_type

            assert numpy.allclose(test_dtopo.dZ, dtopo.dZ), \
                "dZ not equal for %s" % path

    except AssertionError as e:
        test_dump_path = os.path.join(os.getcwd(), "test_dtopo_io")
        shutil.mkdir(test_dump_path)
        shutil.copy(temp_path, test_dump_path)
        raise e
    finally:
        shutil.rmtree(temp_path)
예제 #3
0
 def __init__(self,THRESHOLD=10000,path="./"):
     self.TABLE = skiplist.SkipList(isdup=False)
     self.THRESHOLD = THRESHOLD
     self.path = path
     self.curr_active = max([int(f.replace('.sst', '').replace(self.path,'')) for f in glob(path+'*.sst')] or [1])
     
     if os.path.exists(path) == False:
         shutil.mkdir(path)
예제 #4
0
    def __init__(self, THRESHOLD=10000, path="./"):
        self.TABLE = {}
        self.THRESHOLD = THRESHOLD
        self.path = path
        self.curr_active = max([int(f.replace(".sst", "").replace(self.path, "")) for f in glob(path + "*.sst")] or [1])

        if os.path.exists(path) == False:
            shutil.mkdir(path)
예제 #5
0
    def load_data(self, path=None):
        '''指定路径,加载该文件夹目录下所有数据文件'''
        if path is not None:
            self.path = path
            if os.path.exists(path) == False:
                shutil.mkdir(path)

        for filename in glob(self.path + "*.sst"):
            self.load_file(filename)
예제 #6
0
    def load_data(self, path=None):
        """指定路径,加载该文件夹目录下所有数据文件"""
        if path is not None:
            self.path = path
            if os.path.exists(path) == False:
                shutil.mkdir(path)

        for filename in glob(self.path + "*.sst"):
            self.load_file(filename)
예제 #7
0
파일: moin2.py 프로젝트: happytk/moin
def cda(pagename, wiki='wecanfly', create=False):
	pagename = unquote(pagename)
	cfg = getattr(__import__('wiki_' + wiki), 'Config')
	path = os.path.join(cfg.data_dir, 'pages', pagename, 'attachments')
	if os.path.isdir(path):
		os.chdir(path)
	elif create:
		shutil.mkdir(path)
		os.chdir(path)
	print path
예제 #8
0
    def __init__(self, THRESHOLD=10000, path="./"):
        self.TABLE = {}
        self.THRESHOLD = THRESHOLD
        self.path = path
        self.curr_active = max([
            int(f.replace('.sst', '').replace(self.path, ''))
            for f in glob(path + '*.sst')
        ] or [1])

        if os.path.exists(path) == False:
            shutil.mkdir(path)
예제 #9
0
파일: xyz2sample.py 프로젝트: syam-s/SimEx
def main(xyz):
    if not os.path.isfile(xyz):
        raise IOError("%s is not a file." % (xyz))

    sample_dir = 'sample'
    if not os.path.isdir(sample_dir):
        shutil.mkdir(sample_dir)
    coordinates_fname = os.path.join(sample_dir, "r.txt")
    atom_numbers_fname = os.path.join(sample_dir, "Z.txt")

    Z = []
    r = []
    with open(xyz, 'r', newline='') as xyz_handle:
        reader = csv.reader(xyz_handle, delimiter=' ')

        for line in reader:
            if len(line) < 4:
                print("INFO: " + "".join(line))
                continue
            symbol = line[0]
            element = getattr(elements, symbol)
            Z.append(str(element.number))

            coords = [float(x) for x in line[1:] if x != '']
            r.append(coords)

    # Convert to m.
    r = numpy.array(r) * 1.0e-10

    with open(coordinates_fname, 'w') as r_handle:
        for coords in r:
            r_handle.write("%.8e\t%.8e\t%.8e\n" %
                           (coords[0], coords[1], coords[2]))

    with open(atom_numbers_fname, 'w') as Z_handle:
        Z_handle.write(' '.join(Z))
예제 #10
0
import time
import shutil
import subprocess
experiment_name = time.time()
shutil.mkdir(experiment_name)
PROB_PUT = .1
N_ITER = 1000000
CACHE_SIZE = 100
SIZE_MEAN = 10000000
SIZE_VARIANCE = 1000000
KEY_VARINCE = 5
VERBOSE_GC_FLAG = "-verbose:gc"
BENCH_PROG = "com.scottandrewcarr.caching.BenchMark"
BASE_DIR="/home/carr27/caching"
    

def get_class_path():
    cp = []
    IDEA_OUTPUT = BASE_DIR + "/out"
    COMMONS_LOGGING = BASE_DIR + "/libs/commons-logging-1.1.3.jar"
    JCS = BASE_DIR + "/libs/jcs-1.3.jar"
    cp.append(IDEA_OUTPUT)
    cp.append(COMMONS_LOGGING)
    cp.append(JCS)
    cp_string = ""
    for i in range(len(cp)):
        if i == 0:
            cp_string = cp[i]
        else:
            cp_string = cp_string + ":"+ cp[i]
    return cp_string
예제 #11
0
파일: setup.py 프로젝트: woxin5295/pyNLLoc
def setup_package(install=False, build=False, clean=False):
    """setup_package()

    Function to call distutils setup to install the package to the default location for third party modules.

    Checks to see if required modules are installed and if not tries to install them (apart from Basemap)
    """
    try:
        from .__init__ import __author__, __version__, __email__, __doc__, __looseversion__, __build__
    except:
        from __init__ import __author__, __version__, __email__, __doc__, __looseversion__, __build__
    kwargs = dict(
        name='pyNLLoc',
        version=str(__version__) + 'b' + str(__build__),
        author=__author__,
        author_email=__email__,
        packages=['pyNLLoc'],
        package_dir={'pyNLLoc': '.'},
        requires=[],
        install_requires=[],
        provides=['pyNLLoc', 'Scat2Angle', 'XYZ2Angle'],
        url='https://github.com/djpugh/pyNLLoc',
        download_url='https://github.com/djpugh/pyNLLoc/tarball/v' +
        __version__,
        bugtrack_url='https://github.com/djpugh/pyNLLoc/issues',
        scripts=['pyNLLoc.py', 'Scat2Angle.py', 'XYZ2Angle.py'],
        description='pyNLLoc: Python functions for NonLinLoc and Scat2Angle',
        long_description=__doc__ + '\n\n' + open('README.md').read() + '\n',
        package_data={
            'pyNLLoc': [
                'README', 'make_angles.sh', 'GridLib.c', 'GetAngles.cpp',
                'NLLoc_code/*/*', 'NLLoc_code/*.*'
            ]
        },
        classifiers=[
            "Development Status :: 5 - Production/Stable",
            "Intended Audience :: Science/Research",
            "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)",
            "Natural Language :: English", "Programming Language :: Python",
            "Programming Language :: C++", "Topic :: Scientific/Engineering"
        ])
    if _SETUPTOOLS:
        kwargs['extras_require'] = {'Cluster': ['pyqsub>=1.0.0']}
        kwargs['install_requires'].append('pyqsub>=1.0.0')
        kwargs.pop('scripts')
        kwargs['version'] = __looseversion__
        kwargs['entry_points'] = {
            'console_scripts': [
                'pyNLLoc = pyNLLoc:pyNLLoc_run',
                'Scat2Angle = pyNLLoc:Scat2Angle_run',
                'XYZ2Angle = pyNLLoc:XYZ2Angle_run'
            ]  #,'XYZ2Time = pyNLLoc:XYZ2Time_run']
        }
    if build or 'build_all' in sys.argv or 'build-all' in sys.argv:
        #clean dist dir
        try:
            for fname in glob.glob('dist/*'):
                try:
                    os.remove(fname)
                except:
                    pass
        except:
            pass
        print('------\nBUILDING DISTRIBUTIONS\n-----\n')
        clean_package()
        argv = [sys.executable, "setup.py", "sdist"]
        subprocess.call(argv)
        clean_package()
        argv = [sys.executable, "setup.py", "sdist", "--format=gztar"]
        subprocess.call(argv)
        if _SETUPTOOLS:
            clean_package()
            argv = [sys.executable, "setup.py", "bdist_egg"]
            subprocess.call(argv)
        clean_package()
        argv = [sys.executable, "setup.py", "bdist_wheel"]
        subprocess.call(argv)
        clean_package()
        argv = [sys.executable, "setup.py", "bdist_msi"]
        subprocess.call(argv)
        clean_package()
        print('\n------\nBUILD COMPLETE\n------\n')

    elif 'pypi_upload' in sys.argv:
        argv = [sys.executable, "setup.py", "sdist", "upload", "-r", "pypi"]
        subprocess.call(argv)
        clean_package()
        argv = [
            sys.executable, "setup.py", "sdist", "--format=gztar", "upload",
            "-r", "pypi"
        ]
        subprocess.call(argv)
        clean_package()
        argv = [
            sys.executable, "setup.py", "bdist_wininst", "upload", "-r", "pypi"
        ]
        subprocess.call(argv)
        clean_package()
        argv = [
            sys.executable, "setup.py", "bdist_wheel", "upload", "-r", "pypi"
        ]
        subprocess.call(argv)
        clean_package()
        argv = [
            sys.executable, "setup.py", "bdist_msi", "upload", "-r", "pypi"
        ]
        subprocess.call(argv)
    elif 'clean_all' in sys.argv or clean or 'clean-all' in sys.argv:
        argv = [sys.executable, "setup.py", "clean", "--all"]
        subprocess.call(argv)
        try:
            shutil.rmtree('build/')
        except:
            pass
        try:
            shutil.rmtree('pyNLLoc-' + __looseversion__ + '/')
            shutil.mkdir('pyNLLoc-' + __looseversion__ + '/')
        except:
            try:
                shutil.rmtree('pyNLLoc-' + __version__ + '/')
                shutil.mkdir('pyNLLoc-' + __version__ + '/')
            except:
                pass
        if _SETUPTOOLS:
            try:
                shutil.rmtree('pyNLLoc.egg-info/')
                shutil.mkdir('pyNLLoc.egg-info/')
            except:
                pass
    else:
        if 'install' in sys.argv:
            #Try to build GetNLLOCScatterAngles and add to scripts
            ret = os.system('make all')
            if ret != 0:
                ret = os.system('./make_angles.sh')
            if ret != 0:
                print(
                    '\n\n*******************************\n\nC++ module not automatically compiled.\nPlease build manually.\n\n*******************************\n\n'
                )

        try:
            setup(**kwargs)
        except ValueError:
            kwargs['version'] = __version__
            setup(**kwargs)
예제 #12
0
def test_dynamic_tohoku(verbose=False, plot=False):
    r"""Test dynamic faulting via a Tohoku example"""

    shoreline_fname = os.path.join(testdir, 'data', 'tohoku_shoreline_1min.npy')
    shoreline_xy = numpy.load(shoreline_fname)

    subfault_fname = os.path.join(testdir, 'data', 'tohoku_ucsb.txt')
    fault = dtopotools.UCSBFault()
    fault.read(subfault_fname)
    fault.rupture_type = 'dynamic'

    if plot:
        import matplotlib.pyplot as plt

        fault.plot_subfaults(slip_color=True)  # plot final slip
        plt.show()

    # seafloor deformation:
    quick_test = True

    if quick_test:
        xlower = 140.
        xupper = 146.
        ylower = 35.
        yupper = 41.
        xylim = [xlower,xupper,ylower,yupper]

        # dtopo parameters for 4 min resolution:
        mx = int((xupper - xlower)*15 + 1)
        my = int((yupper - ylower)*15 + 1)
    else:
        xlower = 135.
        xupper = 150.
        ylower = 30.
        yupper = 45.
        xylim = [xlower,xupper,ylower,yupper]

        # dtopo parameters for 1 min resolution:
        mx = int((xupper - xlower)*60 + 1)
        my = int((yupper - ylower)*60 + 1)


    x = numpy.linspace(xlower,xupper,mx)
    y = numpy.linspace(ylower,yupper,my)

    tmax = 0.
    for s in fault.subfaults:
        tmax = max(tmax, s.rupture_time + s.rise_time + s.rise_time_ending)
    if verbose:
        print("rupture ends at time ",tmax)

    times = numpy.linspace(0,tmax,10)
    dtopo = fault.create_dtopography(x,y,times,verbose=True)

    dz_final = dtopo.dZ[-1]
    dz_max = dz_final.max()

    if plot:
        # Incorporate this function in dtopotools to replace animate_dz_colors?
        def plot_subfaults_dz(t, fig=None):
            if fig is None:
                fig = plt.figure(figsize=(12,5))
            else:
                fig.clf()
            ax1 = fig.add_subplot(121)
            ax2 = fig.add_subplot(122)
            fault.plot_subfaults(axes=ax1, slip_color=True, slip_time=t, xylim=xylim)
            dtopo.plot_dz_colors(axes=ax2, t=t, cmax_dz=dz_max)
            ax1.plot(shoreline_xy[:,0],shoreline_xy[:,1],'g')
            ax2.plot(shoreline_xy[:,0],shoreline_xy[:,1],'g')
            plt.axis(xylim)
            fig.show()
            return fig

        dtopo.plot_dz_colors(t=tmax)
        plt.show()
            
        fig = plt.figure(figsize=(12,5))

        for t in list(numpy.linspace(0,150,16)) + [170,200]:
            plot_subfaults_dz(t,fig)
            plt.draw()
            plt.show()
            time.sleep(1)

    temp_path = tempfile.mkdtemp()
    try:
        fname = os.path.join(temp_path, 'tohoku_ucsb_dynamic.tt3')
        dtopo.write(fname, 3)
    except Exception as e:
        test_name = inspect.stack()[1][-2][0][:-3]
        test_dump_path = os.path.join(os.getcwd(), test_name)
        shutil.mkdir(test_dump_path)
        shutil.copy(temp_path, test_dump_path)
        raise e
    finally:
        shutil.rmtree(temp_path)

    if verbose:
        print('Created ',fname)
예제 #13
0
def test_dynamic_tohoku(verbose=False, plot=False):
    r"""Test dynamic faulting via a Tohoku example"""

    shoreline_fname = os.path.join(testdir, 'data',
                                   'tohoku_shoreline_1min.npy')
    shoreline_xy = numpy.load(shoreline_fname)

    subfault_fname = os.path.join(testdir, 'data', 'tohoku_ucsb.txt')
    fault = dtopotools.UCSBFault()
    fault.read(subfault_fname)
    fault.rupture_type = 'dynamic'

    if plot:
        import matplotlib.pyplot as plt

        fault.plot_subfaults(slip_color=True)  # plot final slip
        plt.show()

    # seafloor deformation:
    quick_test = True

    if quick_test:
        xlower = 140.
        xupper = 146.
        ylower = 35.
        yupper = 41.
        xylim = [xlower, xupper, ylower, yupper]

        # dtopo parameters for 4 min resolution:
        mx = int((xupper - xlower) * 15 + 1)
        my = int((yupper - ylower) * 15 + 1)
    else:
        xlower = 135.
        xupper = 150.
        ylower = 30.
        yupper = 45.
        xylim = [xlower, xupper, ylower, yupper]

        # dtopo parameters for 1 min resolution:
        mx = int((xupper - xlower) * 60 + 1)
        my = int((yupper - ylower) * 60 + 1)

    x = numpy.linspace(xlower, xupper, mx)
    y = numpy.linspace(ylower, yupper, my)

    tmax = 0.
    for s in fault.subfaults:
        tmax = max(tmax, s.rupture_time + s.rise_time + s.rise_time_ending)
    if verbose:
        print("rupture ends at time ", tmax)

    times = numpy.linspace(0, tmax, 10)
    dtopo = fault.create_dtopography(x, y, times, verbose=True)

    dz_final = dtopo.dZ[-1]
    dz_max = dz_final.max()

    if plot:
        # Incorporate this function in dtopotools to replace animate_dz_colors?
        def plot_subfaults_dz(t, fig=None):
            if fig is None:
                fig = plt.figure(figsize=(12, 5))
            else:
                fig.clf()
            ax1 = fig.add_subplot(121)
            ax2 = fig.add_subplot(122)
            fault.plot_subfaults(axes=ax1,
                                 slip_color=True,
                                 slip_time=t,
                                 xylim=xylim)
            dtopo.plot_dz_colors(axes=ax2, t=t, cmax_dz=dz_max)
            ax1.plot(shoreline_xy[:, 0], shoreline_xy[:, 1], 'g')
            ax2.plot(shoreline_xy[:, 0], shoreline_xy[:, 1], 'g')
            plt.axis(xylim)
            fig.show()
            return fig

        dtopo.plot_dz_colors(t=tmax)
        plt.show()

        fig = plt.figure(figsize=(12, 5))

        for t in list(numpy.linspace(0, 150, 16)) + [170, 200]:
            plot_subfaults_dz(t, fig)
            plt.draw()
            plt.show()
            time.sleep(1)

    temp_path = tempfile.mkdtemp()
    try:
        fname = os.path.join(temp_path, 'tohoku_ucsb_dynamic.tt3')
        dtopo.write(fname, 3)
    except Exception as e:
        test_name = inspect.stack()[1][-2][0][:-3]
        test_dump_path = os.path.join(os.getcwd(), test_name)
        shutil.mkdir(test_dump_path)
        shutil.copy(temp_path, test_dump_path)
        raise e
    finally:
        shutil.rmtree(temp_path)

    if verbose:
        print('Created ', fname)