|
| 1 | +import inspect |
| 2 | +import os |
| 3 | + |
| 4 | +import pandas as pd |
| 5 | +from pandas.util.testing import assert_frame_equal |
| 6 | +import numpy as np |
| 7 | +from numpy import dtype, nan |
| 8 | + |
| 9 | +from pvlib.iotools import crn |
| 10 | + |
| 11 | + |
| 12 | +test_dir = os.path.dirname( |
| 13 | + os.path.abspath(inspect.getfile(inspect.currentframe()))) |
| 14 | +testfile = os.path.join(test_dir, |
| 15 | + '../data/CRNS0101-05-2019-AZ_Tucson_11_W.txt') |
| 16 | + |
| 17 | + |
| 18 | +def test_read_crn(): |
| 19 | + columns = [ |
| 20 | + 'WBANNO', 'UTC_DATE', 'UTC_TIME', 'LST_DATE', 'LST_TIME', 'CRX_VN', |
| 21 | + 'longitude', 'latitude', 'temp_air', 'PRECIPITATION', 'ghi', |
| 22 | + 'ghi_flag', |
| 23 | + 'SURFACE_TEMPERATURE', 'ST_TYPE', 'ST_FLAG', 'relative_humidity', |
| 24 | + 'relative_humidity_flag', 'SOIL_MOISTURE_5', 'SOIL_TEMPERATURE_5', |
| 25 | + 'WETNESS', 'WET_FLAG', 'wind_speed', 'wind_speed_flag'] |
| 26 | + index = pd.DatetimeIndex(['2019-01-01 16:10:00', |
| 27 | + '2019-01-01 16:15:00', |
| 28 | + '2019-01-01 16:20:00', |
| 29 | + '2019-01-01 16:25:00'], |
| 30 | + freq=None).tz_localize('UTC') |
| 31 | + values = np.array([ |
| 32 | + [53131, 20190101, 1610, 20190101, 910, 3, -111.17, 32.24, nan, |
| 33 | + 0.0, 296.0, 0, 4.4, 'C', 0, 90.0, 0, nan, nan, 24, 0, 0.78, 0], |
| 34 | + [53131, 20190101, 1615, 20190101, 915, 3, -111.17, 32.24, 3.3, |
| 35 | + 0.0, 183.0, 0, 4.0, 'C', 0, 87.0, 0, nan, nan, 1182, 0, 0.36, 0], |
| 36 | + [53131, 20190101, 1620, 20190101, 920, 3, -111.17, 32.24, 3.5, |
| 37 | + 0.0, 340.0, 0, 4.3, 'C', 0, 83.0, 0, nan, nan, 1183, 0, 0.53, 0], |
| 38 | + [53131, 20190101, 1625, 20190101, 925, 3, -111.17, 32.24, 4.0, |
| 39 | + 0.0, 393.0, 0, 4.8, 'C', 0, 81.0, 0, nan, nan, 1223, 0, 0.64, 0]]) |
| 40 | + dtypes = [ |
| 41 | + dtype('int64'), dtype('int64'), dtype('int64'), dtype('int64'), |
| 42 | + dtype('int64'), dtype('int64'), dtype('float64'), dtype('float64'), |
| 43 | + dtype('float64'), dtype('float64'), dtype('float64'), |
| 44 | + dtype('int64'), dtype('float64'), dtype('O'), dtype('int64'), |
| 45 | + dtype('float64'), dtype('int64'), dtype('float64'), |
| 46 | + dtype('float64'), dtype('int64'), dtype('int64'), dtype('float64'), |
| 47 | + dtype('int64')] |
| 48 | + expected = pd.DataFrame(values, columns=columns, index=index) |
| 49 | + for (col, _dtype) in zip(expected.columns, dtypes): |
| 50 | + expected[col] = expected[col].astype(_dtype) |
| 51 | + out = crn.read_crn(testfile) |
| 52 | + assert_frame_equal(out, expected) |
0 commit comments