Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
asccol
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Owen Graham
asccol
Commits
48905b41
Verified
Commit
48905b41
authored
2 years ago
by
Owen Graham
Browse files
Options
Downloads
Patches
Plain Diff
Add README
parent
e10c4cd5
No related branches found
Branches containing commit
Tags
0.2.16
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
README.md
+62
-0
62 additions, 0 deletions
README.md
with
62 additions
and
0 deletions
README.md
0 → 100644
+
62
−
0
View file @
48905b41
# `asccol` ASCII Columnar Data Parser
Use this simple library to parse aligned text data into Python named
tuples, using your own specifications for keyword, type, and column
width.
## Example usage
```
py
import
math
import
sys
from
asccol
import
DataSpec
,
Columns
,
parse_data
def
simple_time
(
s
):
"""
Convert a HHMM string to an (H, M) tuple.
"""
hour
=
s
[:
2
]
minute
=
s
[
2
:
4
]
return
tuple
(
map
(
int
,
(
hour
,
minute
)))
def
filtered_float
(
s
):
"""
Like float, but ignore the special value 444.0.
"""
val
=
float
(
s
)
return
val
if
val
!=
444.0
else
math
.
nan
# 10 minute data
# See https://amrc.ssec.wisc.edu/data/ftp/pub/aws/q10/q10readme.txt
Q10
=
DataSpec
(
leading
=
2
,
# lines to delete
cols
=
Columns
(
(
'
year
'
,
int
,
4
),
# keyword, type (converter function), width
(
'
jdate
'
,
int
,
4
),
(
'
month
'
,
int
,
3
),
(
'
date
'
,
int
,
3
),
(
'
time
'
,
simple_time
,
5
),
(
'
temp
'
,
filtered_float
,
7
),
(
'
pressure
'
,
filtered_float
,
7
),
(
'
wind_speed
'
,
filtered_float
,
7
),
(
'
wind_dir
'
,
filtered_float
,
7
),
(
'
rel_hum
'
,
filtered_float
,
7
),
(
'
delta_t
'
,
filtered_float
,
7
),
),
)
for
row
in
parse_data
(
sys
.
stdin
,
Q10
):
print
(
row
)
```
The program above will transform this input:
```
Year: 2021 Month: 02 ID: BYD ARGOS: 8903 Name: Byrd
Lat: 80.02S Lon: 119.44W Elev: 1539m
2021 32 2 1 0000 -16.3 803.9 8.9 22.0 79.0 444.0
2021 32 2 1 0010 -16.4 803.9 8.6 25.0 79.0 444.0
```
...into this output:
```
row(year=2021, jdate=32, month=2, date=1, time=(0, 0), temp=-16.3, pressure=803.9, wind_speed=8.9, wind_dir=22.0, rel_hum=79.0, delta_t=nan)
row(year=2021, jdate=32, month=2, date=1, time=(0, 10), temp=-16.4, pressure=803.9, wind_speed=8.6, wind_dir=25.0, rel_hum=79.0, delta_t=nan)
```
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment