|
| 1 | +import os.path as op |
| 2 | +from typing import Dict |
| 3 | + |
| 4 | +from siphon.catalog import TDSCatalog |
| 5 | + |
| 6 | +GEOOCEAN_CLUSTER_DATA = "/lustre/geocean/DATA/" |
| 7 | +GEOOCEAN_THREDDS_DATA = "https://geoocean.sci.unican.es/thredds/dodsC/geoceanData/" |
| 8 | + |
| 9 | +# Default paths dictionary |
| 10 | +PATHS = { |
| 11 | + "SHYTCWAVES_COEFS": op.join( |
| 12 | + GEOOCEAN_THREDDS_DATA, "GEOOCEAN/SHyTCWaves_bulk/ibtracs_coef_pmin_wmax.nc" |
| 13 | + ), |
| 14 | + "SHYTCWAVES_BULK": op.join( |
| 15 | + GEOOCEAN_THREDDS_DATA, |
| 16 | + "GEOOCEAN/SHyTCWaves_bulk/library_shytcwaves_bulk_params_int32.nc", |
| 17 | + ), |
| 18 | + "SHYTCWAVES_MDA": op.join( |
| 19 | + GEOOCEAN_THREDDS_DATA, |
| 20 | + "GEOOCEAN/SHyTCWaves_bulk/shytcwaves_mda_indices_clean_int32.nc", |
| 21 | + ), |
| 22 | +} |
| 23 | + |
| 24 | + |
| 25 | +def update_paths(new_paths: dict) -> None: |
| 26 | + """ |
| 27 | + Update the paths dictionary with new values. |
| 28 | +
|
| 29 | + Parameters |
| 30 | + ---------- |
| 31 | + new_paths : dict |
| 32 | + Dictionary containing new path values to update. |
| 33 | +
|
| 34 | + Examples |
| 35 | + -------- |
| 36 | + >>> update_paths({"MY_PATH": "/new/path/to/data"}) |
| 37 | + """ |
| 38 | + |
| 39 | + PATHS.update(new_paths) |
| 40 | + |
| 41 | + |
| 42 | +def get_paths() -> dict: |
| 43 | + """ |
| 44 | + Get the paths dictionary. |
| 45 | +
|
| 46 | + Returns |
| 47 | + ------- |
| 48 | + dict |
| 49 | + Dictionary containing the paths. |
| 50 | + """ |
| 51 | + |
| 52 | + return PATHS |
| 53 | + |
| 54 | + |
| 55 | +def get_thredds_catalog() -> TDSCatalog: |
| 56 | + """ |
| 57 | + Get the Thredds catalog object. |
| 58 | +
|
| 59 | + Returns |
| 60 | + ------- |
| 61 | + TDSCatalog |
| 62 | + Siphon TDSCatalog object containing the catalog information. |
| 63 | + """ |
| 64 | + |
| 65 | + catalog_url = ( |
| 66 | + "https://geoocean.sci.unican.es/thredds/catalog/geoceanData/catalog.xml" |
| 67 | + ) |
| 68 | + |
| 69 | + return TDSCatalog(catalog_url) |
| 70 | + |
| 71 | + |
| 72 | +def get_catalog_folders() -> Dict[str, str]: |
| 73 | + """ |
| 74 | + Get a dictionary of folder names and their links from the first level of the catalog. |
| 75 | +
|
| 76 | + Returns |
| 77 | + ------- |
| 78 | + Dict[str, str] |
| 79 | + Dictionary with folder names as keys and their catalog URLs as values. |
| 80 | + """ |
| 81 | + |
| 82 | + catalog = get_thredds_catalog() |
| 83 | + folders = {} |
| 84 | + |
| 85 | + for name, ref in catalog.catalog_refs.items(): |
| 86 | + folders[ref.title] = ref.href |
| 87 | + |
| 88 | + return folders |
| 89 | + |
| 90 | + |
| 91 | +def print_catalog_table() -> None: |
| 92 | + """ |
| 93 | + Print a formatted table of available folders in the catalog. |
| 94 | + """ |
| 95 | + |
| 96 | + folders = get_catalog_folders() |
| 97 | + |
| 98 | + # Print header |
| 99 | + print("\nAvailable Folders in GeoOcean Thredds Catalog:") |
| 100 | + print("-" * 80) |
| 101 | + print(f"{'Folder Name':<20} | {'Catalog URL':<40}") |
| 102 | + print("-" * 80) |
| 103 | + |
| 104 | + # Print each folder |
| 105 | + for name, url in sorted(folders.items()): |
| 106 | + print(f"{name:<20} | {url:<40}") |
| 107 | + |
| 108 | + print("-" * 80) |
| 109 | + |
| 110 | + |
| 111 | +if __name__ == "__main__": |
| 112 | + print_catalog_table() |
0 commit comments