Project

General

Profile

Feature #579

Add support for writing structured data to SAC

Added by Chad Trabant about 8 years ago. Updated almost 7 years ago.

Status:
Closed
Priority:
Normal
Assignee:
Target version:
Start date:
08/07/2014
Due date:
% Done:

100%

Estimated time:
20.00 h
Resolution:
Fixed

Description

Add a method to write a Trace structure(s) out to SAC file(s)

irisFetch.m (129 KB) irisFetch.m Celso Reyes, 02/24/2015 01:39 PM

History

#1 Updated by Celso Reyes over 7 years ago

  • Status changed from New to In Progress

There are a few ways this could be implemented:

  1. Create a new method that writes an existing structure or array of structures to disk. This would be the most versatile way to deal with the matlab data, but I wouldn't say that it is particularly integrated into the irisFetch.m package.
  2. a new method that takes the java classes and writes them directly to disk, either:
    • Bypassing the creation of matlab structures. This would be the more memory efficient version, wouldn't allow people to take already-downloaded data and save it to sac.
    • Writing to disk and also creating matlab structures. This is less memory efficient, of course, maybe not necessary.

I could possibly shoehorn an additional option into the existing Traces() routine, but think that might not be the best way to handle it.

So, my recommendation is to have a routine that specifically writes sac straight from our java structures to disk. Then, if people wanted it, a second routine that would take the structures to disk.

I've looked through my existing waveform matlab code, which was adapted from Mike Thorne's sac codes and then again at Mike's codes. I think as they stand, they won't come in easily. However, they do provide a good basis for a rewrite, which I think could go relatively quickly.

(thus far, 1.5 hrs - code review, gathering resources, documentation)

#2 Updated by Celso Reyes over 7 years ago

  • Estimated time set to 20.00 h
  • % Done changed from 0 to 80

spent 13h20m implementing and writing into irisFetch. Right now I just have a couple small items (dates) to touch on before I consider it a good rough draft, ready to release for testing, further tweaking, and comments.

Questions:
1. Should we do anything with SAC Poles and Zeros?
I'm assuming at this point that kind of thing doesn't actually go into a sac file, so I'm ignoring it.

2. How should the user access the ability to save SAC files?
I propose a routine parallel to irisFetch.Traces called irisFetch.Sacfiles . This would have a similar signature, but with an additional required parameter writeDirectory , which could be blank. If blank, it indicates the current MATLAB path.

The same functionality is accessible via the Traces method, by adding a "WRITESAC:[...]" option. For example,

