My favorites
▼
|
Sign in
ccc-gistemp
Clear Climate Code reimplementation of GISTEMP
Project Home
Downloads
Wiki
Issues
Source
Checkout
Browse
Changes
Source path:
svn
/
trunk
/
tool
/
v2split.py
r1009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python
# $URL$
# $Rev$
#
# v2split.py
#
# David Jones, Ravenbrook Limited, 2010-02-26
"""
python ghcn_split.py YYYY
Splits a GHCN v2.mean file, on stdin, into two files: v2.mean-preYYYY
v2.mean-postYYYY. The split is made on the basis of which stations are
reporting in the year YYYY or a more recent year. v2.mean-postYYYY will
contain records for all the stations that have a record in the year YYYY
or a more recent year; v2.mean-preYYYY will contain the records for all
the other stations.
"""
def split(inp, out, splitat):
"""Input flle: *inp*;
Output files: *out* (a pair);
The year used to split the stations: *splitat*.
"""
import itertools
def id11(line):
"""The 11-digit station identifier for a v2.mean record."""
return line[:11]
for stationid,lines in itertools.groupby(inp, id11):
lines = list(lines)
# Gather the set of years for which there are records (across
# all duplicates for a single station).
years = set(int(line[12:16]) for line in lines)
if max(years) >= splitat:
out[1].writelines(lines)
else:
out[0].writelines(lines)
def main(argv=None):
import sys
if argv is None:
argv = sys.argv
year = int(argv[1])
out = [open('v2.mean-pre%d' % year, 'w'),
open('v2.mean-post%d' % year, 'w')]
return split(sys.stdin, out, year)
if __name__ == '__main__':
main()
Show details
Hide details
Change log
r321
by d...@pobox.com on Feb 26, 2010
Diff
v2split.py: splits v2.mean file based on date.
Go to:
/trunk/tool/v2split.py
Project members,
sign in
to write a code review
Older revisions
All revisions of this file
File info
Size: 1465 bytes, 54 lines
View raw file
File properties
svn:executable
*
svn:keywords
URL Rev
Powered by
Google Project Hosting