def setUp(self): self.mth5_obj = mth5.MTH5() pd_series = pd.Series({ 'station': 'MT test', 'latitude': 40.90, 'longitude': -115.78, 'elevation': 1234, 'declination': -15.5, 'start_date': '2018-01-01 12:00:00.00', 'end_date': '2018-02-01 12:00:00.00', 'datum': 'WGS84', 'coordinate_system': 'Geographic North', 'units': 'mV', 'instrument_id': 'ZEN_test', 'ex_azimuth': 0, 'ex_length': 50.0, 'ex_sensor': 1, 'ex_num': 1, 'ey_azimuth': 90, 'ey_length': 52.0, 'ey_sensor': 2, 'ey_num': 2, 'hx_azimuth': 0, 'hx_sensor': 2274, 'hx_num': 3, 'hy_azimuth': 90, 'hy_sensor': 2284, 'hy_num': 4, 'hz_azimuth': 0, 'hz_sensor': 2294, 'hz_num': 5 }) self.mth5_obj.update_metadata_from_series(pd_series)
def setUp(self): self.maxDiff = None self.fn = fn_path.joinpath("test.h5") self.mth5_obj = mth5.MTH5(file_version="0.1.0") self.mth5_obj.open_mth5(self.fn, mode="w") self.experiment = Experiment() self.experiment.from_xml(fn=MT_EXPERIMENT_SINGLE_STATION) self.mth5_obj.from_experiment(self.experiment)
def setUp(self): self.translator = stationxml.XMLInventoryMTExperiment() self.experiment = self.translator.xml_to_mt( stationxml_fn=STATIONXML_01) self.fn = fn_path.joinpath("from_stationxml.h5") if self.fn.exists(): self.fn.unlink() self.m = mth5.MTH5(file_version="0.1.0") self.m.open_mth5(self.fn) self.m.from_experiment(self.experiment, 0)
def setUp(self): self.translator = stationxml.XMLInventoryMTExperiment() self.experiment = self.translator.xml_to_mt( stationxml_fn=STATIONXML_01) self.experiment.surveys[0].id = "test" self.base_path = "Experiment/Surveys/test" self.fn = fn_path.joinpath("from_stationxml.h5") self.m = mth5.MTH5(file_version="0.2.0") self.m.open_mth5(self.fn) self.m.from_experiment(self.experiment)
def setUp(self): self.maxDiff = None self.fn = fn_path.joinpath("test.h5") self.mth5_obj = mth5.MTH5(file_version="0.1.0") self.mth5_obj.open_mth5(self.fn, mode="w") self.experiment = Experiment() self.experiment.from_xml(fn=MT_EXPERIMENT_SINGLE_STATION) self.mth5_obj.from_experiment(self.experiment) self.experiment_02 = Experiment() self.experiment_02.from_xml(fn=MT_EXPERIMENT_SINGLE_STATION) self.experiment_02.surveys[0].id = "different_survey_name" self.experiment_02.surveys[0].stations[0].location.latitude = 10
def setUp(self): self.fn = fn_path.joinpath("filter_test.h5") self.m_obj = mth5.MTH5(file_version="0.1.0") self.m_obj.open_mth5(self.fn, "w") self.filter_group = self.m_obj.filters_group self.zpk = PoleZeroFilter() self.zpk.units_in = "counts" self.zpk.units_out = "mv" self.zpk.name = "zpk_test" self.zpk.poles = np.array([1 + 2j, 0, 1 - 2j]) self.zpk.zeros = np.array([10 - 1j, 10 + 1j]) self.coefficient = CoefficientFilter() self.coefficient.units_in = "volts" self.coefficient.units_out = "millivolts per meter" self.coefficient.name = "coefficient_test" self.coefficient.gain = 10.0 self.zpk_group = self.filter_group.add_filter(self.zpk) self.coefficient_group = self.filter_group.add_filter(self.coefficient)
os.mkdir(station_save_dir) print('--> Archiving Station {0} ...'.format(station)) ### capture output to put into a log file with archive.Capturing() as output: station_st = datetime.datetime.now() ### copy edi and png into archive director # if not os.path.isfile(os.path.join(station_save_dir, '{0}.edi'.format(station))): # shutil.copy(os.path.join(edi_path, '{0}.edi'.format(station)), # os.path.join(station_save_dir, '{0}.edi'.format(station))) # if not os.path.isfile(os.path.join(station_save_dir, '{0}.png'.format(station))): # shutil.copy(os.path.join(png_path, '{0}.png'.format(station)), # os.path.join(station_save_dir, '{0}.png'.format(station))) ### Make MTH5 File m = mth5.MTH5() mth5_fn = os.path.join(station_save_dir, '{0}.mth5'.format(station)) m.open_mth5(mth5_fn) if not m.h5_is_write: raise mth5.MTH5Error('Something is wrong') ### update metadata from csv and cfg files m.update_metadata_from_cfg(cfg_fn) if csv_fn is not None: try: station_df = archive.get_station_info_from_csv(csv_fn, station) m.update_metadata_from_series(station_df) except archive.ArchiveError as err: print('{0} {1} {0}'.format('*'*4, err)) m.write_metadata()
def setUp(self): self.fn = fn_path.joinpath("test.mth5") self.mth5_obj = mth5.MTH5(file_version="0.2.0") self.mth5_obj.open_mth5(self.fn, mode="w") self.survey_group = self.mth5_obj.add_survey("test")
h5_fn.unlink() print(f"INFO: Removed existing file {h5_fn}") # need to unzip the data with zipfile.ZipFile(zen_dir.joinpath("zen.zip"), "r") as zip_ref: zip_ref.extractall(zen_dir) # write some simple metadata for the survey survey = metadata.Survey() survey.acquired_by.author = "MT Master" survey.fdsn.id = "TST01" survey.fdsn.network = "MT" survey.name = "test" # open mth5 file m = mth5.MTH5(h5_fn) m.open_mth5() # add survey metadata m.survey_group.metadata.from_dict(survey.to_dict()) # add station metadata from z3d files ch_list = [] for fn in zip_ref.filelist: mtts_obj = read_file(zen_dir.joinpath(fn.filename)) station_group = m.add_station( mtts_obj.station_metadata.id, station_metadata=mtts_obj.station_metadata, )
def test_make_stationxml_from_mt(): fn_path = Path(__file__).parent fn = fn_path.joinpath("example.h5") if fn.exists(): fn.unlink() xml_fn = fn_path.joinpath("example.xml") if fn.exists(): fn.unlink() survey = metadata.Survey() survey.from_dict({ "survey": { "acquired_by.author": "MT", "acquired_by.comments": "tired", "archive_id": "MT01", "fdsn.network": "EM", "citation_dataset.doi": "http://doi.####", "citation_journal.doi": None, "comments": None, "country": None, "datum": "WGS84", "geographic_name": "earth", "name": "entire survey of the earth", "northwest_corner.latitude": 80.0, "northwest_corner.longitude": 179.9, "project": "EM-EARTH", "project_lead.author": "T. Lurric", "project_lead.email": "*****@*****.**", "project_lead.organization": "mt rules", "release_license": "CC-0", "southeast_corner.latitude": -80.0, "southeast_corner.longitude": -179.9, "summary": None, "time_period.end_date": "1980-01-01T00:00:00.000000Z", "time_period.start_date": "2020-01-01T00:00:00.000000Z", } }) station = metadata.Station() station.from_dict({ "station": { "acquired_by.author": "mt", "acquired_by.comments": None, "archive_id": "MT012", "channel_layout": "L", "comments": None, "data_type": "MT", "geographic_name": "london", "id": "mt012", "fdsn.id": "mt012", "location.declination.comments": None, "location.declination.model": "WMM", "location.declination.value": 12.3, "location.elevation": 1234.0, "location.latitude": 10.0, "location.longitude": -112.98, "orientation.method": "compass", "orientation.reference_frame": "geomagnetic", "provenance.comments": None, "provenance.creation_time": "1980-01-01T00:00:00+00:00", "provenance.log": None, "provenance.software.author": "test", "provenance.software.name": "name", "provenance.software.version": "1.0a", "provenance.submitter.author": "name", "provenance.submitter.email": "*****@*****.**", "provenance.submitter.organization": None, "time_period.end": "1980-01-01T00:00:00+00:00", "time_period.start": "1980-01-01T00:00:00+00:00", } }) run = metadata.Run() run.from_dict({ "run": { "acquired_by.author": "MT guru", "acquired_by.comments": "lazy", "channels_recorded_auxiliary": ["temperature"], "channels_recorded_electric": [], "channels_recorded_magnetic": [], "comments": "Cloudy solar panels failed", "data_logger.firmware.author": "MT instruments", "data_logger.firmware.name": "FSGMT", "data_logger.firmware.version": "12.120", "data_logger.id": "mt091", "data_logger.manufacturer": "T. Lurric", "data_logger.model": "Ichiban", "data_logger.power_source.comments": "rats", "data_logger.power_source.id": "12", "data_logger.power_source.type": "pb acid", "data_logger.power_source.voltage.end": 12.0, "data_logger.power_source.voltage.start": 14.0, "data_logger.timing_system.comments": "solid", "data_logger.timing_system.drift": 0.001, "data_logger.timing_system.type": "GPS", "data_logger.timing_system.uncertainty": 0.000001, "data_logger.type": "broadband", "data_type": "mt", "id": "mt01a", "provenance.comments": None, "provenance.log": None, "metadata_by.author": "MT guru", "metadata_by.comments": "lazy", "sampling_rate": 256.0, "time_period.end": "1980-01-01T00:00:00+00:00", "time_period.start": "1980-01-01T00:00:00+00:00", } }) channel = metadata.Auxiliary() channel.from_dict({ "auxiliary": { "comments": "great", "component": "temperature", "channel_number": 1, "data_quality.rating.author": "mt", "data_quality.rating.method": "ml", "data_quality.rating.value": 4, "data_quality.warning": None, "filter.applied": [True, False], "filter.comments": "test", "filter.name": ["lowpass", "counts2mv"], "location.elevation": 1234.0, "location.latitude": 12.324, "location.longitude": -112.03, "measurement_azimuth": 0, "measurement_tilt": 0, "sample_rate": 256.0, "time_period.end": "1980-01-01T00:00:00+00:00", "time_period.start": "1980-01-01T00:00:00+00:00", "type": "temperature", "units": "celsius", } }) m = mth5.MTH5() m.open_mth5(fn) survey_group = m.survey_group survey_group.metadata.from_dict(survey.to_dict()) survey_group.write_metadata() station_group = m.add_station(station.id, station) run_group = station_group.add_run(run.id, run) run_group.add_channel(channel.component, "auxiliary", None, channel_metadata=channel) translator = stationxml.XMLInventoryMTExperiment() translator.mt_to_xml(m.to_experiment(), stationxml_fn=xml_fn)
def setUp(self): self.fn = fn_path.joinpath("test.mth5") self.mth5_obj = mth5.MTH5(file_version="0.1.0") self.mth5_obj.open_mth5(self.fn, mode="w")
channel.metadata.from_xml(read_xml(directory.joinpath(channel_fn))) channel.metadata.time_period.start = run.metadata.time_period.start channel.metadata.time_period.end = run.metadata.time_period.end channel.write_metadata() return new_station xml_root = "path/to/metadata/files.xml" mth5_filename = "from_xml.mth5" if mth5_filename.exists(): mth5_filename.unlink() print(f"--> Rmoved existing file {mth5_filename}") # initialize mth5 object mth5_obj = mth5.MTH5() mth5_obj.open_mth5(mth5_filename, mode="a") ### add survey information survey_element = read_xml(xml_root.joinpath("survey.xml")) survey_obj = mth5_obj.survey_group survey_obj.metadata.from_xml(survey_element) survey_obj.write_metadata() for station in ["FL001", "FL002"]: # add station new_station = add_station(station, xml_root, mth5_obj) mth5_obj.close_mth5()
def setUp(self): self.mth5_obj = mth5.MTH5()
def setUp(self): self.mth5_obj = mth5.MTH5() cfg_fn = r"../examples/example_mth5_cfg.txt" self.assertTrue(os.path.isfile(cfg_fn), "{0} not found".format(cfg_fn)) self.mth5_obj.update_metadata_from_cfg(cfg_fn)