Exemplo n.º 1
0
def main():
    logs.error = log_alert
    logs.warning = log_alert
    logs.notice = log_notice
    logs.info = log_verbose
    logs.debug = log_silent

    if len(sys.argv) not in (2, 3):
        logs.notice("Usage: %s input_file [output_file]" % sys.argv[0])
        return 1

    inv = fdsnxml.Inventory()

    try:
        inv.load_fdsnxml(sys.argv[1])

    except fdsnxml.Error as e:
        logs.error(str(e))
        return 1

    inv.save_xml(sys.argv[2] if len(sys.argv) == 3 else sys.stdout, instr=1)

    return 0
Exemplo n.º 2
0
def get_citation(nets, param, verbose):
    postdata = ""
    for (net, year) in nets:
        postdata += "%s * * * %d-01-01T00:00:00Z %d-12-31T23:59:59Z\n" \
                    % (net, year, year)

    if not isinstance(postdata, bytes):
        postdata = postdata.encode('utf-8')

    try:
        proc = exec_fetch(param, postdata, verbose, True)

    except OSError as e:
        logs.error(str(e))
        logs.error("error running fdsnws_fetch")
        return 1

    net_desc = {}

    for line in proc.stdout:
        try:
            if isinstance(line, bytes):
                line = line.decode('utf-8')

            if not line or line.startswith('#'):
                continue

            (code, desc, start) = line.split('|')[:3]

            year = dateutil.parser.parse(start).year

        except (ValueError, UnicodeDecodeError) as e:
            logs.error("error parsing text format: %s" % str(e))
            continue

        if code[0] in "0123456789XYZ":
            net_desc["%s_%d" % (code, year)] = desc

        else:
            net_desc[code] = desc

    logs.notice("You received seismic waveform data from the following "
                "network(s):")

    for code in sorted(net_desc):
        logs.notice("%s %s" % (code, net_desc[code]))

    logs.notice("\nAcknowledgment is extremely important for network operators\n"
                "providing open data. When preparing publications, please\n"
                "cite the data appropriately. The FDSN service at\n\n"
                "    http://www.fdsn.org/networks/citation/?networks=%s\n\n"
                "provides a helpful guide based on available network\n"
                "Digital Object Identifiers.\n"
                % "+".join(sorted(net_desc)))
Exemplo n.º 3
0
    def __process_response(self, tree, cha, sensor, logger):
        stages = {}
        fallback = None

        for e in tree:
            if e.tag == ns + "InstrumentSensitivity":
                for e1 in e:
                    if e1.tag == ns + "Value":
                        cha.gain = float(e1.text)

                    elif e1.tag == ns + "Frequency":
                        cha.gainFrequency = float(e1.text)

                    elif e1.tag == ns + "InputUnits":
                        for e2 in e1:
                            if e2.tag == ns + "Name":
                                cha.gainUnit = e2.text

            elif e.tag == ns + "InstrumentPolynomial":
                resp, inUnit, outUnit, remark, lowFreq, highFreq = self.__polynomial(
                    e)
                resp.gain = 1.0
                resp.gainFrequency = 0.0
                fallback = (resp, inUnit, outUnit, remark, lowFreq, highFreq,
                            1.0, False, None)
                cha.gainUnit = inUnit

            elif e.tag == ns + "Stage":
                i = int(e.attrib['number'])

                try:
                    stages[i] = self.__stage(e)

                except Error as ex:
                    raise Error("%s stage %d: %s" % (_cha_id(cha), i, ex))

        if not stages and fallback:
            stages[1] = fallback

        logger.gain = 1.0
        unit = None
        afc = []
        dfc = []

        for i in range(1, len(stages) + 1):
            try:
                resp, inUnit, outUnit, remark, lowFreq, highFreq, gain, converted, extraDecimation = stages[
                    i]

            except KeyError:
                raise Error("%s: error: missing stage %d" % (_cha_id(cha), i))

            if converted:
                logs.notice(
                    "%s stage %d: notice: coefficients converted to PAZ" %
                    (_cha_id(cha), i))

            if i == 1:
                sensor.unit = inUnit
                sensor.remark = remark

                if resp is None:
                    raise Error("%s: error: missing stage 1 response" %
                                _cha_id(cha))

                elif _is_fir_response(resp) or (_is_paz_response(resp)
                                                and resp.type == 'D'):
                    # add dummy sensor to digital input
                    uu = _uuid()
                    paz = self.insert_responsePAZ(name=uu, publicID=uu)
                    paz.type = 'A'
                    paz.gain = 1.0
                    paz.gainFrequency = 0.0
                    paz.normalizationFactor = 1.0
                    paz.normalizationFrequency = 0.0
                    paz.numberOfPoles = 0
                    paz.numberOfZeros = 0
                    sensor.response = paz.publicID
                    sensor.lowFrequency = None
                    sensor.highFrequency = None
                    inUnit = "COUNTS"

                else:
                    sensor.response = resp.publicID
                    sensor.lowFrequency = lowFreq
                    sensor.highFrequency = highFreq
                    unit = outUnit
                    continue

            elif resp is None:
                if gain is not None:
                    logger.gain *= gain

                continue

            elif inUnit != unit:
                raise Error(
                    "%s stage %d: error: unexpected input unit: %s, expected: %s"
                    % (_cha_id(cha), i, inUnit, unit))

            if _is_fir_response(resp) and (resp.numberOfCoefficients == 0 or
                                           (resp.numberOfCoefficients == 1
                                            and float(resp.coefficients) == 1.0
                                            and resp.decimationFactor == 1)):
                logger.gain *= resp.gain
                self.remove_responseFIR(resp.name)

            elif _is_paz_response(
                    resp
            ) and resp.numberOfPoles == 0 and resp.numberOfZeros == 0:
                logger.gain *= resp.gain
                self.remove_responsePAZ(resp.name)

            elif _is_fir_response(resp) or (_is_paz_response(resp)
                                            and resp.type == 'D'):
                dfc.append(resp.publicID)

            elif not dfc:
                afc.append(resp.publicID)

            else:
                raise Error(
                    "%s stage %d: error: analogue stage after digital" %
                    (_cha_id(cha), i))

            if extraDecimation:
                logs.notice(
                    "%s stage %d: notice: adding extra decimation stage" %
                    (_cha_id(cha), i))
                dfc.append(extraDecimation)

            unit = outUnit

        deci = logger.insert_decimation(cha.sampleRateNumerator,
                                        cha.sampleRateDenominator)
        deci.analogueFilterChain = " ".join(afc)
        deci.digitalFilterChain = " ".join(dfc)