Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue processing data due to file format without STACK object in masw #29

Open
Valdebenit0 opened this issue Oct 14, 2024 · 5 comments
Open

Comments

@Valdebenit0
Copy link

Greetings of the day!
I'm running the masw code (I'm using swprocess-v0.3.0), but it happens that when I run the analysis cell I get an error because the file format that my system outputs does not include the STACK object in the header. This creates a problem with sensor1c.py when trying to import the data.
How can I do this to process my data?
My data is in this link: https://correouss-my.sharepoint.com/:f:/r/personal/evaldebenitoc_correo_uss_cl/Documents/Data%20San%20Pedro?csf=1&web=1&e=l4kZHi

thank you

@alangi
Copy link

alangi commented Oct 14, 2024

I had a similar issue. You can see it in the closed issues. It was thought to be fixed.

There is a workaround that I used which involves editing the code in sensor1c.py and commenting out the line looking for STACK.

@Valdebenit0
Copy link
Author

@alangi could you share with me how your sensor1c.py code looks like after editing it?
I just commented what you said but I keep getting the same error.

@alangi
Copy link

alangi commented Oct 14, 2024

In "def _from_trace_seg2" find the code below

        header = trace.stats.seg2
        return cls.from_trace(trace,
                              read_header=False,
                              nstacks=int(header.STACK),
                              delay=float(header.DELAY),
                              x=map_x(float(header.RECEIVER_LOCATION)),
                              y=map_y(0),
                              z=0)

delete the line nstacks=int(header.STACK),

Best keep a copy incase it doesn't work.
This assumes that you are using seg2 files.

@Valdebenit0
Copy link
Author

thanks for trying to help me, but I keep getting the same error:


KeyError Traceback (most recent call last)
File ~\anaconda3\Lib\site-packages\obspy\core\util\attribdict.py:140, in AttribDict.getattr(self, name, default)
139 try:
--> 140 return self.getitem(name, default)
141 except KeyError as e:

File ~\anaconda3\Lib\site-packages\obspy\core\util\attribdict.py:96, in AttribDict.getitem(self, name, default)
95 try:
---> 96 return self.dict[name]
97 except KeyError:
98 # check if we got any default value given at class level

KeyError: 'STACK'

During handling of the above exception, another exception occurred:

AttributeError Traceback (most recent call last)
Cell In[92], line 18
16 wavefieldtransforms = []
17 for fnames in fnames_set:
---> 18 wavefieldtransforms.append(swprocess.Masw.run(fnames=fnames, settings=settings))
19 end = time.perf_counter()
20 print(f"Elapsed Time (s): {round(end-start,2)}")

File ~\anaconda3\Lib\site-packages\swprocess\masw.py:87, in Masw.run(fnames, settings, map_x, map_y)
83 workflow = Workflow(fnames=fnames, settings=settings,
84 map_x=map_x, map_y=map_y)
86 # Run and return.
---> 87 return workflow.run()

File ~\anaconda3\Lib\site-packages\swprocess\maswworkflows.py:136, in TimeDomainWorkflow.run(self)
135 def run(self):
--> 136 self.array = Array1D.from_files(self.fnames, map_x=self.map_x,
137 map_y=self.map_y)
138 self.check()
139 self.trim_offsets()

File ~\anaconda3\Lib\site-packages\swprocess\array1d.py:657, in Array1D.from_files(cls, fnames, map_x, map_y)
655 sensors = []
656 for trace in stream.traces:
--> 657 sensor = Sensor1C.from_trace(trace, map_x=map_x, map_y=map_y)
658 sensors.append(sensor)
660 # Define source

File ~\anaconda3\Lib\site-packages\swprocess\sensor1c.py:118, in Sensor1C.from_trace(cls, trace, read_header, map_x, map_y, nstacks, delay, x, y, z)
116 if read_header:
117 if _format == "SEG2":
--> 118 return cls._from_trace_seg2(trace, map_x=map_x, map_y=map_y)
119 elif _format == "SU":
120 return cls._from_trace_su(trace, map_x=map_x, map_y=map_y)

File ~\anaconda3\Lib\site-packages\swprocess\sensor1c.py:151, in Sensor1C._from_trace_seg2(cls, trace, map_x, map_y)
131 """Create a Sensor1C object form a SEG2-style Trace object.
132
133 Parameters
(...)
146
147 """
148 header = trace.stats.seg2
149 return cls.from_trace(trace,
150 read_header=False,
--> 151 nstacks=int(header.STACK),
152 delay=float(header.DELAY),
153 x=map_x(float(header.RECEIVER_LOCATION)),
154 y=map_y(0),
155 z=0)

File ~\anaconda3\Lib\site-packages\obspy\core\util\attribdict.py:142, in AttribDict.getattr(self, name, default)
140 return self.getitem(name, default)
141 except KeyError as e:
--> 142 raise AttributeError(e.args[0])

AttributeError: STACK

@jpvantassel
Copy link
Owner

Hi @Valdebenit0,

As @alangi mentioned, I thought I had patched this issue with v0.3.0, so I am not sure how this error could occur. To figure out what is going on I will need more information.

At least the following:

  • Version of Python
  • Version of swprocess
  • Format of your data (the link you provided does not work for me).
  • If you can import your data with obspy (see syntax below).
  • One of your data files.

#import data with obspy
import obspy
stream = obspy.read("data_file.dat")

Once you provide these, I can see if I can reproduce and we can take it from there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants