ITADN

hypercoast.read_pace does not open non-AOP datasets.

#177ClosedIanTBlack 创建于 2025-10-08
bug
I
IanTBlackcommented
### Environment Information - hypercoast version: 0.14.2 - Python version: 3.12 - Operating System: Windows 11 ### Description The [hypercoast.read_pace](https://github.com/opengeos/HyperCoast/blob/01aa7ef456bca2bdd67673fc6affcd9ce6153bc9/hypercoast/pace.py#L14) function only supports access to AOP datasets. It would be beneficial to generalize this function to also support ingesting IOP, BGC, and PAR datasets. ### Suggestion Here is a rework of the `read_pace` function that supports opening other PACE datasets. I have added a products keyword argument that allows users to select which variables they want if they do not want all of them (such as the uncertainty or flag variables). This function was tested with L2 v3_1 NRT files. ``` import os from numpy.typing import ArrayLike import xarray as xr def read_pace(filepath: str | os.PathLike, wavelengths: ArrayLike| None = None, products: ArrayLike | None = None, method: str = 'nearest', engine: str = 'h5netcdf', **kwargs) -> xr.Dataset: """ Import data from a L2 PACE file and reorient to Earth coordinates. Args: filepath (os.PathLike): Pathlike string to the file to read. wavelengths (array-like, optional): Specific wavelengths to select. If None, all wavelengths are selected. products (array-like, optional): Specific data products or variables to select. If None, all products are selected. method (str, optional): Method to use for selection when wavelengths is not None. Defaults to "nearest". **kwargs: Additional keyword arguments to pass to the xarray `sel` method when wavelengths is not None. Returns: xr.Dataset: An xarray Dataset containing the PACE data. """ # Import nav group as base. dataset = xr.open_dataset(filepath, group = 'navigation_data', engine = engine) dataset = dataset.set_coords(['latitude', 'longitude']) # Import geophysical data products. product = xr.open_dataset(filepath, group = 'geophysical_data', engine = engine) # Import sensor band parameters. band_params = xr.open_dataset(filepath, group = 'sensor_band_parameters', engine = engine) # Merge datasets and rename dimensions/coordinates. dataset = xr.merge([dataset, product], join = 'outer', combine_attrs = 'drop_conflicts') if "pixel_control_points" in dataset.dims: dataset = dataset.rename({'pixel_control_points': 'pixels_per_line'}) if 'wavelength_3d' in band_params.coords: dataset.coords['wavelength_3d'] = band_params.coords['wavelength_3d'] dataset = dataset.rename({'wavelength_3d': 'wavelength'}) dataset = dataset.rename({'number_of_lines': 'latitude', 'pixels_per_line': 'longitude'}) # If specified, only keep products of interest. if products is not None: dataset = dataset[products] # If specified, only keep wavelengths of interest for compatible datasets. if wavelengths is not None and 'wavelength' in dataset.coords: dataset = dataset.sel(wavelength = wavelengths, method = method, **kwargs) return dataset ```
关闭于 2025-10-25 2 条评论