Ejemplo n.º 1
0
    def readdir(self, path, fh):
        """readdir

        If `path` points beyond a node, forward the request to the OS (via
        built-in os module).  Otherwise the result is generated as an empty
        directory plus others depending on the type of the furthest node.  If
        it is an FSNode, its children nodes are added.  If it is additionally a
        TagNode, its files are calculated according to its rules and added.
        """
        logger.debug("readdir(%r, %r)", path, fh)
        node, path = self._getnode(path)
        if path:
            return ['.', '..'] + os.lsdir(_getpath(node, path))
        else:
            node.attr['st_atime'] = time()
            return ['.', '..'] + [node[x] for x in iter(node)]
Ejemplo n.º 2
0
def rm_redundant_files_and_dirs(dst_root_path , new_vdh , keep_stable_vdh) :
    if dst_root_path == "" or not os.path.isdir(dst_root_path) : 
        return
    if new_vdh is None or len(new_vdh) == 0 :
        return
    names = os.lsdir(dst_root_path)
    for fname in names :
        fpath = os.path.join(dst_root_path , fname)
        if fname in new_vdh :
            ## recursive call to clear redundant in sub dir
            next_dst_root_path = fpath
            next_new_vdh = new_vdh[fname]
            next_keep_stable_vdh = keep_stable_vdh.get(fname , {})
            rm_redundant_files_and_dirs(next_dst_root_path , next_new_vdh , next_keep_stable_vdh)
        else :
            if fname not in keep_stable_vdh :
                rm_file_or_dir(fpath)
Ejemplo n.º 3
0
def rm_redundant_files_and_dirs(dst_root_path, new_vdh, keep_stable_vdh):
    if dst_root_path == "" or not os.path.isdir(dst_root_path):
        return
    if new_vdh is None or len(new_vdh) == 0:
        return
    names = os.lsdir(dst_root_path)
    for fname in names:
        fpath = os.path.join(dst_root_path, fname)
        if fname in new_vdh:
            ## recursive call to clear redundant in sub dir
            next_dst_root_path = fpath
            next_new_vdh = new_vdh[fname]
            next_keep_stable_vdh = keep_stable_vdh.get(fname, {})
            rm_redundant_files_and_dirs(next_dst_root_path, next_new_vdh,
                                        next_keep_stable_vdh)
        else:
            if fname not in keep_stable_vdh:
                rm_file_or_dir(fpath)

# m0 = np.load("/home/nienke/Documents/Research/Data/MTI/MT_vs_STR/S0235b/m0s.npy")

## Step 1: Define parameters
or_time = obspy.UTCDateTime("2020-3-10T12:00:00")
lat_src = 90
lon_src = 0
depth = 41.0
name = "Test_Event"

phases = ["P", "S", "S", "P", "S"]

mnt_folder = "/mnt/marshost/"

if not lsdir(mnt_folder):
    print(f"{mnt_folder} is still empty, mounting now...")
    SS_MTI.DataGetter.mnt_remote_folder(
        host_ip="marshost.ethz.ch",
        host_usr="******",
        remote_folder="/data/",
        mnt_folder=mnt_folder,
    )

npz_file = "/home/nienke/Documents/Research/Data/npz_files/TAYAK_BKE.npz"
# npz_file = "/home/nienke/Data_2020/npz_files/TAYAK_BKE.npz"
# npz_file = "/home/nienke/Documents/Research/Data/npz_files/TAYAK.npz"
model = TauPyModel(npz_file)

# db_path = "/mnt/marshost/instaseis/databases/blindtestmodels_1s/TAYAK_1s"
db_path = "/mnt/marshost/instaseis2/databases/TAYAK_15s_BKE"
Ejemplo n.º 5
0
import SS_MTI
from EventInterface import EventObj
from SS_MTI import PostProcessing as _PostProcessing

## Step 1: Define parameters
or_time = obspy.UTCDateTime("2020-3-10T12:00:00")
lat_src = 10.99032013
lon_src = 170
depth = 45.0
name = "Test_Event"

phases = ["P", "S", "S", "P", "S"]

mnt_folder = "/mnt/marshost/"

if not lsdir(mnt_folder):
    print(f"{mnt_folder} is still empty, mounting now...")
    SS_MTI.DataGetter.mnt_remote_folder(
        host_ip="marshost.ethz.ch",
        host_usr="******",
        remote_folder="/data/",
        mnt_folder=mnt_folder,
    )

npz_file = "/home/nienke/Documents/Research/Data/npz_files/TAYAK_BKE.npz"
# npz_file = "/home/nienke/Data_2020/npz_files/TAYAK_BKE.npz"
# npz_file = "/home/nienke/Documents/Research/Data/npz_files/TAYAK.npz"
model = TauPyModel(npz_file)

db_path = "/mnt/marshost/instaseis2/databases/TAYAK_15s_BKE"
# db_path = "/opt/databases/TAYAK_15s_BKE"
Ejemplo n.º 6
0
from os import listdir as lsdir
from Parser import Parser
from CodeWriter import CodeWriter

#get path to input file from command line arguments
if len(sys.argv) < 2:
	print "Usage: [python] vmCompiler pathToProg.vm [output.asm]"
	exit(1)
inPath = sys.argv[1]

vmNames = []

if path.isdir(inPath):
	fileName = inPath + "/" + path.basename(inPath)
	
	for f in lsdir(inPath):
		if path.splitext(f)[1] == ".vm":
			vmNames.append(inPath + "/" + f)
	#print vmNames
else:
	#get the fileName without extension, and the extension from the supplied path
	fileName, extension = path.splitext(inPath)
	
	#make sure the supplied file is a .vm file
	if extension != ".vm":
		print "Input file must be a .vm file."
		print "Usage: [python] vmCompiler pathToProg.vm [output.asm]"
		exit(1)
	
	vmNames.append(inPath)
	
Ejemplo n.º 7
0
## and compiles them into a list so that you can access and
## use.
##
## Updated as of 07/23/2015
## Working as of 07/23/2015
##
import sys, random, math
import time
import os

from FastProgressBar import progressbar

if __name__ == "__main__":
    
    #creates .list file
    dlname = '2015B_ALL_RAW.list'
    file = open(dirname, 'a')
    print("created " + dlname)
    
    retdir = os.getcwd()
    masterdir = '/eos/cms/store/data/Run2015B/AlCaP0/RAW/v1/000/'
    masterList = os.lsdir(datadir)
    
    #Just checking to see if we are in right path
    os.system('eos ls ' + masterdir)

    for k in range(0,len(masterList)):
        currentdir = masterdir + dataList[k]
        while currentdir != masterdir:
            currentList = os.lsdir(currentdir)
            if currentList[1]
Ejemplo n.º 8
0
                              fmin=fmin,
                              fmax=fmax,
                              zerophase=zerophase)
    o_time = tr_full.stats.starttime
    tr = tr_full.slice(
        starttime=o_time + obs_tts[i] - t_pres[i],
        endtime=o_time + obs_tts[i] + t_posts[i],
    )
    st_obs_w += tr
    st_obs_full += tr_full
""" """
# check if folder exists:
if not exist(save_path):
    makedirs(save_path)
# check if folder is empty
if not lsdir(save_path):
    subprocess.call(f"scp {bin_path} .", shell=True, cwd=save_path)
bm_file_path = "/home/nienke/Documents/Research/Data/MTI/MT_vs_STR/bm_models/TAYAK.bm"
Create_Vmod.create_dat_file(
    src_depth=depth,
    focal_mech=focal_mech0,
    M0=None,
    epi_in_km=epi_in_km,
    baz=baz,
    dt=dt,
    save_path=save_path,
    bm_file_path=bm_file_path,
)
""" Get the parameter (m) array ready """
import pandas as pd
Ejemplo n.º 9
0
def read_events_from_cat(
    event_params: dict,
    cat: obspy.Catalog,
    inv: obspy.Inventory,
    local_folder: str,
    host_name: str = None,
    user_name: str = None,
    remote_folder: str = None,
    save_file_name: str = None,
) -> None:
    """
    Read mars-events from catalog.xml and adding waveform data to events.
    If waveforms are on server host_name, user_name, remote_folder should be specified
    :param event_params: Dict of event names for inversion
    :param cat: obspy.Catalog including the updated events
    :param local_folder: path to waveform on local machine
    :param host_name: Host IP address
    :param user_name: username of the server
    :param remote_folder: path to remote folder that contains waveform data
    :param save_file_name: name of .xml file to save the events, only saved when not None. (do not specify the entire folder, because this .xml file will be saved in /events/)
    """
    ## Variables that are set:
    dir_exist_name = "events"
    dir_exist = False

    ## Create empty list of events to invert for:
    events = []

    ## Setup remote directory /mnt/marshost
    event_names = [key for key in event_params.keys()]
    data_exist = False
    if all([isdir(path) for path in [pjoin(dir_exist_name, x) for x in event_names]]):
        data_exist = True
        print("The miniseed data is already saved in /events/.. and used for the inversion")
    else:
        if host_name is not None:
            # Check if your mount folder already exists from previous runs for example:
            if not lsdir(local_folder):
                print(f"{local_folder} is still empty, mounting now...")
                mnt_remote_folder(host_name, user_name, remote_folder, local_folder)
            # TOO: check if local folder exists, otherwise raise error.
    local_folder = pjoin(local_folder, "sc3data")
    for i, v in event_params.items():
        try:
            event = cat.select(name=i).events[0]

            # Reading the event waveforms:
            if data_exist:
                filepath = pjoin(dir_exist_name, i, "waveforms")
                event = read_waveforms_from_saved_dir(file_path=filepath, event=event)
            elif event.waveforms_VBB is not None:
                pass
            else:
                #
                event.read_waveforms(inv=inv, sc3dir=local_folder)

            events.append(event)

        except IndexError as e:
            raise IndexError("Event {} does not exist in the catalog".format(i))

    ## Unmount:
    if host_name is not None and data_exist is False:
        unmnt_remote_folder(local_folder)

    ## save the events as a new catalog
    if save_file_name is not None:
        # event_cat = obspy.Catalog(self.events)
        # event_cat.write(
        #     filename=pjoin(dir_exist_name,save_file_name.strip(".xml")+ ".xml"), format="QUAKEML"
        # )
        pass
        # TODO: IMPLEMENT SAVE FUNCTION!

    return events
Ejemplo n.º 10
0
import os
import sys
import random
import math
import datetime 
try
except


print(dir(os))
os.lsdir()
os.walk()
os.rmdir()
os.chdir()
print(os.stat('test.py'))

'''
x=os.stat('test.py').st_atime
print datetime.fromtimestamp(x)
'''

#print(os.getcwd())
os.mkdir('tempDir')
os.makedir('dir1/dir2')

if not os.path.exists(dirName):
    os.mkdir(dirName)

#print math.sqrt(25) 
#x = datetime.datetime.now()
#print(x)