Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

wrong format of spec files from sardana #735

Closed
jkotan opened this issue Apr 16, 2018 · 19 comments · Fixed by #1355 · May be fixed by #1356
Closed

wrong format of spec files from sardana #735

jkotan opened this issue Apr 16, 2018 · 19 comments · Fixed by #1355 · May be fixed by #1356

Comments

@jkotan
Copy link
Collaborator

jkotan commented Apr 16, 2018

It looks like spec files from sardana do not adhere to the specifications of the SPEC standard data file format from Standard Data File Format. This causes problems in reading them via spec2nexus prjemian/spec2nexus#122 or nexpy nexpy/nexpy#152

@cpascual
Copy link

Before fixing this, I would like to confirm that the official ultimate reference for the spec file syntax is the one linked above. I say so because some years ago, while fixing some other issue in Sardana's spec recorder, we used some reference document for the spec file syntax which I believe it was much more extense and formal than the one in the link... but I cannot find it now among my files or in the web which makes me doubt about my memory... :-\

@rhomspuron
Copy link
Collaborator

rhomspuron commented Apr 17, 2018

Hi, you can find the information on the official specpython library. This block is not mandatory:
https://github.com/specpython/filespec/blob/master/specpython/spec_format.rst
For that reason the specpython and pymca can open the file without problems.

On the other hand, the file generated by sardana use the motor label '#O' and position '#P' for the snapshots and it saves them on each scan.

@prjemian
Copy link

@vrey01 : Can you comment on this? Which is the definitive reference for the SPEC data file format?

@vrey01
Copy link

vrey01 commented Apr 18, 2018

The spec data format is described in detail in https://certif.com/spec_help/scans.html or, in spec, by typing "help scans". (look for paragraph "File Conventions")

The spec data format gives a list of annotation conventions but it does not specify a "minimal" set of annotations that should be present in a file. For example, in the page referenced above, after the list of standard control lines, there is an example of a "simple data file" containing just "#S, #N and #L" lines. Once this said, as it could be expected, spec itself produces data with much richer annotation that the one in that "simple example", including a header block indicating "filename", "date of creation", "application name", "user name that created the file", "epoch (to precisely time-tag each data point)"...

The tools reading spec data files decide what is the minimal information needed to display data. For example, in the case of the "splot" (standard plot program distributed with spec) it is sufficient to have a "#S" and a "#L" control lines to recognise a file as a valid spec data file and display the scans included in it. In the case of the "scans" unix tool (also distributed with spec) only the "#S" is necessary to properly manage spec files. Eventually each tool will decide how tolerant will be to missing control lines and how it will handle them.
As the spec file format is one for a multi-scan container file I would say that, as scan delimiter, only the "#S" control line is mandatory.

My recommendation for sardana would be to include at least a "file header block", starting with "#F" and including metadata about the file, user, creation time, etc... but.. this is not mandatory!

@vrey01
Copy link

vrey01 commented Apr 18, 2018 via email

@cpascual
Copy link

Thanks @vrey01 for the clarification.
Since having the file header is not mandatory, I am marking this issue as "Enhancement" for sardana, but IMHO the original issue should be solved by supporting more generic files in spec2nexus (see prjemian/spec2nexus#122). Do you agreee @prjemian ?

@prjemian
Copy link

@vrey01 : thanks for the information. Until this, I have taken the SPEC user manual at its word, while recognizing that there are no rules in SPEC, just a set of macros implementing what is provided from certif.com.

@jkotan
Copy link
Collaborator Author

jkotan commented Apr 26, 2018

I've just noticed that there are additionally like #@CHANN, #@MCA_NB, #@DET_0, #@CTIME, #@CALIB, #@ROI in spec_format with respect to scans.

Does it mean that scans is outdated or spec_format is beyond the standard?

@rhomspuron
Copy link
Collaborator

We asked to include on filespec new extra-lines: #@MCA_NB, #@DET_0 to save more information related to the 1D detectors.

The other extra-lines are used by PyMCA. AFAIK, spec's scans generates the other extra-lines.

@vrey01: Could you clarify that?

@tiagocoutinho
Copy link

I just came across this issue.

I made two PRs:
#1355 - add user information
#1356 - add missing epoch

They may help improve sardana spec recorder

@tiagocoutinho
Copy link

Concerning the snapshot feature of sardana:

it is storing each snapshot variable as a separate motor (#O & #o fields)
This is obviously not the best because:

  • many snapshot variables are not motors
  • many snapshot values are not numbers

I was asked to add more information to the scan header. In my case it corresponds to a sardana environment variable (explicitly, I was asked to avoid storing stuff as motor)

AFAIK, there is no spec field associated with storing general meta information.
I could extend the sardana spec recorder to fit my own purposes by implementing something like #C <variable> <value>

This would probably not break any client. But before I do, does anyone know of any de-facto syntax out there being used for my case?

Thanks in advance

@tiagocoutinho
Copy link

tiagocoutinho commented Jun 17, 2020

Please forget my previous comment. I now see there are already other issues discussing this: #771 and #776.

@vrey01
Copy link

vrey01 commented Jun 17, 2020 via email

@tiagocoutinho
Copy link

Cool, thanks @vrey01.
That is valuable information I was not aware of.

@guifrecuni
Copy link

Yes! it is really a good contribution to think about.
Both #UVAR and #UMETA proposed options look good to me.
Also, these macros for "adding comments" may be useful for Sardana users.

Thanks Bixente!

@tiagocoutinho
Copy link

I see we have a addCustomData() that produces #C <key> : <value>.

Should we:

  • change it to produce #UVAR <varname> <value> or
  • add another method?

@cpascual
Copy link

I see we have a addCustomData() that produces #C :

Note that addCustomData is called by the DataHandler on all recorders if the macro defines custom data. If you create a different one, it won't be accessible in this way.

I personally would add a kwarg to the SpecFileRecorder.addCustomData to specify a format string and I would set it as an option in sardanacustomsettings (so that anyone looking for bck-compat can recover the previous behaviour):

class SPEC_FileRecorder(BaseFileRecorder):
    ...
    def _addCustomData(self, value, name, spec_custom_fmt=None, **kwargs):
        if spec_custom_fmt is None:
            spec_custom_fmt = getattr(sardanacustomsettings, "SPEC_CUSTOM_DATA_FORMAT", "#UVAR {name} {value}")
       ...
       self.fd.write(spec_custom_fmt.format(value=v, name=name))

And in sardanacustomsettings, SPEC_CUSTOM_DATA_FORMAT would be defined with "#UVAR {name} {value}" but documented with a suggestion of "#C {name} : {value}" for bck-compat

@dschick
Copy link

dschick commented Jun 19, 2020

at bessy we also use the #U tag but instead of having a key: value syntax we do like

#u1 key1 key2 key3
#U1 value1 value2 value3

Is it also possible to add the custom data to hdf5 files?

@cpascual
Copy link

cpascual commented Jun 21, 2020 via email

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
8 participants