windng
Check-in [da152f922f]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Make it work with pandas 0.17.1
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:da152f922f92f55747847513d7d9b0276c97c57f
User & Date: goyo 2015-11-24 08:09:06
Context
2015-11-24
08:26
Make setup.py work with pip in python2. check-in: 9b2e9b9e05 user: goyo tags: trunk
08:09
Make it work with pandas 0.17.1 check-in: da152f922f user: goyo tags: trunk
2015-10-28
23:48
Improvements to turbulence(). check-in: b9977fb29f user: goyo tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to test/test_io.py.

437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
19910201 0200    4.8    350   11.8    1007.2
19910201 0300    6.0    352   11.9    1007.5
19910201 0400    5.3    352   11.0    1007.9
""")
        result = wio.read_vortex(sample, prefix='X')

        tuples = [
            ('WS', 'M(m/s)', 80, 'avg'),
            ('WD', 'D(deg)', 80, 'avg'),
            ('T', 'T(C)', 80, 'avg'),
            ('P', 'PRE(hPa)', 80, 'avg')
        ]
        names = ['kind', 'name', 'height', 'signal']
        expected_columns = pd.MultiIndex.from_tuples(tuples, names=names)
        expected_index = pd.date_range('1991-02-01', periods=5, freq='H',
            name='YYYYMMDD_HHMM')
        expected_data = np.array([
            [6.4, 344, 13.7, 1007.3],
................................................................................
01/08/2010 00:10\t3.1\t3.7	101
01/08/2010 00:20\t2.5\t2.8\t
"""
        )
        result = wio.read_aire(sample, skip_mast_name=True)
        expected_columns = pd.MultiIndex.from_tuples(
            [
                (u'WS', u'78.0_SW_2.5_1_10', 78, u'avg'),
                (u'WS', u'78.0_SW_2.5_1_10', 78, u'max'),
                (u'', u'Etiqueta', 0, u'lbl')
            ],
            names=['kind', 'name', 'height', 'signal']
        )
        expected_index = pd.date_range('2010-07-31 23:40',
            periods=5, freq='10T')
        expected_values = np.array([







|
|
|
|







 







|
|







437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
...
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
19910201 0200    4.8    350   11.8    1007.2
19910201 0300    6.0    352   11.9    1007.5
19910201 0400    5.3    352   11.0    1007.9
""")
        result = wio.read_vortex(sample, prefix='X')

        tuples = [
            ('WS', 'M(m/s)', 80., 'avg'),
            ('WD', 'D(deg)', 80., 'avg'),
            ('T', 'T(C)', 80., 'avg'),
            ('P', 'PRE(hPa)', 80., 'avg')
        ]
        names = ['kind', 'name', 'height', 'signal']
        expected_columns = pd.MultiIndex.from_tuples(tuples, names=names)
        expected_index = pd.date_range('1991-02-01', periods=5, freq='H',
            name='YYYYMMDD_HHMM')
        expected_data = np.array([
            [6.4, 344, 13.7, 1007.3],
................................................................................
01/08/2010 00:10\t3.1\t3.7	101
01/08/2010 00:20\t2.5\t2.8\t
"""
        )
        result = wio.read_aire(sample, skip_mast_name=True)
        expected_columns = pd.MultiIndex.from_tuples(
            [
                (u'WS', u'78.0_SW_2.5_1_10', 78., u'avg'),
                (u'WS', u'78.0_SW_2.5_1_10', 78., u'max'),
                (u'', u'Etiqueta', 0, u'lbl')
            ],
            names=['kind', 'name', 'height', 'signal']
        )
        expected_index = pd.date_range('2010-07-31 23:40',
            periods=5, freq='10T')
        expected_values = np.array([

Changes to test/test_turbines.py.

147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    def test_from_json(self):
        text = r'{"name": "A name", "description": "A description", "rated_power": 10, "power": "{\"2.0\":{\"3\":1.0,\"4\":2.0,\"5\":4.0},\"2.2\":{\"3\":1.2,\"4\":2.2,\"5\":4.2},\"2.4\":{\"3\":1.4,\"4\":2.4,\"5\":4.4}}"}'
        result = turbines.TurbineType.from_json(text)
        power = pd.DataFrame(
            [[1, 1.2, 1.4],
             [2, 2.2, 2.4],
             [4, 4.2, 4.4]],
            index=[3, 4, 5], columns=[2, 2.2, 2.4]
        )
        t = turbines.TurbineType(name='A name', description='A description',
            power=power, rated_power=10)
        self.assertEqual(result.name, t.name)
        self.assertEqual(result.description, t.description)
        self.assertEqual(result._rated_power, t._rated_power)
        pdt.assert_frame_equal(result.power, t.power)







|







147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
    def test_from_json(self):
        text = r'{"name": "A name", "description": "A description", "rated_power": 10, "power": "{\"2.0\":{\"3\":1.0,\"4\":2.0,\"5\":4.0},\"2.2\":{\"3\":1.2,\"4\":2.2,\"5\":4.2},\"2.4\":{\"3\":1.4,\"4\":2.4,\"5\":4.4}}"}'
        result = turbines.TurbineType.from_json(text)
        power = pd.DataFrame(
            [[1, 1.2, 1.4],
             [2, 2.2, 2.4],
             [4, 4.2, 4.4]],
            index=[3., 4., 5.], columns=[2, 2.2, 2.4]
        )
        t = turbines.TurbineType(name='A name', description='A description',
            power=power, rated_power=10)
        self.assertEqual(result.name, t.name)
        self.assertEqual(result.description, t.description)
        self.assertEqual(result._rated_power, t._rated_power)
        pdt.assert_frame_equal(result.power, t.power)

Changes to test/test_wind.py.

1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
....
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
....
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
            348.75
        ]

        speed = abs(np.sin(np.arange(1000)) + 0.2) * 10
        dir = (np.cos(np.arange(1000))**2) * 359

        ftable = wind.freq_table(speed, dir, dataframe=True)
        expected = pd.DataFrame(expected_freqs, index=range(12),
            columns=range(16))
        pdt.assert_frame_equal(ftable, expected)

        freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
        np.testing.assert_array_almost_equal(freqs, expected_freqs)
        np.testing.assert_array_equal(sbins, range(13))
        np.testing.assert_array_equal(dbins, expected_dbins)
................................................................................
        # Add a lot of nans.
        speed = pd.Series(speed, index=np.arange(2000, step=2))
        speed = speed.reindex(np.arange(2000))
        dir = pd.Series(dir, index=np.arange(2000, step=2))
        dir = dir.reindex(np.arange(2000))

        ftable = wind.freq_table(speed, dir, dataframe=True)
        expected = pd.DataFrame(expected_freqs, index=range(12),
            columns=range(16))
        pdt.assert_frame_equal(ftable, expected)

        freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
        np.testing.assert_array_almost_equal(freqs, expected_freqs)
        np.testing.assert_array_equal(sbins, range(13))
        np.testing.assert_array_equal(dbins, expected_dbins)
................................................................................
            348.75
        ]

        speed = list(abs(np.sin(np.arange(1000)) + 0.2) * 10)
        dir = list((np.cos(np.arange(1000))**2) * 359)

        ftable = wind.freq_table(speed, dir, dataframe=True)
        expected = pd.DataFrame(expected_freqs, index=range(12),
            columns=range(16))
        pdt.assert_frame_equal(ftable, expected)

        freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
        np.testing.assert_array_almost_equal(freqs, expected_freqs)
        np.testing.assert_array_equal(sbins, range(13))
        np.testing.assert_array_equal(dbins, expected_dbins)







|







 







|







 







|







1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
....
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
....
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
            348.75
        ]

        speed = abs(np.sin(np.arange(1000)) + 0.2) * 10
        dir = (np.cos(np.arange(1000))**2) * 359

        ftable = wind.freq_table(speed, dir, dataframe=True)
        expected = pd.DataFrame(expected_freqs, index=np.arange(12.),
            columns=range(16))
        pdt.assert_frame_equal(ftable, expected)

        freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
        np.testing.assert_array_almost_equal(freqs, expected_freqs)
        np.testing.assert_array_equal(sbins, range(13))
        np.testing.assert_array_equal(dbins, expected_dbins)
