csv2sef 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- csv2sef-1.0.0/.github/workflows/publish.yml +67 -0
- csv2sef-1.0.0/.gitignore +220 -0
- csv2sef-1.0.0/.python-version +1 -0
- csv2sef-1.0.0/LICENSE +21 -0
- csv2sef-1.0.0/PKG-INFO +41 -0
- csv2sef-1.0.0/README.md +25 -0
- csv2sef-1.0.0/pyproject.toml +36 -0
- csv2sef-1.0.0/setup.cfg +4 -0
- csv2sef-1.0.0/src/csv2sef/__init__.py +5 -0
- csv2sef-1.0.0/src/csv2sef/checks.py +78 -0
- csv2sef-1.0.0/src/csv2sef/cli.py +126 -0
- csv2sef-1.0.0/src/csv2sef/convert.py +591 -0
- csv2sef-1.0.0/src/csv2sef/data/ranges.csv +17 -0
- csv2sef-1.0.0/src/csv2sef/data/units.csv +91 -0
- csv2sef-1.0.0/src/csv2sef/data/variable_aliases.csv +73 -0
- csv2sef-1.0.0/src/csv2sef/data/variables.csv +80 -0
- csv2sef-1.0.0/src/csv2sef/data/weather_terms.csv +71 -0
- csv2sef-1.0.0/src/csv2sef/data/wind_words.csv +40 -0
- csv2sef-1.0.0/src/csv2sef/headers.py +89 -0
- csv2sef-1.0.0/src/csv2sef/metadata.py +245 -0
- csv2sef-1.0.0/src/csv2sef/pipeline.py +485 -0
- csv2sef-1.0.0/src/csv2sef/reader.py +135 -0
- csv2sef-1.0.0/src/csv2sef/sef.py +116 -0
- csv2sef-1.0.0/src/csv2sef/tables.py +101 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/PKG-INFO +41 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/SOURCES.txt +31 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/dependency_links.txt +1 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/entry_points.txt +2 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/requires.txt +1 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/scm_file_list.json +27 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/scm_version.json +8 -0
- csv2sef-1.0.0/src/csv2sef.egg-info/top_level.txt +1 -0
- csv2sef-1.0.0/uv.lock +76 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: "Build package for public consumption"
|
|
3
|
+
|
|
4
|
+
on:
|
|
5
|
+
release:
|
|
6
|
+
types: [published]
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
logLevel:
|
|
10
|
+
description: 'Log level'
|
|
11
|
+
required: true
|
|
12
|
+
default: 'warning'
|
|
13
|
+
type: choice
|
|
14
|
+
options:
|
|
15
|
+
- info
|
|
16
|
+
- warning
|
|
17
|
+
- debug
|
|
18
|
+
|
|
19
|
+
jobs:
|
|
20
|
+
build:
|
|
21
|
+
runs-on: ubuntu-latest
|
|
22
|
+
strategy:
|
|
23
|
+
matrix:
|
|
24
|
+
python-version: ["3.14"]
|
|
25
|
+
|
|
26
|
+
steps:
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
|
+
|
|
29
|
+
- name: Install uv
|
|
30
|
+
uses: astral-sh/setup-uv@v5
|
|
31
|
+
with:
|
|
32
|
+
enable-cache: true
|
|
33
|
+
|
|
34
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
35
|
+
run: uv python install ${{ matrix.python-version }}
|
|
36
|
+
|
|
37
|
+
- name: Build dist
|
|
38
|
+
run: uv build
|
|
39
|
+
|
|
40
|
+
- name: Store the distribution packages
|
|
41
|
+
uses: actions/upload-artifact@v5
|
|
42
|
+
with:
|
|
43
|
+
name: release-dists
|
|
44
|
+
path: dist/
|
|
45
|
+
|
|
46
|
+
pypi-publish:
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
needs:
|
|
49
|
+
- build
|
|
50
|
+
permissions:
|
|
51
|
+
id-token: write
|
|
52
|
+
|
|
53
|
+
environment:
|
|
54
|
+
name: pypi
|
|
55
|
+
url: https://pypi.org/p/csv2sef
|
|
56
|
+
|
|
57
|
+
steps:
|
|
58
|
+
- name: Retrieve release distributions
|
|
59
|
+
uses: actions/download-artifact@v4
|
|
60
|
+
with:
|
|
61
|
+
name: release-dists
|
|
62
|
+
path: dist/
|
|
63
|
+
|
|
64
|
+
- name: Publish release distributions to PyPI
|
|
65
|
+
uses: pypa/gh-action-pypi-publish@release/v1
|
|
66
|
+
with:
|
|
67
|
+
packages-dir: dist/
|
csv2sef-1.0.0/.gitignore
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[codz]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
share/python-wheels/
|
|
24
|
+
*.egg-info/
|
|
25
|
+
.installed.cfg
|
|
26
|
+
*.egg
|
|
27
|
+
MANIFEST
|
|
28
|
+
|
|
29
|
+
# PyInstaller
|
|
30
|
+
# Usually these files are written by a python script from a template
|
|
31
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
32
|
+
*.manifest
|
|
33
|
+
*.spec
|
|
34
|
+
|
|
35
|
+
# Installer logs
|
|
36
|
+
pip-log.txt
|
|
37
|
+
pip-delete-this-directory.txt
|
|
38
|
+
|
|
39
|
+
# Unit test / coverage reports
|
|
40
|
+
htmlcov/
|
|
41
|
+
.tox/
|
|
42
|
+
.nox/
|
|
43
|
+
.coverage
|
|
44
|
+
.coverage.*
|
|
45
|
+
.cache
|
|
46
|
+
nosetests.xml
|
|
47
|
+
coverage.xml
|
|
48
|
+
*.cover
|
|
49
|
+
*.py.cover
|
|
50
|
+
*.lcov
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
cover/
|
|
54
|
+
|
|
55
|
+
# Translations
|
|
56
|
+
*.mo
|
|
57
|
+
*.pot
|
|
58
|
+
|
|
59
|
+
# Django stuff:
|
|
60
|
+
*.log
|
|
61
|
+
local_settings.py
|
|
62
|
+
db.sqlite3
|
|
63
|
+
db.sqlite3-journal
|
|
64
|
+
|
|
65
|
+
# Flask stuff:
|
|
66
|
+
instance/
|
|
67
|
+
.webassets-cache
|
|
68
|
+
|
|
69
|
+
# Scrapy stuff:
|
|
70
|
+
.scrapy
|
|
71
|
+
|
|
72
|
+
# Sphinx documentation
|
|
73
|
+
docs/_build/
|
|
74
|
+
|
|
75
|
+
# PyBuilder
|
|
76
|
+
.pybuilder/
|
|
77
|
+
target/
|
|
78
|
+
|
|
79
|
+
# Jupyter Notebook
|
|
80
|
+
.ipynb_checkpoints
|
|
81
|
+
|
|
82
|
+
# IPython
|
|
83
|
+
profile_default/
|
|
84
|
+
ipython_config.py
|
|
85
|
+
|
|
86
|
+
# pyenv
|
|
87
|
+
# For a library or package, you might want to ignore these files since the code is
|
|
88
|
+
# intended to run in multiple environments; otherwise, check them in:
|
|
89
|
+
# .python-version
|
|
90
|
+
|
|
91
|
+
# pipenv
|
|
92
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
93
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
94
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
95
|
+
# install all needed dependencies.
|
|
96
|
+
# Pipfile.lock
|
|
97
|
+
|
|
98
|
+
# uv
|
|
99
|
+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
|
|
100
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
101
|
+
# commonly ignored for libraries.
|
|
102
|
+
# uv.lock
|
|
103
|
+
|
|
104
|
+
# poetry
|
|
105
|
+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
|
|
106
|
+
# This is especially recommended for binary packages to ensure reproducibility, and is more
|
|
107
|
+
# commonly ignored for libraries.
|
|
108
|
+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
|
|
109
|
+
# poetry.lock
|
|
110
|
+
# poetry.toml
|
|
111
|
+
|
|
112
|
+
# pdm
|
|
113
|
+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
|
|
114
|
+
# pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
|
|
115
|
+
# https://pdm-project.org/en/latest/usage/project/#working-with-version-control
|
|
116
|
+
# pdm.lock
|
|
117
|
+
# pdm.toml
|
|
118
|
+
.pdm-python
|
|
119
|
+
.pdm-build/
|
|
120
|
+
|
|
121
|
+
# pixi
|
|
122
|
+
# Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
|
|
123
|
+
# pixi.lock
|
|
124
|
+
# Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
|
|
125
|
+
# in the .venv directory. It is recommended not to include this directory in version control.
|
|
126
|
+
.pixi/*
|
|
127
|
+
!.pixi/config.toml
|
|
128
|
+
|
|
129
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
|
|
130
|
+
__pypackages__/
|
|
131
|
+
|
|
132
|
+
# Celery stuff
|
|
133
|
+
celerybeat-schedule*
|
|
134
|
+
celerybeat.pid
|
|
135
|
+
|
|
136
|
+
# Redis
|
|
137
|
+
*.rdb
|
|
138
|
+
*.aof
|
|
139
|
+
*.pid
|
|
140
|
+
|
|
141
|
+
# RabbitMQ
|
|
142
|
+
mnesia/
|
|
143
|
+
rabbitmq/
|
|
144
|
+
rabbitmq-data/
|
|
145
|
+
|
|
146
|
+
# ActiveMQ
|
|
147
|
+
activemq-data/
|
|
148
|
+
|
|
149
|
+
# SageMath parsed files
|
|
150
|
+
*.sage.py
|
|
151
|
+
|
|
152
|
+
# Environments
|
|
153
|
+
.env
|
|
154
|
+
.envrc
|
|
155
|
+
.venv
|
|
156
|
+
env/
|
|
157
|
+
venv/
|
|
158
|
+
ENV/
|
|
159
|
+
env.bak/
|
|
160
|
+
venv.bak/
|
|
161
|
+
|
|
162
|
+
# Spyder project settings
|
|
163
|
+
.spyderproject
|
|
164
|
+
.spyproject
|
|
165
|
+
|
|
166
|
+
# Rope project settings
|
|
167
|
+
.ropeproject
|
|
168
|
+
|
|
169
|
+
# mkdocs/Zensical documentation
|
|
170
|
+
/site
|
|
171
|
+
|
|
172
|
+
# mypy
|
|
173
|
+
.mypy_cache/
|
|
174
|
+
.dmypy.json
|
|
175
|
+
dmypy.json
|
|
176
|
+
|
|
177
|
+
# Pyre type checker
|
|
178
|
+
.pyre/
|
|
179
|
+
|
|
180
|
+
# pytype static type analyzer
|
|
181
|
+
.pytype/
|
|
182
|
+
|
|
183
|
+
# Cython debug symbols
|
|
184
|
+
cython_debug/
|
|
185
|
+
|
|
186
|
+
# PyCharm
|
|
187
|
+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
|
|
188
|
+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
|
|
189
|
+
# and can be added to the global gitignore or merged into this file. For a more nuclear
|
|
190
|
+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
|
|
191
|
+
# .idea/
|
|
192
|
+
|
|
193
|
+
# Abstra
|
|
194
|
+
# Abstra is an AI-powered process automation framework.
|
|
195
|
+
# Ignore directories containing user credentials, local state, and settings.
|
|
196
|
+
# Learn more at https://abstra.io/docs
|
|
197
|
+
.abstra/
|
|
198
|
+
|
|
199
|
+
# Visual Studio Code
|
|
200
|
+
# Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore that
|
|
201
|
+
# can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
|
|
202
|
+
# and can be added to the global gitignore or merged into this file. However, if you prefer, you
|
|
203
|
+
# could uncomment the following to ignore the entire vscode folder
|
|
204
|
+
# .vscode/
|
|
205
|
+
# Temporary file for partial code execution
|
|
206
|
+
tempCodeRunnerFile.py
|
|
207
|
+
|
|
208
|
+
# Ruff stuff:
|
|
209
|
+
.ruff_cache/
|
|
210
|
+
|
|
211
|
+
# PyPI configuration file
|
|
212
|
+
.pypirc
|
|
213
|
+
|
|
214
|
+
# Marimo
|
|
215
|
+
marimo/_static/
|
|
216
|
+
marimo/_lsp/
|
|
217
|
+
__marimo__/
|
|
218
|
+
|
|
219
|
+
# Streamlit
|
|
220
|
+
.streamlit/secrets.toml
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.14
|
csv2sef-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Open Data Rescue
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
csv2sef-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: csv2sef
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: convert transcribed historical weather observations (csv / Excel) into the Station Exchange Format (SEF 1.0.0).
|
|
5
|
+
Author-email: Vicky Slonosky <VickyS08@users.noreply.github.com>, Hervé Hacot <hhacot@users.noreply.github.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/open-data-rescue/csv2sef
|
|
8
|
+
Project-URL: Issues, https://github.com/open-data-rescue/csv2sef/issues
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.14
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE
|
|
14
|
+
Requires-Dist: cdrutilities>=1.0.1
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# csv2sef
|
|
18
|
+
csv2sef - convert transcribed historical weather observations (csv / Excel)
|
|
19
|
+
into the Station Exchange Format (SEF 1.0.0).
|
|
20
|
+
|
|
21
|
+
Authors: Hervé Hacot, Victoria Slonosky (Open Data Rescue)
|
|
22
|
+
|
|
23
|
+
Please cite:
|
|
24
|
+
Slonosky, V., Black, R., Podolsky, L., Wang, X. & Cheng, V. (2026).
|
|
25
|
+
Transcribing historical Canadian weather data. Scientific Data 13, 678.
|
|
26
|
+
https://doi.org/10.1038/s41597-025-06036-y
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
If using this repository, ensure that you have uv installed
|
|
31
|
+
|
|
32
|
+
1. clone the repo
|
|
33
|
+
2. run `uv sync`
|
|
34
|
+
3. build using `uv build`
|
|
35
|
+
4. run csv2sef using
|
|
36
|
+
```
|
|
37
|
+
uv run csv2sef
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Development
|
|
41
|
+
|
csv2sef-1.0.0/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# csv2sef
|
|
2
|
+
csv2sef - convert transcribed historical weather observations (csv / Excel)
|
|
3
|
+
into the Station Exchange Format (SEF 1.0.0).
|
|
4
|
+
|
|
5
|
+
Authors: Hervé Hacot, Victoria Slonosky (Open Data Rescue)
|
|
6
|
+
|
|
7
|
+
Please cite:
|
|
8
|
+
Slonosky, V., Black, R., Podolsky, L., Wang, X. & Cheng, V. (2026).
|
|
9
|
+
Transcribing historical Canadian weather data. Scientific Data 13, 678.
|
|
10
|
+
https://doi.org/10.1038/s41597-025-06036-y
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
If using this repository, ensure that you have uv installed
|
|
15
|
+
|
|
16
|
+
1. clone the repo
|
|
17
|
+
2. run `uv sync`
|
|
18
|
+
3. build using `uv build`
|
|
19
|
+
4. run csv2sef using
|
|
20
|
+
```
|
|
21
|
+
uv run csv2sef
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
## Development
|
|
25
|
+
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "csv2sef"
|
|
3
|
+
dynamic = ["version"]
|
|
4
|
+
description = "convert transcribed historical weather observations (csv / Excel) into the Station Exchange Format (SEF 1.0.0)."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
authors = [
|
|
7
|
+
{ name = "Vicky Slonosky", email = "VickyS08@users.noreply.github.com" },
|
|
8
|
+
{ name = "Hervé Hacot", email = "hhacot@users.noreply.github.com" }
|
|
9
|
+
]
|
|
10
|
+
requires-python = ">=3.14"
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Programming Language :: Python :: 3",
|
|
13
|
+
"Operating System :: OS Independent",
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"cdrutilities>=1.0.1",
|
|
17
|
+
]
|
|
18
|
+
license = "MIT"
|
|
19
|
+
license-files = ["LICEN[CS]E*"]
|
|
20
|
+
|
|
21
|
+
[project.scripts]
|
|
22
|
+
csv2sef = "csv2sef:main"
|
|
23
|
+
|
|
24
|
+
[build-system]
|
|
25
|
+
requires = ["setuptools>=68", "setuptools-scm>=8"]
|
|
26
|
+
build-backend = "setuptools.build_meta"
|
|
27
|
+
|
|
28
|
+
[project.urls]
|
|
29
|
+
Homepage = "https://github.com/open-data-rescue/csv2sef"
|
|
30
|
+
Issues = "https://github.com/open-data-rescue/csv2sef/issues"
|
|
31
|
+
|
|
32
|
+
[tool.setuptools_scm]
|
|
33
|
+
fallback_version = "0.0.0"
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["src"]
|
csv2sef-1.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""Range checks (in SI units, by region) and cross-variable checks."""
|
|
3
|
+
import datetime as dt
|
|
4
|
+
from collections import defaultdict
|
|
5
|
+
|
|
6
|
+
from . import tables
|
|
7
|
+
from .convert import Context
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def range_check(records, region, log):
|
|
11
|
+
limits = tables.ranges(region)
|
|
12
|
+
for r in records:
|
|
13
|
+
q = r["quantity"]
|
|
14
|
+
x = r["iso_value"]
|
|
15
|
+
if not q or q not in limits or not isinstance(x, (int, float)):
|
|
16
|
+
continue
|
|
17
|
+
lim = limits[q]
|
|
18
|
+
flag = None
|
|
19
|
+
if (lim["out_min"] is not None and x < lim["out_min"]) or \
|
|
20
|
+
(lim["out_max"] is not None and x > lim["out_max"]):
|
|
21
|
+
flag = "out of range"
|
|
22
|
+
elif lim["low"] is not None and x < lim["low"]:
|
|
23
|
+
flag = "low value"
|
|
24
|
+
elif lim["high"] is not None and x > lim["high"]:
|
|
25
|
+
flag = "high value"
|
|
26
|
+
if flag:
|
|
27
|
+
r["flag"] = "; ".join(filter(None, [r["flag"], flag]))
|
|
28
|
+
log.write(Context(r["row"], r["column"], r["date"], r["var"]), "RANGE",
|
|
29
|
+
f"{r['orig_value']} -> {x} {r['iso_unit']}: {flag} ({region} limits)")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def cross_checks(records, log, tn_night_after=False):
|
|
33
|
+
by_key = defaultdict(dict)
|
|
34
|
+
for r in records:
|
|
35
|
+
if isinstance(r["iso_value"], (int, float)):
|
|
36
|
+
by_key[(r["date"], r["hour"], r["minute"])][r["var"]] = r
|
|
37
|
+
|
|
38
|
+
def note(rec, msg, flag=None):
|
|
39
|
+
log.write(Context(rec["row"], rec["column"], rec["date"], rec["var"]), "CROSS", msg)
|
|
40
|
+
if flag:
|
|
41
|
+
rec["flag"] = "; ".join(filter(None, [rec["flag"], flag]))
|
|
42
|
+
|
|
43
|
+
for (date, h, mi), v in by_key.items():
|
|
44
|
+
if h is None:
|
|
45
|
+
continue
|
|
46
|
+
if "tb" in v and "tdb" in v and v["tb"]["iso_value"] > v["tdb"]["iso_value"] + 0.3:
|
|
47
|
+
note(v["tb"], f"Wet bulb {v['tb']['orig_value']} > dry bulb {v['tdb']['orig_value']}",
|
|
48
|
+
"wet bulb > dry bulb")
|
|
49
|
+
if "ta" in v and "tdb" in v and abs(v["ta"]["iso_value"] - v["tdb"]["iso_value"]) > 3:
|
|
50
|
+
note(v["ta"], f"Air temperature {v['ta']['orig_value']} differs from dry bulb "
|
|
51
|
+
f"{v['tdb']['orig_value']}")
|
|
52
|
+
|
|
53
|
+
day_ta = defaultdict(list)
|
|
54
|
+
for (date, h, mi), v in by_key.items():
|
|
55
|
+
if h is not None and "ta" in v:
|
|
56
|
+
day_ta[date].append(v["ta"])
|
|
57
|
+
for (date, h, mi), v in by_key.items():
|
|
58
|
+
if h is not None:
|
|
59
|
+
continue
|
|
60
|
+
for mn, mx in (("Tn", "Tx"),):
|
|
61
|
+
if mn in v and mx in v and v[mn]["iso_value"] > v[mx]["iso_value"]:
|
|
62
|
+
note(v[mn], f"Minimum {v[mn]['orig_value']} > maximum {v[mx]['orig_value']}")
|
|
63
|
+
if "Tn" in v and day_ta.get(date):
|
|
64
|
+
if tn_night_after:
|
|
65
|
+
nxt = date + dt.timedelta(days=1)
|
|
66
|
+
cands = [r for r in day_ta[date] if r["hour"] >= 12] + \
|
|
67
|
+
[r for r in day_ta.get(nxt, []) if r["hour"] < 12]
|
|
68
|
+
else:
|
|
69
|
+
cands = day_ta[date]
|
|
70
|
+
if cands:
|
|
71
|
+
low = min(cands, key=lambda r: r["iso_value"])
|
|
72
|
+
if v["Tn"]["iso_value"] > low["iso_value"] + 0.5:
|
|
73
|
+
note(v["Tn"], f"Minimum {v['Tn']['orig_value']} > {low['column']} "
|
|
74
|
+
f"{low['orig_value']} on {low['date']}")
|
|
75
|
+
if "Tx" in v and day_ta.get(date):
|
|
76
|
+
high = max(day_ta[date], key=lambda r: r["iso_value"])
|
|
77
|
+
if v["Tx"]["iso_value"] < high["iso_value"] - 0.5:
|
|
78
|
+
note(v["Tx"], f"Maximum {v['Tx']['orig_value']} < {high['column']} {high['orig_value']}")
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Command line interface.
|
|
4
|
+
|
|
5
|
+
csv2sef check DATA METADATA dry run: how each column will be read
|
|
6
|
+
csv2sef convert DATA METADATA [-o DIR] write clean/ISO csv, log and SEF files
|
|
7
|
+
csv2sef template [DATA] [-o FILE] write a blank metadata file
|
|
8
|
+
csv2sef validate SEF_FILE ... check SEF files against SEF 1.0.0
|
|
9
|
+
csv2sef variables list known variables and units
|
|
10
|
+
"""
|
|
11
|
+
import argparse
|
|
12
|
+
import importlib.metadata
|
|
13
|
+
import os
|
|
14
|
+
import sys
|
|
15
|
+
|
|
16
|
+
# from . import CITATION
|
|
17
|
+
from . import metadata as mdmod
|
|
18
|
+
from . import pipeline, reader, sef, tables
|
|
19
|
+
from .headers import parse_header
|
|
20
|
+
|
|
21
|
+
# from importlib.metadata
|
|
22
|
+
|
|
23
|
+
CITATION = ("Slonosky, V., Black, R., Podolsky, L., Wang, X. & Cheng, V. (2026). "
|
|
24
|
+
"Transcribing historical Canadian weather data. Scientific Data 13, 678. "
|
|
25
|
+
"https://doi.org/10.1038/s41597-025-06036-y")
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def cmd_check(a):
|
|
29
|
+
print(pipeline.run(a.data, a.metadata, check_only=True, local_time=a.local))
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def cmd_convert(a):
|
|
33
|
+
print(pipeline.run(a.data, a.metadata, outdir=a.outdir, local_time=a.local))
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def cmd_template(a):
|
|
37
|
+
found = []
|
|
38
|
+
if a.data:
|
|
39
|
+
t = reader.read(a.data)
|
|
40
|
+
cols, julian = reader.date_columns(t.headers)
|
|
41
|
+
known = tables.variables()
|
|
42
|
+
seen = set()
|
|
43
|
+
for i, hd in enumerate(t.headers):
|
|
44
|
+
if i in cols.values() or i == julian or not hd:
|
|
45
|
+
continue
|
|
46
|
+
h = parse_header(hd)
|
|
47
|
+
if h.var in seen:
|
|
48
|
+
continue
|
|
49
|
+
seen.add(h.var)
|
|
50
|
+
if h.unit_token:
|
|
51
|
+
continue # unit already in the header
|
|
52
|
+
d = known.get(h.var)
|
|
53
|
+
found.append((h.var, d["unit"] if d else "", d["description"] if d else "UNKNOWN variable"))
|
|
54
|
+
out = a.output or "metadata.csv"
|
|
55
|
+
if os.path.exists(out) and not a.force:
|
|
56
|
+
sys.exit(f"{out} exists; use --force to overwrite")
|
|
57
|
+
mdmod.write_template(out, found)
|
|
58
|
+
print(f"Wrote {out}. Fill in the site details"
|
|
59
|
+
+ (" and check the unit.<variable> lines." if found else "."))
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def cmd_validate(a):
|
|
63
|
+
bad = 0
|
|
64
|
+
for p in a.files:
|
|
65
|
+
probs = sef.validate(p)
|
|
66
|
+
print(f"{p}: {'OK' if not probs else 'INVALID'}")
|
|
67
|
+
for x in probs[:10]:
|
|
68
|
+
print(" ", x)
|
|
69
|
+
bad += bool(probs)
|
|
70
|
+
sys.exit(1 if bad else 0)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def cmd_variables(a):
|
|
74
|
+
print(f"{'code':11} {'default unit':13} {'stat':8} description")
|
|
75
|
+
for code, d in tables.variables().items():
|
|
76
|
+
print(f"{code:11} {d['unit']:13} {d['stat']:8} {d['description']}")
|
|
77
|
+
print("\nUnits (write in the header in [ ], e.g. 'ta 07:00 [F]'):")
|
|
78
|
+
for u, desc in tables.unit_descriptions().items():
|
|
79
|
+
print(f" {u:13} {desc}")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def main(argv=None):
|
|
83
|
+
p = argparse.ArgumentParser(
|
|
84
|
+
prog="csv2sef",
|
|
85
|
+
description=f"csv2sef {importlib.metadata.metadata(__package__)['Version']}: historical weather csv/Excel -> SEF 1.0.0. "
|
|
86
|
+
f"Authors: {', '.join(importlib.metadata.metadata(__package__)['Author-email'])}.",
|
|
87
|
+
epilog="Please cite: " + CITATION)
|
|
88
|
+
p.add_argument("--version", action="version", version=f"csv2sef {importlib.metadata.metadata(__package__)['Version']}")
|
|
89
|
+
sub = p.add_subparsers(dest="cmd")
|
|
90
|
+
|
|
91
|
+
for name, fn, hlp in (("check", cmd_check, "dry run: show how each column will be read"),
|
|
92
|
+
("convert", cmd_convert, "convert and write SEF files")):
|
|
93
|
+
s = sub.add_parser(name, help=hlp)
|
|
94
|
+
s.add_argument("data", help="csv, tsv or xlsx file")
|
|
95
|
+
s.add_argument("metadata", help="metadata csv (or json)")
|
|
96
|
+
s.add_argument("--local", action="store_true", help="keep local times (no UTC conversion)")
|
|
97
|
+
if name == "convert":
|
|
98
|
+
s.add_argument("-o", "--outdir", help="output directory")
|
|
99
|
+
s.set_defaults(func=fn)
|
|
100
|
+
|
|
101
|
+
s = sub.add_parser("template", help="write a blank metadata file")
|
|
102
|
+
s.add_argument("data", nargs="?", help="optional data file: adds unit lines for its variables")
|
|
103
|
+
s.add_argument("-o", "--output", help="output file (default metadata.csv)")
|
|
104
|
+
s.add_argument("--force", action="store_true")
|
|
105
|
+
s.set_defaults(func=cmd_template)
|
|
106
|
+
|
|
107
|
+
s = sub.add_parser("validate", help="validate SEF files")
|
|
108
|
+
s.add_argument("files", nargs="+")
|
|
109
|
+
s.set_defaults(func=cmd_validate)
|
|
110
|
+
|
|
111
|
+
s = sub.add_parser("variables", help="list known variables and units")
|
|
112
|
+
s.set_defaults(func=cmd_variables)
|
|
113
|
+
|
|
114
|
+
argv = sys.argv[1:] if argv is None else argv
|
|
115
|
+
# shorthand: csv2sef DATA METADATA == convert
|
|
116
|
+
if len(argv) >= 2 and argv[0] not in sub.choices and not argv[0].startswith("-"):
|
|
117
|
+
argv = ["convert"] + argv
|
|
118
|
+
a = p.parse_args(argv)
|
|
119
|
+
if not getattr(a, "func", None):
|
|
120
|
+
p.print_help()
|
|
121
|
+
return
|
|
122
|
+
a.func(a)
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
if __name__ == "__main__":
|
|
126
|
+
main()
|