Exemplo n.º 1
0
def test_adding_arbitrary_files(tmpdir):
    """
    Tests that adding arbitrary files works.
    """
    test_filename = os.path.join(tmpdir.strpath, "temp.json")
    test_dict = {"a": 1, "b": 2}
    with open(test_filename, "wt") as fh:
        json.dump(test_dict, fh, sort_keys=True)

    asdf_filename = os.path.join(tmpdir.strpath, "test.h5")
    data_set = ASDFDataSet(asdf_filename)

    data_set.add_auxiliary_data_file(
        test_filename, tag="test_file", parameters={"1": 1})

    data_set.__del__()
    del data_set

    new_data_set = ASDFDataSet(asdf_filename)
    # Extraction works the same as always, but now has a special attribute,
    # that returns the data as a BytesIO.
    aux_data = new_data_set.auxiliary_data.File.test_file
    assert aux_data.parameters == {"1": 1}
    assert aux_data.tag == "test_file"

    new_test_dict = json.loads(aux_data.file.read().decode())
    assert test_dict == new_test_dict

    aux_data.file.seek(0, 0)

    with open(test_filename, "rb") as fh:
        assert fh.read() == aux_data.file.read()
Exemplo n.º 2
0
                        code=network,
                        stations=[
                            obspy.core.inventory.Station(
                                code=station,
                                latitude=group2[0][2],
                                longitude=group2[0][3],
                                elevation=group2[0][4],
                                start_date=starttime,
                                end_date=endtime,
                                creation_date=obspy.UTCDateTime(),
                                site=obspy.core.inventory.Site(name=""),
                                channels=[
                                    obspy.core.inventory.Channel(
                                        code=channel,
                                        location_code=location,
                                        latitude=latitude,
                                        longitude=longitude,
                                        elevation=elevation,
                                        depth=depth,
                                        start_date=starttime,
                                        end_date=endtime)
                                ])
                        ])
                ],
                source="pyasdf sac2asdf converter")
            ds.add_stationxml(inventory)

    # add sac_headers as auxiliary data
    ds.add_auxiliary_data_file(dumpjson(headers), path='SacHeaders')
    del ds
Exemplo n.º 3
0
            sources[coords] = source_id

        # use trace index in place of network/station/channel
        trace.stats.station = _i

        # keep track of receivers
        coords = get_receiver_coords(trace)
        if coords in sources:
            source_id = sources[coords]
        else:
            source_id = get_source_id()
            sources[coords] = source_id

        ds.add_waveforms(trace, args.tag, source_id)

    # add events
    # longitude = source_coord_x, latitude = source_coord_y
    catalog = obspy.core.event.Catalog()
    for source_coords, source_id in sources.items():
        latitude, longitude, depth = source_coords
        origin = obspy.core.event.Origin(latitude=coords[0],
                                         longitude=coords[1],
                                         depth=coords[2])
        catalog.append(
            obspy.core.event.Event(resource_id=source_id, origins=[origin]))
    ds.add_quakeml(catalog)

    # add su_headers as auxiliary data
    ds.add_auxiliary_data_file(dump(headers), path='SUHeaders')
    del ds