Skip to content

Commit

Permalink
Change output data format (#108)
Browse files Browse the repository at this point in the history
* Update TPM.jl

Change the output file name.

* Update TPM.jl

Change the data format of the surface temperature `result.surf_temp`

* Update TPM.jl

Change the output file name

* Update TPM.jl

Change the data format of the subsurface temperature `result.face_temp`

* Update TPM.jl

Just a cleanup
  • Loading branch information
MasanoriKanamaru authored Dec 10, 2023
1 parent 9890ec2 commit 709c544
Showing 1 changed file with 22 additions and 13 deletions.
35 changes: 22 additions & 13 deletions src/TPM.jl
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,6 @@ Export the result of `SingleTPM` to CSV files.
# Arguments
- `dirpath` : Path to the directory to save CSV files
- `result` : Output data format for `SingleTPM`
# TO DO
- Save the depths of the calculation nodes
- Save README for the data file
"""
function export_TPM_results(dirpath, result::SingleTPMResult)

Expand All @@ -407,23 +403,36 @@ function export_TPM_results(dirpath, result::SingleTPMResult)
df.torque_y = [τ[2] for τ in result.torque]
df.torque_z = [τ[3] for τ in result.torque]

CSV.write(joinpath(dirpath, "data.csv"), df)
CSV.write(joinpath(dirpath, "physical_quantities.csv"), df)

##= Surface temperature =##
filepath = joinpath(dirpath, "surf_temp.csv")
header = string.(result.times_to_save)
df = DataFrame(result.surf_temp, header)
filepath = joinpath(dirpath, "surface_temperature.csv")
df = hcat(
DataFrame(time=result.times_to_save),
DataFrame(result.surf_temp', ["face_$(i)" for i in 1:size(result.surf_temp, 1)]),
)

CSV.write(filepath, df)

##= Subsurface temperature =##
for (nₛ, temp) in result.face_temp
filepath = joinpath(dirpath, "face_temp_$(lpad(nₛ, 7, '0')).csv")
header = string.(result.times_to_save)
df = hcat(DataFrame(depth_nodes=result.depth_nodes), DataFrame(temp, header))
filepath = joinpath(dirpath, "subsurface_temperature.csv")

nrows = length(result.depth_nodes) * length(result.times_to_save)
df = DataFrame(
time = reshape([t for _ in result.depth_nodes, t in result.times_to_save], nrows),
depth = reshape([d for d in result.depth_nodes, _ in result.times_to_save], nrows),
)

CSV.write(filepath, df)
# Add a column for each face
for (nₛ, face_temp) in collect(result.face_temp)
df[:, "face_$(nₛ)"] = reshape(face_temp, length(face_temp))
end

# Sort the columns by the face ID
keys_sorted = sort(names(df[:, 3:end]), by=x->parse(Int, replace(x, r"[^0-9]" => "")))
df = df[:, ["time", "depth", keys_sorted...]]

CSV.write(filepath, df)
end


Expand Down

0 comments on commit 709c544

Please sign in to comment.