PIC-IRIS / PH5

Library of PH5 clients, apis, and utilities
Other
15 stars 9 forks source link

[BUG] PH5 cannot extract timeseries data that exist in miniPH5 files #424

Closed timronan closed 3 years ago

timronan commented 4 years ago

Describe the bug PH5 does not successfully extract time series data as ms even though the data exist in miniPH5 file. DAS tables seems to exist as well.

ph5toms returns nothing.

ph5 availability returns ph5.core.ph5api - WARNING: No Das table found for XXXXX for every station.

Environment (please complete the following information):

Expected behavior ph5toms should return miniseed data because they seems to exist in the miniPH5 files. ph5availability should return available data.

Screenshots

Screen Shot 2020-08-03 at 11 38 41 AM

Additional context At a first pass it is hard to tell exactly why this error is occurring. PH5Availability makes it seem like the paths to the DAS table are corrupt or incorrect in the master.ph5 file. Issue needs to be tracked through the code stack.

timronan commented 4 years ago

Incorrect sample rates are being fed into the lines 543-548 of

                traces = self.ph5.cut(stc.das, start_time,
                                      stc.endtime,
                                      chan=stc.component,
                                      sample_rate=actual_sample_rate,
                                      apply_time_correction=nt, das_t=das)

sample_rate=actual_sample_rate values is coming from line 508:

station_to_cut_segments = PH5toMSeed.get_nonrestricted_segments(
            [station_to_cut], self.restricted)

and does not accurately reflect the sample rate in the DAS table. This sample rate is automatically set to 100 somewhere but I can't find out where it is happening.

The inaccuate sample rate is causing ph5toms to fail in two places:

            das = self.ph5.query_das_t(stc.das, stc.component,
                                       stc.starttime,
                                       stc.endtime,
                                       stc.sample_rate,
                                       stc.sample_rate_multiplier)

line 512-516 causes

ph5api line 837-847:

            for row in tbl.where(
                    '(channel_number_i == '
                    + str(chan) + ' )&(epoch_i+micro_seconds_i/1000000>='
                    + str(start_epoch) +
                    '-sample_count_i/sample_rate_i/sample_rate_multiplier_i)'
                    '&(epoch_i+micro_seconds_i/1000000<='
                    + str(stop_epoch) + ')&(sample_rate_i==' +
                    str(sample_rate) +
                    ')&(sample_rate_multiplier_i==' +
                    str(sample_rate_multiplier) + ')'
            ):

to not return das information, because it is looking for a DAS table with a different sample rate.

If the For loop is adjusted to run than the program then if fails again at PH5API.cut lines 1181-1183.

            if (d['channel_number_i'] != chan) or (
                    sr != sample_rate) or (window_start_fepoch > stop_fepoch):
                continue

sr comes from the das the das table and the sample_rate is derived from PH5toMSeed.get_nonrestricted_segments. The DAS table is the true sample rate and needs to be used.

If the sample rate from the das table is used in self.ph5.query_das_t and ph5toms lines 545-549

               traces = self.ph5.cut(stc.das, start_time,
                                      stc.endtime,
                                      chan=stc.component,
                                      sample_rate=actual_sample_rate,
                                      apply_time_correction=nt, das_t=das)

the ph5toms and therefore the dataselect service works. We should probably figure out why PH5toMSeed.get_nonrestricted_segments returns the incorrect sample rate. This is a fairly common problem throughout the PH5 archive. I'll submit a PR on it tomorrow.

timronan commented 4 years ago

It is likely that getavailabilty is also affected by this issue.

timronan commented 3 years ago

This issue has been closed by merging pull request #427