Beispiel #1
0
 def rand(self, snr=1.0):
     """Fill vector with random number (~U[1,-1]) with a given SNR"""
     # Computing RMS amplitude of the vector
     rms = RunShellCmd("Attr < %s want=rms param=1 maxsize=5000" %
                       (self.vecfile),
                       get_stat=False)[0]
     rms = float(rms.split("=")[1])  # Standard deviation of the signal
     amp_noise = 1.0
     if rms != 0.:
         amp_noise = np.sqrt(3.0 / snr) * rms  # sqrt(3*Power_signal/SNR)
     # Filling file with random number with the proper scale
     RunShellCmd(
         "Noise file=%s rep=1 type=0 var=0.3333333333; Solver_ops file1=%s scale1_r=%s op=scale"
         % (self.vecfile, self.vecfile, amp_noise),
         get_stat=False,
         get_output=False)
     return
Beispiel #2
0
HOME = os.environ["HOME"]
datapath = None
# Checking environment definition first
if "DATAPATH" in os.environ:
    datapath = os.environ["DATAPATH"]
# Checking local directory
elif os.path.isfile('.datapath'):
    out = (RunShellCmd("cat .datapath | head -N 1", check_code=False, get_stat=False)[0]).rstrip()
    datapath = out.split("=")[1]
# Checking whether the local host has a datapath
else:
    if os.path.isfile(HOME + "/.datapath"):
        out = RunShellCmd("cat $HOME/.datapath | grep $HOST", check_code=False, get_stat=False)[0]
        if len(out) == 0:
            out = (RunShellCmd("cat $HOME/.datapath | head -N 1", check_code=False, get_stat=False)[0]).rstrip()
        datapath = out.split("=")[1]

# Checking if datapath was found
_already_warned = False
if datapath is None:
    if os.path.isdir("/tmp/"):
        datapath = "/tmp/"
        if not _already_warned:
            print("WARNING! DATAPATH not found. The folder /tmp will be used to write binary files")
        _already_warned = True
    else:
        raise IOError("SEP datapath not found\n Set env variable DATAPATH to a folder to write binary files")


def rm_file(filename):
    """File to remove header and binary files"""