async def async_update(self): """Fetch new state data for the sensor.""" dry_temp = self.get_dry_temp(self._entity_dry_temp) rel_hum = self.get_rel_hum(self._entity_rel_hum) if dry_temp is not None and rel_hum is not None: import psychrolib psychrolib.SetUnitSystem(psychrolib.SI) TDewPoint = psychrolib.GetTDewPointFromRelHum(dry_temp, rel_hum) self._state = round(TDewPoint, 1)
async def async_update(self): """Fetch new state data for the sensor.""" dry_temp = self.get_dry_temp(self._entity_dry_temp) rel_hum = self.get_rel_hum(self._entity_rel_hum) pressure = self.get_press(self._entity_press) if dry_temp is not None and rel_hum is not None and press is not None: import psychrolib psychrolib.SetUnitSystem(psychrolib.SI) MoistAirDensity = psychrolib.GetMoistAirDenisity(dry_temp, rel_hum, press) self._state = round(MoistAirDensity, 1)
def import_weather_data(self, file_path): """Reads weather hourly data from file path. 8760hrs of DB and Dew Point expected""" psychrolib.SetUnitSystem(psychrolib.IP) self.tmy3 = pd.read_csv(file_path, skiprows=list(range(18)), header=0, index_col=[0, 1], usecols=[0, 1, 3, 4, 5]) self.ambient_db = np.array( self.tmy3['Dry Bulb Temperature {C}']) * 9 / 5 + 32 self.ambient_dp = np.array( self.tmy3['Dew Point Temperature {C}']) * 9 / 5 + 32 self.ambient_rh = np.array(self.tmy3['Relative Humidity {%}']) / 100 self.air_entering_w = psychrolib.GetHumRatioFromRelHum( self.ambient_db, self.ambient_rh, self.PRESSURE) self.air_entering_h = psychrolib.GetMoistAirEnthalpy( self.ambient_db, self.air_entering_h) self.air_entering_wb = psychrolib.GetTWetBulbFromTDewPoint( self.ambient_db, self.ambient_dp, self.PRESSURE)
import psychrolib psychrolib.SetUnitSystem(psychrolib.SI) print("") inval = input ("Please enter the dry-bulb temperature: ") inv = float(inval) print("") inval3 = input ("Please enter the humidity ratio: ") inv3 = float(inval3) enth = psychrolib.GetMoistAirEnthalpy(inv, inv3) ens = str(enth) enth2 = psychrolib.GetSatAirEnthalpy(inv, inv3) ensb = str(enth2) enth3 = psychrolib.GetDryAirEnthalpy(inv) ensc = str(enth3) print("") print ("The moist-air enthalpy is: " + ens)
import regionmask import seaborn as sns import warnings import xarray as xr from collections import defaultdict from intake import open_catalog from matplotlib.colors import Normalize from matplotlib.lines import Line2D from pathlib import Path from scipy import stats from src import Labour absolute_zero = -273.15 psl.SetUnitSystem(psl.SI) plt.style.use("seaborn-colorblind") # Dictionary for translating month names month_dict = defaultdict(lambda: -1) for i in range(1, 13): month_dict[calendar.month_abbr[i]] = i month_dict[None] = -1 # Silence warning about dividing by 0 or nan. np.seterr(divide="ignore", invalid="ignore") warnings.filterwarnings("once", ".*No gridpoint belongs to any region.*") warnings.filterwarnings("once", ".*Geometry is in a geographic CRS.*") warnings.filterwarnings("once", ".*invalid value .*") warnings.filterwarnings("once", ".*All-NaN slice.*") warnings.filterwarnings("once", ".*invalid value encountered in.*")
## Memory Optimization # https://www.kaggle.com/rohanrao/ashrae-divide-and-conquer @vopani # Original code from https://www.kaggle.com/gemartin/load-data-reduce-memory-usage by @gemartin import gc import numpy as np import pandas as pd from pandas.api.types import is_datetime64_any_dtype as is_datetime from pathlib import Path import zipfile from sklearn.experimental import enable_iterative_imputer from sklearn.impute import IterativeImputer import psychrolib as psychrometric psychrometric.SetUnitSystem(psychrometric.SI) DATA_PATH = Path.cwd() / 'data/raw' assert DATA_PATH.exists(), DATA_PATH DATA_FEATHER_PATH = Path.cwd() / 'data/feather' DATA_FEATHER_PATH.mkdir(parents=True, exist_ok=True) ZIPPED = False MERGE = True MERGE_ON_NAN_CLEANING = True def reduce_mem_usage(df, use_float16=False): """ iterate through all the columns of a dataframe and modify the data type to reduce memory usage. """
# Fig 1c import psychrolib as psy import numpy as np # Set the unit system, for example to SI (can be either psychrolib.SI or psychrolib.IP) psy.SetUnitSystem(psy.SI) amb_pressure = 86846.203 #pa Tdb = np.array([[20.5, 19.8, 18.1, 20.2, 21.5], [20.8, 19.9, 17.4, 19.5, 21.4], [21.2, 20.2, 19.4, 21.2, 21.9]]) Twb = np.array([[10.0, 13.9, 17.2, 19.8, 19.0], [10.3, 13.1, 16.2, 18.6, 18.7], [10.3, 15.6, 18.8, 21.1, 19.6]]) spec_vol_air = np.zeros([Tdb.shape[0], Tdb.shape[1]]) spec_hum = np.zeros([Tdb.shape[0], Tdb.shape[1]]) for i in range(Tdb.shape[0]): for j in range(Tdb.shape[1]): spec_hum[i, j] = psy.GetSpecificHumFromHumRatio( psy.GetHumRatioFromTWetBulb(Tdb[i, j], Twb[i, j], amb_pressure)) # spec_vol_air[i,j] = psy.GetDryAirVolume(Tdb[i,j], amb_pressure) spec_vol_air[i, j] = psy.GetMoistAirVolume( Tdb[i, j], psy.GetHumRatioFromTWetBulb(Tdb[i, j], Twb[i, j], amb_pressure), amb_pressure) print(spec_vol_air) # fig 1e print(spec_hum) # fig 1f for i in range(3):
def SetUnitSystem_SI(): psychrolib.SetUnitSystem(psychrolib.SI) psyf.setunitsystem(2) psyc.SetUnitSystem(2)
def SetUnitSystem_IP(): psychrolib.SetUnitSystem(psychrolib.IP) psyf.setunitsystem(1) psyc.SetUnitSystem(1)