def test_gueymard94_pw(): temp_air = np.array([0, 20, 40]) relative_humidity = np.array([0, 30, 100]) temps_humids = np.array( list(itertools.product(temp_air, relative_humidity))) pws = atmosphere.gueymard94_pw(temps_humids[:, 0], temps_humids[:, 1]) expected = np.array( [ 0.1 , 0.33702061, 1.12340202, 0.1 , 1.12040963, 3.73469877, 0.1 , 3.44859767, 11.49532557]) assert_allclose(pws, expected, atol=0.01)
def preprocess(self): if self.timezone != 'Asia/Kolkata': self.weather_data['Timestamp'] = pd.to_datetime(self.weather_data['Timestamp'].values, \ utc=True).tz_convert(self.timezone) self.solar_data['Timestamp'] = pd.to_datetime(self.solar_data['Timestamp'].values, \ utc=True).tz_convert(self.timezone) if 'Timestamp' in self.weather_data.columns: self.weather_data.drop('Timestamp', inplace=True, axis=1) if 'Timestamp' in self.solar_data.columns: self.solar_data.drop('Timestamp', inplace=True, axis=1) for col in self.weather_data.columns: if self.weather_data[col].isnull().sum() > 0: self.weather_data[col].interpolate(method='time', axis=0, inplace=True) # if sum(self.weather_data.isnull().sum(axis=0)) == 0: # print('All Null values removed') self.weather_data['precipitable_water'] = gueymard94_pw(self.weather_data['temp_air'],\ self.weather_data['relative_humidity']) # This row has relative humidity = 100, which is practically not possible if len(self.weather_data.loc[ self.weather_data['precipitable_water'] > 8, 'relative_humidity']) > 0: print( 'Invalid values in the relative humidity column \n Removing such values' ) self.weather_data.loc['2018-08-19 13:03:00+05:30', 'relative_humidity'] = 70 self.weather_data['precipitable_water'] = gueymard94_pw( self.weather_data['temp_air'], self.weather_data['relative_humidity'])
def get_from_pvgis(lat, lon, tz): """Return the pvgis data""" # PVGIS information info = get_pvgis_tmy(lat, lon) # Altitude alt = info[2]['location']['elevation'] # Get th principal information df = info[0] # Convert UTC to time zone df.index = df.index.tz_convert(tz) df.index.name = f'Time {tz}' # Get the solar position solpos = get_solarposition(time=df.index, latitude=lat, longitude=lon, altitude=alt, pressure=df.SP, temperature=df.T2m) # Create the schema data = df data = data.drop(df.columns, axis=1) data['HourOfDay'] = df.index.hour data['Zenith'] = solpos['zenith'] data['Temperature'] = df.T2m data['Humidity'] = df.RH data['WindSpeed'] = df.WS10m data['WindDirection'] = df.WD10m data['PrecipitableWater'] = gueymard94_pw(df.T2m, df.RH) data['Pressure'] = df.SP data['ExtraRadiation'] = get_extra_radiation(df.index) data['GHI'] = df['G(h)'] return data