# Harpmerge on the command line | ingestion question on GOME2AB SO2 flags

**URL:** https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581
**Category:** HARP
**Created:** [December 1, 2022, 2:27pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581 "2022-12-01T14:27:51Z")
**Posts on this page:** 19
**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: [December 1, 2022, 2:27pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/1 "2022-12-01T14:27:51Z")

</div>

Dear Sander, dear all forum users,

I wish to make some daily gridded files for the GOME2AB SO2 operational GDP4.8 product. I am using :

harpmerge -o ‘detailed\_results=SO2;corrected=true;so2\_column=2.5km’ -ap ‘bin\_spatial(361,-90.,0.5,721,-180.,0.5);derive(latitude {latitude});derive(longitude {longitude});derive(SO2\_column\_number\_d  
ensity [DU]);derive(SO2\_slant\_column\_number\_density [DU]);exclude(weight,solar\_zenith\_angle\_weight,SO2\_column\_number\_density\_count)’ -a ‘keep(latitude\_bounds,longitude\_bounds,SO2\_column\_number\_dens  
ity,solar\_zenith\_angle, cloud\_fraction,SO2\_column\_number\_density\_validity, scan\_direction\_type, SO2\_slant\_column\_number\_density); solar\_zenith\_angle \<= 75; cloud\_fraction \<= 0.2; scan\_direction\_ty  
pe==0’ -l $filename outputfile.nc

Is there a way to filter only for the SO2\_flag using harpmerge as such, via the command line and not via python i.e. using both harp ingest and coda\_fetch and then merging? for this product, for the 2.5km placing SO2\_column\_number\_density\_validity==0 is fine as I am not interested in the volcanic component. But when I use so2\_column=15km I also wish the volcanic pixels left untouched, which requires a different kind of filtering.

Many thanks!  
MariLiza

---

<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 1, 2022, 3:14pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/2 "2022-12-01T15:14:18Z")

</div>

I am not entirely sure what you mean, do you mean just adding a `SO2_column_number_density_validity==0` filter?

If so, you can just add it to the start of the `-a` operation block:

```auto
harpmerge -o ‘detailed_results=SO2;corrected=true;so2_column=2.5km’ -ap ‘bin_spatial(361,-90.,0.5,721,-180.,0.5);derive(latitude {latitude});derive(longitude {longitude});derive(SO2_column_number_density [DU]);derive(SO2_slant_column_number_density [DU]);exclude(weight,solar_zenith_angle_weight,SO2_column_number_density_count)’ -a ‘SO2_column_number_density_validity == 0; keep(latitude_bounds,longitude_bounds,SO2_column_number_density,solar_zenith_angle, cloud_fraction,SO2_column_number_density_validity, scan_direction_type,SO2_slant_column_number_density); solar_zenith_angle <= 75; cloud_fraction <= 0.2; scan_direction_type==0’ -l $filename outputfile.nc

```

---

<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: [December 1, 2022, 6:41pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/3 "2022-12-01T18:41:49Z")

</div>

