Using the EbasMetadata object

The EbasMetadata object defines the syntax of the ebas.io file objects. It is used internally by the io.file objects for creating the output files and parsing input files.

The user migtht, when creating an output file use the object for retrieving information about how to set a specific attribute in the file object in order to create a specifig metadata element in the output file.

Or vice versa, when reading an input file, know which attribute to access when the contents of a specific metadata element in the file is needed.

Please find below some examples how to list this kind of information interactively.

General setup: imports and instanciation

This part is needed for all the examples below.

Be aware to specify the datalevel if you want to see metadata that are only allowed for level 0. This is important if you want to write a script for level 0 data submissions. For some templates (e.g. mmps, nephelometer and filter_absorption_potometer), additional metadata are used which are only valid for data level 0.

In [1]:
from ebas.io.ebasmetadata import EbasMetadata, EBAS_IOFORMAT_NASA_AMES
meta = EbasMetadata('EBAS_1.1', EBAS_IOFORMAT_NASA_AMES, data_level='0')

List all possible metadata elements

This code sequence lists all possible metadata elements in EBAS. Each line contains the tag (the tag used in the Nasa Ames files) and the key (the key used in the io object's metadata). We only list metadata which are allowed either as global metadata (main) or as variable metadata (vname)

In [2]:
for elem in [x for x in meta.metadata if x['main'] or x['vname']]:
    if not 'renamed_tag' in elem:
        print("{:45s} {}".format(elem['tag']+":", elem['key']))
Data definition:                              datadef
Set type code:                                type
Timezone:                                     timezone
Timeref:                                      timeref
File name:                                    filename
File creation:                                creation_time
Export state:                                 export_state
Export filter:                                export_filter
Startdate:                                    startdate
Revision date:                                revdate
Version:                                      revision
Version description:                          revdesc
Statistics:                                   statistics
Data level:                                   datalevel
Period code:                                  period
Resolution code:                              resolution
Sample duration:                              duration
Orig. time res.:                              rescode_sample
Station code:                                 station_code
Platform code:                                platform_code
Station name:                                 station_name
Station WDCA-ID:                              station_wdca_id
Station GAW-ID:                               station_gaw_id
Station GAW-Name:                             station_gaw_name
Station AIRS-ID:                              station_airs_id
Station other IDs:                            station_other_ids
Station state/province:                       station_state_code
Station land use:                             station_landuse
Station setting:                              station_setting
Station GAW type:                             station_gaw_type
Station WMO region:                           station_wmo_region
Station latitude:                             station_latitude
Station longitude:                            station_longitude
Station altitude:                             station_altitude
Measurement latitude:                         mea_latitude
Measurement longitude:                        mea_longitude
Measurement altitude:                         mea_altitude
Measurement height:                           mea_height
Regime:                                       regime
Component:                                    comp_name
Unit:                                         unit
Matrix:                                       matrix
Laboratory code:                              lab_code
Instrument type:                              instr_type
Instrument name:                              instr_name
Instrument manufacturer:                      instr_manufacturer
Instrument model:                             instr_model
Instrument serial number:                     instr_serialno
Sensor type:                                  sensor_type
Analytical laboratory code:                   ana_lab_code
Analytical measurement technique:             ana_technique
Analytical instrument name:                   ana_instr_name
Analytical instrument manufacturer:           ana_instr_manufacturer
Analytical instrument model:                  ana_instr_model
Analytical instrument serial number:          ana_instr_serialno
Ext. lab. code:                               ext_lab
Method ref:                                   method
Standard method:                              std_method
Calibration scale:                            cal_scale
Calibration standard ID:                      cal_std_id
Secondary standard ID:                        sec_std_id
Inlet type:                                   inlet_type
Inlet description:                            inlet_desc
Inlet tube material:                          inlet_tube_material
Inlet tube outer diameter:                    inlet_tube_outerD
Inlet tube inner diameter:                    inlet_tube_innerD
Inlet tube length:                            inlet_tube_length
Time from entry inlet line to entry of converter: time_inlet_to_converter
Duration of stay in converter or bypass line: time_converter_or_bypass_line
Duration of stay in converter:                time_stay_converter
Converter temperature:                        converter_temp
Maintenance description:                      maintenance_desc
Flow rate:                                    flow_rate
Filter face velocity:                         filter_face_velocity
Exposed filter area:                          filter_area
Filter description:                           filter_descr
Medium:                                       medium
Coating/Solution:                             coating_solution
Filter prefiring:                             filter_prefiring
Filter conditioning:                          filter_conditioning
Filter type:                                  filter_type
Sample preparation:                           sample_prep
Blank correction:                             blank_corr
Artifact correction:                          artifact_corr
Artifact correction description:              artifact_corr_desc
Charring correction:                          charring_corr
Ozone correction:                             ozone_corr
Water vapor correction:                       watervapor_corr
Zero/span check type:                         zero_span_type
Zero/span check interval:                     zero_span_interval
Humidity/temperature control:                 hum_temp_ctrl
Humidity/temperature control description:     hum_temp_ctrl_desc
Volume std. temperature:                      vol_std_temp
Volume std. pressure:                         vol_std_pressure
Detection limit:                              detection_limit
Detection limit expl.:                        detection_limit_desc
Upper range limit:                            upper_range_limit
Measurement uncertainty:                      uncertainty
Measurement uncertainty expl.:                uncertainty_desc
Zero/negative values code:                    zero_negative
Zero/negative values:                         zero_negative_desc
Absorption cross section:                     abs_cross_section
Mass absorption cross section:                mass_abs_cross_section
Multi-scattering correction factor:           multi_scattering_corr_fact
Maximum attenuation:                          max_attenuation
Leakage factor zeta:                          leakage_factor_zeta
Compensation threshold attenuation 1:         comp_thresh_atten1
Compensation threshold attenuation 2:         comp_thresh_atten2
Compensation parameter k min:                 comp_param_kmin
Compensation parameter k max:                 comp_param_kmax
Coincidence correction:                       coincidence_corr
Charge type:                                  charge_type
Inlet diffusion loss data:                    inlet_diffusion_loss_data
CPC default pulse width:                      cpc_default_pulse_width
QA measure ID:                                qm_id
QA measure description:                       qm_desc
QA date:                                      qa_date
QA outcome:                                   qa_outcome
QA bias:                                      qa_bias
QA variability:                               qa_variability
QA document name:                             qa_doc_name
QA document date:                             qa_doc_date
QA document URL:                              qa_doc_url
Originator:                                   originator
Submitter:                                    submitter
Acknowledgement:                              acknowledgements
Comment:                                      comment

List only metadata which are mandatory when writing files

Here we restrict to global metadata (main) which are mandatory when writing (& 2) a file:

In [3]:
for elem in [x for x in meta.metadata if x['main'] & 2]:
    if not 'renamed_tag' in elem:
        print("{:45s} {}".format(elem['tag']+":", elem['key']))
Data definition:                              datadef
Set type code:                                type
Timezone:                                     timezone
File name:                                    filename
File creation:                                creation_time
Startdate:                                    startdate
Revision date:                                revdate
Data level:                                   datalevel
Period code:                                  period
Resolution code:                              resolution
Station code:                                 station_code
Platform code:                                platform_code
Regime:                                       regime
Component:                                    comp_name
Matrix:                                       matrix
Laboratory code:                              lab_code
Instrument type:                              instr_type
Instrument name:                              instr_name
Method ref:                                   method
Originator:                                   originator
Submitter:                                    submitter

specifications for cardinality

  • main: specifies the cardinality of the element in the main header (NNCOM lines)

    Bitfield:                                                        
        0 not allowed                                                    
        1 allowed but not mandatory                                      
        2 mandatory on export                                            
        4 mandatory on import                                            
        8 critical on import (if missing, exit after reading header)     
  • vname: specifies the cardinality of the element in the vname line.

    Bitfield:                                                        
        0 not allowed                                                    
        1 allowed but not mandatory                                      
        2 mandatory on export (not used)                                 
        4 mandatory on import                                            
        8 critical on import (if missing, exit after reading header)     

Finding the key to a tag

If you see a metadata element in the NASA Ames file and want to access it after reading the file using the ebas.io module, you need to find the element's key when knowing the tag:

In [4]:
meta.metadata_tags['Instrument manufacturer']['key']
Out[4]:
'instr_manufacturer'
In [5]:
meta.metadata_tags['Orig. time res.']['key']
Out[5]:
'rescode_sample'

Finding the tag to a key

The other way around, you might want to find the tag to a known key:

In [6]:
meta.metadata_keys['instr_manufacturer']['tag']
Out[6]:
'Instrument manufacturer'