Skip to content

Commit

Permalink
Organize plots into subfolders (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
zexianli authored Feb 6, 2023
1 parent e64a7c1 commit c79b9e7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 26 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ data.zip
test_data
plots
.vscode
data_processed

# Byte-compiled / optimized / DLL files
__pycache__/
Expand Down
19 changes: 1 addition & 18 deletions data_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ def find_valid_files(self, min_file_size: int = 1000000) -> dict:
return folder_file_map

def get_time_delta(self, df: pd.DataFrame, deploy_time: pd.Timestamp):
# print(type(df.iloc[0]["Time"].item()))
print("-", deploy_time, df.iloc[0]["Time"].item())
print("- Time delta:", pd.Timedelta(
deploy_time - df.iloc[0]["Time"].item()))
Expand All @@ -76,8 +75,6 @@ def l1_formatting(self, folders: dict):

dfs[dendrometer_id] = (file, df.copy())
# print(df.head())
# print(type(df["VPD"].values.flatten()),
# df["VPD"].values.flatten())
print("-------------------------------------------")

plotter = Plotter()
Expand All @@ -87,6 +84,7 @@ def l1_formatting(self, folders: dict):
for _, (filename, df) in dfs.items():
plotter.save_plot(filename, df)
plotter.save_plot_vpd(filename, df)
plotter.save_csv(filename, df)

for pair in pair_mapping.values():
dend1, dend2 = pair
Expand Down Expand Up @@ -172,21 +170,6 @@ def adjust_flow(self, df: pd.DataFrame) -> pd.DataFrame:

return df

def save_plot(self, df: pd.DataFrame, filename) -> None:
filename = filename.with_suffix('')
dend_file_name = str(filename).split("/")[-2:]
plot_title = f"Dendrometer_{dend_file_name[0]}_{dend_file_name[1]}"

plt.figure(dpi=600, figsize=(11.69, 8.27))
fig1 = plt.subplot()
fig1.set_title(plot_title)
fig1.plot(df["Time"], df[('AS5311', 'Serial_Value')])
fig1.plot(df["Time"], df['Calculated'])
fig1.legend(['Raw data', 'Over/Under flow adjusted'])
fig1.set_xlabel("Time")
fig1.set_ylabel("Displacement (serial value)")
plt.savefig(f"data/{dend_file_name[0]}/{dend_file_name[1]}.pdf")


def main():
formatter = DataFormatter()
Expand Down
35 changes: 27 additions & 8 deletions plotter.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,22 @@ def load_deployment_map(self):
def get_pair_mapping(self):
return self.pairs

def save_plot(self, filename, df: pd.DataFrame) -> None:
def save_csv(self, filename, df: pd.DataFrame) -> None:
filename = filename.with_suffix('')
dend_file_name = str(filename).split("/")[-2:]
plot_title = f"Dendrometer_{dend_file_name[0]}_{dend_file_name[1]}"

Path(Path.joinpath(Path.cwd(), "data_processed", "csv")) \
.mkdir(parents=True, exist_ok=True)

df.to_csv(
f"data_processed/{dend_file_name[0]}_{dend_file_name[1]}.csv"
f"data_processed/csv/{dend_file_name[0]}_{dend_file_name[1]}.csv"
)

def save_plot(self, filename, df: pd.DataFrame) -> None:
filename = filename.with_suffix('')
dend_file_name = str(filename).split("/")[-2:]
plot_title = f"Dendrometer_{dend_file_name[0]}_{dend_file_name[1]}"

plt.figure(dpi=600, figsize=(11.69, 8.27))
fig1 = plt.subplot()
fig1.set_title(plot_title)
Expand All @@ -51,7 +59,12 @@ def save_plot(self, filename, df: pd.DataFrame) -> None:
fig1.legend(['Raw data', 'Over/Under flow adjusted'])
fig1.set_xlabel("Time")
fig1.set_ylabel("Displacement (serial value)")
plt.savefig(f"data/{dend_file_name[0]}/{dend_file_name[1]}.pdf")

Path(Path.joinpath(Path.cwd(), "data_processed", "single")) \
.mkdir(parents=True, exist_ok=True)
plt.savefig(
f"data_processed/single/{dend_file_name[0]}_{dend_file_name[1]}.pdf")

plt.close()

def save_plot_pair(self,
Expand Down Expand Up @@ -81,7 +94,11 @@ def save_plot_pair(self,

fig1.set_xlabel("Time")
fig1.set_ylabel("Displacement (serial value)")
plt.savefig(f"data/pairs/{plot_title}.pdf")

Path(Path.joinpath(Path.cwd(), "data_processed", "pairs")) \
.mkdir(parents=True, exist_ok=True)
plt.savefig(f"data_processed/pairs/{plot_title}.pdf")

plt.close()

def save_plot_vpd(self, filename, df: pd.DataFrame) -> None:
Expand All @@ -100,13 +117,11 @@ def save_plot_vpd(self, filename, df: pd.DataFrame) -> None:

ax2.fill_between(df["Adjusted Time"], df["VPD"].values.flatten(),
color="skyblue", alpha=0.4)
# ax2.plot(df["Adjusted Time"], df['VPD'])
else:
ax1.plot(df["Time"], df['Calculated Serial'], color="orange")

ax2.fill_between(df["Time"], df["VPD"].values.flatten(),
color="skyblue", alpha=0.4)
# ax2.plot(df["Time"], df['VPD'])

fig1.legend(['Serial', 'VPD'])

Expand All @@ -115,7 +130,11 @@ def save_plot_vpd(self, filename, df: pd.DataFrame) -> None:

ax2.set_ylabel("VPD")

Path(Path.joinpath(Path.cwd(), "data_processed", "vpd")) \
.mkdir(parents=True, exist_ok=True)

plt.savefig(
f"data_processed/vpd/{dend_file_name[0]}_{dend_file_name[1]}_vpd.pdf"
)
plt.close()

plt.close('all')

0 comments on commit c79b9e7

Please sign in to comment.