@lheagy , @kkappler , @domfournier, @kujaku11 Need help figuring out an efficient way to validate any metadata that is input into xarray.DataArray.attrs, which is the container for the data.
For example, say we have a channel of 1-D array magnetic data. The container is mth5.timeseries.ChannelTS, and it will have appropriate metadata attached to it. Here is a simple example
import numpy as np
from mth5.timeseries import ChannelTS
hx = ChannelTS("magnetic")
sample rate is a property which uses hx.metadata.sample_rate under the hood
hx.sample_rate = 10
start is a property which uses hx.metadata.time_period.start under the hood
hx.start = "2020-01-01T12:00:00"
Set the data to random numbers
hx.ts = np.random.rand(4096)
Print a summary of the channel
hx
Out[13]:
Channel Summary:
Station: None
Run: None
Channel Type: magnetic
Component: None
Sample Rate: 10.0
Start: 2020-01-01T12:00:00+00:00
End: 2020-01-01T12:06:49.500000+00:00
N Samples: 4096
Print what the metadata looks like
hx.metadata
Out[14]:
{
"magnetic": {
"channel_number": null,
"component": null,
"data_quality.rating.value": 0,
"filter.applied": [
false
],
"filter.name": [
"none"
],
"location.elevation": 0.0,
"location.latitude": 0.0,
"location.longitude": 0.0,
"measurement_azimuth": 0.0,
"measurement_tilt": 0.0,
"sample_rate": 10.0,
"sensor.id": null,
"sensor.manufacturer": null,
"sensor.type": null,
"time_period.end": "2020-01-01T12:06:49.500000+00:00",
"time_period.start": "2020-01-01T12:00:00+00:00",
"type": "magnetic",
"units": null
}
}
Print what the xarray metadata looks like
hx.ts.attrs
Out[15]:
{'channel_number': None,
'component': None,
'data_quality.rating.value': 0,
'filter.applied': [False],
'filter.name': ['none'],
'location.elevation': 0.0,
'location.latitude': 0.0,
'location.longitude': 0.0,
'measurement_azimuth': 0.0,
'measurement_tilt': 0.0,
'sample_rate': 10.0,
'sensor.id': None,
'sensor.manufacturer': None,
'sensor.type': None,
'time_period.end': '2020-01-01T12:06:49.500000+00:00',
'time_period.start': '2020-01-01T12:00:00+00:00',
'type': 'magnetic',
'units': None}
The current method to update the xarray attrs when a user changes some metadata is with a manual function call:
hx.metadata.sensor.id = 4096
hx.metadata.measurement_azimuth = "90"
hx.metadata
Out[19]:
{
"magnetic": {
"channel_number": null,
"component": null,
"data_quality.rating.value": 0,
"filter.applied": [
false
],
"filter.name": [
"none"
],
"location.elevation": 0.0,
"location.latitude": 0.0,
"location.longitude": 0.0,
"measurement_azimuth": 90.0,
"measurement_tilt": 0.0,
"sample_rate": 10.0,
"sensor.id": "4096",
"sensor.manufacturer": null,
"sensor.type": null,
"time_period.end": "2020-01-01T12:06:49.500000+00:00",
"time_period.start": "2020-01-01T12:00:00+00:00",
"type": "magnetic",
"units": null
}
}
Update xarray attrs manually
hx.update_xarray_metadata()
hx.ts.attrs
Out [21]:
{'channel_number': None,
'component': None,
'data_quality.rating.value': 0,
'filter.applied': [False],
'filter.name': ['none'],
'location.elevation': 0.0,
'location.latitude': 0.0,
'location.longitude': 0.0,
'measurement_azimuth': 90.0,
'measurement_tilt': 0.0,
'sample_rate': 10.0,
'sensor.id': '4096',
'sensor.manufacturer': None,
'sensor.type': None,
'time_period.end': '2020-01-01T12:06:49.500000+00:00',
'time_period.start': '2020-01-01T12:00:00+00:00',
'type': 'magnetic',
'units': None}