crotwell / seisFile

A library for reading and writing seismic file formats in java.
GNU Lesser General Public License v3.0
27 stars 20 forks source link

Default Sample Rate of 10000 #7

Closed dlnorgaard closed 7 years ago

dlnorgaard commented 7 years ago

I see in edu.sc.seis.seisFile.mseed.DataHeader.getSampleRate that the default sample rate is 10000 if factor or multiplier is 0. Should it not throw an error or NaN instead? Also, Obspy package correctly reads the sample rate at 100Hz for one of my files, but the seisFile library does not. Possible bug? Sample file attached. 20090405.zip

crotwell commented 7 years ago

10000 is probably a bad default. I actually think that 0 is probably a better option in case of either factor or multiplier being zero since the seed manual says this means "= 0 — Seconds/sample Use this for ASCII/OPAQUE DATA records (see Blockette 2000 description)".

As to your data, the sample rate in the DataHeader is kind of wrong as the factor is 0 and the multiplier is 1. But, it also has a blockette100 which has the sample rate as 100.0. The getSampleRate() in the DataHeader() just does the conversion from what is in the header, it doesn't know about any extra b100 that might exist. So in general when processing mseed data, you want to first check for a b100 and use that value if it exists. If not, then use the value in the DataHeader. So something like this:

        DataRecord mseed = ...
        float sampleRate;
        Blockette[] blocketts = mseed.getBlockettes(100);
        if (blocketts.length != 0) {
            Blockette100 b100 = (Blockette100)blocketts[0];
            sampleRate = b100.getActualSampleRate();
        } else {
            sampleRate = mseed.getHeader().getSampleRate();
        }

I will add something like this to the DataRecord as a helper method, along with warnings in the javadocs on the existing method.

Here is a snip from the output of mseedlh showing the first data record:

    DataRecord      seq=18 type=D cont=false
      SG.UMJS.  .BHZ start=2009,095,00:00:00.0000 numPTS=3712 sampFac=0 sampMul=1 ac=0 io=0 qual=0 numBlockettes=2 blocketteOffset=48 dataOffset=128 tcor=0
        Blockette100 100.0
        Blockette1000 encod=10 wOrder=1 recLen=12

Note also that this is not strictly miniseed as it has control records in it as well. SeisFile can read these, but it won't try to parse the non-data records.

crotwell commented 7 years ago

Fixed in 03a68627e5369c4e287958696d1e074a4b163e99