# Creating a harp compliant L2 file

**URL:** https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416
**Category:** Uncategorized
**Created:** [November 4, 2021, 3:55pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416 "2021-11-04T15:55:29Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![jonasv](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jonasv](https://forum.atmospherictoolbox.org/u/jonasv)
#### Post date: [November 4, 2021, 3:55pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/1 "2021-11-04T15:55:29Z")

</div>

I want to create a harp compliant L2 file (one that is not in the list of ingestions definitions), and would like to ask for some advice. This is a rather general question, but my plan is to do:  
1)a mapping of the variable names where possible, according to [Variable names — HARP 1.14 documentation](http://stcorp.github.io/harp/doc/html/conventions/variable_names.html).  
2)Then adding the needed global and variable attributes ([Variable attributes — HARP 1.14 documentation](http://stcorp.github.io/harp/doc/html/conventions/variable_attributes.html))  
3)Then changing the fillvalues to Nan or capture them by valid\_min, valid\_max, since harp doesn’t recognize FillValue attribute.  
4)Then I dont know how to deal with the dimensions. In the picture below, I have on the left test\_l2.nc, which is the L2 that should be (almost) harp compliant and on the right test\_l2\_harp.nc, which is the output after the command:  
harpmerge -f hdf5 test\_l2.nc test\_l2\_harp.nc  
Except for the time dimension all dimension in test\_l2.nc gets converted to ‘independent\_\*\*\*’ dimensions, which can (by definition) not be flattened.  
So, my question here is actually how we can create dimensions that are not converted to independent dimensions by Harp?

 ![fig](https://forum.atmospherictoolbox.org/uploads/default/original/1X/0ef8f43e6157b531ff7a93d4e0eb9b32c242583c.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: [November 4, 2021, 4:22pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/2 "2021-11-04T16:22:04Z")

</div>

The short answer is that you have to squash those dimensions.

You can also see this if you look at how the S5P products are supported by HARP. What is a 3D [time x scanline x ground\_pixel] variable in the original product is a single [time] variable in HARP.

So in your case, you should create 1D arrays of length 1423360 (being the time dimension).

The reason why we don’t support arbitrary independent dimensions is because this doesn’t work together with the [derivations](http://stcorp.github.io/harp/doc/html/algorithms/index.html#variable-conversions) that we support in HARP (which depend on variables having specific dimensions).

---

<div class="post-metadata">

### Author: ![jonasv](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jonasv](https://forum.atmospherictoolbox.org/u/jonasv)
#### Post date: [November 4, 2021, 5:02pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/3 "2021-11-04T17:02:21Z")

</div>

thanks a lot for this quick reply. So, I understand that in order to create a harp compliant L2 file I have to squash variable dimensions (like the number of scanline and ground\_pixels) beforehand into the time dimension. Since the command  
harpmerge -f hdf5 test\_l2.nc test\_l2\_harp.nc  
will only create independent dimensions that cannot be squashed anymore with HARP.

This also implies then, that the command  
harpmerge -f hdf5 S5P\_OFFL\_L2\_\_HCHO\_\_\_20211001T011729\_20211001T025859\_20553\_02\_020201\_20211002T165738.nc s5p\_test.nc  
does squashes scanline x ground\_pixels into the time dimension because of the ingestions definitions? So, that Harp recognizes the filename and see it as an s5p product, and that it has to use the appropriate ingestions definition or specific algorithms for s5p files?

I just wonder why there is an independent\_4 dimension in the s5p\_test.nc (where s5p\_test.nc is the output from the above command). This independent\_4 dimension appears in the latitude\_bounds and longitude\_bounds variables (time x independent\_4), so how does the derivations in HARP are dealing with this independent dimension?

---

<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: [November 11, 2021, 10:54am UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/4 "2021-11-11T10:54:43Z")

</div>

> [@jonasv](#):
>
> thanks a lot for this quick reply. So, I understand that in order to create a harp compliant L2 file I have to squash variable dimensions (like the number of scanline and ground\_pixels) beforehand into the time dimension. Since the command  
> harpmerge -f hdf5 test\_l2.nc test\_l2\_harp.nc  
> will only create independent dimensions that cannot be squashed anymore with HARP.
> 
> This also implies then, that the command  
> harpmerge -f hdf5 S5P\_OFFL\_L2\_\_HCHO\_\_\_20211001T011729\_20211001T025859\_20553\_02\_020201\_20211002T165738.nc s5p\_test.nc  
> does squashes scanline x ground\_pixels into the time dimension because of the ingestions definitions? So, that Harp recognizes the filename and see it as an s5p product, and that it has to use the appropriate ingestions definition or specific algorithms for s5p files?

Exactly. The mapping is also fully described in the last table in [the ingestion definitions for these products](http://stcorp.github.io/harp/doc/html/ingestions/S5P_L2_HCHO.html).

> [@jonasv](#):
>
> I just wonder why there is an independent\_4 dimension in the s5p\_test.nc (where s5p\_test.nc is the output from the above command). This independent\_4 dimension appears in the latitude\_bounds and longitude\_bounds variables (time x independent\_4), so how does the derivations in HARP are dealing with this independent dimension?

These are intentional independent dimensions. HARP knows how to deal with those for corner coordinates. This is all linked to the variable conversions that HARP can perform with the `derive` operation. All the supported dimension combinations are described in the Algorithms part of the HARP document, such as, for instance, for [latitude](http://stcorp.github.io/harp/doc/html/algorithms/derivations/latitude.html). Wherever you see a fixed number (such as ‘2’) or `N` for a dimension, this is where HARP will expect an ‘independent dimension’.

---

<div class="post-metadata">

### Author: ![jonasv](https://forum.atmospherictoolbox.org/letter_avatar_proxy/v4/letter/j/22d042/32.png) [@jonasv](https://forum.atmospherictoolbox.org/u/jonasv)
#### Post date: [December 6, 2021, 1:06pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/5 "2021-12-06T13:06:05Z")

</div>

I wonder when Harp uses an ingestion definition, I thought harp recognized the filename, so for example when the filename starts with ‘QA4ECV\_L2\_HCHO’ harp uses [QA4ECV\_L2\_HCHO — HARP 1.14 documentation](http://stcorp.github.io/harp/doc/html/ingestions/QA4ECV_L2_HCHO.html) .  
However after doing some tests, I could conclude that harp only looks if the _id_ main attribute starts with QA4ECV\_L2\_HCHO ? Is this the case for all ingestion definitions? Can I also conclude that when the _id_ main attribute does not start with a prefix that is mentioned in [Ingestion definitions — HARP 1.14 documentation](http://stcorp.github.io/harp/doc/html/ingestions/index.html) it will then skip trying to use an ingestion definition?

---

<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: [December 6, 2021, 1:29pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/6 "2021-12-06T13:29:41Z")

</div>

The logic is that HARP first tries to see if the product is a file matching HARP conventions (based on the [Conventions global attribute value](http://stcorp.github.io/harp/doc/html/conventions/global_attributes.html). This works for HDF5(/netCDF4), netCDF3, and HDF4 products.

If that doesn’t work, HARP tries an import from a supported external format. It does this based on the coda detection rules (you can see the product class+type of a product with `codacheck -V <product>`). The combination of product class/type is also included in the tables in the [harp ingestion documentation](http://stcorp.github.io/harp/doc/html/ingestions/index.html) for each supported type of product.

If that also doesn’t work, you will get an error.

---

<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: [December 6, 2021, 1:33pm UTC](https://forum.atmospherictoolbox.org/t/creating-a-harp-compliant-l2-file/416/7 "2021-12-06T13:33:04Z")

</div>

For the QA4ECV products specifically you can find the coda detection rules in the associated [index.xml file of the QA4ECV codadef](https://github.com/stcorp/harp/blob/master/definitions/QA4ECV/index.xml).
