OAFuncs
Oceanic and Atmospheric Functions for Python.
OAFuncs provides utilities for NetCDF files, geoscience arrays, plotting, geographic masks, downloads, file operations, model data, and small workflow tools.
Installation
pip install oafuncs
Optional dependency groups:
data, interp, nc, draw, geo, down, office, parallel, sign, science, all, full
Package Structure
oafuncs
|-- oa_nc.py NetCDF utilities
|-- oa_data.py data interpolation helpers
|-- oa_geo.py geographic and land/ocean mask helpers
|-- oa_draw.py plotting helpers
|-- oa_cmap.py colormap helpers
|-- oa_file.py file operation helpers
|-- oa_date.py date and timing helpers
|-- oa_down/ download helpers
|-- oa_model/ ROMS and WRF helpers
|-- oa_linux.py Linux, HPC, and Slurm helpers
|-- oa_office.py Office document helpers
|-- oa_sign/ website sign-in helpers
`-- oa_tool.py command, progress bar, email, and parallel helpers
Public API
oa_nc
| Function | Purpose |
|---|---|
save |
Write arrays, DataArrays, or Datasets to NetCDF. |
merge |
Merge multiple NetCDF files. |
modify |
Modify a variable value or variable attribute. |
rename |
Rename a NetCDF variable or dimension. |
check |
Check whether a NetCDF file is readable. |
convert_longitude |
Convert longitude coordinates between [-180, 180] and [0, 360]. |
isel |
Select NetCDF data by dimension indices. |
draw |
Plot variables from a NetCDF file or xarray object. |
compress |
Apply NetCDF compression. |
unscale |
Decode and remove scale_factor / add_offset storage encoding. |
oa_nc.save(write_mode="w") and oa_nc.merge() write to a temporary file
before replacing an existing output. Failed writes preserve the previous file;
append mode (write_mode="a") still updates the file in place.
For NumPy input, preserve_mask_values=True keeps underlying masked values;
False writes them as missing values. Explicit missing_value values remain
missing even for integer arrays, and all-NaN arrays remain missing rather than 0.
merge() preserves raw encoding and input order: units, calendars, non-merged
variables and non-merged coordinates must match. It raises ValueError for
incompatible inputs rather than converting time units or aligning different grids.
oa_nc.rename() checks variable and dimension name conflicts before changing
either name, so a conflicting coordinate rename does not leave a partial change.
oa_nc.draw() accepts a NetCDF path, xarray.Dataset, or xarray.DataArray.
File-backed workloads use parallel="auto" by default: small batches remain
serial, while sufficiently large collections of independent 2D slices use
oafuncs.oa_tool.Pex with automatic worker sizing. Use parallel=False to
force serial rendering or parallel=True to force Pex. The default output is
300 dpi; set save_dpi=600 when publication-resolution PNG files are needed.
On Windows, Pex calls must run below an if __name__ == "__main__": guard.
For strongly skewed fields, robust=True displays colors using the 1st–99th
percentiles while the title continues to report the complete data range and
the clipped color range. The default robust=False preserves the full range.
oa_data
| Function | Purpose |
|---|---|
ensure_list |
Convert a value to a list. |
interp_vertical |
Interpolate along the fixed z axis in [t, z, y, x] order. |
interp_horizontal |
Interpolate horizontal fields over the fixed y, x axes. |
oa_geo
mask_land_ocean() preserves existing xarray dimension coordinates, including
x/y grid indices. Longitude and latitude describe mask positions; two-dimensional
longitude/latitude arrays must have the same shape.
| Function | Purpose |
|---|---|
earth_distance |
Calculate great-circle distance between two lon/lat points. |
mask_shapefile |
Mask a 2D field using a shapefile. |
mask_land_ocean |
Keep land or ocean values using a land/ocean mask. |
is_land |
Check whether a lon/lat point is on land. |
is_ocean |
Check whether a lon/lat point is in the ocean. |
oa_draw
| Function | Purpose |
|---|---|
fig_minus |
Format minus signs in axis or colorbar tick labels. |
gif |
Create a GIF from image files. |
movie |
Create a video from image files. |
setup_map |
Configure a Cartopy map. |
ticks_symmetric |
Generate ticks symmetric around a center value. |
font_CN |
Configure Chinese font support for Matplotlib. |
oa_draw.gif(frame_duration=0.2) uses seconds (200 milliseconds per frame).
Unreadable images are skipped; automatic dimensions come from the first readable image.
oa_cmap
| Function | Purpose |
|---|---|
show |
Preview a colormap. |
to_color |
Convert a colormap to a list of colors. |
create |
Create a custom colormap from colors or an RGB text file. |
get |
Load a Matplotlib or custom colormap. |
random_color |
Generate a random hex color. |
oa_file
| Function | Purpose |
|---|---|
script_dir |
Return the caller script directory, independent of current working directory. |
find |
Find files by pattern. |
link |
Create symbolic links with wildcard support. |
copy |
Copy files or directories with wildcard support. |
move |
Move files or directories with wildcard support. |
rename |
Rename files by replacing text in filenames. |
remove_empty |
Remove empty folders recursively. |
remove |
Delete files or directories by pattern. |
size |
Return file size in the requested unit. |
replace |
Replace text content by replace_dict and save it to output_path. |
Example:
from oafuncs.oa_file import replace
replace(
input_path="config.txt",
replace_dict={"old_value": "new_value"},
output_path=r"D:\run\config.txt",
)
output_path accepts either a file name, such as "result.txt", or an absolute
file path. A file name is saved in the input file's directory. Directory-only paths
and relative paths containing directories are rejected to avoid ambiguous output.
oa_date
| Function / Class | Purpose |
|---|---|
month_days |
Return the number of days in a month. |
hour_range |
Generate datetime strings at an hourly interval. |
adjust_time |
Offset a base time by a time delta. |
timeit |
Decorator class for timing function execution. |
oa_down
| Function | Purpose |
|---|---|
download |
Download HYCOM data for one time or a time range. |
draw_time_range |
Draw the available HYCOM time range. |
download_by_doi |
Download literature files from DOI lists. |
downloader |
Send a download task to Internet Download Manager. |
get_ua |
Return the default user-agent string for download requests. |
Literature downloads require a PDF header and the configured min_size_kb
before replacing an existing file. This is a basic content check, not a full
PDF integrity check. Each mirror receives its own tries_each_url budget;
an HTTP failure moves on to the next mirror and failure records are deduplicated.
For hycom_3hourly.download(), interval_hours for a time range must be a positive multiple of 3. When using IDM, idm_timeout controls how many seconds without a completed valid file are allowed before remaining files are reported as failed; it defaults to 24 hours.
oa_model
| Function | Purpose |
|---|---|
interp |
Interpolate and remap ROMS data to target lon/lat/depth grids. |
header_record |
Build a WRF little_r header record. |
data_record |
Build a WRF little_r data record. |
ending_record |
Build a WRF little_r ending record. |
tail_record |
Build a WRF little_r tail record. |
The little_r helpers retain the existing fixed-width record layout and units.
Overlong text fields are truncated to their documented widths; invalid record
lengths raise ValueError rather than terminating the caller's Python process.
oa_linux
| Function | Purpose |
|---|---|
patch_slurm |
Update selected #SBATCH directives in a Slurm script. |
submit |
Submit a Slurm job with queue-aware retry logic; partitions not visible in sinfo are skipped, race=True races eligible queues, and race=False uses single-queue retry. |
job_state |
Query Slurm job state. |
is_linux |
Check whether the current system is Linux. |
get_jobid |
Return an ID only when exactly one pending/running Slurm job matches; otherwise return None. |
cancel_job |
Cancel all active Slurm replicas matching an exact path and/or exact job name. |
scancel_dir |
Cancel every pending/running Slurm job submitted from one exact directory. |
dir_queued |
Check whether one exact directory has any pending/running Slurm job, including race replicas. |
oa_office
| Function | Purpose |
|---|---|
extract_pptx_notes |
Extract PowerPoint notes to a Word document. |
oa_sign
| Function | Purpose |
|---|---|
sign_in_love_ocean |
Sign in to 52ocean. |
sign_in_meteorological_home |
Sign in to Meteorological Home. |
sign_in_scientific_research |
Sign in to AbleSci. |
oa_tool
On Windows, Pex uses its own spawn context without changing the caller's
global multiprocessing start method. Calls still require the main guard.
| Function / Class | Purpose |
|---|---|
run_command |
Run an external command safely without using a shell. |
Pex |
Parallel executor wrapper with progress and timing. PEx remains as a deprecated compatibility alias until 2026-12-22. |
email |
Send an email. |
pbar |
Create a colored progress bar. |
Links
- PyPI: https://pypi.org/project/oafuncs
- GitHub: https://github.com/OAKun/OAFuncs
- Download stats: https://pypistats.org/packages/oafuncs
- Wiki: https://deepwiki.com/OAKun/OAFuncs
License
MIT License. See LICENSE.txt.
Metadata
Release files for oafuncs 0.0.99.74
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| oafuncs-0.0.99.74.tar.gz | 178.4 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| oafuncs-0.0.99.74-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 344.4 kB
Release files / oafuncs-0.0.99.74.tar.gz
| Download URL | oafuncs-0.0.99.74.tar.gz |
|---|---|
| Size | 178.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5babbedbf89b25fd4156c415b28f6a50a8248f30b521c7f7a777b7cc2fd8f2da
|
|
BLAKE2b-256 checksum How to use checksums |
52d8e867ae1da61219f104d4ba5e1f74576f1893a17039c195fca8fb8f9e357d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / oafuncs-0.0.99.74-py3-none-any.whl
| Download URL | oafuncs-0.0.99.74-py3-none-any.whl |
|---|---|
| Size | 166.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
756a876c7dac4e595aa8274c07bd32fce9a1daa3fcc7f78d4c4a0e14d12780db
|
|
BLAKE2b-256 checksum How to use checksums |
cc54cbd4be7dc260b07a849a2aebe3548fe07767235485d0ff9df69bd8563151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|