Example #1
0
    def test_is_resp(self):
        for filename in self.seed_files:
            self.assertFalse(_is_resp(filename), filename)

        for filename in self.xseed_files:
            self.assertFalse(_is_resp(filename), filename)

        for filename in self.resp_files:
            self.assertTrue(_is_resp(filename), filename)

        for filename in self.other_files:
            self.assertFalse(_is_resp(filename), filename)
Example #2
0
    def test_is_resp(self):
        for filename in self.seed_files:
            self.assertFalse(_is_resp(filename), filename)

        for filename in self.xseed_files:
            self.assertFalse(_is_resp(filename), filename)

        for filename in self.resp_files:
            self.assertTrue(_is_resp(filename), filename)

        for filename in self.other_files:
            self.assertFalse(_is_resp(filename), filename)
Example #3
0
 def test_is_resp(self):
     """
     Checks _is_resp() routine on all files in signal/tests/data.
     """
     signal_test_files = os.path.abspath(
         os.path.join(inspect.getfile(inspect.currentframe()),
                      os.path.pardir, os.path.pardir, os.path.pardir,
                      os.path.pardir, "signal", "tests", "data", "*"))
     # List of files that are actually RESP files, all other files are
     # considered non-RESP files
     resp_filenames = [
         "IUANMO.resp", "RESP.NZ.CRLZ.10.HHZ", "RESP.NZ.CRLZ.10.HHZ.mac",
         "RESP.NZ.CRLZ.10.HHZ.windows", "RESP.OB.AAA._.BH_"
     ]
     for filename in glob.glob(signal_test_files):
         got = _is_resp(filename)
         expected = os.path.basename(filename) in resp_filenames
         self.assertEqual(
             got, expected,
             "_is_resp() returns %s for file %s" % (got, filename))
Example #4
0
 def test_is_resp(self):
     """
     Checks _is_resp() routine on all files in signal/tests/data.
     """
     signal_test_files = os.path.abspath(os.path.join(
         inspect.getfile(inspect.currentframe()),
         os.path.pardir, os.path.pardir, os.path.pardir, os.path.pardir,
         "signal", "tests", "data", "*"))
     # List of files that are actually RESP files, all other files are
     # considered non-RESP files
     resp_filenames = [
         "IUANMO.resp",
         "RESP.NZ.CRLZ.10.HHZ",
         "RESP.NZ.CRLZ.10.HHZ.mac",
         "RESP.NZ.CRLZ.10.HHZ.windows",
         "RESP.OB.AAA._.BH_"]
     for filename in glob.glob(signal_test_files):
         got = _is_resp(filename)
         expected = os.path.basename(filename) in resp_filenames
         self.assertEqual(
             got, expected,
             "_is_resp() returns %s for file %s" % (got, filename))
Example #5
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
Example #6
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