irisFetch.Traces('IU', 'ANMO', '00', 'BH?', '2010-02-27 06:30:00', '2010-02-27 10:30', 'WRITESAC:c:\Users\someone\sacfiles\')

which is equivalent to:

irisFetch.Sacfiles('IU', 'ANMO', '00', 'BH?', '2010-02-27 06:30:00', '2010-02-27 10:30', 'c:\Users\someone\sacfiles\')

However, irisFetch.sacfiles accepts NO output arguments. Data goes only to disk.

while doing these modifications, I've added a couple new Trace options that could help with debugging...
  • ASJAVA - the java objects are returned instead of MATLAB structs

3. The ISYNTH flag - should it be set?
Since it was really quick to do, I added a test for network SY, with appropriate checks for locations S1 & S3, and their respective channels. If these match up, then the ISYNTH flag can be turned on.

4. Data Quality - Should that be set?
IRIS data quality flags aren't the same as the SAC quality flags IQUAL . Should they be set? If so, how should they be mapped?

5. Scale factor ( SCALE )
Should this be set form somewhere?

#3 Updated by Chad Trabant over 7 years ago

Questions:

1. Should we do anything with SAC Poles and Zeros?
I'm assuming at this point that kind of thing doesn't actually go into a sac file, so I'm ignoring it.

Let's not do anything with it for now. We could write them out to annotated SAC PZ files like the irisws-sacpz service produces, but let's think about it a bit.

2. How should the user access the ability to save SAC files?
I propose a routine parallel to irisFetch.Traces called irisFetch.Sacfiles . This would have a similar signature, but with an additional required parameter writeDirectory, which could be blank. If blank, it indicates the current MATLAB path.

This sounds good to me.

I think we ALSO need a way to write an existing Trace structure out to SAC. This would allow, for example, a user to access data via irisFetch.Traces, performs some pre-processing and then save to the disk in SAC.

3. The ISYNTH flag - should it be set?
Since it was really quick to do, I added a test for network SY, with appropriate checks for locations S1 & S3, and their respective channels. If these match up, then the ISYNTH flag can be turned on.

Sure, a little extra. Needs to be briefly documented in the usage for the function.

4. Data Quality - Should that be set?
IRIS data quality flags aren't the same as the SAC quality flags IQUAL . Should they be set? If so, how should they be mapped?

Do not set it.

5. Scale factor ( SCALE )
Should this be set form somewhere?

Hmm, this could be the total sensitivity value. But I'm unclear on what sac does with it, let me refresh my notion of what this is and get back to you.

I've added Robert Weekly who will eventually end up testing this along with me and might also have input.

#4 Updated by Celso Reyes over 7 years ago

  • Resolution set to Fixed
  • % Done changed from 80 to 100
  • Status changed from In Progress to Resolved
  • File irisFetch.m irisFetch.m added

OK. I think this should do it.

to write out either trace structures or javatraces...
irisFetch.Traces2SACfile( tracejavaobject, directory)
or
irisFetch.Traces2SACfile(tracestructure(s), directory)
or
irisFetch.Traces(....,'WRITESAC')

I have left some debugging messages in the code, I thought I'd leave it in your hands to deactivate after testing (unless you would like me to do it)

#5 Updated by Chad Trabant over 7 years ago

5. Scale factor ( SCALE )
Should this be set form somewhere?

Hmm, this could be the total sensitivity value. But I'm unclear on what sac does with it, let me refresh my notion of what this is and get back to you.

For the record, sac does not do anything with the value value automatically on read. Perhaps there are functions that use it for something but for now let's leave it empty.

#6 Updated by Chad Trabant over 7 years ago

  • Assignee changed from Celso Reyes to Robert Weekly

OK, Robert and I will test this version.

#7 Updated by Robert Weekly almost 7 years ago

  • Status changed from Resolved to Feedback

The functionality works as described and these are very useful additions to the irisFetch toolbox. In particular, having a standalone function to deal with processed traces is hugely beneficial.

As a remaining outstanding issue, please add documentation / usage examples for both irisFetch.Traces and irisFetch.Traces2SACfile.

Currently the documentation is little more than a placeholder:

>> help irisFetch.Traces2SACfile
 irisFetch.javaTraces2sacfile
   temporarily public function.  To be integrated into a call
   routine, such as TracesAsSAC

The method Traces2SACfile should also be listed under the main help section for irisFetch under "miscelleneous Methods": <---note the misspelling of miscellaneous as well.

#8 Updated by Celso Reyes almost 7 years ago

  • Status changed from Feedback to Resolved

Hi Robert,
The documentation has been updated, and spelling corrected.
Since irisFetch now incorporates the federated feature, I will upload it to seiscode under issue #580.
Please check it out and get back to me as soon as possible with suggestions.
Thanks!
Celso

#9 Updated by Robert Weekly almost 7 years ago

  • Target version set to 2.0.7

#10 Updated by Robert Weekly almost 7 years ago

Fixed a bug where sample RATE was being written out to SAC file instead of sample INTERVAL.

Changes pushed to GitHub.

#11 Updated by Chad Trabant almost 7 years ago

  • Status changed from Resolved to Closed

Sample rate fix confirmed. With that we are done.

Also available in: Atom PDF