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

Trim function #2760

Closed
msaezuchile opened this issue Nov 28, 2020 · 6 comments · Fixed by #2765
Closed

Trim function #2760

msaezuchile opened this issue Nov 28, 2020 · 6 comments · Fixed by #2765
Assignees
Labels

Comments

@msaezuchile
Copy link

I have a SAC file with a length major than 1 day. When I cut the file into a 1-day length, the "stats.sac" information is the same that the original file. How I can update this information?

Thank you

Miguel

@jkmacc-LANL
Copy link
Contributor

When you write the trimmed trace to a new SAC file, is that header correct?

Trace.trim modifies the Obspy headers, but doesn't know about the .stats.sac header, so it can't modify it. When you write to a file and specify SAC, though, the SAC plugin takes responsibility to rectify the current Obspy header and the output SAC file header. It should be correct in the written file.

@msaezuchile
Copy link
Author

msaezuchile commented Nov 30, 2020

I solved the problem. When I wrote the SAC file, the stats.sac information was not modified. I added 'st2[0].stats.sac = AttribDict({})' before writing the SAC file and it worked.
Best
Miguel

@jkmacc-LANL
Copy link
Contributor

If you have to delete the .stats.sac header in order to write a valid header, that sounds like a bug. I'm happy to look into this further with you, if you'd like. Pasting the full .stats and .stats.sac headers before and after trimming and writing the file would be helpful to diagnose. If you'd prefer to just close the issue, I won't push further:-) Thanks for raising the issue, regardless.

@msaezuchile
Copy link
Author

msaezuchile commented Nov 30, 2020

This is the "stats" information of the trimmed object:

Stats(
    {
        "sampling_rate": 200.0,
        "delta": 0.005,
        "starttime": UTCDateTime(2008, 1, 1, 0, 0),
        "endtime": UTCDateTime(2008, 1, 1, 23, 59, 59, 995000),
        "npts": 17280000,
        "calib": 1.0,
        "network": "Y9",
        "station": "ALG",
        "location": "",
        "channel": "HHE",
        "sac": AttribDict(
            {
                "delta": 0.0049999999,
                "depmin": -55782.0,
                "depmax": 54891.0,
                "scale": 1.0,
                "b": 0.0,
                "e": 87614.445,
                "stla": -22.85915,
                "stlo": -69.80658,
                "stel": 1407.0,
                "stdp": 0.0,
                "depmen": 140.41512,
                "cmpaz": 90.0,
                "cmpinc": 0.0,
                "nzyear": 2007,
                "nzjday": 365,
                "nzhour": 23,
                "nzmin": 49,
                "nzsec": 55,
                "nzmsec": 910,
                "nvhdr": 6,
                "npts": 17522890,
                "iftype": 1,
                "iztype": 9,
                "leven": 1,
                "lpspol": 1,
                "lovrok": 1,
                "lcalda": 0,
                "kstnm": "ALG",
                "kcmpnm": "HHE",
                "knetwk": "Y9",
            }
        ),
        "_format": "SAC",
        "processing": [
            "ObsPy 1.2.2: trim(endtime=UTCDateTime(2008, 1, 1, 23, 59, 59, 995000)::fill_value=None::nearest_sample=True::pad=False::starttime=UTCDateTime(2008,1, 1, 0, 0))"
        ],
    }
)

if you observe the stats.starttime is not the same that the stats.sac information. The stats.sac information is the same that the original file.

If you write this SAC file and open with sac iris, the information of the file is the stats.sac.
Best Miguel

edit: formatting

@megies
Copy link
Member

megies commented Dec 1, 2020

Flagging this as a bug for now until we can be sure it isn't.

@megies megies added the bug confirmed bug label Dec 1, 2020
@jkmacc-LANL
Copy link
Contributor

@msaezuchile When I save the trimmed Trace as a SAC file, I also see that the nz-times haven't changed, but I do see that the b value does reflect the trimming. No relative timing information has been lost, it's just that the reference time doesn't update to the first sample time. Do you see that b is 604.09, equal to the time that has been trimmed off the front of the time series, in your SAC file header?

To solve this you deleted the stats.sac header before writing, but there is a boolean keep_sac_header used in the internal SAC write function that does the same thing. I could exposed it to the main write plugin, which would allow you to write tr.write('filename.sac', format='SAC', keep_sac_header=False) to accomplish this. Would you like me to make a PR for this?

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

Successfully merging a pull request may close this issue.

3 participants