Apologies. What I mean is this: according to the PUM, [Microsoft Word - DLR\_GOME-2\_PUM\_3B\_Nov2019 (acsaf.org)](https://acsaf.org/docs/pum/Product_User_Manual_NTO_OTO_Nov_2019.pdf), on page 46, it is stated that there exists an SO2\_flag [Table 6.7.6] whose value, if set to 0, assures no SSA, no polar regions and other nastiness. There exists also an SO2\_Volcano\_Flag [Table 6.7.7] which assumes a value of 0 when no volcano is detected.

Now, if I want to access the SO2=15km product, i.e. the volcanic product, if I set SO2\_column\_number\_density\_validity==0 I also exclude the volcanic flagged pixels, see the two [quick] plots attached. In the one without filtering, the Hawaii emissions are there, in the one with SO2\_column\_number\_density\_validity==0 the Hawaii eruption disappears.

Hope I explained it better!  
M

 ![SO2_column_number_density_in_outputfile_volc_noflag](https://forum.atmospherictoolbox.org/uploads/default/original/1X/3abe292d83352a2cb3a1eeed8bf2846e18f5a6ce.jpeg)  
 ![SO2_column_number_density_in_outputfile_volc_flag0](https://forum.atmospherictoolbox.org/uploads/default/original/1X/ffccf0a8644d9feb8bb87f08d456155820ccabcf.jpeg)  
ariLiza

---

<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 1, 2022, 7:06pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/4 "2022-12-01T19:06:04Z")

</div>

Ok. I think I start to understand what you mean. The `SO2_column_number_density_validity` variable in HARP is a combination of the three flag variables `QualityFlags`, `SO2_Flag`, and `SO2_Volcano_Flag` from the product. These are treated as a bitfield.

If you _only_ want to have values where `SO2_Flag==0` (and `QualityFlags` and `SO2_Volcano_Flag` can be any value), you would have to use [a bitfield operation](http://stcorp.github.io/harp/doc/html/operations.html#comparison-filter) on it. Since `SO2_Flag` is bit 5-8 within `SO2_column_number_density_validity`, you would have to match against 2^4 + … + 2^7 = 240.  
So, if you use `SO2_column_number_density_validity !& 240` you will only get measurements for which bits 5-8 are 0.

I believe this is what you were looking for.

---

<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: [December 2, 2022, 11:16am UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/5 "2022-12-02T11:16:00Z")

</div>

Good morning Sander,

I think we are now getting somewhere!

You load onto “SO2\_column\_number\_density\_validity” the Quality Flag, as bits 0-3, the SO2\_Flag, as bits 4-7 and the SO2\_Volcano\_Flag as bits 8-11. correct?

For e.g. if I want to be sure that the retrieval is overall fine and it is a volcanic eruption, I need bits 0-7 not raised and bits 8 & 9 to be raised, i.e. 2^8 + 2^9 = 768 will be my check?

Thanks again,  
MariLiza

---

<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 2, 2022, 11:37am UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/6 "2022-12-02T11:37:47Z")

</div>

> [@mariliza](#):
>
> You load onto “SO2\_column\_number\_density\_validity” the Quality Flag, as bits 0-3, the SO2\_Flag, as bits 4-7 and the SO2\_Volcano\_Flag as bits 8-11. correct?

Almost. See the [mapping documentation](http://stcorp.github.io/harp/doc/html/ingestions/GOME2_L2_O3MOTO.html). QualityFlags is bits 0-3, SO2\_Flag is bits 4-7, but SO2\_Volcano\_Flag is mapped using `2^(SO2_Volcano_Flag-1)` which only captures 3 bits (bits 8-10).

> [@mariliza](#):
>
> For e.g. if I want to be sure that the retrieval is overall fine and it is a volcanic eruption, I need bits 0-7 not raised and bits 8 & 9 to be raised, i.e. 2^8 + 2^9 = 768 will be my check?

If you use `SO2_column_number_density_validity =& 768` this will return true if only bits 8 and 9 are set, but it will not care about the values of bits 0…7. If you want bits 0…7 to be 0 _and_ bits 8 and 9 to be 1, you will have to perform two separate filters: `SO2_column_number_density_validity !& 255; SO2_column_number_density_validity =& 768`.

---

<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: [December 2, 2022, 12:45pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/7 "2022-12-02T12:45:37Z")

</div>

Dear Sander,

I am honoured that you think I can simply read and understand this,

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

out of its computational context! 🙂

Now that you’ve explained this in English, yes, I follow. Careful thinking is required to make sure I do not filter too much.

How about adding this thread as a hyperlink to the mapping documentation?! I am sure it will help more than one person in properly filtering their SO2 fields.

Best wishes  
MariLiza

---

<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: [January 19, 2023, 4:31pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/8 "2023-01-19T16:31:03Z")

</div>

Dear Sander,

I have now come back to this issue and have a further clarification that I would greatly appreciate. I start with what I have come to understand from our chat and by reading the PUM and by reading the data both using harp as well as the simple netCDF4 python module.

The original SO2\_Volcano\_Flag is not in bits, but just one number which may be either 0, 1, 2 or 3, as per the PUM [[https://acsaf.org/docs/pum/Product\_User\_Manual\_NTO\_OTO\_Nov\_2019.pdf](https://acsaf.org/docs/pum/Product_User_Manual_NTO_OTO_Nov_2019.pdf)].

The SO2\_column\_number\_density\_validity` variable in HARP is a bitfield, and you have translated those 4 possible values into three bits, namely bit 8, 9 and 10, correct? so you are ignoring the value of 0, obviously, since it means no volcanoes, and giving the opportunity for someone to check if the values of 1, 2 or 3 appear.

Now, contrary to bits 0 - 7, which we want to be zero, i.e. not raised, for a volcanic pixel we require either bit 8 [original value 1] OR bit 9 [original value 2] to be raised. Not both at the same time, either/or.

I went through the bitfield operators HAPR has, but I fail to see this either/or option. Might have been an option on numerical values [\<=, \>=] but not on bitfields. If I understand the online harp explanations on the bitfield operators properly.

Any way out of this predicament?

Of course I can always simply ignore bit 9, original value 2, which tells me there is volcano near an anthropogenic source. If the PUM speaks the truth then all original value 2 SO2\_Volcano\_Flag pixels have also the original value 1 SO2\_Volcano\_Flag pixels included. I will not be missing anything.

Many thanks, as ever,  
MariLiza

---

<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: [January 20, 2023, 9:38am UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/9 "2023-01-20T09:38:51Z")

</div>

I should have realised this before. You can never have both bits 8 and 9 set at the same time due to the way we map the flag.

We didn’t actually have an operator in HARP to filter for ‘any’ bits in the mask to be non-zero.  
I just added this to HARP (the ‘=|’ operator). This will be included in the next HARP release.

Just for me to test this a bit. Do you know of a GOME2 orbit where there is actually an SO2\_Volcano\_Flag set to 2? I checked for instance 21 Sep 2021, where [S5P shows a plume going from Sicily to Greece,](https://maps.s5p-pal.com/so2/) where I would potentially expect such a flag near Greece, but GOME2(b) doesn’t show anything in that area (maybe due to different overpass time?)

---

<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: [January 20, 2023, 10:03am UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/10 "2023-01-20T10:03:51Z")

</div>

Hi Sander,

Yes, you can try GOME2A 2010 05 15, it was during the Eyja eruption. In one of the orbits I found a volc flag of 2, and in multiple others volc flag of 1. Should I try and find out in which ones?

Just so you can verify, this one is with SO2\_column\_number\_density\_validity !& 255 only:

 ![SO2_column_number_density_in_20100515_6km_no_cloud_flag](https://forum.atmospherictoolbox.org/uploads/default/original/1X/cfb12eb672d5991ed948c77b866e803034d63feb.jpeg)

And this one, also with SO2\_column\_number\_density\_validity =& 256

 ![SO2_column_number_density_in_20100515_6km_no_cloud_flag_volc_flag_applied](https://forum.atmospherictoolbox.org/uploads/default/original/1X/e06c5ff53ddf05296ebe677c53fd8cfef486ea16.jpeg)

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: [January 20, 2023, 1:30pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/11 "2023-01-20T13:30:46Z")

</div>

I got all the O3MOTO products from [acsaf.eoc.dlr.de](http://acsaf.eoc.dlr.de) for GOME-2A for 2010-05-15, but I only found SO2\_Volcano\_Flag values 0 and 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: [January 20, 2023, 1:42pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/12 "2023-01-20T13:42:32Z")

</div>

Oh, of course! I am working on the reprocessed dataset. Check your email. 🙂

---

<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: [January 20, 2023, 2:30pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/13 "2023-01-20T14:30:14Z")

</div>

Thanks for the test data. I was able to verify that using `SO2_column_number_density_validity=|768` now does the trick with new HARP change.

---

<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: [January 21, 2023, 12:04pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/14 "2023-01-21T12:04:55Z")

</div>

Thanks Sander. Will you include it in v1.17? [Release 1.17 · stcorp/harp · GitHub](https://github.com/stcorp/harp/releases/tag/1.17) this is also the one avaliable via conda install -c conda-forge harp.

I note that it exists as one of the two commits here: [Comparing 1.17…master · stcorp/harp · GitHub](https://github.com/stcorp/harp/compare/1.17...master)

But it is not clear to me if these are also in the anaconda channel?

Thanks!  
MariLiza

---

<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: [January 22, 2023, 10:44am UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/15 "2023-01-22T10:44:03Z")

</div>

A version of HARP that is released will not get modified (that is fundamentally how versioning works).

As I mentioned, this new operator will be included in the _next_ HARP release. When that will arrive exactly isn’t planned yet.

Users that really need a recent change that was committed can install HARP from github (which is a bit more involved than just performing a conda install).

---

<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: [February 10, 2023, 12:03pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/16 "2023-02-10T12:03:04Z")

</div>

Hey Sander,

I do not wish to be the bearer of bad news, however I should probably warn you that there is a difference between the volcanic flag for GOME2A & 2B, compared to GOME2C. If you look at page 46-47 of the PUM, [Microsoft Word - DLR\_GOME-2\_PUM\_3B\_Nov2019 (acsaf.org)](https://acsaf.org/docs/pum/Product_User_Manual_NTO_OTO_Nov_2019.pdf), you will note that there is an extra value for the GOME2C products.

Not sure if this eventuality is covered by the new commit you made last month.

Many thanks,  
MariLiza

---

<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: [February 10, 2023, 1:10pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/17 "2023-02-10T13:10:53Z")

</div>

We were not aware of this. It seems rather inconvenient that they chose to use different processor versions for the different MetOp satellites. This makes it rather hard to combine MetOp B and C SO2 data.

I will see whether we can accommodate these changes.

---

<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: [February 10, 2023, 1:26pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/18 "2023-02-10T13:26:36Z")

</div>

I checked, and I think we can leave the current HARP implementation as-is. It will then be up to the user to interpret the resulting `SO2_column_number_density_validity` variable appropriately according to whether it comes from MetOp B or C (as they would have had to do if they would have extracted the SO2\_Volcano\_Flag directly from the product instead of using HARP).

I don’t see an easy way to ‘harmonise’ the flags between GDP 4.8 and 4.9.

---

<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: [February 10, 2023, 7:11pm UTC](https://forum.atmospherictoolbox.org/t/harpmerge-on-the-command-line-ingestion-question-on-gome2ab-so2-flags/581/19 "2023-02-10T19:11:55Z")

</div>

Thanks for checking, Sander! Indeed, it makes using the command line harp tools more complicated. I should mention here that yours truly [and team!] is currently validating the reprocessed GOME2A & 2B which are also run with GDP4.8, and not GDP4.9, so the issue will be with us for some time to come.

On the positive side, the extra volcanic flag of GDP4.9 can be tackled with in GDP4.8 using the flag that covers the SAA region with NaNs, and of course adding a SZA filter is always a good idea with SO2.

Many thanks for all,  
MariLiza
