[docs]defobtain_paths(location):"""Obtain the correct name for the data files Args: location (string): Location identifier Raises: ValueError: If location identifier is not defined Returns: List[string]: Naming for the data files """if'az'inlocation.lower():return['AZ','USA_AZ_Phoenix-Sky.Harbor.epw']elif'ca'inlocation.lower():return['CA','USA_CA_San.Jose-Mineta.epw']elif'ga'inlocation.lower():return['GA','USA_GA_Atlanta-Hartsfield-Jackson.epw']elif'il'inlocation.lower():return['IL','USA_IL_Chicago.OHare.epw']elif'ny'inlocation.lower():return['NY','USA_NY_New.York-LaGuardia.epw']elif'tx'inlocation.lower():return['TX','USA_TX_Dallas-Fort.Worth.epw']elif'va'inlocation.lower():return['VA','USA_VA_Leesburg.Exec.epw']elif"wa"inlocation.lower():return['WA','USA_WA_Seattle-Tacoma.epw']else:raiseValueError(f"Location not found, please define the location {location} on obtain_paths() function in utils_cf.py")
[docs]defget_energy_variables(state):"""Obtain energy variables from the energy observation Args: state (List[float]): agent_dc observation Returns: List[float]: Subset of the agent_dc observation """energy_vars=np.hstack((state[4:7],(state[7]+state[8])/2))returnenergy_vars
importjson# Function to get the initial index of the day of a given month from a time-stamped dataset
[docs]defget_init_day(weather_file,start_month=0):""" Obtain the initial day of the year to start the episode. Args: weather_file (str): Path to the weather JSON file. start_month (int, optional): Starting month (0=Jan, 11=Dec). Defaults to 0. Returns: int: Day of the year corresponding to the first day of the month. """assert0<=start_month<=11,"start_month should be between 0 and 11 (inclusive, 0=January, 11=December)."# Load the JSON weather datawithopen(weather_file,'r')asf:weather_data=json.load(f)# Convert timestamps to pandas datetime formattimestamps=pd.to_datetime(weather_data["hourly"]["time"])# Extract the month for each timestampmonths=timestamps.month# Find the first occurrence of the desired monthfirst_index=(months==start_month+1).argmax()# Convert index to day (each day has 24 hours)init_day=first_index//24returninit_day