climate_ref_core.esgf
#
ESGF dataset fetching
This module provides classes for searching and fetching datasets from ESGF (Earth System Grid Federation) and other data registries.
CMIP6Request
#
Bases: IntakeESGFMixin
Represents a CMIP6 dataset request.
These data are fetched from ESGF based on the provided facets.
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/cmip6.py
__init__(slug, facets, remove_ensembles=False, time_span=None)
#
Initialize a CMIP6 request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Unique identifier for this request |
required |
facets
|
dict[str, Any]
|
ESGF search facets (e.g., source_id, variable_id, experiment_id) |
required |
remove_ensembles
|
bool
|
If True, keep only one ensemble member per model |
False
|
time_span
|
tuple[str, str] | None
|
Optional time range filter (start, end) in YYYY-MM format |
None
|
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/cmip6.py
CMIP7Request
#
Represents a CMIP7 dataset request.
Since CMIP7 data is not yet available on ESGF, this class fetches CMIP6 data and converts it to CMIP7 format using convert_cmip6_dataset().
The facets use CMIP7 naming conventions (e.g., variant_label instead of member_id).
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/cmip7.py
119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |
__init__(slug, facets, remove_ensembles=False, time_span=None)
#
Initialize a CMIP7 request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Unique identifier for this request |
required |
facets
|
dict[str, Any]
|
CMIP7 search facets (e.g., source_id, variable_id, variant_label) |
required |
remove_ensembles
|
bool
|
If True, keep only one ensemble member per model |
False
|
time_span
|
tuple[str, str] | None
|
Optional time range filter (start, end) in YYYY-MM format |
None
|
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/cmip7.py
fetch_datasets()
#
Fetch CMIP6 datasets and convert them to CMIP7 format.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing CMIP7 dataset metadata and file paths. |
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/cmip7.py
ESGFFetcher
#
Fetches datasets from ESGF and returns metadata with file paths.
Uses intake-esgf to search and download datasets. Files that cannot be found locally are stored in intake-esgf's cache directory.
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/fetcher.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
fetch_for_test_case(requests)
#
Fetch all data for a test case's requests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requests
|
tuple[ESGFRequest, ...] | None
|
The ESGF requests from the test case |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Combined DataFrame with all datasets, grouped by source_type |
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/fetcher.py
fetch_request(request)
#
Fetch datasets for a single ESGF request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
request
|
ESGFRequest
|
The ESGF request specifying what to fetch |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing dataset metadata and file paths. Each row represents one file, with a 'path' column pointing to the file (either in intake-esgf's cache or one of the root data locations). This format is not identical to the DataCatalog, but it is broadly compatible. |
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/fetcher.py
list_requests_for_diagnostic(diagnostic)
#
List all ESGF requests for a diagnostic across all test cases.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
diagnostic
|
AbstractDiagnostic
|
The diagnostic to list requests for |
required |
Returns:
| Type | Description |
|---|---|
list[tuple[str, ESGFRequest]]
|
List of (test_case_name, request) tuples |
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/fetcher.py
ESGFRequest
#
Bases: Protocol
Protocol for ESGF dataset requests.
Implementations provide the logic for searching ESGF and generating output paths for downloaded datasets.
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/base.py
slug
instance-attribute
#
Unique identifier for this request.
source_type
instance-attribute
#
Type of dataset (e.g., 'CMIP6', 'obs4MIPs').
time_span
instance-attribute
#
Optional time range to filter datasets (start, end).
fetch_datasets()
#
Fetch dataset metadata from ESGF.
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame containing dataset metadata and file paths. Must contain at minimum: - key: A unique identifier for the dataset - files: A list of files for the dataset |
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/base.py
IntakeESGFMixin
#
Mixin that fetches datasets from ESGF using intake-esgf.
Subclasses must define: - facets: dict[str, str | tuple[str, ...]] - remove_ensembles: bool - time_span: tuple[str, str] | None
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/base.py
fetch_datasets()
#
Fetch dataset metadata from ESGF.
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/base.py
Obs4MIPsRequest
#
Bases: IntakeESGFMixin
Represents an Obs4MIPs dataset request.
These data are fetched from ESGF based on the provided facets.
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/obs4mips.py
__init__(slug, facets, remove_ensembles=False, time_span=None)
#
Initialize an Obs4MIPs request.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Unique identifier for this request |
required |
facets
|
dict[str, Any]
|
ESGF search facets (e.g., source_id, variable_id) |
required |
remove_ensembles
|
bool
|
If True, keep only one ensemble member (typically not relevant for obs) |
False
|
time_span
|
tuple[str, str] | None
|
Optional time range filter (start, end) in YYYY-MM format |
None
|
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/obs4mips.py
fetch_datasets()
#
Fetch dataset metadata from ESGF with project=obs4MIPs.
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/obs4mips.py
RegistryRequest
#
Request for data from a pooch registry (e.g., pmp-climatology).
These data are fetched from a pooch registry rather than ESGF. This is useful for pre-processed datasets like PMP climatologies that are hosted externally but not on ESGF.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
slug
|
str
|
Unique identifier for this request |
required |
registry_name
|
str
|
Name of the registry to fetch from (e.g., "pmp-climatology") |
required |
facets
|
dict[str, str | tuple[str, ...]]
|
Facets to filter datasets (e.g., {"variable_id": "psl", "source_id": "ERA-5"}) |
required |
source_type
|
str
|
Type of dataset source (default: "PMPClimatology") |
'PMPClimatology'
|
time_span
|
tuple[str, str] | None
|
Optional time range filter (not used for registry filtering, but required for protocol) |
None
|
Example
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/registry.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 | |
fetch_datasets()
#
Fetch matching datasets from the registry.
Returns:
| Type | Description |
|---|---|
DataFrame containing dataset metadata and file paths.
|
Each row represents one file, with columns for metadata and a 'files' column containing a list with the file path. |
Source code in packages/climate-ref-core/src/climate_ref_core/esgf/registry.py
sub-packages#
| Sub-package | Description |
|---|---|
| base | Base classes and protocols for ESGF data requests. |
| cmip6 | CMIP6 dataset request implementation. |
| cmip7 | CMIP7 dataset request implementation. |
| fetcher | ESGF dataset fetcher for downloading test data. |
| obs4mips | Obs4MIPs dataset request implementation. |
| registry | Registry-based dataset request implementation. |