# Harp.Variable dimensions

**URL:** https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329
**Category:** HARP
**Tags:** python
**Created:** [May 24, 2021, 9:36am UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329 "2021-05-24T09:36:51Z")
**Posts on this page:** 6
**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 24, 2021, 9:36am UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329/1 "2021-05-24T09:36:51Z")

</div>

Greetings Sander,

I wish to create ncdf files using the harp.Variable via the python interface. I have ozone profiles, however I have to different sized vertical dimensions, one in 10 layers and the other in 16 layers. The code complains if I add a second variable using the [‘time’, ‘vertical’] dimension whose vertical legth is different from the previous one. I tried assigning one of the profiles as [‘time’,‘independent’] to trick the system, but it replies that :  
Error: variable ‘‘RetrievedOzoneProfileIn10Layers’’ could not be exported (unsupported dimension ‘independent’)

Is there a way to “cheat” and have a harp product where the vertical dimension can be of varying length?

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: [May 24, 2021, 9:49am UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329/2 "2021-05-24T09:49:40Z")

</div>

The way to do this is to use the maximum length for the vertical dimension and pad elements at the end with NaN for shorter profiles. This approach is also documented in the [HARP conventions](http://stcorp.github.io/harp/doc/html/conventions/dimensions.html).

---

<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 24, 2021, 10:14am UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329/3 "2021-05-24T10:14:55Z")

</div>

Thanks Sander, I was looking at the python interface convention and missed the link you emailed me!

---

<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 25, 2021, 6:31am UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329/4 "2021-05-25T06:31:01Z")

</div>

Greetings again Sander,

Following the topic above, I would like to add some global attributes to the ncdf file I am creating, such as information on the algorithm, the data provider, and such like. I read in the documentation that:

_Note that files using the HARP data format can include global attributes in addition to the ones mentioned above. However, such attributes will be ignored when the product is imported._

However, I fail to see how this will be accomplished, I am missing the syntax. I am performing the following set of operations:

product = harp.Product()  
product.SomeDataArray = harp.Variable(array, dims, description)  
…  
productlist.append(product)  
output = harp.concatenate(productlist)  
harp.export\_product(output, OutFile.nc)

I am guessing that I need to define this in the harp.Product initialisation in some manner or other?

Many thanks and best wishes,  
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: [May 25, 2021, 9:44am UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329/5 "2021-05-25T09:44:26Z")

</div>

The HARP software itself does not allow exporting additional attributes.  
If you want to store additional information, then you would have to create the netcdf file yourself (using e.g. the python netcdf library).  
It is actually perfectly valid to create your HARP compatible files without using the HARP software itself (this is probably recommended if you want to add your own metadata on top of it).

Trying to write a HARP compatible file without the HARP software will take a bit more effort, since you will have to create some standard global attributes yourself (such as the Conventions and datetime\_start/datetime\_stop attributes).

If you want a quick solution then you could just reopen the created HARP file with the netcdf library and add any missing attributes (but then your code would depend on both the HARP library _and_ the netcdf library).

---

<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 26, 2021, 1:04pm UTC](https://forum.atmospherictoolbox.org/t/harp-variable-dimensions/329/6 "2021-05-26T13:04:40Z")

</div>

Thanks Sander. I actually do not know how to make nc files using the standard python libraries, only via the harp tool. I do not think that the users of this dataset will need harp-compliant files in any case, so I will add the attributes using the nominal python libraries, thanks again. Time for me to learn new things.  
MariLiza
