Skip to content

Commit

Permalink
Merge pull request #13 from MineralsCloud:DimensionalData
Browse files Browse the repository at this point in the history
Return `DimArray` instead of `DataFrame` in `read_f_tv` & `read_f_tp`
  • Loading branch information
singularitti committed Sep 1, 2023
2 parents 14863ac + 8009b43 commit f6cf1c8
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 6 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ version = "0.1.2-DEV"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
CondaPkg = "992eb4ea-22a4-4c89-a5bb-47a3300528ab"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0"
PythonCall = "6099a3de-0909-46bc-b1f4-468b9a2dfc0d"
PythonCallHelpers = "82926614-86f1-43a3-92dc-771be2bbc0fa"
RecipesBase = "3cdcf5f2-1ef4-517c-9805-6587b60abb01"
Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"

[compat]
CondaPkg = "0.2"
Expand Down
1 change: 1 addition & 0 deletions src/PyQHA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function __init__()
end
end

include("data.jl")
include("Settings.jl")
include("Calculators.jl")
include("io.jl")
Expand Down
16 changes: 16 additions & 0 deletions src/data.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using DimensionalData: DimensionalData, Dimensions, DimArray, @dim

export Temperature, Volume, Pressure, FreeEnergy

@dim Temperature "Temperature"
@dim Volume "Volume"
@dim Pressure "Pressure"

FreeEnergy(data::AbstractMatrix, temperature::Temperature, pressure::Pressure) =
DimArray(data, (temperature, pressure); name="free energy")
FreeEnergy(data::AbstractMatrix, pressure::Pressure, temperature::Temperature) =
DimArray(data, (pressure, temperature); name="free energy")
FreeEnergy(data::AbstractMatrix, temperature::Temperature, volume::Volume) =
DimArray(data, (temperature, volume); name="free energy")
FreeEnergy(data::AbstractMatrix, volume::Volume, temperature::Temperature) =
DimArray(data, (volume, temperature); name="free energy")
16 changes: 11 additions & 5 deletions src/io.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
using CSV: File
using DataFrames: DataFrame
using Tables: matrix

export read_f_tv, read_f_tp

function read_f_tv(path)
file = File(path; delim=" ", header=1, ignorerepeated=true)
return DataFrame(file)
file = File(path; delim=" ", header=false, ignorerepeated=true)
rawdata = matrix(file)
volumes = Volume(rawdata[1, 2:end])
temperatures = Temperature(map(Base.Fix1(parse, Float64), rawdata[2:end, 1]))
return DimArray(rawdata[2:end, 2:end], (temperatures, volumes))
end

function read_f_tp(path)
file = File(path; delim=" ", header=1, ignorerepeated=true)
return DataFrame(file)
file = File(path; delim=" ", header=false, ignorerepeated=true)
rawdata = matrix(file)
pressures = Pressure(rawdata[1, 2:end])
temperatures = Temperature(map(Base.Fix1(parse, Float64), rawdata[2:end, 1]))
return DimArray(rawdata[2:end, 2:end], (temperatures, pressures))
end

function save_x_tp(df, t, desired_pressures_gpa, p_sample_gpa, outfile_name)
Expand Down
35 changes: 35 additions & 0 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,38 @@ using RecipesBase: @recipe, @userplot, @series
end
end
end

@userplot TempPressPlot
@recipe function f(plot::TempPressPlot)
# See http://juliaplots.org/RecipesBase.jl/stable/types/#User-Recipes-2
path = first(plot.args)
rawdata = read_f_tp(path)
pressures = map(Base.Fix1(parse, Float64), names(rawdata)[2:end])
r = length(plot.args) == 2 ? plot.args[end] : range(1; stop=size(rawdata, 1), length=5)
r = convert(StepRange{Int64,Int64}, r)
temperatures = collect(rawdata[r, 1])
data = (collect(values(row)) for row in eachrow(rawdata[r, 2:end]))
size --> (800, 500)
markersize --> 2
markerstrokecolor --> :auto
markerstrokewidth --> 0
xlims --> extrema(pressures)
xguide --> "pressures"
guidefontsize --> 11
tickfontsize --> 9
legendfontsize --> 9
legend_foreground_color --> nothing
legend_position --> :top
frame --> :box
margin --> (1.3, :mm)
palette --> :tab20
grid --> nothing
for (temperature, datum) in Iterators.reverse(zip(temperatures, data))
@series begin
seriestype --> :path
z_order --> :back
label --> "T=" * string(temperature) * " K"
pressures, datum
end
end
end

0 comments on commit f6cf1c8

Please sign in to comment.