Exemplo n.º 1
0
def main():
    args = parse_args()
    configure_logging(args.log_config)
    config = load_config(args.config)

    stations_pf = load_stations(config)
    data_gridded, data_gridded_lt, timestamps = load_forecast(
        args.wrfout, args.wrfout_long_term, args.components,
        config.get('spinup', 0))

    for location in stations_pf:
        try:
            pf = timeseries_for_location(location, args, data_gridded,
                                         data_gridded_lt)
        except TargetOutsideGridError:
            LOG.info(
                'Location of station %s outside wrfout grid, ignoring the station.',
                location['ref'])
            continue

        filename = templated_filename(config,
                                      analysis_date=args.analysis,
                                      ref=location['ref'],
                                      create_dirs=True)

        metadata = OrderedDict([
            ('ref', location['ref']), ('name', location['name']),
            ('analysis_date', args.analysis.strftime('%Y-%m-%dT%H:%M:%S')),
            ('longitude', '{:.4f}'.format(location['lon'])),
            ('latitude', '{:.4f}'.format(location['lat']))
        ])

        save_timeseries(timestamps, pf, filename, metadata)
Exemplo n.º 2
0
def test_save_timeseries__formating():
    m = mock_open()
    with patch('data_utils.codecs.open', m):
        data_utils.save_timeseries(ts, data, test_path, separator='::', valueformat='{:.2f}')

    calls = [
        call('time::wind_dir\n'),
        call('2014-02-01T10:00::2.45\n'),
        call('2014-02-01T11:00::2.50\n')
    ]
    assert_list_equal(m().write.call_args_list, calls)
Exemplo n.º 3
0
def test_save_timeseries__header():
    m = mock_open()
    with patch('data_utils.codecs.open', m):
        data_utils.save_timeseries(ts, data, test_path, {'this_is_header': 'HEADER'})

    calls = [
        call('# this_is_header: HEADER\ntime, wind_dir\n'),
        call('2014-02-01T10:00, 2.4545\n'),
        call('2014-02-01T11:00, 2.5000\n')
    ]
    assert_list_equal(m().write.call_args_list, calls)
Exemplo n.º 4
0
def test_save_timeseries__simple():
    m = mock_open()
    with patch('data_utils.codecs.open', m):
        data_utils.save_timeseries(ts, data, test_path)

    calls = [
        call('time, wind_dir\n'),
        call('2014-02-01T10:00, 2.4545\n'),
        call('2014-02-01T11:00, 2.5000\n')
    ]
    assert_list_equal(m().write.call_args_list, calls)
Exemplo n.º 5
0
def test_save_timeseries__header__not_comment_column_names():
    m = mock_open()
    with patch('data_utils.codecs.open', m):
        data_utils.save_timeseries(ts, data, test_path, {'name': 'Ólafsfjarðarmúli'}, comment_column_names=True)

    calls = [
        call('# name: Ólafsfjarðarmúli\n# columns: time, wind_dir\n'),
        call('2014-02-01T10:00, 2.4545\n'),
        call('2014-02-01T11:00, 2.5000\n')
    ]

    assert_list_equal(m().write.call_args_list, calls)
Exemplo n.º 6
0
def test_save_timeseries__error():
    with assert_raises(TypeError):
        save_timeseries('a;b;c;d;', '.')