Skip to content

Commit 44c266a

Browse files
committed
Add initial README.md with project overview, data structure, and workflow
1 parent 8f93d23 commit 44c266a

File tree

1 file changed

+179
-0
lines changed

1 file changed

+179
-0
lines changed

README.md

Lines changed: 179 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,179 @@
1+
# dms_datastore
2+
3+
Delta Modeling Section Datastore provides tools for downloading and managing continuous data. This repository is a work in progress.
4+
5+
## Table of Contents
6+
- [Overview](#overview)
7+
- [Data Repository Structure](#data-repository-structure)
8+
- [Data Quality and Flags](#data-quality-and-flags)
9+
- [Data Screening and Error Detection Methods](#data-screening-and-error-detection-methods)
10+
- [Metadata and Station Concepts](#metadata-and-station-concepts)
11+
- [File Naming Conventions](#file-naming-conventions)
12+
- [Units and Standardization](#units-and-standardization)
13+
- [Data Fetching and Priority](#data-fetching-and-priority)
14+
- [Challenges and Exceptions](#challenges-and-exceptions)
15+
- [Installation](#installation)
16+
17+
## Overview
18+
19+
The overarching goal of this data organization effort is to retrieve data from data providers and store in a common format, validate data (screened) and for use in applications such as boundary conditions (filled/aggregated or derived data), which is referred to as "processed" data. The system aims to move away from manually manipulated data in favor of standardized formats for programmatic access.
20+
21+
## Data Repository Structure
22+
23+
The centralized data repository is housed in a file system-based share at
24+
25+
`<internal shared directory server>\Modeling_Data\continuous_station_repo`.
26+
27+
A mirrored copy is available at http://tinyurl.com/dmsdatastore.
28+
29+
The system processes data through distinct stages:
30+
31+
1. **Raw**: Data is stored exactly "as downloaded" without transformation or unit changes. This includes data fetched from various sources in their original formats, even if proprietary or unusual. Raw files are unique per datastream per time block.
32+
33+
2. **Formatted**: Data in this stage adheres to file naming conventions and includes prescribed metadata. While the original intention for unit conversion at this stage was questioned, it's noted that units were not typically changed here.
34+
35+
3. **Screened**: This stage incorporates data that has undergone quality assurance and quality control (QA/QC) processes, including flagging data rejected by providers or users. At this stage, units are standardized and consistent across data.
36+
37+
4. **Processed**: This represents the final stage where data may have been filled by algorithms and is ready for specific applications like boundary conditions, where smoothing or no missing values are required. These files are not necessarily unique in the same way as raw or screened data.
38+
39+
### Data Repository Workflow
40+
41+
```mermaid
42+
flowchart LR
43+
subgraph datasources ["Data Sources"]
44+
direction LR
45+
d1["USGS"]
46+
d2["DWR"]
47+
d3["NOAA"]
48+
d4["CDEC"]
49+
d5["USBr"]
50+
end
51+
subgraph dropbox ["Drop Box"]
52+
53+
end
54+
subgraph repograph ["Repository"]
55+
C2["raw/"]
56+
D1["formatted/"]
57+
E1["screened/"]
58+
F1["processed/"]
59+
end
60+
subgraph userqaqc ["User QA/QC"]
61+
H["Flag Editing"]
62+
H-- updates user flag -->E1
63+
end
64+
datasources --> B("Download")
65+
B --> C2
66+
C2 --> D("Format")
67+
D --> D1
68+
D1 --> E("Automated Screening")
69+
E --> E1
70+
E1 --> F("Process")
71+
F --> F1
72+
F1 --> G["Modeling Applications & Boundary Conditions"]
73+
74+
dropbox --> repograph
75+
76+
```
77+
78+
### User Access
79+
80+
Users typically have write access only to "incoming" subdirectories within `raw`, `screened`, and `processed` directories, with submissions formatted correctly then being ingested into the main, read-only directories. Users are generally not expected to access raw data directly; `formatted` data allows review of original downloaded values, and `screened` data includes user flags and consistent units.
81+
82+
## Data Quality and Flags
83+
84+
Data quality is tracked through several concepts:
85+
86+
- **Status**: Data can be "Accepted" (flagged by provider or with a QAQC flag indicating attention) or "Provisional" (from a real-time source). The system prioritizes data from the "provider of record" (e.g., Water Data Library - WDL) over real-time sources (e.g., CDEC) for "accepted" data, while provisional data may come from real-time backups.
87+
88+
- **Quality**: This includes "Provider quality" and "User quality". Provider flags indicating bad data are honored and lead to values being set to NaN (Not a Number). "User quality" allows the project's QA/QC process to signal bad data while respecting original values. A `user_flag` column in screened data indicates anomalous data, where `1` means anomalous and `0` (or `NA`) means the anomaly was overridden by a user.
89+
90+
### Data Quality Flow
91+
92+
```mermaid
93+
graph LR
94+
A[Raw Data] --> B{Provider Flags}
95+
B --(Set to NaN)--> C[Formatted Data]
96+
C --> D{Automated Screening}
97+
D --> E[User QA/QC & Manual Review]
98+
E --(Overrides auto flags, sets user_flag)--> F[Screened Data]
99+
F --> G[Processed Data]
100+
```
101+
102+
## Data Screening and Error Detection Methods
103+
104+
The `auto_screen.py` module in `dms_datastore` performs YAML-specified screening protocols on time series data. Key screening methods include:
105+
106+
- **dip_test(ts, low, dip)**: Checks for anomalies based on dips below a threshold.
107+
- **repeat_test(ts, max_repeat, lower_limit=None, upper_limit=None)**: Identifies anomalies due to values repeating more than a specified number of times.
108+
- **short_run_test(ts, small_gap_len, min_run_len)**: Flags small clusters of valid data points surrounded by larger gaps as anomalies.
109+
110+
Additional error detection methods from `vtools3` include:
111+
112+
- **nrepeat(ts)**: Returns the length of consecutive runs of repeated values.
113+
- **threshold(ts, bounds, copy=True)**: Masks values outside specified bounds.
114+
- **bounds_test(ts, bounds)**: Detects anomalies based on specified bounds.
115+
- **median_test(ts, ...) / med_outliers(ts, ...)**: Detects outliers using a median filter.
116+
- **median_test_oneside(ts, ...)**: Uses a one-sided median filter for outlier detection.
117+
- **median_test_twoside(ts, ...)**: Similar to `med_outliers` but uses a two-sided median filter.
118+
- **gapdist_test_series(ts, smallgaplen=0)**: Fills small gaps to facilitate gap analysis.
119+
- **steep_then_nan(ts, ...)**: Identifies outliers near large data gaps.
120+
- **despike(arr, n1=2, n2=20, block=10)**: Implements an algorithm to remove spikes from data.
121+
122+
## Metadata and Station Concepts
123+
124+
The system defines clear concepts for organizing time series data:
125+
126+
- **Station**: A well-defined concept tied to a (location, institution) pair, acknowledging that physical locations may vary slightly and different agencies at the same approximate location may have subtly different platforms. The `station_dbase.csv` contains station information like ID, agency ID, name, latitude, and longitude. These locations are corrected to fit the SCHISM mesh.
127+
128+
- **Sublocation**: Used when a "station" doesn't uniquely describe a datastream, such as top/bottom sensors or different programs within the same agency measuring the same variable. The `station_subloc_new.csv` table is used to define sublocations. The `subloc` concept generalizes depths and other ambiguities.
129+
130+
- **Datastream**: This term describes a single sensor and is uniquely identified by the combination of (station, sublocation, variable).
131+
132+
## File Naming Conventions
133+
134+
A simplified file naming convention is used for data files:
135+
`agency_dwrID@subloc_agencyID_variable_YYYY_9999.csv`
136+
137+
For example: `usgs_sjj@bgc_11337190_turbidity_2016_2020.csv`
138+
139+
Components include:
140+
141+
- **agency**: The agency that collects the data, potentially including a high-level program name (e.g., `dwr_des`).
142+
- **dwr id and sublocation**: The DWR ID from `stations_utm.csv` and the `subloc` from `station_subloc_new.csv`, separated by an `@` sign if a sublocation exists.
143+
- **agency_id**: The identifier used by the agency (e.g., `11337190` for USGS).
144+
- **variable**: The variable name using the project's standardized naming convention (e.g., `turbidity`, `temp`).
145+
- **_YYYY_9999**: Indicates the time shard, with `9999` representing "until now".
146+
147+
File formats use `#` for comments, `,` as a separator, and ISO/CF compliant timestamps (e.g., `2009-02-10T00:00`). Metadata is included as key-value pairs in the header.
148+
149+
## Units and Standardization
150+
151+
The system aims for standardization of variables and units:
152+
153+
- **CF Compliance**: Variable names and units are intended to be CF (Climate and Forecast) compliant wherever possible.
154+
- **Unit Handling**: The "screened" data should have consistent units. The standard practice for stage and flow is feet and cubic feet per second, respectively, while SI units are used for everything else like temperature.
155+
- **PSU Exception**: Practical Salinity Unit (PSU) is noted as an exception, as it's technically a ratio and not a true unit.
156+
- **Specific Conductivity (EC)**: This is the standard way salinity data is collected and is always normalized to 25°C.
157+
158+
## Data Fetching and Priority
159+
160+
Data is fetched through download scripts (`download_noaa`, `download_cdec`, `download_nwis`, `download_des.py`). The `auto_screen` process uses `custom_fetcher` functions to retrieve data.
161+
162+
The system handles cases where data for the same station comes from different sources. The `src_priority` mechanism in `read_ts_repo` ensures that data from higher-priority sources is preferred.
163+
164+
## Challenges and Exceptions
165+
166+
Several challenges and workarounds are identified:
167+
168+
- **WDL Station IDs**: WDL station IDs may not have the same `station_id` due to appended "00" or "Q". The solution is to use an internal alias as the `station_id` to ensure uniqueness.
169+
- **SWP/CVP Exports**: These exports are calculated differently for hourly and instantaneous values, leading to them being distinct data sets. The solution is to treat these different calculations as "sublocations".
170+
- **USGS Multiple Instruments**: USGS may have multiple instruments measuring the same variable for one `station_id` due to different programs or sublocations. The `/raw` directory can store these dual versions for QA/QC, though the "processed" set should ideally be unified.
171+
172+
## Installation
173+
174+
```bash
175+
git clone https://github.com/CADWRDeltaModeling/dms_datastore
176+
conda env create -f environment.yml # should create a dms_datastore and pip install the package
177+
# alternatively, pip install -e . after running the above command if you want to develop the package
178+
conda activate dms_datastore
179+
```

0 commit comments

Comments
 (0)