Ejemplo n.º 1
0
 def test_warning_response_list_extrapolation(self):
     """
     Tests that a warning message is shown when a response calculation
     involving a response list stage includes (spline) extrapolation into
     frequency ranges outside of the band defined by the response list stage
     elements (frequency-amplitude-phase pairs).
     """
     # create some bogus response list stage for the test
     elems = [
         ResponseListElement(x, 1, 0) for x in (1, 2, 5, 10, 20, 40, 50)
     ]
     stage = ResponseListResponseStage(1,
                                       1,
                                       10,
                                       "M/S",
                                       "M/S",
                                       response_list_elements=elems)
     sens = InstrumentSensitivity(1, 10, "M/S", "M/S")
     resp = Response(response_stages=[stage], instrument_sensitivity=sens)
     msg = ("The response contains a response list stage with frequencies "
            "only from 1.0000 - 50.0000 Hz. You are requesting a response "
            "from 25.0000 - 100.0000 Hz. The calculated response will "
            "contain extrapolation beyond the frequency band constrained "
            "by the response list stage. Please consider adjusting "
            "'pre_filt' and/or 'water_level' during response removal "
            "accordingly.")
     with CatchAndAssertWarnings(expected=[(UserWarning, msg)]):
         resp.get_evalresp_response(0.005, 2**3)
Ejemplo n.º 2
0
 def test_resp_from_paz_loading_vs_evalresp(self):
     zeros = [0., 0.]
     poles = [-8.443 + 1.443j, -8.443 - 1.443j]
     filename = os.path.join(self.data_dir,
                             'RESP.XX.NS306..SHZ.GS13.1.2180')
     resp_er = read_inventory(filename)[0][0][0].response
     loaded_resp = resp_er.get_evalresp_response(.1, 2**6, output='VEL')
     # The optional kwargs are the same as those being set in the RESP file.
     resp = Response.from_paz(zeros=zeros,
                              poles=poles,
                              stage_gain=22.0,
                              stage_gain_frequency=5.0,
                              normalization_frequency=5.0,
                              normalization_factor=1.070401)
     paz_resp = resp.get_evalresp_response(.1, 2**6, output='VEL')
     np.testing.assert_allclose(paz_resp, loaded_resp)
Ejemplo n.º 3
0
 def test_resp_from_paz_setting_zeros_poles_and_sensitivity(self):
     poles = [1 + 2j, 1 - 2j, 2 + 1j, 2 - 1j]
     zeros = [0, 0, 5]
     sensitivity = 1201. * (2**26 / 40.)
     # a0 normalization factor at 1Hz for these values
     normalization = np.prod(2 * pi * 1j - np.array(zeros))
     normalization /= np.prod(2 * pi * 1j - np.array(poles))
     normalization = np.abs(normalization)
     resp = Response.from_paz(zeros, poles, sensitivity)
     r_zeros = resp.response_stages[0].zeros
     r_poles = resp.response_stages[0].poles
     r_stage_gain = resp.response_stages[0].stage_gain
     r_sens = resp.instrument_sensitivity.value
     np.testing.assert_array_equal(r_zeros, zeros)
     np.testing.assert_array_equal(r_poles, poles)
     np.testing.assert_equal(r_stage_gain, sensitivity)
     np.testing.assert_equal(r_sens / normalization, sensitivity)
Ejemplo n.º 4
0
    def get_response_inv(self, obs_channel):

        sensor_keys = [
            obs_channel.sensor.manufacturer, obs_channel.sensor.model
        ]
        datalogger_keys = [
            obs_channel.data_logger.manufacturer,
            obs_channel.data_logger.model, obs_channel.sample_rate
        ]
        if not self.resp_manager.is_already_requested(sensor_keys,
                                                      datalogger_keys):
            self.manager.ph5.read_response_t()
            Response_t = \
                self.manager.ph5.get_response_t_by_n_i(self.response_table_n_i)
            if Response_t:
                response_file_das_a_name = Response_t.get(
                    'response_file_das_a', None)
                response_file_sensor_a_name = Response_t.get(
                    'response_file_sensor_a', None)
            else:
                LOGGER.error('Response table not found')
                return Response()
            # parse datalogger response
            if response_file_das_a_name:
                response_file_das_a = \
                    self.manager.ph5.ph5_g_responses.get_response(
                                                    response_file_das_a_name
                                            )

                with io.BytesIO(response_file_das_a) as buf:
                    buf.seek(0, 0)
                    if _is_resp(buf):
                        buf.seek(0, 0)
                        dl_resp = read_inventory(buf, format="RESP")
                        dl_resp = dl_resp[0][0][0].response
                    else:
                        buf.seek(0, 0)
                        dl_resp = pickle.loads(response_file_das_a)

            # parse sensor response if present
            if response_file_sensor_a_name:
                response_file_sensor_a = \
                    self.manager.ph5.ph5_g_responses.get_response(
                                                response_file_sensor_a_name
                                            )

                with io.BytesIO(response_file_sensor_a) as buf:
                    buf.seek(0, 0)
                    if _is_resp(buf):
                        buf.seek(0, 0)
                        sensor_resp = read_inventory(buf, format="RESP")
                        sensor_resp = sensor_resp[0][0][0].response
                    else:
                        buf.seek(0, 0)
                        sensor_resp = pickle.loads(response_file_sensor_a)

            inv_resp = None
            if response_file_das_a_name and response_file_sensor_a_name:
                # both datalogger and sensor response
                dl_resp.response_stages.pop(0)
                dl_resp.response_stages.insert(0,
                                               sensor_resp.response_stages[0])
                dl_resp.recalculate_overall_sensitivity()
                inv_resp = dl_resp
            elif response_file_das_a_name:
                # only datalogger response
                inv_resp = dl_resp
            elif response_file_sensor_a_name:
                # only sensor response
                inv_resp = sensor_resp

            if inv_resp:
                # update response manager and return response
                self.resp_manager.add_response(sensor_keys, datalogger_keys,
                                               inv_resp)
                if self.manager.level == "CHANNEL":
                    return Response(
                        instrument_sensitivity=inv_resp.instrument_sensitivity)
                else:
                    return inv_resp
            else:
                return Response()
        else:
            inv_resp = self.resp_manager.get_response(sensor_keys,
                                                      datalogger_keys)
            if self.manager.level == "CHANNEL":
                return Response(
                    instrument_sensitivity=inv_resp.instrument_sensitivity)
            else:
                return inv_resp
Ejemplo n.º 5
0
    def get_response_inv(self, obs_channel, a_id, sta_id, cha_id, spr, spr_m,
                         emp_resp):

        sensor_keys = [
            obs_channel.sensor.manufacturer, obs_channel.sensor.model
        ]
        datalogger_keys = [
            obs_channel.data_logger.manufacturer,
            obs_channel.data_logger.model, obs_channel.sample_rate
        ]

        if not self.resp_manager.is_already_requested(sensor_keys,
                                                      datalogger_keys):
            info = {
                'n_i': self.response_table_n_i,
                'array': a_id,
                'sta': sta_id,
                'cha_id': cha_id,
                'cha_code': obs_channel.code,
                'dmodel': obs_channel.data_logger.model,
                'smodel': obs_channel.sensor.model,
                'spr': spr,
                'sprm': spr_m,
            }
            if info['dmodel'].startswith("ZLAND"):
                info['smodel'] = ''
            check_info = validation.check_response_info(
                info, self.manager.ph5, self.checked_data_files,
                self.unique_errors, None)

            if check_info[0] is False:
                if emp_resp:
                    for errmsg in check_info[1]:
                        self.unique_errors.add((errmsg, 'error'))
                    return Response()
                else:
                    raise PH5toStationXMLError('\n'.join(check_info[1]))
            response_file_das_a_name, response_file_sensor_a_name = check_info

            # parse datalogger response
            if response_file_das_a_name:
                response_file_das_a = \
                    self.manager.ph5.ph5_g_responses.get_response(
                                                    response_file_das_a_name
                                            )

                with io.BytesIO(response_file_das_a) as buf:
                    buf.seek(0, 0)
                    if _is_resp(buf):
                        buf.seek(0, 0)
                        dl_resp = read_inventory(buf, format="RESP")
                        dl_resp = dl_resp[0][0][0].response
                    else:
                        buf.seek(0, 0)
                        dl_resp = pickle.loads(response_file_das_a)

            # parse sensor response if present
            if response_file_sensor_a_name:
                response_file_sensor_a = \
                    self.manager.ph5.ph5_g_responses.get_response(
                                                response_file_sensor_a_name
                                            )

                with io.BytesIO(response_file_sensor_a) as buf:
                    buf.seek(0, 0)
                    if _is_resp(buf):
                        buf.seek(0, 0)
                        sensor_resp = read_inventory(buf, format="RESP")
                        sensor_resp = sensor_resp[0][0][0].response
                    else:
                        buf.seek(0, 0)
                        sensor_resp = pickle.loads(response_file_sensor_a)

            inv_resp = None
            if response_file_das_a_name and response_file_sensor_a_name:
                # both datalogger and sensor response
                dl_resp.response_stages.pop(0)
                dl_resp.response_stages.insert(0,
                                               sensor_resp.response_stages[0])
                dl_resp.recalculate_overall_sensitivity()
                inv_resp = dl_resp
            elif response_file_das_a_name:
                # only datalogger response
                inv_resp = dl_resp
            elif response_file_sensor_a_name:
                # only sensor response
                inv_resp = sensor_resp

            if inv_resp:
                # update response manager and return response
                self.resp_manager.add_response(sensor_keys, datalogger_keys,
                                               inv_resp)
                if self.manager.level == "CHANNEL":
                    return Response(
                        instrument_sensitivity=inv_resp.instrument_sensitivity)
                else:
                    return inv_resp
            else:
                return Response()
        else:
            inv_resp = self.resp_manager.get_response(sensor_keys,
                                                      datalogger_keys)
            if self.manager.level == "CHANNEL":
                return Response(
                    instrument_sensitivity=inv_resp.instrument_sensitivity)
            else:
                return inv_resp