# Sentinel 5P- CO NaN array after using Harp convert

**URL:** https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169
**Category:** HARP
**Tags:** sentinel-5p
**Created:** [June 25, 2020, 11:12am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169 "2020-06-25T11:12:05Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![Peaceout21](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/peaceout21/32/77_2.png) [@Peaceout21](https://forum.atmospherictoolbox.org/u/Peaceout21)
#### Post date: [June 25, 2020, 11:12am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/1 "2020-06-25T11:12:05Z")

</div>

Dear team,  
I downloaded the data

S5P\_OFFL\_L2\_\_CO\_\_\_\_\_20200610T210512\_20200610T224642\_13783\_01\_010302\_20200612T104836.nc  
and was trying to create a geotiff image from this.  
As mentioned I used harp to convert to an intermediate nc file using this :

harpconvert -a ‘CO\_column\_number\_density\_validity\>50;bin\_spatial(920,-5,0.025,1160,86,0.025);’  
S5P\_OFFL\_L2\_\_CO\_\_\_\_\_20200610T210512\_20200610T224642\_13783\_01\_010302\_20200612T104836.nc testing.nc

as wel as this :  
harpconvert -a ‘CO\_column\_number\_density\_validity\>50;keep(datetime\_start,datetime\_length,CO\_column\_number\_density,latitude\_bounds,longitude\_bounds);bin\_spatial(2001,-90,0.01,2001,-180,0.01);derive(CO\_column\_number\_density)”,derive(CO\_column\_number\_density)”,post\_operations=  
“bin();squash(time,  
(latitude\_bounds,longitude\_bounds));derive(latitude  
{latitude});derive(longitude {longitude})’  
S5P\_OFFL\_L2\_\_CO\_\_\_\_\_20200610T210512\_20200610T224642\_13783\_01\_010302\_20200612T104836.nc ll3.nc

It does covert to the new nc files, however, when i try to open this  
using gdal and read the array it shows a unique single value

import gdal  
sc=gdal.Open(’/home/arjundebnath21/s5/[ll3.nc](http://ll3.nc/)’,gdal.GA\_ReadOnly)  
band\_ds = gdal.Open(sc.GetSubDatasets()[0][0], gdal.GA\_ReadOnly)  
band\_array = band\_ds.ReadAsArray()  
np.unique(band\_array)

The array has the value array([9.96920997e+36]), which i believe is  
the Nodata value.

Can you please help me understand why this is happening ?

Also , After converting to a h5 file , if I want to convert it to a  
tiff file , there are different bands for the lat and long bounds (  
whose shapes are different from the CO column density ) . Can you also  
please guide how to create a single geotiff file from this ?

Your help would be much appreciated .  
Thanks and regards,  
Arjun

---

<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: [June 26, 2020, 8:24am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/2 "2020-06-26T08:24:31Z")

</div>

There are several things wrong with what you are trying to do.

First of all, the harpconvert command that you posted could never have worked. You are mixing up the python and command line interfaces. If you post something, please post what you actually did. That command could never have produced a ll3.nc file.

Second, you are using a very strange target grid. you are using a grid that uses 2000x2000 cells starting at (-90,-180) with a cell size of 0.01. This means that your upper left corner is (-70,-160). Are you really looking for a South Pole area?

The value is 9.96920997e+36 is something that GDAL comes up with. The original data values are NaN. Which makes sense, since there is like no SO2 detected around the South Pole.

---

<div class="post-metadata">

### Author: ![Peaceout21](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/peaceout21/32/77_2.png) [@Peaceout21](https://forum.atmospherictoolbox.org/u/Peaceout21)
#### Post date: [June 26, 2020, 8:29am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/3 "2020-06-26T08:29:02Z")

</div>

Right i see the error now, im using this command and this is working

harpconvert -a ‘CO\_column\_number\_density\_validity\>50 latitude \> -55 [degree\_north]; latitude \< 80 [degree\_north];keep(datetime\_start,datetime\_length,CO\_column\_number\_density,latitude\_bounds,longitude\_bounds);bin\_spatial(271,-55,0.5,721,-180,0.5);bin();squash(time, (latitude\_bounds,longitude\_bounds));derive(latitude {latitude});derive(longitude {longitude});exclude(latitude\_bounds,longitude\_bounds,latitude\_bounds\_weight,longitude\_bounds\_weight,count,weight)’.nc onefile.nc

---

<div class="post-metadata">

### Author: ![Peaceout21](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/peaceout21/32/77_2.png) [@Peaceout21](https://forum.atmospherictoolbox.org/u/Peaceout21)
#### Post date: [June 26, 2020, 8:30am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/4 "2020-06-26T08:30:46Z")

</div>

Also, is it possible to use the harp merge from the python script itself? by using the  
harp.import\_product

---

<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: [June 26, 2020, 9:00am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/5 "2020-06-26T09:00:01Z")

</div>

Yes. You can just provide a list of product file paths as first argument to `harp.import_product()`. It will then perform the merge as part of the import. You would have to use this `post_operations` as you quoted above to properly split the operations to be performed on each file _before_ the merge, or on the result _after_ the merge.

---

<div class="post-metadata">

### Author: ![Peaceout21](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/peaceout21/32/77_2.png) [@Peaceout21](https://forum.atmospherictoolbox.org/u/Peaceout21)
#### Post date: [June 26, 2020, 9:01am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/6 "2020-06-26T09:01:33Z")

</div>

yeah thanks, just figured this out based on the docs

import harp  
p=harp.import\_product(filename=glob.glob(os.path.join(’~/s5/oneday/’,‘S\*.nc’)),  
operations=“CO\_column\_number\_density\_validity\>50;latitude \> -55 [degree\_north]; latitude \< 80 [degree\_north];bin\_spatial(271,-55,0.5,721,-180,0.5); derive(longitude {longitude}); derive(latitude{latitude})”,  
-55 [degree\_north]; latitude \< 80 [degree\_north];bin\_spatial(271,-55,0.5,721,-180,0.5); derive(longitude {longitude}); derive(latitude{latitude})",  
post\_operations=“bin();squash(time, (latitude,longitude))”)

harp.export\_product(p, “h\_script.nc”, file\_format=‘netcdf’)

---

<div class="post-metadata">

### Author: ![Peaceout21](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/peaceout21/32/77_2.png) [@Peaceout21](https://forum.atmospherictoolbox.org/u/Peaceout21)
#### Post date: [June 26, 2020, 9:13am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/7 "2020-06-26T09:13:17Z")

</div>

Also, Any suggestion on how to convert the merged nc files to a single raster ? like how do we handle the nodata value while exporting to tiff  
Thanks 🙂

---

<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: [June 26, 2020, 9:27am UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/8 "2020-06-26T09:27:19Z")

</div>

Personally, I am using `gdal_translate` for this, which works fine.  
I am not sure what you mean with ‘dealing with nodata values’. How you deal with NaN data is very domain specific and depends on what you actually want to use the data for.

---

<div class="post-metadata">

### Author: ![Peaceout21](https://forum.atmospherictoolbox.org/user_avatar/forum.atmospherictoolbox.org/peaceout21/32/77_2.png) [@Peaceout21](https://forum.atmospherictoolbox.org/u/Peaceout21)
#### Post date: [June 26, 2020, 7:06pm UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/9 "2020-06-26T19:06:42Z")

</div>

Hi,  
I used this tool to merge all 14 orbit files to a single file ( 1 day )

> product = harp.import\_product(filename=glob.glob(os.path.join(‘~/’,‘S\*.zip’)),  
> operations=‘CO\_column\_number\_density\_validity\>50;derive(CO\_column\_volume\_mixing\_ratio {time} [ppbv]);keep(latitude\_bounds,longitude\_bounds,CO\_column\_volume\_mixing\_ratio);bin\_spatial(1801,-90,0.1,3601,-180,0.1)’,  
> post\_operations=‘bin();squash(time, (latitude\_bounds,longitude\_bounds));derive(latitude {latitude});derive(longitude {longitude});exclude(latitude\_bounds,longitude\_bounds,latitude\_bounds\_weight,longitude\_bounds\_weight,count,weight)’)  
> harp.export\_product(product, “all.nc”, file\_format=‘netcdf’)

when i try to visualise this is what i get  
i just wanted to check if this looks normal , because it seems to have missed regions above canada

 ![image](https://forum.atmospherictoolbox.org/uploads/default/original/1X/1e04ad28fa0eed5b7904b7cf1765c5cf214d1f98.png)

---

<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: [June 27, 2020, 12:26pm UTC](https://forum.atmospherictoolbox.org/t/sentinel-5p-co-nan-array-after-using-harp-convert/169/10 "2020-06-27T12:26:45Z")

</div>

Tropomi measures reflected sunlight, so you will not have measurements where the poles are (near) dark (i.e. if it is winter there).
