asrad_reader is a small Python package for reading CWA long-term observational data from ASRAD and turning it into a pandas-friendly dataset.
This project is built around two ideas:
- quick loading of many observation files with multi-threading
- convenient time-series processing through a pandas
DataFrameextension
The main public entry points are:
asrad_reader.load_fileasrad_reader.load_folderasrad_reader.NanMode- the
obsDataFrame accessor on returned datasets
asrad_reader/
__init__.py
loader.py
nan_mode.py
obs_data_frame.py
special_value.py
main.py
readme.md
read_me.html
setup.py
test_read/
_run_notebook_check.py
read_folder_test.ipynb
- Python 3.11.7 or higher
- NumPy 1.26.2 or higher
- pandas 2.1.4 or higher
For published releases, users should install the package from PyPI:
pip install asrad-readerFor local development in this repository, install in editable mode from the repository root:
pip install -e .Import the package and the NaN mode enum:
from pathlib import Path
from asrad_reader import NanMode, load_file, load_folderfile_path = Path("datas/20029999_cwb_hr/20021099.cwb_hr.txt")
df = load_file(file_path)load_file supports these parameters:
mode: controls which special values are treated as NaN. Default isNanMode.AllEmpty.drop_nan: removes rows whose data columns are all missing. Default isFalse.is_utf8:Truefor UTF-8,Falsefor Big5. Default isTrue.
Available NanMode values:
| Mode | Description |
|---|---|
ObsEmpty |
Missing because of observation-related reasons |
AllEmpty |
All special values |
NotInObs |
Missing because the station was not observed |
folder_path = Path("datas")
df = load_folder(folder_path)load_folder reads all .txt files under the folder with multi-threading.
Supported parameters:
mode: defaultNanMode.AllEmptymax_threads: default4drop_nan: defaultFalseselected_cols: columns to keep, defaultNonemeans keep the default observation columnsstation_number: filter a specific station, defaultNone
The returned object is an ObsDataFrame, so you can also use the registered accessor:
df.obs.station("467490")
df.obs.get_item_with_time(["TX01", "PP01", "RH01"])
df.obs.find_observe_patterns()
df.obs.find_nan_periods()The accessor expects a # stno column and either a datetime column or a DatetimeIndex.
ASRAD_reader.__init__exportsNanMode,ObsDataFrame,ObservePattern,NanPeriod,load_file, andload_folder.ASRAD_readeris intended to be used as a library, not as a standalone script.