................................................................................
        # Add a lot of nans.
        speed = pd.Series(speed, index=np.arange(2000, step=2))
        speed = speed.reindex(np.arange(2000))
        dir = pd.Series(dir, index=np.arange(2000, step=2))
        dir = dir.reindex(np.arange(2000))

        ftable = wind.freq_table(speed, dir, dataframe=True)
        expected = pd.DataFrame(expected_freqs, index=np.arange(12.),
            columns=range(16))
        pdt.assert_frame_equal(ftable, expected)

        freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
        np.testing.assert_array_almost_equal(freqs, expected_freqs)
        np.testing.assert_array_equal(sbins, range(13))
        np.testing.assert_array_equal(dbins, expected_dbins)
................................................................................
            348.75
        ]

        speed = list(abs(np.sin(np.arange(1000)) + 0.2) * 10)
        dir = list((np.cos(np.arange(1000))**2) * 359)

        ftable = wind.freq_table(speed, dir, dataframe=True)
        expected = pd.DataFrame(expected_freqs, index=np.arange(12.),
            columns=range(16))
        pdt.assert_frame_equal(ftable, expected)

        freqs, sbins, dbins = wind.freq_table(speed, dir, dataframe=False)
        np.testing.assert_array_almost_equal(freqs, expected_freqs)
        np.testing.assert_array_equal(sbins, range(13))
        np.testing.assert_array_equal(dbins, expected_dbins)

