Skip to main content

A toolkit for processing CWA long-term observation station data from https://asrad.pccu.edu.tw.

Project description

About This Repository

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 DataFrame extension

The main public entry points are:

  • asrad-reader.load_file
  • asrad-reader.load_folder
  • asrad-reader.NanMode
  • the obs DataFrame accessor on returned datasets

Current Structure

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

Development Environment

  • Python 3.11.7 or higher
  • NumPy 1.26.2 or higher
  • pandas 2.1.4 or higher

Installation

For published releases, users should install the package from PyPI:

pip install asrad-reader

For local development in this repository, install in editable mode from the repository root:

pip install -e .

Getting Started

Import the package and the NaN mode enum:

from pathlib import Path

from asrad-reader import NanMode, load_file, load_folder

Read a File

file_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 is NanMode.AllEmpty.
  • drop_nan: removes rows whose data columns are all missing. Default is False.
  • is_utf8: True for UTF-8, False for Big5. Default is True.

Available NanMode values:

Mode Description
ObsEmpty Missing because of observation-related reasons
AllEmpty All special values
NotInObs Missing because the station was not observed

Read a Folder

folder_path = Path("datas")
df = load_folder(folder_path)

load_folder reads all .txt files under the folder with multi-threading.

Supported parameters:

  • mode: default NanMode.AllEmpty
  • max_threads: default 4
  • drop_nan: default False
  • selected_cols: columns to keep, default None means keep the default observation columns
  • station_number: filter a specific station, default None

DataFrame Accessor

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.

Notes

  • ASRAD_reader.__init__ exports NanMode, ObsDataFrame, ObservePattern, NanPeriod, load_file, and load_folder.
  • ASRAD_reader is intended to be used as a library, not as a standalone script.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

asrad_reader-0.4.5.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

asrad_reader-0.4.5-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file asrad_reader-0.4.5.tar.gz.

File metadata

  • Download URL: asrad_reader-0.4.5.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for asrad_reader-0.4.5.tar.gz
Algorithm Hash digest
SHA256 696a5ea22f6eac1e7409c2b9f4f780806a79e473b9f834c03a578ca7068631c8
MD5 c4c3e11c77ce662a2046f0ac36d912aa
BLAKE2b-256 11c06454aab16157d1bc3df9bf677418cfd76a3bd28fa2fef19a3ab0ac29d2e4

See more details on using hashes here.

File details

Details for the file asrad_reader-0.4.5-py3-none-any.whl.

File metadata

  • Download URL: asrad_reader-0.4.5-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for asrad_reader-0.4.5-py3-none-any.whl
Algorithm Hash digest
SHA256 f3e4949afb512848b8ef8bb1795106b36cefa6761bd629180c8dde44d95514e8
MD5 abac66c8d489a26d8c4d77d6ed0d5401
BLAKE2b-256 f5ad5d992a430711af2fa30ab00a4291f31af3c91152b15b193567b55c06819f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page