Skip to content

Commit

Permalink
Bugfix for OutputWriters
Browse files Browse the repository at this point in the history
Use PALEOmodel.field_single_element(field) to ensure that DataFrame has same record types for each output Field
as corresponding FieldRecord
  • Loading branch information
Stuart Daines committed Apr 19, 2022
1 parent 4e3e68d commit c724648
Showing 1 changed file with 17 additions and 9 deletions.
26 changes: 17 additions & 9 deletions src/OutputWriters.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ function PB.add_field!(output::PALEOmodel.AbstractOutputWriter, fr::PALEOmodel.F
OutputMemoryDomain
In-memory model output, for one model Domain.
Includes an additional `coords_record` (usually `:tmodel`, when storing output vs time).
# Implementation
`data::DataFrame` contains columns of same type as `FieldRecord.records` for each Variable.
"""
mutable struct OutputMemoryDomain
"Domain name"
Expand Down Expand Up @@ -165,18 +170,20 @@ function OutputMemoryDomain(

# add variables
for var in odom._all_vars
values = PB.get_data_output(var, modeldata)
if length(values) == 1
# save as Vector of scalars
arraytype = eltype(values)
# records storage type is that of FieldRecord.records
field = PB.get_field(var, modeldata)
if PALEOmodel.field_single_element(field)
# if Field contains single elements, store as a Vector of elements
records = Vector{eltype(field.values)}(undef, nrecords)
else
# save as Vector of arrays
arraytype = typeof(values)
# if Field contains something else, store as a Vector of those things
records = Vector{typeof(field.values)}(undef, nrecords)
end

DataFrames.insertcols!(
odom.data,
DataFrames.ncol(odom.data)+1,
Symbol(var.name) => Vector{arraytype}(undef, nrecords)
Symbol(var.name) => records
)

attrbs = deepcopy(var.attributes)
Expand Down Expand Up @@ -261,9 +268,10 @@ function add_record!(odom::OutputMemoryDomain, modeldata, rec_coord)
df[!, odom.coords_record][odom._nrecs] = rec_coord

for var in odom._all_vars
values = PB.get_data_output(var, modeldata)
field = PB.get_field(var, modeldata)
values = PB.get_values_output(field)

if length(values) == 1
if PALEOmodel.field_single_element(field)
df[!, Symbol(var.name)][odom._nrecs] = values[]
else
# copy array(s) data
Expand Down

2 comments on commit c724648

@sjdaines
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request updated: JuliaRegistries/General/58608

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.14.0 -m "<description of version>" c724648ff3eeff96724f093794274dacfb329f6e
git push origin v0.14.0

Also, note the warning: This looks like a new registration that registers version 0.14.0.
Ideally, you should register an initial release with 0.0.1, 0.1.0 or 1.0.0 version numbers
This can be safely ignored. However, if you want to fix this you can do so. Call register() again after making the fix. This will update the Pull request.

Please sign in to comment.