跳转到主要内容

Python包,提供对WOUDC扩展CSV格式的读写支持。

项目描述

Build Status Build status Downloads this month on PyPI Latest release License

WOUDC扩展CSV库

Python包,提供对WOUDC扩展CSV格式的读写支持。

安装

需求

woudc-extcsv需要Python 2.7,pywoudc和unicodecsv。

依赖项

请参阅requirements.txt

安装包

# via pip
pip install woudc-extcsv
# via easy_install
easy_install woudc-extcsv

用法

读取器对象

from woudc_extcsv import Reader
# read from file
with open('file.csv', 'rb') as ff:
    ecsv = Reader(ff.read(), encoding='utf-8')
# read from string
ecsv = Reader(my_ecsv_string)

写入器对象

import woudc_extcsv
# create new writer object with common/metadata tables and fields available
ecsv = woudc_extcsv.Writer(template=True)

# Add file comments
ecsv.add_comment('This is a file level comment.')
ecsv.add_comment('This is another file level comment.')

# Add metadata
ecsv.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 table
ecsv.add_table('TIMESTAMP')
# Add fields
ecsv.add_field('TIMESTAMP', 'UTCOffset,Date,Time')
# Add data
ecsv.add_data('TIMESTAMP', '+08:38:47', field='UTCOffset')
# Add more data
ecsv.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 time
ecsv.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 groupings
ecsv.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 string
ecsvs = 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 violations
woudc_extcsv.dump(ecsv, 'spectral-sample.csv')

便利函数

import woudc_extcsv
# load from file into Reader object
ecsv = woudc_extcsv.load('file.csv')
# load from string into Reader object
ecsv = woudc_extcsv.loads(my_ecsv_string)
# dump to file from Writer object
ecsv = woudc_extcsv.dump('file.csv')
# dump to string from Writer object
ecsv = woudc_extcsv.dumps(my_ecsv_string)

错误处理

from woudc_extcsv import loads, WOUDCExtCSVReaderError

try:
    loads('bad content!')
except WOUDCExtCSVReaderError as err:
    print(err.message)
    for error in err.errors:
         print(error)

示例

请参阅examples/目录中的示例脚本。

开发

对于开发环境,请在Python virtualenv中安装

virtualenv foo
cd foo
. bin/activate
# fork master
# fork https://github.com/woudc/woudc-extcsv on GitHub
# clone your fork to create a branch
git clone https://github.com/{your GitHub username}/woudc-extcsv.git
cd woudc-extcsv
# install dev packages
pip install -r requirements-dev.txt
# create upstream remote
git remote add upstream https://github.com/woudc/woudc-extcsv.git
git pull upstream master
git branch my-cool-feature
git checkout my-cool-feature
# start dev
git commit -m 'implement cool feature'
# push to your fork
git push origin my-cool-feature
# issue Pull Request on GitHub
git checkout master
# cleanup/update once your branch is merged on GitHub
# remove branch
git branch -D my-cool-feature
# update your fork
git pull upstream master
git push origin master

运行测试

# via distutils
python setup.py test
# manually
python run_tests.py
# report test coverage
coverage run --source woudc_extcsv setup.py test
coverage report -m

代码约定

woudc_extcsv代码约定遵循PEP8

# code should always pass the following
find -type f -name "*.py" | xargs flake8

问题

所有错误、增强和问题均由GitHub管理。

历史

WOUDC-EXTCSV 的根源在于 WOUDC 后端处理系统中,用于支持数据处理提交。WOUDC-EXTCSV 被重构为一个独立的库,提供数据中心核心导入格式的读写支持。

2015 年,WOUDC-EXTCSV 公开提供,以支持财政部 [网络和设备使用政策] (http://www.tbs-sct.gc.ca/pol/doc-eng.aspx?id=27122)。

联系

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源分发

此版本没有可用的源分发文件。请参阅 生成分发存档的教程

构建分发

woudc_extcsv-0.3.1-py2.py3-none-any.whl (17.6 kB 查看哈希值)

上传时间 Python 2 Python 3

由...