# Um2netcdf4 returns error

**URL:** <https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753>\
**Category:** AM3\
**Created:** [7 January 2026 04:04 UTC](https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753 "2026-01-07T04:04:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![paocorrales](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/paocorrales/32/3326_2.png) [@paocorrales](https://forum.access-hive.org.au/u/paocorrales)\
**Post date:** [7 January 2026 04:04 UTC](https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753/1 "2026-01-07T04:04:29Z")

</div>

I’m running AM3 with a different STASH list. It works well with the alpha release branch but I’m getting an error when I try to run the model in a different resolution.

The error is associated with the conversion to netcdf:

```auto
Exception: Unable to match levels of heaviside function to variable geopotential_height

```

The file I’m trying to convert to netcdf does not include the geopotential hight, it includes only:

| Variable name | sec | item | code | type | freq |
| --- | --- | --- | --- | --- | --- |
| TEMPERATURE AT 1.5M | 3 | 236 | m01s03i236 | max | daily |
| TEMPERATURE AT 1.5M | 3 | 236 | m01s03i236 | min | daily |
| LARGE SCALE RAIN AMOUNT KG/M2/TS | 4 | 201 | m01s04i201 | accum | daily |
| LARGE SCALE SNOW AMOUNT KG/M2/TS | 4 | 202 | m01s04i202 | accum | daily |
| CONVECTIVE RAIN AMOUNT KG/M2/TS | 5 | 201 | m01s05i201 | accum | daily |
| CONVECTIVE SNOW AMOUNT KG/M2/TS | 5 | 202 | m01s05i202 | accum | daily |
| TOTAL PRECIPITATION AMOUNT KG/M2/TS | 5 | 226 | m01s05i226 | accum | daily |

Looking at the code, I’m not sure why it returning that error.

When running the script from the terminal (outside the suite) it works fine:

```auto
python /g/data/access/apps/pythonlib/um2netcdf4/2.1/um2netcdf4.py n640a.pb1983jan test_b.nc

```

I’m now testing if this problem persist for other output streams, but for now this is the only problematic one.

I appreciate any ideas to try next 🫠

---

<div class="post-metadata">

**Author:** ![bethanwhite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/bethanwhite/32/3080_2.png) [@bethanwhite](https://forum.access-hive.org.au/u/bethanwhite)\
**Post date:** [7 January 2026 05:50 UTC](https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753/2 "2026-01-07T05:50:24Z")

</div>

Hi Pao,

> When running the script from the terminal (outside the suite) it works fine

Is this on the same model output file, but running inside vs outside the suite? i.e. the model is _definitely_ writing the variables that you think it is, having modified the stash?

Did you run the ‘tidy STASH’ macro in the suite after redefining your output?

My first guess (from looking at the block of code in `/g/data/access/apps/pythonlib/um2netcdf4/2.1/um2netcdf4.py`that contains the error message) would be that something isn’t doing what you think it should be, and `geopotential_height`is being written to one of the fields that you think is now defined as something else.

I can’t see how running the script as a standalone (on the same output file?) would run successfully if that were the case, though 🤔

---

<div class="post-metadata">

**Author:** ![bethanwhite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/bethanwhite/32/3080_2.png) [@bethanwhite](https://forum.access-hive.org.au/u/bethanwhite)\
**Post date:** [7 January 2026 06:01 UTC](https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753/3 "2026-01-07T06:01:55Z")

</div>

Quick idea, add `itemcode `to the error message output in L226 of `/g/data/access/apps/pythonlib/um2netcdf4/2.1/um2netcdf4.py`to check that the STASH codes are doing what you think they should be?

i.e. `raise Exception(‘Unable to match levels of heaviside function to variable %s’ % c.name())`

==\> `raise Exception(‘Unable to match levels of heaviside function to variable %s’ % (c.name(), itemcode))`

(not sure if that second set of brackets is needed).

---

<div class="post-metadata">

**Author:** ![paocorrales](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/paocorrales/32/3326_2.png) [@paocorrales](https://forum.access-hive.org.au/u/paocorrales)\
**Post date:** [8 January 2026 01:00 UTC](https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753/4 "2026-01-08T01:00:35Z")

</div>

I found the problem, of course it was me 🥲

Along with the new output file there where a few old files created with a different stash. The netcdf conversion step in the suite was picking those up along with the correct files.

But when I was running the script from outside the suite, I was using the correct file.

Thanks a lot for the suggestions @bethanwhite! it helped me to understand the problem and I learned a thing or two!

---

<div class="post-metadata">

**Author:** ![bethanwhite](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.access-hive.org.au/bethanwhite/32/3080_2.png) [@bethanwhite](https://forum.access-hive.org.au/u/bethanwhite)\
**Post date:** [8 January 2026 01:10 UTC](https://forum.access-hive.org.au/t/um2netcdf4-returns-error/5753/5 "2026-01-08T01:10:59Z")

</div>

Yay! Great to hear @paocorrales 🦆
