Skip to main content

Find files using regular expression to feed them to Xarray.

Project description

Xarray-regex

Find files based on regular expression to pass them to Xarray

PyPI version Release status

Xarray-regex allows to find files based on regular expressions, in order to feed them to Xarray. It allows to easily create regular expressions using 'Matchers', to fix some elements of the expressions to select only certain files, and to easily retrieve information from filenames.

Minimal example

The following example will find files with names Data/[month]/SST_[date].nc (and only those!). For each file, the date can be retrieved as a datetime object.

from xarray_regex import FileFinder, library

finder = FileFinder('/.../Data', r'%(m)/SST_%(Y)%(m)%(d)\.nc')
files = finder.get_files()
for f in files:
    print(f, library.get_date(finder.get_matches(f, relative=False)))

We can also only select some files, for instance only the first day of each month:

finder.fix_matcher('d', '01')
print(finder.get_files())

Requirements

Python >= 3.7.

Installation

From pip:

pip install xarray-regex

From source:

git clone https://github.com/Descanonge/xarray-regex.git
cd xarray-regex
pip install -e .

Documentation

Documentation is available at xarray-regex.readthedocs.io.

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

xarray-regex-0.2.0.tar.gz (16.6 kB view hashes)

Uploaded Source

Built Distribution

xarray_regex-0.2.0-py3-none-any.whl (10.4 kB view hashes)

Uploaded Python 3

Supported by

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