Created
November 28, 2020 14:29
-
-
Save rogervs/ff54a81167466cc7de3c103ecb58dd35 to your computer and use it in GitHub Desktop.
Relates to cadCAD tutorial, lecture 7.3, 21:00 minutes in.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Get system events and attribute index | |
df = (pd.DataFrame(system_events) | |
.assign(years=lambda df: df.timestep) | |
.assign(temperature_celsius=lambda df: df.temperature - 273) | |
.query('timestep > 0') | |
) | |
# Clean substeps | |
first_ind = (df.substep == 0) & (df.timestep == 0) | |
class tcolors: | |
HEADER = '\033[95m' | |
OKBLUE = '\033[94m' | |
OKCYAN = '\033[96m' | |
OKGREEN = '\033[92m' | |
WARNING = '\033[93m' | |
FAIL = '\033[91m' | |
ENDC = '\033[0m' | |
BOLD = '\033[1m' | |
UNDERLINE = '\033[4m' | |
print("first_ind evaluation: ") | |
print("--------------------") | |
for i in [0,1,2,3]: | |
if i == 0: | |
watch = tcolors.OKBLUE | |
else: | |
watch = '' | |
print(f"{watch}df.substep == {i} TRUE count:", (df.substep == i).sum(), f"{tcolors.ENDC}") | |
print() | |
for i in [0,1,2,3,99,100,101]: | |
if i == 0: | |
watch = tcolors.OKBLUE | |
else: | |
watch = '' | |
print(f"{watch}df.timestep == {i} TRUE count:", (df.timestep == i).sum(), f"{tcolors.ENDC}") | |
print() | |
print(f"{tcolors.OKBLUE}first_ind = (df.substep == 0) & (df.timestep == 0){tcolors.ENDC}") | |
print("first_ind total:", first_ind.count()) | |
print("first_ind TRUE count:", (first_ind == True).sum()) | |
print("first_ind FALSE count:", (first_ind == False).sum()) | |
print() | |
print("-"*70) | |
print() | |
print("last_ind evaluation: ") | |
print("--------------------") | |
last_ind = df.substep == max(df.substep) | |
print(f"{tcolors.OKBLUE}last_ind = max(df.substep){tcolors.ENDC}") | |
print(last_ind[:10]) | |
print() | |
print("last_ind total:", last_ind.count()) | |
print("last_ind TRUE count:", (last_ind == True).sum()) | |
print("last_ind FALSE count:", (last_ind == False).sum()) | |
print() | |
print("-"*70) | |
print("inds_to_drop evaluation:") | |
print("------------------------") | |
print("# of True in first_ind: ", (first_ind == True).sum()) | |
print("Length of first_ind", len(first_ind)) | |
print("# of True last_ind: ", (last_ind == True).sum()) | |
print("Length of last_ind", len(last_ind)) | |
print() | |
print(f"{tcolors.OKBLUE}inds_to_drop = (first_ind | last_ind){tcolors.ENDC}") | |
inds_to_drop = (first_ind | last_ind) | |
print("inds_to_drop total: ", inds_to_drop.count()) | |
print("inds_to_drop True count: ",(inds_to_drop == True).sum()) | |
print("inds_to_drop False count: ",(inds_to_drop == False).sum()) | |
df = df.loc[inds_to_drop].drop(columns=['substep']) | |
# Attribute parameters to each row | |
df = df.assign(**configs[0].sim_config['M']) | |
for i, (_, n_df) in enumerate(df.groupby(['simulation', 'subset', 'run'])): | |
df.loc[n_df.index] = n_df.assign(**configs[i].sim_config['M']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment