Package: woudc-extcsv
WOUDC Extended CSV libraryPython package providing read/write support of theWOUDCExtended CSV format.InstallationRequirementswoudc-extcsv requires Python 2.7,pywoudc, and unicodecsv.DependenciesSeerequirements.txtunicodecsvpywoudcInstalling the Package# via pippipinstallwoudc-extcsv# via easy_installeasy_installwoudc-extcsvUsageReader Objectsfromwoudc_extcsvimportReader# read from filewithopen('file.csv','rb')asff:ecsv=Reader(ff.read(),encoding='utf-8')# read from stringecsv=Reader(my_ecsv_string)Writer Objectsimportwoudc_extcsv# create new writer object with common/metadata tables and fields availableecsv=woudc_extcsv.Writer(template=True)# Add file commentsecsv.add_comment('This is a file level comment.')ecsv.add_comment('This is another file level comment.')# Add metadataecsv.add_data('CONTENT','WOUDC,Spectral,1.0,1')ecsv.add_data('DATA_GENERATION','2002-05-29,JMA,1.0')ecsv.add_data('PLATFORM','STN,7,Kagoshima,JPN,47827')ecsv.add_data('INSTRUMENT','Brewer,MKII,059')ecsv.add_data('LOCATION','31.63,130.6,283')# Add new tableecsv.add_table('TIMESTAMP')# Add fieldsecsv.add_field('TIMESTAMP','UTCOffset,Date,Time')# Add dataecsv.add_data('TIMESTAMP','+08:38:47',field='UTCOffset')# Add more dataecsv.add_data('TIMESTAMP','1991-01-01',field='Date')ecsv.add_data('TIMESTAMP','06:38:47',field='Time')# Add new table, fields, and data at the same timeecsv.add_data('GLOBAL_SUMMARY','06:38:47,7.117E-04,8.980E-03,94.12,99.99,114.64,001000,999',field='Time,IntACGIH,IntCIE,ZenAngle,MuValue,AzimAngle,Flag,TempC')ecsv.add_data('GLOBAL','290.0,0.000E+00',field='Wavelength,S-Irradiance,Time')ecsv.add_data('GLOBAL','290.5,0.000E+00')ecsv.add_data('GLOBAL','291.0,0.000E+00')# Add table for new groupingsecsv.add_data('TIMESTAMP','+08:38:46,1991-01-01,07:38:46',field='UTCOffset,Date,Time',index=2)ecsv.add_data('GLOBAL_SUMMARY','07:38:46,2.376E-02,3.984E-01,82.92,6.75,122.69,100000,999',field='Time,IntACGIH,IntCIE,ZenAngle,MuValue,AzimAngle,Flag,TempC',index=2,table_comment='This is a table level comment.')# Write to stringecsvs=woudc_extcsv.dumps(ecsv)# Write to file# validate (check if all common tables and their fields are present), if so dump to file# if not, print violationswoudc_extcsv.dump(ecsv,'spectral-sample.csv')Convenience Functionsimportwoudc_extcsv# load from file into Reader objectecsv=woudc_extcsv.load('file.csv')# load from string into Reader objectecsv=woudc_extcsv.loads(my_ecsv_string)# dump to file from Writer objectecsv=woudc_extcsv.dump('file.csv')# dump to string from Writer objectecsv=woudc_extcsv.dumps(my_ecsv_string)Error Handlingfrom woudc_extcsv import loads, WOUDCExtCSVReaderError

try:
    loads('bad content!')
except WOUDCExtCSVReaderError as err:
    print(err.message)
    for error in err.errors:
         print(error)ExamplesSee theexamples/directory for sample scripts.DevelopmentFor development environments, install
in a Pythonvirtualenv:virtualenvfoocdfoo
.bin/activate# fork master# fork https://github.com/woudc/woudc-extcsv on GitHub# clone your fork to create a branchgitclonehttps://github.com/{yourGitHubusername}/woudc-extcsv.gitcdwoudc-extcsv# install dev packagespipinstall-rrequirements-dev.txt# create upstream remotegitremoteaddupstreamhttps://github.com/woudc/woudc-extcsv.git
gitpullupstreammaster
gitbranchmy-cool-feature
gitcheckoutmy-cool-feature# start devgitcommit-m'implement cool feature'# push to your forkgitpushoriginmy-cool-feature# issue Pull Request on GitHubgitcheckoutmaster# cleanup/update once your branch is merged on GitHub# remove branchgitbranch-Dmy-cool-feature# update your forkgitpullupstreammaster
gitpushoriginmasterRunning Tests# via distutilspythonsetup.pytest# manuallypythonrun_tests.py# report test coveragecoveragerun--sourcewoudc_extcsvsetup.pytestcoveragereport-mCode Conventionswoudc_extcsv code conventions are as perPEP8.# code should always pass the followingfind-typef-name"*.py"|xargsflake8IssuesAll bugs, enhancements and issues are managed onGitHub.HistoryThe roots of woudc-extcsv originate within the WOUDC backend processing system
in support of processing data submissions.  woudc-extcsv was refactored
into a standalone library providing read/write support of the data centre's
core ingest format.In 2015 woudc-extcsv was made publically available in support of the Treasury
Board [Policy on Acceptable Network and Device Use]
(http://www.tbs-sct.gc.ca/pol/doc-eng.aspx?id=27122).ContactTom KralidisThinesh Sornalingam