khaeru / sdmx

SDMX information model and client in Python
https://sdmx1.readthedocs.io
Apache License 2.0
23 stars 18 forks source link

Add tutorial/docs: write structure-specific SDMX-ML #93

Open PalGal2 opened 2 years ago

PalGal2 commented 2 years ago

Hi,

I would like to know if there is a method to write a Structure Specific Data SDMX-ML 2.1 with sdmx package.

>>> sdmx.format.FORMATS[1]
Format(mime='application/vnd.sdmx.structurespecificdata+xml;version=2.1', base='xml', data=True, meta=False, extra=<Extra.ss: 1>)

It looks like that the to_xml function writes in generic by default. Is there a way to specify the "structure specific data" parameter ?

Many thanks

khaeru commented 2 years ago

Is there a way to specify the "structure specific data" parameter ?

There is, but it's not very obvious, sorry.

In short:

Other thoughts:

PalGal2 commented 2 years ago

Many thanks @khaeru, this is perfect.

I have just a minor question related to your answer : changing DataSet to StructureSpecificDataset works great, but I still have a repetition of dimensions at the level of observation, whereas I would like to have them at the series level (i.e. for a given series, the value changes only on the time period dimension). My demo is "cross-sectional data".

I wasn't able to find any documentation on that, but I am sure it is feasible with your library. Could you please give me some advice ?

Thank you so much.

khaeru commented 2 years ago

I still have a repetition of dimensions at the level of observation, whereas I would like to have them at the series level (i.e. for a given series, the value changes only on the time period dimension). My demo is "cross-sectional data".

Without a specimen or example code, it's really not clear what precisely you're trying to do, and what result you're getting instead.

A wild guess: taking this example https://github.com/khaeru/sdmx-test-data/blob/f040d18abbcf6b40b1640e510fbea0f91aa22d60/ECB_EXR/ng-xs-ss.xml#L14-L20 —what you are saying is that some dimension, e.g. CURRENCY_DENOM, is being written as part of the individual <Obs …/> XML elements, instead of as part of the containing <Series …></Series> elements. Is that correct?

If so, note the writer code follows the structure of the data, e.g.

I hope that helps to investigate the data structures you are writing out.

PalGal2 commented 2 years ago

Thank you again for your precious help @khaeru. The example perfectly matches with what I would like to have in my final SDMX-ML file. I followed this tutorial which, however, does not present the <Series ...> elements.

How can I adapt this tutorial to add the element in the final xml file? I would guess I have to specify the series argument in the sdmx.model.StructureSpecificDataset but I do not know how. Is that correct ? Could you please give me some guidance please ?

Can you give some examples for the following arguments in sdmx.model.StructureSpecificDataSet drawing on the tutorial (maybe to implement in the doc for other users?) :

khaeru commented 2 years ago

maybe to implement in the doc for other users?

As you note, this is a substantial expansion of the docs, i.e. a whole new tutorial. I think that would be a nice enhancement to have, but do not have time to do it at this moment. I also cannot write your code for you.

What I would suggest you do is:

PalGal2 commented 2 years ago

Many thanks @khaeru for your time.

khaeru commented 2 years ago

Let's keep the issue open as a TODO item for the eventual new tutorial.

PalGal2 commented 2 years ago

If this may help someone, I found here a sample code to build SeriesKey / Observation edited by @brockfanning.