Changes to windng/io.py.

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
...
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
...
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
from datetime import datetime
import io
import warnings

import numpy as np
import pandas as pd
from pandas.io.common import get_filepath_or_buffer  # filepath_or_buffer, encoding
from pandas.core.common import _get_handle  # path, mode, encoding=None, compression=None

import windng.wind as wind


def _date_parser(date_format):
    strptime = datetime.strptime
    def theparser(*s):
................................................................................
        'u2': lambda x: format(x, '8.2f'),
        'std_speed': lambda x: format(x, '6.2f'),
    }

    if hasattr(path_or_buf, 'write'):
        buf = path_or_buf
    else:
        buf = _get_handle(path_or_buf, 'w',)


    # XXX This does not work due to a bug in pandas (ignores col_space).
    #~ dframe.to_string(buf, header=False, index=False,
        #~ formatters=formatters, col_space=0)

    # Temporary workaround.
................................................................................
        ('TI', getcol(ticol, 'TI'))
    ])
    dframe.index = index
    dframe = dframe.dropna(how='any', subset=['Speed', 'Direction'])
    if hasattr(path_or_buf, 'write'):
        buf = path_or_buf
    else:
        buf = _get_handle(path_or_buf, 'w',)

    buf.write('MM,{}\n'.format(mm))
    buf.write('{},{},{}\n'.format(lon, lat, hubheight))
    buf.write('{},{},{}\n'.format(uncertainty, shortname, longname))
    buf.write('Year,Month,Day,Hour,Minute,WS,DIR,Temp,Density,TI[%]\n')

    # XXX This does not work due to a bug in pandas (ignores col_space).







<







 







|







 







|







31
32
33
34
35
36
37

38
39
40
41
42
43
44
...
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
...
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
from datetime import datetime
import io
import warnings

import numpy as np
import pandas as pd
from pandas.io.common import get_filepath_or_buffer  # filepath_or_buffer, encoding


import windng.wind as wind


def _date_parser(date_format):
    strptime = datetime.strptime
    def theparser(*s):
................................................................................
        'u2': lambda x: format(x, '8.2f'),
        'std_speed': lambda x: format(x, '6.2f'),
    }

    if hasattr(path_or_buf, 'write'):
        buf = path_or_buf
    else:
        buf = open(path_or_buf, 'w')


    # XXX This does not work due to a bug in pandas (ignores col_space).
    #~ dframe.to_string(buf, header=False, index=False,
        #~ formatters=formatters, col_space=0)

    # Temporary workaround.
................................................................................
        ('TI', getcol(ticol, 'TI'))
    ])
    dframe.index = index
    dframe = dframe.dropna(how='any', subset=['Speed', 'Direction'])
    if hasattr(path_or_buf, 'write'):
        buf = path_or_buf
    else:
        buf = open(path_or_buf, 'w')

    buf.write('MM,{}\n'.format(mm))
    buf.write('{},{},{}\n'.format(lon, lat, hubheight))
    buf.write('{},{},{}\n'.format(uncertainty, shortname, longname))
    buf.write('Year,Month,Day,Hour,Minute,WS,DIR,Temp,Density,TI[%]\n')

    # XXX This does not work due to a bug in pandas (ignores col_space).