JuliaRheology / RHEOS.jl

RHEOS - Open Source Rheology data analysis software
MIT License
39 stars 9 forks source link

Unicode symbols cause problems with PyJulia #118

Closed akabla closed 3 years ago

akabla commented 3 years ago

This is related to #116

I think we should provide options to access all RHEOS functionalities without having to use Unicode symbols.

This would involve:

  1. providing alternative names for passing model parameter values, eg eta or c_beta, and let RHEOS convert the symbols where appropriate.
  2. allowing several keyword parameters for certain functions, such as importcsv and RheoTimeData constructor.
  3. providing functions to access the stress and strain fields of RheoTimeData, and in other relevant places.

One option for 1 is to have a const named tuple with a symbol conversion table, and then convert symbols in check_and_reorder_parameters

julia> d=(eta=:η, c_alpha=:c_α)
(eta = :η, c_alpha = :c_α)

julia> nt = (k=1.0, eta=2.0, c_alpha=4.5)
(k = 1.0, eta = 2.0, c_alpha = 4.5)

julia> NamedTuple{Tuple([ s in keys(d) ? d[s] : s for s in keys(nt) ])}(values(nt))
(k = 1.0, η = 2.0, c_α = 4.5)

For 2, this could maybe be achieved like this:

function RheoTimeData(;strain = RheoFloat[],  ϵ::Vector{T1} = strain, stress = RheoFloat[], σ::Vector{T2} = stress, ...
akabla commented 3 years ago

Here is a bit of code that now works fine without using unicode symbols.

using RHEOS
using Plots

data = importcsv("C1_S_0A5_90_rheos.csv", time = 1, strain = 2, stress = 3)
plot(gettime(data), getstrain(data), getstress(data))

model=modelfit(data, FractD_Maxwell, stress_imposed, p0=(beta=0.05, c_beta=0.05, eta=10.0))

print(getparams(model, unicode=false))
# (eta = 65.17997591394088, c_beta = 0.08515319205963537, beta = 0.08989064046489526)

data_stress = extract(data, stress_only)

data_fit = modelpredict(data_stress, model)

plot(gettime(data_fit),[getstrain(data_fit), getstrain(data)])