valeriupredoi / bgcval2

Package for BGCVal v2.0
3 stars 0 forks source link

BGCVal2 over two variables #101

Open DrYool opened 11 months ago

DrYool commented 11 months ago

This is a quick yes/no question rather than a service request.

Basically, most (all?) of the variables we process for plots with BGCVal2 are single diagnostics from the model's output files. We might scale with a factor to change units, but that's as far as it goes.

For some TerraFIRMA runs, I'm thinking of culling a lot of diagnostics that BGCVal2 currently uses because they are - essentially - duplicates of other diagnostics that I need to keep for CMOR-isation. However, I can recalculate the versions BGCVal2 currently uses from two variables in the same files as before, e.g. DIN (as before) = DIN_E3T / E3T (proposed).

Before I do the culling, is this something that BGCVal2 would find easy to do? I suspect that it is, but I don't want to just assume this without asking an expert!

Thanks in advance.

(P.S. If this is possible, this is something that I will try myself - I'm not expecting anyone to do this for me.)

valeriupredoi commented 11 months ago

Hi @DrYool and thanks for bringing this up! Of course for an expert-expert opinion I'd defer this to @ledm but if you accept the engineer's version of an answer I'd say yes - I don't think BGCVal2 can do the var derivation for you, and subsequent analysis of the derived variable (we could overload it and ask it to do it, but am pretty sure that's not that easily done); but if you do the derivation yourself and have output at hand, then running BGCVal2 on the derived output should be OK - does this answer your question? :beer:

DrYool commented 11 months ago

Thanks @valeriupredoi. I'm trying to avoid doing any processing of fields outside of BGCVal2. Are you suggesting that this additional step would be necessary? Essentially, netCDF file myfile.nc contains 3D fields X and Y, and I want BGCVal2 to calculate X/Y as part of its operations. If this can't be done, I won't delete the existing variable X' (which is effectively X/Y). As the model currently produces both X (for CMOR) and X' (for BGCVal2), I'm only asking to see if I can decrease the file size of myfile.nc (it would be a halving, so not trivial). Cheers

valeriupredoi commented 11 months ago

gotcha! AFAIK it won't be able to perform the variable derivation X/Y operation since, even if it can read multiple variables for the same diagnostic from the same file, I am not aware of code that does the derivation and takes that output (well, from memory) to go about and do stuff with it. It is, however, something that I reckon we can overload BGCVal2 with, but not just yet

ledm commented 11 months ago

Just to say that we don't have a standard function to do this, but we have several similar ones, ie:

https://github.com/valeriupredoi/bgcval2/blob/main/bgcval2/functions/standard_functions.py#L142

def sums(nc,keys):
    """
    Loads Key[0] from the netcdf, then sums the other keys.
    """
    a = nc.variables[keys[0]][:]
    for k in keys[1:]:
        a += nc.variables[k]
    return a

Here's a way to do it. Just need to add it to standard_functions.py

def divide_by(nc, keys):
    """
    Loads keys[0] from the netcdf, then divided it by keys[1]. (Not Lazy)
    """
    return nc.variables[keys[0]][:]/ nc.variables[keys[1]][:]
...

std_functions['divide_by'] = divide_by
DrYool commented 11 months ago

Excellent. Although I don't understand a word of that. An example involving model fields might make it clearer for an idiot like me. But this does look to have the sort of functionality that I'm after.