Skip to content

Conversation

@DanTanAtAims
Copy link
Collaborator

Update result store to use YAXArrays and NetCDF.

After each counterfactual and intervention run call.

append_all_results(result_store::ResultStore, start_year::Int, end_year::Int, reps::Int)

This will add the results to the YAXArray dataset and add rows to the scenario DataFrame reflecting scenario intervention factors.

├─RME_outcomes_yyyy-mm-dd-HH-MM-SS
│       results.nc
│       scenarios.csv

rename append_all_results! to concat_results! and preallocate_append to preallocate_concat
Comment on lines 31 to 33
```julia
count::Float64 = @getRME ivOutplantCountPerM2("iv_name"::Cstring)::Cdouble.
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

Hey @DanTanAtAims what's the difference between the two below?

@getRME ivOutplantCountPerM2("iv_name"::Cstring)::Cdouble

# and

@RME ivOutplantCountPerM2("iv_name"::Cstring)::Cdouble

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The second will error out when there was no error. In the RME macro

macro RME(func)
    local m = esc(Meta.parse("@ccall RME.$(func)"))
    return quote
        local err = $m

---->   if !(typeof(err) <: Cstring) && err != 0 && !(typeof(err) <: Cvoid) # <--- this condition prevents function calls that return numbers to fail.
            local err_msg = @ccall RME.lastError()::Cstring
            throw(ArgumentError("Call to RME failed with message: $(unsafe_string(err_msg))"))
        end
        ...
    end
end

The conditions of the if statement are evaluated as follows for getters that return numeric, non-error values

!(Cdouble <: Cstring) (true)
err != 0 (true) # Importantly no error has occurred. 
!(typeof(err) <: Cvoid) (true)

So we enter the error if block. We should only use the new macro @getRME when we have no choice as we lose the safety of the error checking in the original macro.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yep, obvious now, sorry.

Copy link
Collaborator

@ConnectedSystems ConnectedSystems left a comment

Choose a reason for hiding this comment

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

Very last comment to address Dan, thank you.


# Collect and store all results, where `reps` is the total number of expected runs.
collect_all_results!(result_store, start_year, end_year, reps)
append_all_results!(result_store, start_year, end_year, reps)
Copy link
Collaborator

Choose a reason for hiding this comment

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

These examples need to be updated

# Examples
```julia
count::Float64 = @getRME ivOutplantCountPerM2("iv_name"::Cstring)::Cdouble
Copy link
Collaborator

Choose a reason for hiding this comment

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

One more - update example variable as count is also a function.

Suggested change
count::Float64 = @getRME ivOutplantCountPerM2("iv_name"::Cstring)::Cdouble
count_per_m2::Float64 = @getRME ivOutplantCountPerM2("iv_name"::Cstring)::Cdouble

Copy link
Collaborator

@ConnectedSystems ConnectedSystems left a comment

Choose a reason for hiding this comment

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

Thanks @DanTanAtAims

@ConnectedSystems ConnectedSystems merged commit e045821 into main Apr 18, 2024
@ConnectedSystems ConnectedSystems deleted the result-store-update branch April 18, 2024 00:30
@ConnectedSystems ConnectedSystems mentioned this pull request Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants