|
16 | 16 |
|
17 | 17 | import click |
18 | 18 | import datatree |
| 19 | +import earthaccess |
19 | 20 | import xarray as xr |
20 | 21 | from loguru import logger |
21 | 22 | from pm_tb_data._types import Hemisphere |
22 | | -from pm_tb_data.fetch.nsidc_0080 import ( |
23 | | - NSIDC_0080_PLATFORM_ID, |
24 | | - get_nsidc_0080_tbs_from_disk, |
25 | | -) |
| 23 | +from pm_tb_data.fetch import nsidc_0080 |
26 | 24 |
|
27 | 25 | from seaice_ecdr._types import ECDR_SUPPORTED_RESOLUTIONS |
28 | 26 | from seaice_ecdr.ancillary import ANCILLARY_SOURCES |
@@ -91,18 +89,36 @@ def _get_nsidc_0080_tbs( |
91 | 89 | *, |
92 | 90 | date: dt.date, |
93 | 91 | hemisphere: Hemisphere, |
94 | | - platform_id: NSIDC_0080_PLATFORM_ID, |
| 92 | + platform_id: nsidc_0080.NSIDC_0080_PLATFORM_ID, |
95 | 93 | ) -> EcdrTbData: |
96 | 94 | # TODO: consider extracting the fetch-related code here to `tb_data` module. |
97 | 95 | data_source: Final = "NSIDC-0080" |
98 | 96 | try: |
99 | | - xr_tbs = get_nsidc_0080_tbs_from_disk( |
100 | | - date=date, |
| 97 | + expected_fn = ( |
| 98 | + "NSIDC0080_TB_PS" f"_{hemisphere[0].upper()}25km" f"_{date:%Y%m%d}_v2.0.nc" |
| 99 | + ) |
| 100 | + |
| 101 | + results = earthaccess.search_data( |
| 102 | + short_name="NSIDC-0080", |
| 103 | + version="2", |
| 104 | + cloud_hosted=True, |
| 105 | + granule_name=expected_fn, |
| 106 | + ) |
| 107 | + if len(results) != 1: |
| 108 | + raise FileNotFoundError(f"Could not find {expected_fn} via `earthaccess`.") |
| 109 | + granule_result = results[0] |
| 110 | + _earthaccess_granule = earthaccess.open([granule_result]) |
| 111 | + |
| 112 | + # TODO: ideally, we would use datatree here. xarray >2024.9 should have |
| 113 | + # datatree integrated directly. |
| 114 | + ds = xr.open_dataset(_earthaccess_granule[0], group=platform_id) |
| 115 | + |
| 116 | + xr_tbs = nsidc_0080._normalize_nsidc_0080_tbs( |
| 117 | + ds=ds, |
101 | 118 | hemisphere=hemisphere, |
102 | | - resolution=NRT_RESOLUTION, |
103 | 119 | platform_id=platform_id, |
104 | 120 | ) |
105 | | - except Exception: |
| 121 | + except (FileNotFoundError, OSError): |
106 | 122 | # This would be a `FileNotFoundError` if a data files is completely |
107 | 123 | # missing. Currently, an OSError may also be raised if the data file exists |
108 | 124 | # but is missing the data variable we expect. Other errors may also be |
|
0 commit comments