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

Extend perturbIC functionality #11

Open
3 tasks
atteggiani opened this issue Nov 16, 2024 · 2 comments
Open
3 tasks

Extend perturbIC functionality #11

atteggiani opened this issue Nov 16, 2024 · 2 comments

Comments

@atteggiani
Copy link
Collaborator

Currently, the perturbIC function can only accept a restart dump file (UM Dump File) as input, and perturb its theta field (STASH itemcode = 4).
Although this meets the most likely use case, the function could be easily extended to:

  • work with any type of fields file (Ancil files or Output Fieldsfiles too), perturbing by default its theta field. If the field is not present, an error would get raised.
  • accept a STASH itemcode as command line argument, to choose a different field to perturb (for example if user wants to perturb the surface temperature (STASH itemcode = 24) something like --stash-to-perturb 24 could be passed as an argument)
  • if the input fields file contains only one single field, automatically perturb that field (even if is not THETA and the --stash-to-perturb has not been passed.

This additions would cover some edge use cases of perturbIC, extending its functionality without degrading its current performance.

@leoberhelman
Copy link
Contributor

Question here for mule and other output currently I am using Mule.dumpfile to open and work with the file. The ouput fieldsfiles and ancil files would need Mule.fieldfile? Or can they all be opened by dumpfile?

@atteggiani
Copy link
Collaborator Author

The ouput fieldsfiles and ancil files would need Mule.fieldfile? Or can they all be opened by dumpfile?

Output fieldsfiles would need mule.FieldsFile and ancillary files would need mule.AncilFile.

In general, mule has different type of files it can work with, and there are a few more than the ones mentioned here.

It would probably make sense to use the convenient method mule.load_umfile which will allow you to attempt to load a file when you aren’t sure of the type (or more likely - where you are writing a script which can accept any type of UM file).
The method will return whichever type appears to be correct.
You can find details here.

Then, if we need to restrict the file types for any reason (for example if part of the logic is valid only for ancillary files - mule.AncilFile), we can put conditions that test that the opened file correspond to that specific type.
For example, to test if an opened file is an ancillary file we could do:

opened_file = mule.load_umfile(filepath)
if isinstance(opened_file, mule.AncilFile):
    ...

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

2 participants