IO.py
- sloth.IO.createNetCDF(fileName, domain=None, nz=None, calcLatLon=False, author=None, description=None, source=None, contact=None, institution=None, history=None, timeCalendar=None, timeUnit=None, NBOUNDCUT=0)[source]
Create a NetCDF file with typical metadata and dimensions.
- Parameters:
fileName (str) – Name of the output NetCDF file.
domain (str or None, optional) – Path to the domain definition file or a valid CORDEX/Griddes domain name. If None, default domain definitions will be used.
nz (int or None, optional) – Number of vertical levels. If None, no z-axis will be created.
calcLatLon (bool, optional) – Flag indicating whether to calculate latitude and longitude values. If True, lat and lon variables will be created.
author (str or None, optional) – Name of the author.
description (str or None, optional) – Description of the NetCDF file.
source (str or None, optional) – Source of the data.
contact (str or None, optional) – Contact information.
institution (str or None, optional) – Institution associated with the data.
history (str or None, optional) – History information.
timeCalendar (str or None, optional) – Calendar type for the time-axis.
timeUnit (str or None, optional) – Unit of measurement for the time-axis.
NBOUNDCUT (int, optional) – Number of pixels to cut at the domain border.
- Returns:
fileName – Name of the created NetCDF file.
- Return type:
str
Example
>>> # Create a NetCDF file with default domain definitions and no z-axis >>> createNetCDF("output.nc")
>>> # Create a NetCDF file with a specific domain and 10 vertical levels >>> createNetCDF("output.nc", domain="my_domain.txt", nz=10, calcLatLon=True)
- sloth.IO.create_pfb(filename, var, delta=(1, 1, 1), subgrids=(1, 1, 1))[source]
Create a ParFlow PFB file from a 3D array of variable data.
- Parameters:
filename (str) – Name of the PFB file to be created.
var (ndarray) – 3D array of variable data to be stored in the PFB file.
delta (tuple of float, optional) – Grid spacing values in the x, y, and z directions. Default is (1, 1, 1).
subgrids (tuple of int, optional) – Number of subgrids in the x, y, and z directions. Default is (1, 1, 1).
Examples
>>> import numpy as np >>> data = np.random.rand(10, 20, 30) >>> create_pfb('output.pfb', data, delta=(0.5, 0.5, 0.5)) ... This creates a PFB file named 'output.pfb' from a 3D array 'data' with custom delta settings.
- sloth.IO.readSa(file)[source]
Reads data from a file in ASCI format and returns a NumPy array.
- Parameters:
file (str) – The file path to read the data from.
- Returns:
A NumPy array containing the data read from the file.
- Return type:
numpy.ndarray
Example
>>> data = readSa('data.txt') >>> print(data) [[1.2 3.4] [5.6 7.8]]
- sloth.IO.read_pfb(filename)[source]
Read a ParFlow PFB file and return the data as a numpy ndarray.
- Parameters:
filename (str) – Name of the PFB file to be read.
- Returns:
data – 3D array containing the data read from the PFB file.
- Return type:
ndarray
Examples
>>> data = read_pfb('input.pfb') >>> print(data.shape) (10, 20, 30) ... This reads a PFB file named 'input.pfb' and returns the data as a 3D array.
- sloth.IO.writeSa(file, data)[source]
Writes data to a file in ASCI format.
- Parameters:
file (str) – The file path to write the data to.
data (numpy.ndarray) – The NumPy array containing the data to be written.
- Return type:
None
Example
>>> data = np.array([[1.2, 3.4], [5.6, 7.8]]) >>> writeSa('output.txt', data)