NASA-IMPACT / veda-data

3 stars 0 forks source link

Fix floating point EPSG codes in all collections #81

Open j08lue opened 12 months ago

j08lue commented 12 months ago

For example the code in our demo notebook https://github.com/NASA-IMPACT/veda-docs/blob/main/notebooks/tutorials/gif-generation.ipynb that attempts to load the item OMI_trno2_0.10x0.10_201601_Col3_V4.nc with stackstac fails:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
Cell In[7], line 1
----> 1 da = stackstac.stack(search.item_collection(), gdal_env=gdal_env)
      2 da = da.assign_coords({"time": pd.to_datetime(da.start_datetime)})
      3 da

File /srv/conda/envs/notebook/lib/python3.10/site-packages/stackstac/stack.py:287, in stack(items, assets, epsg, resolution, bounds, bounds_latlon, snap_bounds, resampling, chunksize, dtype, fill_value, rescale, sortby_date, xy_coords, properties, band_coords, gdal_env, errors_as_nodata, reader)
    280 if sortby_date is not False:
    281     plain_items = sorted(
    282         plain_items,
    283         key=lambda item: item["properties"].get("datetime", "") or "",
    284         reverse=sortby_date == "desc",
    285     )
--> 287 asset_table, spec, asset_ids, plain_items = prepare_items(
    288     plain_items,
    289     assets=assets,
    290     epsg=epsg,
    291     resolution=resolution,
    292     bounds=bounds,
    293     bounds_latlon=bounds_latlon,
    294     snap_bounds=snap_bounds,
    295 )
    296 arr = items_to_dask(
    297     asset_table,
    298     spec,
   (...)
    306     errors_as_nodata=errors_as_nodata,
    307 )
    309 return xr.DataArray(
    310     arr,
    311     *to_coords(
   (...)
    320     name="stackstac-" + dask.base.tokenize(arr),
    321 )

File /srv/conda/envs/notebook/lib/python3.10/site-packages/stackstac/prepare.py:166, in prepare_items(items, assets, epsg, resolution, bounds, bounds_latlon, snap_bounds)
    158     elif out_epsg != asset_epsg:
    159         raise ValueError(
    160             f"Cannot pick a common CRS, since assets have multiple CRSs: asset {id!r} of item "
    161             f"{item_i} {item['id']!r} is in EPSG:{asset_epsg}, "
    162             f"but assets before it were in EPSG:{out_epsg}.\n\n"
    163             "Please specify a CRS with the `epsg=` argument."
    164         )
--> 166 assert isinstance(out_epsg, int), f"`out_epsg` not found. {out_epsg=}"
    167 # ^ because if it was None initially, and we didn't error out in the above check, it's now always set
    169 if bounds_latlon is not None and out_bounds is None:

AssertionError: `out_epsg` not found. out_epsg=4326.0

Resulting from proj:epsg being a floating point value.

image

Acceptance criteria