def fromProducts(cls, directory, process=True):
        """
        Read obspy and geojson from a directory and return an EventSummary object.

        Args:
            directory (str): Path to input files
            process (bool): Process the streams as documented in the
                processing_parameters property of each parametric file.
                Not used at this time.

        Returns:
            EventSummary: EventSummary object.
        """
        # gather streams so that they can be grouped
        station_dict = OrderedDict()
        uncorrected_streams = {}
        for file_path in glob.glob(directory + '/*'):
            if file_path.find('.json') < 0:
                stream = read(file_path)
                file_name = os.path.basename(file_path).split('.')[0]
                json_path = os.path.join(directory, file_name + '.json')
                if not os.path.isfile(json_path):
                    raise FileNotFoundError('No parametric data available for '
                                            'this stream: %r.' % file_path)
                with open(json_path) as f:
                    parametric = json.load(f)
                for trace in stream:
                    trace_channel = trace.stats['channel']
                    for channel in parametric['properties']['channels']:
                        chdict = parametric['properties']['channels'][channel]
                        channel_stats = chdict['stats']
                        if trace_channel == channel:
                            trace.stats = channel_stats
                station = stream[0].stats['station']
                pgms = parametric['properties']['pgms']
                station_dict[station] = StationSummary.from_pgms(station, pgms)
                uncorrected_streams[station] = stream
        ## TODO: add processing option after next amptools release
        event = cls()
        event._station_dict = station_dict
        event.uncorrected_streams = uncorrected_streams
        return event
def test_stationsummary():
    homedir = os.path.dirname(
        os.path.abspath(__file__))  # where is this script?
    datafile = os.path.join(homedir, '..', 'data', 'geonet',
                            '20161113_110259_WTMC_20.V2A')
    target_imcs = np.sort(
        np.asarray([
            'GREATER_OF_TWO_HORIZONTALS', 'HN1', 'HN2', 'HNZ', 'ROTD50.0',
            'ROTD100.0'
        ]))
    target_imts = np.sort(np.asarray(['SA1.0', 'PGA', 'PGV']))
    stream = read_geonet(datafile)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        stream_summary = StationSummary.from_stream(stream, [
            'greater_of_two_horizontals', 'channels', 'rotd50', 'rotd100',
            'invalid'
        ], ['sa1.0', 'PGA', 'pgv', 'invalid'])
        original_stream = stream_summary.stream
        stream_summary.stream = []
        final_stream = stream_summary.stream
        assert original_stream == final_stream
        original_code = stream_summary.station_code
        stream_summary.station_code = ''
        final_code = stream_summary.station_code
        assert original_code == final_code
        original_oscillators = stream_summary.oscillators
        final_oscillators = stream_summary.oscillators
        assert original_oscillators == final_oscillators
        np.testing.assert_array_equal(np.sort(stream_summary.components),
                                      target_imcs)
        np.testing.assert_array_equal(np.sort(stream_summary.imts),
                                      target_imts)
        np.testing.assert_almost_equal(stream_summary.get_pgm('PGA', 'HN1'),
                                       99.3173469387755,
                                       decimal=1)
        target_available = np.sort(
            np.asarray([
                'calculate_greater_of_two_horizontals', 'calculate_channels',
                'calculate_gmrotd', 'calculate_rotd'
            ]))
        imcs = stream_summary.available_imcs
        np.testing.assert_array_equal(np.sort(imcs), target_available)
        target_available = np.sort(
            np.asarray([
                'calculate_pga', 'calculate_pgv', 'calculate_sa',
                'calculate_arias'
            ]))
        imts = stream_summary.available_imts
        np.testing.assert_array_equal(np.sort(imts), target_available)
    test_pgms = {
        'PGV': {
            'ROTD100.0': 114.24894584734818,
            'ROTD50.0': 81.55436750525355,
            'HNZ': 37.47740000000001,
            'HN1': 100.81460000000004,
            'HN2': 68.4354,
            'GREATER_OF_TWO_HORIZONTALS': 100.81460000000004
        },
        'PGA': {
            'ROTD100.0': 100.73875535385548,
            'ROTD50.0': 91.40178541935455,
            'HNZ': 183.7722361866693,
            'HN1': 99.24999872535474,
            'HN2': 81.23467239067368,
            'GREATER_OF_TWO_HORIZONTALS': 99.24999872535474
        },
        'SA1.0': {
            'ROTD100.0': 146.9023350124098,
            'ROTD50.0': 106.03202302692158,
            'HNZ': 27.74118995438756,
            'HN1': 136.25041187387063,
            'HN2': 84.69296738413021,
            'GREATER_OF_TWO_HORIZONTALS': 136.25041187387063
        }
    }
    datafile = os.path.join(homedir, '..', 'data', 'geonet',
                            '20161113_110313_THZ_20.V2A')
    invalid_stream = read_geonet(datafile)
    station_code = 'WTMC'
    pgm_summary = StationSummary.from_pgms(station_code, test_pgms)
    # assert pgm_summary.pgms == stream_summary.pgms
    adict = pgm_summary.pgms
    bdict = stream_summary.pgms
    cmp_dicts(adict, bdict)

    # oscillators cannot be calculated without a stream
    try:
        pgm_summary.generate_oscillators(pgm_summary.imts, 0.05)
        success = True
    except Exception:
        success = False
    assert success is False
    # Invalid stream inputs should be rejected
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        pgm_summary.stream = []
        assert pgm_summary.stream is None
        pgm_summary.stream = invalid_stream
        assert pgm_summary.stream is None
        pgm_summary.stream = stream
        assert pgm_summary.stream == stream