Skip to content

Commit 80d76d8

Browse files
Add WOUDC Data Registry's Parsers
Parser from WOUDC data registry added into woudc-extcsv. Reader and Writer classes modified to used the ExtendedCSV class. Includes warning and error reporting for WOUDC's extcsv format.
1 parent c4c4551 commit 80d76d8

File tree

60 files changed

+12308
-6992
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+12308
-6992
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ are asked to read the 3rd Party Licenses referenced with those assets.
1919
The MIT License (MIT)
2020
=====================
2121

22-
Copyright (c) 2015 Government of Canada
22+
Copyright (c) 2022 Government of Canada
2323

2424
Permission is hereby granted, free of charge, to any person
2525
obtaining a copy of this software and associated documentation

README.md

+46-20
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@
55

66
# WOUDC Extended CSV library
77

8-
Python package providing read/write support of the
8+
Python package providing read/write support for files of the
99
[WOUDC](https://woudc.org) Extended CSV format.
1010

1111
## Installation
1212

1313
### Requirements
1414

15-
woudc-extcsv requires Python 3 and [pywoudc](https://github.com/woudc/pywoudc).
15+
woudc-extcsv requires Python 3 or above. See `requirements.txt`.
1616

17-
### Dependencies
17+
### Development
1818

19-
See `requirements.txt`
20-
- [pywoudc](https://github.com/woudc/pywoudc)
19+
```bash
20+
# install dev requirements
21+
pip install -r requirements-dev.txt
22+
```
2123

2224
### Installing the Package
2325

@@ -69,10 +71,7 @@ ecsv.add_table('TIMESTAMP')
6971
# Add fields
7072
ecsv.add_field('TIMESTAMP', 'UTCOffset,Date,Time')
7173
# Add data
72-
ecsv.add_data('TIMESTAMP', '+08:38:47', field='UTCOffset')
73-
# Add more data
74-
ecsv.add_data('TIMESTAMP', '1991-01-01', field='Date')
75-
ecsv.add_data('TIMESTAMP', '06:38:47', field='Time')
74+
ecsv.add_data('TIMESTAMP', '+08:38:47,1991-01-01,06:38:47')
7675

7776
# Add new table, fields, and data at the same time
7877
ecsv.add_data('GLOBAL_SUMMARY',
@@ -85,6 +84,7 @@ ecsv.add_data('GLOBAL',
8584
'290.5,0.000E+00')
8685
ecsv.add_data('GLOBAL',
8786
'291.0,0.000E+00')
87+
ecsv.add_table_comment('GLOBAL', 'This is a table level comment', index=1)
8888
# Add table for new groupings
8989
ecsv.add_data('TIMESTAMP',
9090
'+08:38:46,1991-01-01,07:38:46',
@@ -95,7 +95,7 @@ ecsv.add_data('GLOBAL_SUMMARY',
9595
'07:38:46,2.376E-02,3.984E-01,82.92,6.75,122.69,100000,999',
9696
field='Time,IntACGIH,IntCIE,ZenAngle,MuValue,AzimAngle,Flag,TempC',
9797
index=2, table_comment='This is a table level comment.')
98-
98+
ecsv.add_table_comment('GLOBAL_SUMMARY', 'This is another table level comment', index=2)
9999
# Write to string
100100
ecsvs = woudc_extcsv.dumps(ecsv)
101101

@@ -114,28 +114,54 @@ ecsv = woudc_extcsv.load('file.csv')
114114
# load from string into Reader object
115115
ecsv = woudc_extcsv.loads(my_ecsv_string)
116116
# dump to file from Writer object
117-
ecsv = woudc_extcsv.dump('file.csv')
117+
ecsv = woudc_extcsv.dump(ecsv_writer, 'file.csv')
118118
# dump to string from Writer object
119-
ecsv = woudc_extcsv.dumps(my_ecsv_string)
119+
ecsv = woudc_extcsv.dumps(ecsv_writer)
120+
```
121+
122+
### ExtendedCSV Objects
123+
The ExtendedCSV class is a parser class used in the Reader and Writer classes, and can be used to both read and write to an Extended CSV object.
124+
125+
```python
126+
from woudc_extcsv import ExtendedCSV
127+
# read from file
128+
with open('file.csv', 'r') as ff:
129+
ecsv = ExtendedCSV(ff.read())
130+
# read from string
131+
ecsv = Extended(my_ecsv_string)
132+
133+
# Add a file-level comment
134+
ecsv.add_comment('This is a file level comment')
135+
# Add new table to object
136+
ecsv.init_table('GLOBAL', ['Wavelength', 'S-Irradiance'], line_num)
137+
# Add another field to the new table
138+
ecsv.add_field_to_table('GLOBAL', ['Time'])
139+
# Add data to table
140+
ecsv.add_values_to_table('GLOBAL', ['290.5', '0.000E+00', ''], line_num)
141+
# Add a table comment
142+
ecsv.add_table_comment('GLOBAL', 'This is a table level comment')
143+
# Remove a table
144+
ecsv.remove_table('GLOBAL')
145+
# Validate Extended CSV and collimate the tables
146+
# Check metadata tables
147+
ecsv.validate_metadata_tables()
148+
# Check dataset-specific tables
149+
ecsv.validate_dataset_tables()
120150
```
121151

122152
### Error Handling
123153

124-
```pyhon
125-
from woudc_extcsv import loads, WOUDCExtCSVReaderError
154+
```python
155+
from woudc_extcsv import ExtendedCSV, NonStandardDataError, MetadataValidationError
126156

127157
try:
128-
loads('bad content!')
129-
except WOUDCExtCSVReaderError as err:
158+
ecsv = ExtendedCSV('bad content!')
159+
except (NonStandardDataError, MetadataValidationError) as err:
130160
print(err.message)
131161
for error in err.errors:
132162
print(error)
133163
```
134164

135-
## Examples
136-
137-
See the `examples/` directory for sample scripts.
138-
139165
## Development
140166

141167
For development environments, install

requirements.txt

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
jsonschema
2+
pyyaml

setup.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# those files. Users are asked to read the 3rd Party Licenses
1919
# referenced with those assets.
2020
#
21-
# Copyright (c) 2015 Government of Canada
21+
# Copyright (c) 2022 Government of Canada
2222
#
2323
# Permission is hereby granted, free of charge, to any person
2424
# obtaining a copy of this software and associated documentation
@@ -126,7 +126,10 @@ def get_package_version():
126126
url=URL,
127127
install_requires=INSTALL_REQUIRES,
128128
packages=find_packages('.'),
129-
package_data={'woudc_extcsv': ['table_configuration.csv']},
129+
package_data={
130+
'woudc_extcsv': ['tables-schema.json', 'tables-backfilling.yml',
131+
'errors-backfilling.csv']
132+
},
130133
scripts=SCRIPTS,
131134
classifiers=[
132135
'Development Status :: 4 - Beta',
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#CONTENT
2+
Class,Category,Level,Form
3+
WOUDC,Broad-band,1.0,1
4+
5+
#DATA_GENERATION
6+
Date,Agency,Version,ScientificAuthority
7+
2009-12-08,PMOD-WRC,3.0,Julian Groebner
8+
9+
#INSTRUMENT
10+
Name,Model,Number
11+
Kipp_Zonen,UV-S-E-T,000560
12+
13+
#PLATFORM
14+
Type,ID,Name,Country,GAW_ID
15+
STN,501,DAVOS,CHE
16+
17+
#LOCATION
18+
Latitude,Longitude,Height
19+
46.82,9.85,1590
20+
21+
#TIMESTAMP
22+
UTCOffset,Date
23+
+00:00:00,2008-01-01
24+
25+
#GLOBAL
26+
Time,Irradiance
27+
00:01:02,0.000000
28+
00:03:02,0.000000
29+
00:05:02,0.000000
30+
00:07:02,0.000000
31+
00:09:02,0.000001
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#CONTENT
2+
Class,Category,Level,Form
3+
WOUDC,Broad-band,1.0,1
4+
5+
#DATA_GENERATION
6+
Date,Agency,Version,ScientificAuthority
7+
2010-02-04,ASM-ARG,1.0,Dr. A. Aculinin
8+
9+
#PLATFORM
10+
Type,ID,Name,Country,GAW_ID
11+
STN,455,Kishinev,MDA
12+
13+
#INSTRUMENT
14+
Name,Model,Number
15+
Kipp_Zonen,UV-S-B-C,020579
16+
17+
#LOCATION
18+
Latitude,Longitude,Height
19+
47.0,28.82,205
20+
21+
#TIMESTAMP
22+
UTCOffset,Date,Time
23+
+00:00:00,2010-01-09
24+
25+
#DIFFUSE
26+
Time,Irradiance
27+
06:00:00,0.002
28+
06:01:00,0.002
29+
06:02:00,0.002
30+
06:03:00,0.002
31+
06:04:00,0.002

tests/data/general/ecsv-comments.csv

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
* These data were originally received by the WOUDC in SHADOZ file format and
2+
* have been translated into extCSV file format for WOUDC archiving.
3+
* This translation process re-formats these data to comply with WOUDC standards.
4+
5+
* This file was generated by SHADOZ_TO_CSX - version 3.1.
6+
* 'na' is used where Instrument Model or Number are not available.
7+
8+
* Source File: ronbrown_20040709_L1.txt
9+
10+
* NASA/GSFC/INTEX-NA/IONS04 Archive
11+
* Created 12 March, 2007, SHADOZ V4 Format
12+
* STATION : R/V R.H. Brown
13+
* Station Principal Investigator : Samuel J. Oltmans (NOAA/ESRL, CO, US)
14+
* Latitude (deg) : 43.4400
15+
* Longitude (deg) : -66.5700
16+
* Elevation (m) : m.s.l.
17+
* Launch Date : 20040709
18+
* Launch Time (UT) : 14:00
19+
* Sonde Type/KI Solution : 2Z EnSci, 0.5% buffered
20+
* Applied pump corrections : NOAA/ESRL measured
21+
* Burst Pressure (hPa) : 2.60
22+
* Integrated O3 (DU) : 372.57
23+
* Sonde/Sage Climatology(1988-2002): 7.4
24+
* Const. Mixing Ratio Residual (DU): 27.1
25+
26+
#CONTENT
27+
Class,Category,Level,Form
28+
IONS,OzoneSonde,1.0,1
29+
30+
#DATA_GENERATION
31+
Date,Agency,Version,ScientificAuthority
32+
2007-03-12,NOAA-CMDL,1.0,"Samuel J. Oltmans (NOAA/ESRL, CO, US)"
33+
* IONS Project Co-ordinator: Anne M. Thompson (NASA/GSFC)
34+
35+
#PLATFORM
36+
Type,ID,Name,Country,GAW_ID
37+
SHP,440,R H BROWN RESEARCH SHIP,*IW,
38+
39+
#INSTRUMENT
40+
Name,Model,Number
41+
ECC,2Z,2ZL1
42+
43+
#LOCATION
44+
Latitude,Longitude,Height
45+
43.44,-66.57,2
46+
47+
#TIMESTAMP
48+
UTCOffset,Date,Time
49+
+00:00:00,2004-07-09,14:00:00
50+
51+
#FLIGHT_SUMMARY
52+
IntegratedO3,CorrectionCode,SondeTotalO3,CorrectionFactor,TotalO3,WLcode,ObsType,Instrument,Number
53+
372.57,,,,,,,,
54+
55+
#AUXILIARY_DATA
56+
MeteoSonde,ib1,ib2,PumpRate,BackgroundCorr,SampleTemperatureType,MinutesGroundO3
57+
,,,,,PUMP,
58+
59+
#PROFILE
60+
Pressure,O3PartialPressure,Temperature,WindSpeed,WindDirection,LevelCode,Duration,GPHeight,RelativeHumidity,SampleTemperature
61+
1007.70,2.540,9.50,1.6,18.4,,,0,94,
62+
1008.00,2.450,9.30,2.2,68.0,,,20,94,
63+
1006.40,2.630,9.20,3.1,109.8,,,30,95,
64+
1004.90,2.620,9.10,3.6,137.2,,,40,95,
65+
1004.90,2.540,9.40,5.3,145.7,,,40,96,

0 commit comments

Comments
 (0)