SpeedyWeather / SpeedyWeather.jl

Play atmospheric modelling like it's LEGO.
https://speedyweather.github.io/SpeedyWeather.jl/dev
MIT License
400 stars 24 forks source link

Modularise netCDF output #522

Open milankl opened 2 months ago

milankl commented 2 months ago

Motivated by discussion in #507 we need to refactor our OutputWriter. Something like this should be possible

# initialise output writer generally but not variable specific
output = OutputWriter(spectral_grid, schedule = Schedule(every = Hour(6)), output_Grid = ...)

# add some variables that should be output with some variable-specific options
add!(output, StreamfunctionOutput(spectral_grid), keepbits=15, compression_level = 2)

# also adds default variables to output, u, v, vor, ...
model = PrimitiveWetModel(;spectral_grid, output)

# remove or add other variables to output
remove!(output, DivergenceOutput)
add!(output, ConvectivePrecipitationOutput(spectral_grid))

so that we have for every variable that should be outputted something like

struct TemperatureOutput{NF} <: AbstractOutputVariable
    NF::DataType = Float32
    dimensions = [true, true, true, true]    # x, y, z, t
    long_name::String = "Temperature"
    units::String = "degC"
    ...
end

output!(::OutputWriter, ::StreamfunctionOutput, ::PrognosticVariables, ::DiagnosticVariables, ::ModelSetup)
    # define here how to take variables from progn, diagn and put them into
    # the nc file in output
    # some variables need unscaling, temperature needs -273.15 for K->˚C
    # pressure needs a exp, precipitation needs unit adjustment etc...
end

which would allow users to define their own output variables with any possible processing