<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://climate-cms.wikis.unsw.edu.au/index.php?action=history&amp;feed=atom&amp;title=Modifying_UM_Files</id>
	<title>Modifying UM Files - Revision history</title>
	<link rel="self" type="application/atom+xml" href="http://climate-cms.wikis.unsw.edu.au/index.php?action=history&amp;feed=atom&amp;title=Modifying_UM_Files"/>
	<link rel="alternate" type="text/html" href="http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;action=history"/>
	<updated>2026-11-18T05:06:59Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.31.0</generator>
	<entry>
		<id>http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;diff=1801&amp;oldid=prev</id>
		<title>S.wales at 03:38, 12 December 2019</title>
		<link rel="alternate" type="text/html" href="http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;diff=1801&amp;oldid=prev"/>
		<updated>2019-12-12T03:38:54Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 03:38, 12 December 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l4&quot; &gt;Line 4:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 4:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Mule is included in the 'analysis27' conda environment, which you can load with&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;Mule is included in the 'analysis27' conda environment, which you can load with&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;lang=bash&lt;/ins&gt;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;module use /g/data3/hh5/public/modules&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;module use /g/data3/hh5/public/modules&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;module load conda/analysis27&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;module load conda/analysis27&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>S.wales</name></author>
		
	</entry>
	<entry>
		<id>http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;diff=449&amp;oldid=prev</id>
		<title>S.wales at 23:33, 11 March 2019</title>
		<link rel="alternate" type="text/html" href="http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;diff=449&amp;oldid=prev"/>
		<updated>2019-03-11T23:33:50Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;en&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;Revision as of 23:33, 11 March 2019&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l86&quot; &gt;Line 86:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 86:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://code.metoffice.gov.uk/doc/um/mule/latest/ | Mule documentation]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://code.metoffice.gov.uk/doc/um/mule/latest/ | Mule documentation]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://code.metoffice.gov.uk/doc/um/latest/papers/umdp_F03.pdf | UMDP F03: File Formats]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;* [https://code.metoffice.gov.uk/doc/um/latest/papers/umdp_F03.pdf | UMDP F03: File Formats]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;UM&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Category:&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;Unified Model&lt;/ins&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>S.wales</name></author>
		
	</entry>
	<entry>
		<id>http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;diff=213&amp;oldid=prev</id>
		<title>ScottWales: Imported from Wikispaces</title>
		<link rel="alternate" type="text/html" href="http://climate-cms.wikis.unsw.edu.au/index.php?title=Modifying_UM_Files&amp;diff=213&amp;oldid=prev"/>
		<updated>2018-03-02T04:02:23Z</updated>

		<summary type="html">&lt;p&gt;Imported from Wikispaces&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
