API reference¶
All public functions are available directly from the top-level pyo_oracle
namespace, e.g. pyo_oracle.list_layers(...).
Discovery¶
pyo_oracle.list_layers(search=None, variables=None, ssp=None, time_period=None, depth=None, dataframe=True, simplify=False, _include_allDatasets=False)
¶
list_layers(search: Optional[Union[str, Iterable[str]]] = None, variables: Optional[Union[Variable, Iterable[Variable]]] = None, ssp: Optional[Union[SSP, Iterable[SSP]]] = None, time_period: Optional[TimePeriod] = None, depth: Optional[Union[Depth, Iterable[Depth]]] = None, dataframe: Literal[True] = True, simplify: bool = False, _include_allDatasets: bool = False) -> pd.DataFrame
list_layers(search: Optional[Union[str, Iterable[str]]] = None, variables: Optional[Union[Variable, Iterable[Variable]]] = None, ssp: Optional[Union[SSP, Iterable[SSP]]] = None, time_period: Optional[TimePeriod] = None, depth: Optional[Union[Depth, Iterable[Depth]]] = None, dataframe: Literal[False] = False, simplify: bool = False, _include_allDatasets: bool = False) -> List[str]
Lists available layers in the Bio-ORACLE server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search
|
str | list
|
Natural text search term, eg. 'Temperature', 'Oxygen'. |
None
|
variables
|
str | list
|
Variables to filter from. Valid values are ['po4','o2','si','ph','sws','phyc','so','thetao','dfe','no3','sithick','tas','siconc','chl','mlotst','clt','terrain']. |
None
|
ssp
|
str | list
|
Future scenario to choose from. Valid values are ['ssp119', 'ssp126', 'ssp370', 'ssp585', 'ssp460', 'ssp245', 'baseline']. |
None
|
time_period
|
str
|
Time period to choose from. Valid values are either 'present' or 'future'. |
None
|
depth
|
str | list
|
Depth category to choose from. Valid values are ['min', 'mean', 'max', 'surf']. |
None
|
dataframe
|
bool
|
Whether to return a Pandas DataFrame. If False, will return a list. |
True
|
simplify
|
bool
|
Whether to simplify the output. If True, will return only dataset ID and dataset title. If dataframe=False, this doesn't do anything. |
False
|
_include_allDatasets
|
bool
|
Internal flag for including all datasets. |
False
|
Returns:
| Type | Description |
|---|---|
Union[DataFrame, List[str]]
|
pd.DataFrame or list: If 'dataframe' is True (default), returns a Pandas DataFrame containing filtered layers' information. If 'dataframe' is False, returns a list of filtered dataset IDs. |
Notes
- This function queries the Bio-ORACLE server to list available layers based on the provided filters.
- Filtering can be done by specifying 'variables', 'ssp', and 'time_period'.
- The function provides flexibility in choosing to return a DataFrame or a list of dataset IDs.
Example
List all available layers¶
all_layers = list_layers()
List layers for specific variables and future scenarios¶
filtered_layers = list_layers(variables=['po4', 'o2'], ssp='ssp585', dataframe=True)
Source code in pyo_oracle/main.py
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 | |
pyo_oracle.info_layer(dataset_id, verbose=True)
¶
Returns metadata about a single layer (dataset).
Mirrors biooracler::info_layer: reports the dimension ranges
(time, latitude, longitude, and depth when present) and the available
variables together with their units and long names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
The dataset ID to inspect, e.g. "thetao_baseline_2000_2019_depthsurf". |
required |
verbose
|
bool
|
If True (default), pretty-print the metadata as well as returning it. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
A dictionary with keys |
Dict[str, Any]
|
(mapping dim name -> (min, max)), |
|
Dict[str, Any]
|
{"units", "long_name"}) and |
|
Dict[str, Any]
|
constraints dict accepted by |
Example
info = info_layer("thetao_baseline_2000_2019_depthsurf")
Source code in pyo_oracle/main.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 | |
Subsetting¶
pyo_oracle.build_constraints(dataset_id=None, time=None, latitude=None, longitude=None, depth=None, time_step=1, latitude_step=1, longitude_step=1, depth_step=1, validate=True)
¶
Build a griddap constraints dictionary from human-friendly bounds.
Instead of hand-writing the {"time>=": ..., "time<=": ..., "time_step": ...}
dictionary, pass (min, max) tuples per dimension and optional strides.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
If given and |
None
|
time
|
tuple
|
|
None
|
latitude
|
tuple
|
|
None
|
longitude
|
tuple
|
|
None
|
depth
|
tuple
|
|
None
|
time_step
|
int
|
Stride along time. Default 1. |
1
|
latitude_step
|
int
|
Stride along latitude. Default 1. |
1
|
longitude_step
|
int
|
Stride along longitude. Default 1. |
1
|
depth_step
|
int
|
Stride along depth. Default 1. |
1
|
validate
|
bool
|
If True and |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
Dict[str, Any]
|
A constraints dictionary suitable for |
Example
constraints = build_constraints( time=("2000-01-01T00:00:00Z", "2010-01-01T00:00:00Z"), latitude=(0, 10), longitude=(0, 10), )
Source code in pyo_oracle/utils.py
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
Data access¶
pyo_oracle.load_layer(dataset_id, constraints=None, variables=None, fmt='pandas', verbose=False)
¶
Loads a layer directly into memory instead of writing it to a file.
This is the in-memory counterpart of download_layers and mirrors
biooracler::download_layers returning data into the session.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_id
|
str
|
The dataset ID to load. |
required |
constraints
|
dict
|
Constraints to apply. See |
None
|
variables
|
list
|
Subset of variables to load. If None, all are loaded. |
None
|
fmt
|
str
|
"pandas" (default) returns a |
'pandas'
|
verbose
|
bool
|
If True, print selection details. |
False
|
Returns:
| Type | Description |
|---|---|
Any
|
pandas.DataFrame or xarray.Dataset: The requested data. |
Example
df = load_layer("thetao_baseline_2000_2019_depthsurf", constraints=constraints) ds = load_layer("thetao_baseline_2000_2019_depthsurf", fmt="xarray")
Source code in pyo_oracle/main.py
413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 | |
pyo_oracle.download_layers(dataset_ids, output_directory=None, response='nc', constraints=None, variables=None, skip_confirmation=None, verbose=True, log=True, timestamp=True, timeout=120, skip_convert_to_lowercase=False, **httpx_kwargs)
¶
Downloads one or more layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataset_ids
|
str or list
|
Dataset ID(s) to download. A single dataset ID or a list of IDs. |
required |
output_directory
|
str or Path
|
Directory where downloaded files will be saved. If not provided, the default directory will be used. |
None
|
response
|
str
|
Format of the response to download. Default is 'nc'. |
'nc'
|
constraints
|
dict
|
Constraints to apply to the downloaded data. See |
None
|
variables
|
list
|
Subset of variables to download. If not provided, all variables in the dataset are downloaded. |
None
|
skip_confirmation
|
bool
|
If True, confirmation prompts will be skipped. If None, the value from the configuration will be used. |
None
|
verbose
|
bool
|
If True, detailed information will be printed during the download process. |
True
|
log
|
bool
|
If True, a log of the download will be created. |
True
|
timestamp
|
bool
|
If True, a timestamp will be added to the downloaded files' names. |
True
|
timeout
|
int
|
Timeout in seconds for the download request. |
120
|
skip_convert_to_lowercase
|
bool
|
If True, the dataset ID will not be converted to lowercase. |
False
|
httpx_kwargs
|
dict
|
Additional keyword arguments to pass to the httpx function. |
{}
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Note
This function downloads the specified dataset(s) and saves them to the provided or default output directory.
Example
Download a single dataset with default settings¶
download_layers(dataset_ids="dataset123")
Download multiple datasets with custom settings, restricting to two variables¶
download_layers( dataset_ids=["dataset456", "dataset789"], output_directory="/path/to/output", response="csv", variables=["thetao_mean"], verbose=False, )
Source code in pyo_oracle/main.py
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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | |
pyo_oracle.list_local_data(data_directory=None, verbose=True)
¶
Lists datasets that are locally downloaded.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_directory
|
str
|
Path to the data directory. If not provided, the path from the configuration will be used. |
None
|
verbose
|
bool
|
If True, detailed information will be printed. If False, only basic file names will be printed. |
True
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Note
This function lists the datasets available in the specified data directory.
Example
List all datasets in the default data directory with detailed information¶
list_local_data()
List datasets in a specific directory without verbose output¶
list_local_data(data_directory="/path/to/data", verbose=False)
Source code in pyo_oracle/main.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 | |