Coder Social home page Coder Social logo

Comments (2)

timronan avatar timronan commented on September 27, 2024

@timronan already created this class but does not have permissions to branch from the code main branch to submit a a Pull request for review.

Class could be /mth5/mth5/utils/make_mth5.py

And to start would contain the code

 from obspy import UTCDateTime
 
 from mt_metadata.timeseries.stationxml import XMLInventoryMTExperiment
 from mth5.mth5 import MTH5
 from mth5.timeseries import RunTS
 import os
 
 
 class Make_MTH5():
 
     def make_mth5_from_iris(network, station, starttime, endtime, path=None,
                             client='IRIS'):
 
         if path is None:
             path = str(os.getcwd()) + '/'
         network = network
         station = station
         start = UTCDateTime(starttime)
         end = UTCDateTime(endtime)
         file_name = path + network + '_' + station + '_' + starttime + '.h5'
         # need to know network, station, start and end times before hand
         client = fdsn.Client(client)
 
         # get the data
         streams = client.get_waveforms(network, station, None, None, start, end)
 
         # get the metadata
         inventory = client.get_stations(
             start, end, network=network, station=station, level="channel"
         )
         # translate obspy.core.Inventory to an mt_metadata.timeseries.Experiment
         translator = XMLInventoryMTExperiment()
         experiment = translator.xml_to_mt(inventory)
 
         # initiate MTH5 file
         m = MTH5()
         m.open_mth5(r"" + file_name, "w")
         # fill metadata
         m.from_experiment(experiment)
         station_group = m.get_station(station)
 
         # runs can be split into channels with similar start times and sample rates
         start_times = sorted(list(set([tr.stats.starttime.isoformat() for tr in streams])))
         end_times = sorted(list(set([tr.stats.endtime.isoformat() for tr in streams])))
 
         for index, times in enumerate(zip(start_times, end_times), 1):
             run_stream = streams.slice(UTCDateTime(times[0]), UTCDateTime(times[1]))
             run_ts_obj = RunTS()
             run_ts_obj.from_obspy_stream(run_stream)
             run_group = station_group.add_run(f"{index:03}")
             run_group.from_runts(run_ts_obj)
         print(file_name + " has been built.")
         m.close_mth5()
         return file_name

or similar.

from mth5.

timronan avatar timronan commented on September 27, 2024

Closed by merging branch enhancement_42

from mth5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.