ACCESS-NRI / umfile_utils

0 stars 0 forks source link

Extend perturbIC functionality #11

Open atteggiani opened 1 week ago

atteggiani commented 1 week ago

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:

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

leoberhelman commented 2 days ago

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 commented 2 days ago

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):
    ...