sluyspy.weather module
Weather functions for the sluyspy package
- sluyspy.weather.absolute_humidity_from_tempc_rh(temp_c, rh)[source]
Compute the absolute humidity (water-vapor density) from the temperature and relative humidity.
- Parameters:
temp_c (float) – Air temperature (degrees Celsius).
rh (float) – Relative humidity (fraction).
- Returns:
Absolute humidity (water-vapor density; g/m^3).
- Return type:
(float)
- sluyspy.weather.dew_point_from_tempc_rh(temp_c, rh)[source]
Compute the dew point from the temperature and relative humidity.
- Parameters:
temp_c (float) – Air temperature (degrees Celsius).
rh (float) – Relative humidity (fraction).
- Returns:
Dew point (degrees Celsius).
- Return type:
(float)
- sluyspy.weather.knmi_datetime_from_datehour(knmi_data)[source]
Return a datetime column named ‘dtm’ for given KNMI date and hour columns.
The KNMI date is expressed as an integer formatted as YYYYMMDD, while the hours run from 1-24 rather than from 0-23. This causes problems when converting to Python or Pandas datetime objects.
- Parameters:
knmi_data (Pandas df) – KNMI weather dataframe.
- Returns:
KNMI weather dataframe.
- Return type:
(Pandas df)
- sluyspy.weather.knmi_read_hourly_weather(filename, start_date=None, end_date=None, tidy=True)[source]
Reads a KNMI file containing hourly weather measurement data from a particular station.
Reads the CSV files provided on the KNMI website for the weather data over the last decade from a chosen station. This function reads the weather data from a chosen start date to the chosen end date, which is NOT included. For example, for the whole of the year 2020, specify 2020,1,1, 2021,1,1.
- Parameters:
filename (str) – filename to select the specific station, this is “uurgeg_260_2011-2020_Bilt.csv” for De Bilt
start_date (datetime) – start date: date of the first data entry to be returned (timezone aware; optional).
end_date (datetime) – end date: date of the first data entry NOT to be returned (timezone aware; optional).
tidy (bool) – tidy up: remove station column, convert silly date and time to datetime, temperature to °C and sunshine to a fraction (optional).
- Returns:
Table containing ~23-25 columns with weather data.
yyyymmdd (int): Date (YYYY=year,MM=month,DD=day).
hh (int): Time in hours (note: 1-24!), the hourly division 05 runs from 04.00 UT to 5.00 UT.
dtm (datetime): Date and time of the entry (UT), replacing yyyymmdd and hh.
t (float): Temperature at 1.50 m at the time of observation (°C).
sq (float): Fraction of the hour with sunshine (0-1).
q (float): Global horizontal radiation (W/m^2 (or J/cm^2/h)).
- Return type:
pandas.DataFrame
- sluyspy.weather.knmi_station_data(remove_nans=False)[source]
Return a Pandas DataFrame containing the data of Dutch KNMI weather stations.
- Parameters:
remove_nans (bool) – Remove entries containing a NaN. Optional; defaults to False.
- Returns:
Pandas DataFrame containing and index and five columns:
index (int): Station number. Note that most stations start with a leading zero, which is omitted here.
lon (float): Geographical longitude of the station, in radians east of Greenwich.
lat (float): Geographical latitude of the station, in radians north of the equator.
alt (float): Altitude of the station above sea level, in metres.
name (str): (A) name of the station.
- fname (str): String to compose a file name from. This is the name from the KNMI .nc files,
in lower case, with spaces and slashes replaced by underscores, and brackets removed.
- Return type:
(pd.df)
- sluyspy.weather.water_vapor_saturated_density_from_tempc(temp_c)[source]
Compute the saturated water-vapor density in air for a given temperature.
- Parameters:
temp_c (float) – Air temperature (degrees Celsius).
- Returns:
Saturated water-vapor density (g/m^3).
- Return type:
(float)
Note
uses data from http://hyperphysics.phy-astr.gsu.edu/hbase/kinetic/relhum.html#c3: - for T= -10 - +60°C.
drops to 0 below T~-25°C;
significantly better results than original fit (3rd order polynomial): - for T<~-15°C and T>~45°C: by eye; - for -10°C < T < 60°C (range original fit -0°C < T < 40°C):
typical sigma 0.116 (T=0-40°C) -> 0.030 g/m^3 (T=-10-60°C);
max. abs. deviation: 0.168 g/m^3 (T=0-40°C; @T=0°C) -> 0.0445 g/m^3 (T=-10-60°C; @T=25°C)
max. rel. deviation: 3.46 % (T=0-40°C; @T=0°C) -> 0.194 % (T=-10-60°C; @T=25°C)
- sluyspy.weather.wind_chill_temperature(temp, wind_vel)[source]
Compute wind-chill (“real-feel”) temperature from the air temperature and wind velocity.
- Parameters:
temp (float) – Air temperature at 1.5m above ground (°C).
wind_vel (float) – Wind velocity at 10m above ground (m/s).
- Returns:
Wind-chill temperature (°C).
- Return type:
(float)
- Source:
https://en.wikipedia.org/wiki/Wind_chill - but wind speed in m/s instead of km/h (3.6^0.16*11.37=13.96; 3.6^0.16*39.65=48.67). - ensure that the wind chill NEVER exceeds the temperature (was: only if wind_vel < 1.3).
note: the power 0.16 converts 10m wind velocity to 1.5m.