# Unexplained harp error with v1.17

**URL:** https://forum.atmospherictoolbox.org/t/unexplained-harp-error-with-v1-17/647
**Category:** HARP
**Tags:** python
**Created:** [May 16, 2023, 11:17am UTC](https://forum.atmospherictoolbox.org/t/unexplained-harp-error-with-v1-17/647 "2023-05-16T11:17:59Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![mariliza](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/m/c77e96/32.png) [@mariliza](https://forum.atmospherictoolbox.org/u/mariliza)
#### Post date: [May 16, 2023, 11:17am UTC](https://forum.atmospherictoolbox.org/t/unexplained-harp-error-with-v1-17/647/1 "2023-05-16T11:17:59Z")

</div>

Dear Sander,

I am encountering a harp error, via python, on a code that I was using back in February. The code is attached to the end of this message. It reads, via coda, the NASA OMI L2G daily product and outputs in harp-compliant form gridded monthly data. Nothing fancy. I repeat, this was working in February, with the previous harp version.

The error is :

_File ~/.conda/envs/myCondaEnvName/lib/python3.9/site-packages/harp/\_harppy.py:1110 in \_export\_product_

- \_export\_variable(name, product[name], c\_product)\*

- File ~/.conda/envs/myCondaEnvName/lib/python3.9/site-packages/harp/\_harppy.py:1068 in \_export\_variable\*

- raise CLibraryError()\*

_CLibraryError: invalid unit ‘degree\_north’_

_During handling of the above exception, another exception occurred:_

_Traceback (most recent call last):_

- File ~/.conda/envs/myCondaEnvName/lib/python3.9/site-packages/spyder\_kernels/py3compat.py:356 in compat\_exec\*

- exec(code, globals, locals)\*

- File /mnt/lapsat/groups/lapsat/OMI\_SO2/Programs/harp\_convert\_OMI\_L3.py:99\*

- average = harp.execute\_operations(productlist,\*

- File ~/.conda/envs/myCondaEnvName/lib/python3.9/site-packages/harp/\_harppy.py:1517 in execute\_operations\*

- \_export\_product(product, c\_product\_ptr[0])\*

- File ~/.conda/envs/myCondaEnvName/lib/python3.9/site-packages/harp/\_harppy.py:1112 in \_export\_product\*

- raise Error(“variable ‘%r’ could not be exported (%s)” % (name, str(\_error)))\*

_Error: variable ‘‘latitude’’ could not be exported (invalid unit ‘degree\_north’)_

My conda env only contains module via the conda forge channel, and is a dedicated harp env. Conda list replies, for harp & coda:  
_harp 1.17 py39r42h92210e6\_0 conda-forge_  
_coda 2.24.1 py39h92210e6\_0 conda-forge_

I am running the script on spyder with  
\*Python 3.9.15 | packaged by conda-forge | (main, Nov 22 2022, 15:55:03) \*  
_Type “copyright”, “credits” or “license” for more information._  
_IPython 8.8.0 – An enhanced Interactive Python._

Any ideas on how this may be going wrong?  
Many thanks  
MariLiza

#!/usr/bin/env python3

# -_- coding: utf-8 -_-

“”"  
Created on Thu Jun 25 12:06:13 2020

@author: mariliza  
“”"

import coda  
import harp  
import numpy  
import os  
import calendar  
from datetime import datetime, date  
import sys  
import numpy as np  
import fnmatch

#from os import listdir

# twelve months

mon = [i+1 for i in range(12)]  
matchex = [“%02d” %x for x in mon]

# local variables

path = ‘/mnt/lapsat/groups/lapsat/OMI\_SO2/EvenMoreData/’  
outpath = ‘/mnt/lapsat/groups/lapsat/OMI\_SO2/HARP\_EvenMoreData/’

# output directory

if not os.path.exists(outpath):  
os.makedirs(outpath)

# load all the filenames

filenames =   
for file in os.listdir(path):  
if file.endswith(“.he5”):  
filenames.append(file)  
filenames.sort()

# loop in months

for minas in range(len(matchex)):

```
productlist = []

# locate only the files within that month

allfilenames = []
for ffile in filenames: #os.listdir(folder):
    # if fnmatch.fnmatch(ffile.decode(encoding='utf-8'), str('*2021m'+matchex[minas]+'*')):
    if fnmatch.fnmatch(ffile, str('OMI-Aura_L3-OMSO2e_2023m'+matchex[minas]+'*')):
        allfilenames.append(os.fsdecode(ffile))
if len(allfilenames) == 0:
    continue 
allfilenames.sort()

# read in all the files in that month
for ffile in allfilenames:
    filename = os.fsdecode(ffile)
    
    infile = path+filename
    print(infile)
    
    pf = coda.open(infile)
       
    try:
        
        latitude = coda.fetch(pf, 'HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/Latitude')
        longitude = coda.fetch(pf, '/HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/Longitude')
        so2 = coda.fetch(pf, '/HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/ColumnAmountSO2')
        # so2_scd = coda.fetch(pf,'/HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/SlantColumnAmountSO2')
        time = coda.fetch(pf,'/HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/Time')
        so2_flag = coda.fetch(pf, '/HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/QualityFlags_SO2')
        sza = coda.fetch(pf, '/HDFEOS/GRIDS/OMI_Total_Column_Amount_SO2/Data_Fields/SolarZenithAngle')
        # sys.exit()
        
    finally:
        coda.close(pf)

    product = harp.Product()

    lat = latitude[:,0]   
    lon = longitude[0,:]

    product.latitude = harp.Variable(lat, ['latitude']) #, longitude'])
    product.latitude.unit = 'degree_north'
    product.longitude = harp.Variable(lon, ['longitude'])
    product.longitude.unit = 'degree_east'
    product.so2_column_number_density = harp.Variable(so2, ['latitude', 'longitude'])
    product.so2_column_number_density.unit = 'DU'
    # product.so2_slant_column_number_density = harp.Variable(so2_scd, ['latitude', 'longitude'])
    # product.so2_slant_column_number_density.unit = 'DU'
    product.time = harp.Variable(time, ['latitude', 'longitude'])
    
    
    productlist.append(product)
    
average = harp.execute_operations(productlist, 
                operations='latitude>=-10.0;latitude<=50.0;longitude>=50.0;longitude<=170.0',
                post_operations="bin();squash(time, (latitude,longitude))")

# sys.exit()
OutFile = outpath + '2023'+matchex[minas]+'.nc'
# filename[19:23] + filename[24:28] + '.nc'
harp.export_product(average, OutFile)

print(OutFile)
# sys.exit()

```

---

<div class="post-metadata">

### Author: ![sander.niemeijer](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/sander.niemeijer/32/5_2.png) [@sander.niemeijer](https://forum.atmospherictoolbox.org/u/sander.niemeijer)
#### Post date: [May 16, 2023, 11:38am UTC](https://forum.atmospherictoolbox.org/t/unexplained-harp-error-with-v1-17/647/2 "2023-05-16T11:38:29Z")

</div>

This might be because the udunits configuration files could not be found. Do you have a set of `udunits2*.xml` files in `~/.conda/envs/myCondaEnvName/share/harp`?  
Or do you maybe have a `UDUNITS2_XML_PATH` environment variable set that points to a wrong location?

---

<div class="post-metadata">

### Author: ![mariliza](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/m/c77e96/32.png) [@mariliza](https://forum.atmospherictoolbox.org/u/mariliza)
#### Post date: [May 16, 2023, 11:50am UTC](https://forum.atmospherictoolbox.org/t/unexplained-harp-error-with-v1-17/647/3 "2023-05-16T11:50:35Z")

</div>

Yes, I do have a set of udinits2\*.xml files in my env  
[mariliza@aristotle5 ~]$ ls ~/.conda/envs/myCondaEnvName/share/harp  
doc udunits2-accepted.xml udunits2-base.xml udunits2-common.xml udunits2-derived.xml udunits2-prefixes.xml udunits2.xml

But you are right! The `UDUNITS2_XML_PATH` environment variable set that is in my \*bashrc file was pointing in the wrong direction. Our sysadmins were upgrading harp&coda for me to use with IDL and this was not updated.

I did not know that even though I am in my conda env, the udunits are picked from the \*bashrc. A bit strange to me, but I am no expert.

I reloaded everything, works fine. Many thanks!  
MariLiza
