Skip to content
Snippets Groups Projects
ObservatoryMetadata.py 41.6 KiB
Newer Older
            'second': {
                'data_interval_type': ''
            }
        }
    }
}


DEFAULT_INTERVAL_SPECIFIC = {
        'minute': {'data_interval_type': 'filtered 1-minute (00:15-01:45) '},
        'second': {'data_interval_type': 'Average 1-Second'}
}


class ObservatoryMetadata(object):
    """Helper class for providing all the metadata needed for a geomag
          timeseries.
    Notes
    -----
    Currently the only method is set_metadata.  Eventually this will probably
    pull from a database, or maybe a config file.
    """

    def __init__(self, metadata=None, interval_specific=None):
        self.metadata = metadata or DEFAULT_METADATA
        self.interval_specific = interval_specific or \
                DEFAULT_INTERVAL_SPECIFIC

    def set_metadata(self, stats, observatory, channel, type, interval):
        """Set timeseries metadata (aka a traces stats)

        Parameters
        ----------
        stats : obspy.core.trace.stats
            the class associated with a given obspy trace, which contains
            it's metadata
        observatory : string
            the observatory code to look up.
        channel : str
            single character channel {H, E, D, Z, F}
        type : {'variation', 'quasi-definitive'}
            data type.
        interval : {'minute', 'second'}
            data interval.

        Returns
        -------
        obspy.core.trace.stats
          the combined stats and the default metadata.
        """
        stats['channel'] = channel
        stats['data_interval'] = interval
        stats['data_type'] = type
        if observatory not in self.metadata:
        # copy in standard metadata
        metadata = self.metadata[observatory]['metadata']
        for key in metadata:
            stats[key] = metadata[key]
        # copy in interval specific metadata
        interval_specific = self.interval_specific
        if 'interval_specific' in self.metadata[observatory]:
            interval_specific = \
                self.metadata[observatory]['interval_specific']
        # stats['data_interval_type'] = data_interval_type[interval]
        for key in interval_specific[interval]:
            stats[key] = interval_specific[interval][key]