Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BGCVal2 over two variables #101

Open
DrYool opened this issue Jul 27, 2023 · 5 comments
Open

BGCVal2 over two variables #101

DrYool opened this issue Jul 27, 2023 · 5 comments

Comments

@DrYool
Copy link
Collaborator

DrYool commented Jul 27, 2023

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
Copy link
Owner

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? 🍺

@DrYool
Copy link
Collaborator Author

DrYool commented Jul 27, 2023

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
Copy link
Owner

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
Copy link
Collaborator

ledm commented Jul 31, 2023

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
Copy link
Collaborator Author

DrYool commented Aug 3, 2023

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.

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

No branches or pull requests

3 participants