8000 Add map_variables and -99999 nan value to read_crn by AdamRJensen · Pull Request #1368 · pvlib/pvlib-python · GitHub
[go: up one dir, main page]

Skip to content

Add map_variables and -99999 nan value to read_crn #1368

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 21 commits into from
Feb 17, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Reformat setting of dtypes
  • Loading branch information
AdamRJensen committed Jan 12, 2022
commit a07acbc6ce5bb1a4b3ea51532f58a4981be634d4
21 changes: 10 additions & 11 deletions pvlib/iotools/crn.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
import pandas as pd


HEADERS = (
'WBANNO UTC_DATE UTC_TIME LST_DATE LST_TIME CRX_VN LONGITUDE LATITUDE '
'AIR_TEMPERATURE PRECIPITATION SOLAR_RADIATION SR_FLAG '
'SURFACE_TEMPERATURE ST_TYPE ST_FLAG RELATIVE_HUMIDITY RH_FLAG '
'SOIL_MOISTURE_5 SOIL_TEMPERATURE_5 WETNESS WET_FLAG WIND_1_5 WIND_FLAG'
)
HEADERS = [
'WBANNO', 'UTC_DATE', 'UTC_TIME', 'LST_DATE', 'LST_TIME', 'CRX_VN',
'LONGITUDE', 'LATITUDE', 'AIR_TEMPERATURE', 'PRECIPITATION',
'SOLAR_RADIATION', 'SR_FLAG', 'SURFACE_TEMPERATURE', 'ST_TYPE', 'ST_FLAG',
'RELATIVE_HUMIDITY', 'RH_FLAG', 'SOIL_MOISTURE_5', 'SOIL_TEMPERATURE_5',
'WETNESS', 'WET_FLAG', 'WIND_1_5', 'WIND_FLAG']

VARIABLE_MAP = {
'LONGITUDE': 'longitude',
Expand Down Expand Up @@ -107,13 +107,12 @@ def read_crn(filename, map_variables=True):
"""

# read in data
data = pd.read_fwf(filename, header=None, names=HEADERS.split(' '),
widths=WIDTHS, na_values=NAN_DICT)
data = pd.read_fwf(filename, header=None, names=HEADERS, widths=WIDTHS,
na_values=NAN_DICT)
# Remove rows with all nans
data = data.dropna(axis=0, how='all')
# loop here because dtype kwarg not supported in read_fwf until 0.20
for (col, _dtype) in zip(data.columns, DTYPES):
data[col] = data[col].astype(_dtype)
# set dtypes here because dtype kwarg not supported in read_fwf until 0.20
data = data.astype(dict(zip(HEADERS, DTYPES)))
Comment on lines +114 to +115
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pvlib now requires pandas > 0.22 so perhaps we can remove this line in favor of the dtype kwarg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do not believe this is possible as there are rows with all nans - and you cannot set the column dtype to int if the column contains nans. In the current version, the dtypes are set after the all nan rows are removed.

I get the following error when i set dtype=dict(zip(HEADERS, DTYPES)) with read_fwf:

ValueError: Unable to convert column WBANNO to type int64


# set index
# UTC_TIME does not have leading 0s, so must zfill(4) to comply
Expand Down
0