seagrid.inventory#
Which dates of a data source are downloaded, as a collapsed summary.
seagrid caches one file (or Zarr store) per time step and variable.
scan() checks which days have every needed variable on disk, and
summary() prints the result compactly: a year that is fully
downloaded or fully missing is one line, a partly downloaded year is
listed by month, and a partly downloaded month by day. Runs of years or
months with the same status are merged (2008-2012 missing). Data
sources wrap this as downloaded().
Checking every file is slow on a large cache, so each source also keeps a
SQLite inventory of its downloads in its data directory (e.g.
glorys_inventory.sqlite). record() adds a file when a download
finishes, scan() trusts the files it lists and checks only the rest on
disk (adding the ones it finds), and scan(..., force=True) checks every
file again and drops the rows of files that are gone. records()
returns the inventory as a DataFrame.
Ported from tracmass.seagrid.inventory (tracmass_jax), which will import
it from here.
Functions
|
Daily dates from dtm1 to dtm2, defaulting to the years on disk. |
|
Add a completed download to the inventory db. |
|
Return the inventory db as a DataFrame. |
|
Combine per-variable flags into days, print the summary, return days. |
|
Check every (day, variable) file. |
|
Collapsed text summary of a daily bool series. |
- seagrid.inventory.record(db, dtm, data_var, path)[source]#
Add a completed download to the inventory db.
- Parameters:
db (
pathlib.Path) – The SQLite inventory, created if missing.dtm (
strordatetime-like) – Day of the file.data_var (
str) – Variable key, e.g."uvel".path (
pathlib.Path) – The downloaded file or Zarr store.
- Warns:
UserWarning – If db cannot be written. The download itself is not affected.
- Return type:
None
- seagrid.inventory.records(db)[source]#
Return the inventory db as a DataFrame.
- Returns:
pd.DataFrame– Columnspath(relative to the directory of db),data_var,dateandrecorded(UTC), sorted by date and variable. Empty if db does not exist.- Parameters:
db (Path)
- Return type:
DataFrame
- seagrid.inventory.date_range(dtm1, dtm2, year_dirs)[source]#
Daily dates from dtm1 to dtm2, defaulting to the years on disk.
Without dtm1 the range starts on 1 January of the first year directory (a non-empty directory named by a 4-digit year) in year_dirs; without dtm2 it ends on 31 December of the last one, but not after today.
- seagrid.inventory.scan(dates, data_vars, path, complete, db=None, force=False)[source]#
Check every (day, variable) file.
Each year directory is listed once, so only files that exist are opened by complete. With an inventory db, files it lists count as downloaded without looking at the disk, and files found on disk are added to it.
- Parameters:
dates (
pd.DatetimeIndex) – Days to check.data_vars (
iterableofstr) – Variable keys, e.g.("uvel", "vvel", "wvel").path (
callable) –path(dtm, data_var) -> Pathof the cached file.complete (
callable) –complete(path, data_var) -> boolfor a file that exists (e.g. a Zarr store that holds data chunks).db (
pathlib.PathorNone, optional) – SQLite inventory (seerecord()). Default None: check every file and keep no inventory.force (
bool, optional) – Check every file on disk even if db lists it, and drop the rows of the checked files that are missing or incomplete. Default False.
- Returns:
pd.DataFrame– Bool, one row per day, one column per variable.- Return type:
DataFrame
Notes
Without force, a file deleted by hand stays listed in db and still counts as downloaded.
- seagrid.inventory.summary(available, title='')[source]#
Collapsed text summary of a daily bool series.
- Parameters:
available (
pd.Series) – Bool, indexed by consecutive days.title (
str, optional) – First part of the header line.
- Returns:
str– One line per run of fully downloaded / missing years, then per month inside partly downloaded years, then the downloaded and missing days of partly downloaded months.- Return type:
Examples
>>> print(summary(avail, "GLORYS12V1")) GLORYS12V1, 2006-01-01 to 2008-12-31: 457 of 1096 days downloaded 2006 downloaded 2007 partial (92 of 365 days) Jan-May missing Jun-Aug downloaded Sep partial (5 of 30 days) downloaded 1-5 missing 6-30 Oct-Dec missing 2008 missing