Plot an interferogram

[1]:
import os
if "SPHINX_DOC_BUILD" in os.environ:
    if "MSNOISE_DOC" in os.environ:
        os.chdir(os.environ["MSNOISE_DOC"])

import matplotlib
matplotlib.use("agg")

import matplotlib.pyplot as plt

plt.style.use("ggplot")

from msnoise.core.db import connect
from msnoise.results import MSNoiseResult

# connect to the database
db = connect()

# Build a result object at the default stack step
result = MSNoiseResult.from_ids(db, preprocess=1, cc=1, filter=1, stack=1)
params = result.params

# Get the first mov_stack configured:
mov_stack = params.stack.mov_stack[0]

# Get the CCF for two stations, filter 1, ZZ component, first mov_stack:
ccf = result.get_ccf(pair="PF.FJS.00:PF.FOR.00", components="ZZ",
                     mov_stack=mov_stack)

# Plot the interferogram
ccf.plot(robust=True, figsize=(10, 8))
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
File D:\PythonForSource\MSNoise_Stack\MSNoise\msnoise\core\db.py:153, in read_db_inifile(inifile)
    152 try:
--> 153     f = open(inifile, 'rb')
    154 #except FileNotFoundError:  # This is better but only for python3

FileNotFoundError: [Errno 2] No such file or directory: 'D:\\PythonForSource\\MSNoise_Stack\\MSNoise\\doc\\auto_examples\\db.ini'

During handling of the above exception, another exception occurred:

DBConfigNotFoundError                     Traceback (most recent call last)
Cell In[1], line 17
     14 from msnoise.results import MSNoiseResult
     16 # connect to the database
---> 17 db = connect()
     19 # Build a result object at the default stack step
     20 result = MSNoiseResult.from_ids(db, preprocess=1, cc=1, filter=1, stack=1)

File D:\PythonForSource\MSNoise_Stack\MSNoise\msnoise\core\db.py:104, in connect(inifile)
    101 if not inifile:
    102     inifile = os.path.join(os.getcwd(), 'db.ini')
--> 104 engine = get_engine(inifile)
    105 session = sessionmaker(bind=engine)
    106 return session()

File D:\PythonForSource\MSNoise_Stack\MSNoise\msnoise\core\db.py:67, in get_engine(inifile)
     65 from sqlalchemy import create_engine
     66 from sqlalchemy.pool import NullPool
---> 67 dbini = read_db_inifile(inifile)
     68 if dbini.tech == 1:
     69     engine = create_engine('sqlite:///%s' % dbini.hostname, echo=False,
     70                            connect_args={'check_same_thread': False})

File D:\PythonForSource\MSNoise_Stack\MSNoise\msnoise\core\db.py:156, in read_db_inifile(inifile)
    154 #except FileNotFoundError:  # This is better but only for python3
    155 except IOError:
--> 156     raise DBConfigNotFoundError(
    157             "No db.ini file in this directory, please run "
    158             "'msnoise db init' in this folder to initialize it as "
    159             "an MSNoise project folder.")
    160 try:
    161     # New ini file with prefix support
    162     tech, hostname, database, username, password, prefix = pickle.load(f)

DBConfigNotFoundError: No db.ini file in this directory, please run 'msnoise db init' in this folder to initialize it as an MSNoise project folder.

Running a simple moving window average can be done with xarray’s rolling:

[2]:
smooth = ccf.rolling(times=5).mean()

smooth.plot(robust=True, figsize=(10, 8))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 smooth = ccf.rolling(times=5).mean()
      3 smooth.plot(robust=True, figsize=(10, 8))

NameError: name 'ccf' is not defined

Plotting the sub-daily stacks and zooming on +- 20 seconds:

[3]:
if "SPHINX_DOC_BUILD" in os.environ:
    if "MSNOISE_DOC" in os.environ:
        os.chdir(os.environ["MSNOISE_DOC"])

# Get the last mov_stack configured:
mov_stack = params.stack.mov_stack[-1]

ccf = result.get_ccf(pair="PF.FJS.00:PF.FOR.00", components="ZZ",
                     mov_stack=mov_stack)

# Plot and zoom to +-20 seconds lag
ccf.loc[:, -20:20].plot(robust=True, figsize=(10, 8))
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[3], line 6
      3         os.chdir(os.environ["MSNOISE_DOC"])
      5 # Get the last mov_stack configured:
----> 6 mov_stack = params.stack.mov_stack[-1]
      8 ccf = result.get_ccf(pair="PF.FJS.00:PF.FOR.00", components="ZZ",
      9                      mov_stack=mov_stack)
     11 # Plot and zoom to +-20 seconds lag

NameError: name 'params' is not defined

Finally, stacking to a Reference function

[4]:
ccf.mean(axis=0).plot(figsize=(10, 8))

#EOF
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
Cell In[4], line 1
----> 1 ccf.mean(axis=0).plot(figsize=(10, 8))
      3 #EOF

NameError: name 'ccf' is not defined