&lt;br /&gt;
You can manually modify UM files using the Mule python library&lt;br /&gt;
&lt;br /&gt;
Mule is included in the 'analysis27' conda environment, which you can load with&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
module use /g/data3/hh5/public/modules&lt;br /&gt;
module load conda/analysis27&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Reading and writing files ===&lt;br /&gt;
&lt;br /&gt;
There are several sub-types of UM file. The ones you'll come across most frequently are 'fields files' - which are used for the model input and output, and 'ancil files' which are used for external data sources like emissions.&lt;br /&gt;
&lt;br /&gt;
Fields files are read using `mule.ff.FieldsFile.from_file()`, ancil files are read using `mule.ancil.AncilFile.from_file()`.&lt;br /&gt;
&lt;br /&gt;
Once you've opened a file, you can write it to disk again using [https://code.metoffice.gov.uk/doc/um/mule/latest/mule.html#mule.UMFIle.to_file | `.to_file()`]:&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
filename_in = 'ab123.astart'&lt;br /&gt;
data = mule.ff.FieldsFile.from_file(filename_in)&lt;br /&gt;
&lt;br /&gt;
filename_out = 'ab123.astart.modified'&lt;br /&gt;
data.to_file(filename_out)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Accessing Fields ===&lt;br /&gt;
&lt;br /&gt;
The fields within the file can be accessed using the `.fields` property, which returns a list of all the fields in the file. Each field in the file is a 2d slice of a model variable, almost always a horizontal slice at a single level and time (ozone is an exception, it is often stored as a zonal average)&lt;br /&gt;
&lt;br /&gt;
Each field has its LOOKUP header values available, see [https://code.metoffice.gov.uk/doc/um/latest/papers/umdp_F03.pdf | UMDP F03] for the details of what all of them mean. As an example `lbuser4` is the STASH code of the field.&lt;br /&gt;
&lt;br /&gt;
Fields are loaded lazily, only the headers get loaded when you read a file. You can get the values in the field as a numpy array using `.get_data()`&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
filename_in = 'ab123.astart'&lt;br /&gt;
data = mule.ff.FieldsFile.from_file(filename_in)&lt;br /&gt;
&lt;br /&gt;
for field in data.fields:&lt;br /&gt;
    print(&amp;quot;STASH code: &amp;quot;%field.lbuser4)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Modifying Fields ===&lt;br /&gt;
&lt;br /&gt;
[https://code.metoffice.gov.uk/doc/um/mule/2017.08.1/examples_data.html | Examples in the Mule docs]&lt;br /&gt;
&lt;br /&gt;
Fields in Mule get modified using 'operators'. Operators act on the fields as they are getting written - so rather than reading the whole file into memory, modifying all the fields and then writing back to disk, Mule will read one field at a time, apply any operators, then write out that field before moving on to the next. This dramatically reduces memory usage when working with large files.&lt;br /&gt;
&lt;br /&gt;
An operator looks like&lt;br /&gt;
&amp;lt;syntaxhighlight lang=python&amp;gt;&lt;br /&gt;
import mule&lt;br /&gt;
import numpy as np&lt;br /&gt;
&lt;br /&gt;
class SetConstantOperator(mule.DataOperator):&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    Set all field values to a constant&lt;br /&gt;
    &amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
    def &amp;lt;u&amp;gt;init&amp;lt;/u&amp;gt;(self, constant):&lt;br /&gt;
        self.constant = constant&lt;br /&gt;
    def new_field(self, source_field):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Creates the new field object&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        return source_field.copy()&lt;br /&gt;
    def transform(self, source_field, new_field):&lt;br /&gt;
        &amp;quot;&amp;quot;&amp;quot;Performs the data manipulation&amp;quot;&amp;quot;&amp;quot;&lt;br /&gt;
        data = source_field.get_data()&lt;br /&gt;
        # Multiply by 0 to keep the array shape&lt;br /&gt;
        return data * 0.0 + self.constant&lt;br /&gt;
&lt;br /&gt;
# Sets all values in the field to '50'&lt;br /&gt;
setconst_50 = SetConstantOperator(50)&lt;br /&gt;
&lt;br /&gt;
ff = mule.FieldsFile.from_file(&amp;quot;InputFile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
for ifield, field in enumerate(ff.fields):&lt;br /&gt;
    # Set the surface temperature to 50&lt;br /&gt;
    if field.lbuser4 == 24:&lt;br /&gt;
        # SURFACE TEMPERATURE AFTER TIMESTEP&lt;br /&gt;
        ff.fields[ifield] = setconst_50(field)&lt;br /&gt;
&lt;br /&gt;
    # All other fields are their original value&lt;br /&gt;
        &lt;br /&gt;
ff.to_file(&amp;quot;OutputFile&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* [https://code.metoffice.gov.uk/doc/um/mule/latest/ | Mule documentation]&lt;br /&gt;
* [https://code.metoffice.gov.uk/doc/um/latest/papers/umdp_F03.pdf | UMDP F03: File Formats]&lt;br /&gt;
[[Category:UM]]&lt;/div&gt;</summary>
		<author><name>ScottWales</name></author>
		
	</entry>
</feed>