GeoscienceAustralia / HiQGA.jl

High Quality Geophysical Analysis provides a general purpose Bayesian and deterministic inversion framework for various geophysical methods and spatially distributed / timeseries data
MIT License
38 stars 5 forks source link

Write ASEG-GDF files for deterministic inversions #63

Closed a2ray closed 6 months ago

a2ray commented 7 months ago

Can do by using https://github.com/GeoscienceAustralia/HiQGA.jl/blob/251725931dac63a885999d558791f8dc5470b721/src/CommonToAll.jl#L1893 and writing out appropriate headers

a2ray commented 7 months ago

A nice first try. Now see if writing something like this as a function doesn't help. This will work for an arbitrary number of inputs, both scalar and vector fields, for a row of data in vtest. The function should take in a vector like vtest and a format string for each element of vtest like sfmt.

vtest=[1, [2., 3.]]
sfmt = ["%2i", "%15.2f"]
for (el, fmt) in zip(vtest, sfmt)
    # @show el, fmt
    if isa(el, Array) 
        ifmt = ""
        for iel in el
               ifmt *= fmt
        end
        s = Printf.format(Printf.Format(ifmt), el...)
    else
        s = Printf.format(Printf.Format(fmt), el)
    end
    print(s)
end
print("\n")

which gives

1           2.00           3.00

also, for the DFN header lines, an easier way is to write in triple quotes

somevalue = 2
a = 
"""
this is formatted to $somevalue
and also to $(2somevalue)
"""
print(a)

which gives

julia> this is formatted to 2
and also to 4

remembering to redirect output to io where io is an opened file pointer.

rade7 commented 7 months ago

Will also need as an input, a vector of strings of same size as vtest in https://github.com/GeoscienceAustralia/HiQGA.jl/issues/63#issuecomment-1905205744 so as to make DFN file fieldnames.

a2ray commented 7 months ago

As discussed, two ways to work over rows in a matrix, through a function that accepts vectors (i.e., rows)

function vecref(vectest, stringwithvec)
    for (el, str) in zip(vectest, stringwithvec)
        print(" $el "*str)
    end
    print("\n")
end

## write one line
vecref([1990, 2000],["year 1", "year 2"]) 
## write 2 lines
vecref.([[1990, 2000], [1995, 2003]], Ref(["year 1", "year 2"]))
## write 3 lines as a map
A = [1990 2000; 1995 2003; 2000 2008]
str = ["year 1", "year 2"]
map(eachrow(A)) do a
    vecref(a, str)
end
rade7 commented 7 months ago

Initial changes made in bd50840b35f93e3aa580966ffe037a0af7f16967

a2ray commented 7 months ago

Please see comments made to commit bd50840 and open a pull request once addressed.

a2ray commented 6 months ago

fixed by edde0ac974d3d90ae3aca926c87963f9df1b3164