77import pandas as pd
88import numpy as np
99import os
10- import pkg_resources
10+ import importlib_resources
1111from typing import Tuple
1212from calendar import isleap
1313
@@ -85,7 +85,7 @@ def create_amy_epw_file(
8585 amy_file_path , amy_next_year_file_path = amy_files
8686 else :
8787 if amy_dir is None :
88- amy_dir = pkg_resources . resource_filename ("diyepw" , "data/noaa_isd_lite_files" )
88+ amy_dir = importlib_resources . files ("diyepw" ) / "data/noaa_isd_lite_files"
8989 _logger .info (f"No amy_dir was specified - downloaded AMY files will be stored in the default location at { amy_dir } " )
9090
9191 amy_file_path = get_noaa_isd_lite_file (wmo_index , year , output_dir = amy_dir , allow_downloads = allow_downloads )
@@ -110,7 +110,7 @@ def create_amy_epw_file(
110110 new_row_vals = [1982 , 2 , 29 , hour , 0 ]
111111 new_row_vals .extend (np .repeat (np .nan , len (col_names ) - len (new_row_vals )))
112112 new_row = pd .DataFrame ([new_row_vals ], columns = col_names )
113- tmy .observations = tmy .observations . append ( new_row )
113+ tmy .observations = pd . concat ([ tmy .observations , new_row ], ignore_index = True )
114114
115115 # We sort by month, day and hour. We do *not* sort by year, because the year column doesn't matter and because
116116 # it is in any case not consistent throughout a TMY data set
@@ -140,15 +140,15 @@ def create_amy_epw_file(
140140 # to handle the largest possible timezone shift) of the subsequent year - the subsequent year's data will be
141141 # used to populate the last hours of the year because of the time shift that we perform, which moves the first
142142 # hours of January 1 into the final hours of December 31.
143- amy_df = pd .read_csv (amy_file_path , delim_whitespace = True , header = None )
144- amy_next_year_df = pd .read_csv (amy_next_year_file_path , delim_whitespace = True , header = None , nrows = 23 )
143+ amy_df = pd .read_csv (amy_file_path , sep = ' \\ s+' , header = None )
144+ amy_next_year_df = pd .read_csv (amy_next_year_file_path , sep = ' \\ s+' , header = None , nrows = 23 )
145145 amy_df = pd .concat ([amy_df , amy_next_year_df ]).reset_index (drop = True )
146146
147147 amy_df = _set_noaa_df_columns (amy_df )
148148 amy_df = _create_timestamp_index_for_noaa_df (amy_df )
149149
150150 # Shift the timestamp (index) to match the time zone of the WMO station.
151- amy_df = amy_df .shift (periods = tmy .timezone_gmt_offset , freq = 'H ' )
151+ amy_df = amy_df .shift (periods = tmy .timezone_gmt_offset , freq = 'h ' )
152152
153153 # Remove time steps that aren't applicable to the year of interest
154154 amy_df = _map_noaa_df_to_year (amy_df , year )
@@ -237,7 +237,7 @@ def _map_noaa_df_to_year(df, year):
237237 The assumption of this function is that the dataframe ranges from the beginning of the year to some
238238 """
239239 # Create series of continuous timestamp values for that year
240- all_timestamps = pd .date_range (str (year ) + '-01-01 00:00:00' , str (year ) + '-12-31 23:00:00' , freq = 'H ' )
240+ all_timestamps = pd .date_range (str (year ) + '-01-01 00:00:00' , str (year ) + '-12-31 23:00:00' , freq = 'h ' )
241241 all_timestamps = pd .DataFrame (all_timestamps , columns = ['timestamp' ])
242242
243243 # Merge to one dataframe containing all continuous timestamp values.
@@ -352,13 +352,13 @@ def get_indices_to_replace(df, col_name):
352352 replacement_value_index += imputation_step
353353
354354 # Take the mean of the values pulled. Will ignore NaNs.
355- df [ col_name ][ index_to_impute ] = pd .Series (replacement_values , dtype = np .float64 ).mean ()
355+ df . loc [ index_to_impute , col_name ] = pd .Series (replacement_values , dtype = np .float64 ).mean ()
356356
357357 # Perform interpolation on any remaining missing values. At this point we know that there are no
358358 # sequences larger than the max permitted for interpolation, because they would have been imputed
359359 # or caused an exception (if larger than the imputation limit), so we can just call interpolate()
360360 # on anything that is still missing.
361- df [col_name ].interpolate (inplace = True )
361+ df [col_name ] = df [ col_name ] .interpolate ()
362362
363363def _split_list_into_contiguous_segments (l :list , step ):
364364 """
@@ -417,4 +417,4 @@ def _convert_sea_level_pressure_to_station_pressure(Pa, h_m) -> object:
417417 # convert from inHg to Pa
418418 Pstn = Pstn_inHg * 3386.389
419419
420- return Pstn
420+ return Pstn
0 commit comments