Skip to content

Commit fb04c33

Browse files
authored
Create mule_fields_subset.py
This is the beginnings of a few ideas I had to change um_fields_subset. that I explored while trying to figure out a way to remove the timeseries
1 parent b14ee09 commit fb04c33

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

src/mule_fields_subset.py

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import mule
2+
import numpy as np
3+
4+
def remove_fields(umfile, output_file, fields_to_remove):
5+
"""
6+
This function so far does all of the work
7+
"""
8+
# Iterate over a copy of `um_file.fields` to avoid modifying the list while looping
9+
for field in um_file.fields[:]:
10+
11+
if field.lbuser4 in fields_to_remove:
12+
#if field.stash in fields_to_remove:
13+
14+
um_file.fields.remove(field) # Directly remove the field if it matches
15+
16+
# Save the modified UM file
17+
um_file.to_file(output_file)
18+
19+
def main()
20+
21+
# Define input/output file paths and the fields you want to remove
22+
input_file = "/home/198/lo9311/access-esm1.5/preindustrial+concentrations/archive/restart000/atmosphere/restart_dump_old_perturb.astart"
23+
output_file = "/home/198/lo9311/access-esm1.5/preindustrial+concentrations/archive/restart000/atmosphere/modified_file.astart"
24+
fields_to_remove = [155,156,3100, 3101, 33001, 33002] # Example list of STASH codes or section numbers to remove
25+
26+
um_file = mule.UMfile.from_file(input_file)
27+
28+
29+
remove_fields(um_file, output_file, fields_to_remove)
30+
31+
if __name == "__main__":
32+
main()

0 commit comments

Comments
 (0)