Hi @tik65536
I am working on a feature that would allow automatically calculating the aggregated zone data from finer levels provided in a collection provider configuration to produce coarser zones levels requested by the API.
The idea is that if a collection provider only contains a dataset of, eg: L15 zones, it could return any L0-L15 zones, even when the L0-L14 ones are not in the stored dataset. The feature would be able to also support many sub-groups (eg: L0, L5, L10, L15) to offer "checkpoints" where requested data would aggregate based on the closest higher-level the collection providers offers. When there are a lot of fine-resolution zones, that should help reduce the amount of storage necessary for all other coarser levels.
To implement this feature, I need to invoke a function that does the finer->coarser quantization step within the get_data of the various AbstractCollectionProvider, since the higher level zone Ids must be fetched to get a match, and then quantized to coarser zones.
In other words, some kind of "groupby(finer->coarser)" call of the result dataframe after each of the following:
|
try: |
|
db_result = self.db.execute(query, {'cellid_list': zoneIds}, with_column_types=True) |
|
except Exception as e: |
|
logger.error(f'{__name__} get_data failed : {e}') |
|
raise Exception(f'{__name__} get_data failed : {e}') |
|
try: |
|
result_df = datasource.conn.sql(sql, params=[zoneIds]).df() |
|
except Exception as e: |
|
logger.error(f'{__name__} {datasource_id} query data error: {e}') |
|
raise Exception(f'{__name__} {datasource_id} query data error: {e}') |
|
sql = f"""select {cols} from ds where ("{id_col}" in ({', '.join(f"'{z}'" for z in zoneIds)})) and ({cql_sql}) """ |
|
zarr_result = xr.Dataset.from_dataframe(ctx.sql(sql).to_pandas().set_index(id_col)) |
|
else: |
|
cols = set(datatree.data_vars) if ("*" in datasource.data_cols) else set(datasource.data_cols) |
|
cols = list(cols - set(datasource.exclude_data_cols)) |
|
idx_mask = datatree[id_col].isin(np.array(zoneIds, dtype=datatree[id_col].dtype)) |
|
zarr_result = datatree.sel({id_col: idx_mask}) |
|
zarr_result = zarr_result.to_dataset()[cols] |
|
except Exception as e: |
|
# Zarr will raise exception if nothing matched |
|
logger.error(f'{__name__} {datasource_id} sel failed: {e}') |
|
return result |
Since I am aware you are working on https://github.com/LandscapeGeoinformatics/pydggsapi/compare/alternative_dggrs_representations with notable fixes for datetime support in Zarr, I would like to synchronize to facilitate the PR merges/avoid conflicts with this feature.
However, because of the datetime-per-depth naming that creates repeated temporal dimensions (#65 (comment)), I cannot merge it directly, as I believe it defies the concept of datetime dimension in the first place.
Do you think the unique datetime could be applied in the Zarr provider?
Hi @tik65536
I am working on a feature that would allow automatically calculating the aggregated zone data from finer levels provided in a collection provider configuration to produce coarser zones levels requested by the API.
The idea is that if a collection provider only contains a dataset of, eg: L15 zones, it could return any L0-L15 zones, even when the L0-L14 ones are not in the stored dataset. The feature would be able to also support many sub-groups (eg: L0, L5, L10, L15) to offer "checkpoints" where requested data would aggregate based on the closest higher-level the collection providers offers. When there are a lot of fine-resolution zones, that should help reduce the amount of storage necessary for all other coarser levels.
To implement this feature, I need to invoke a function that does the finer->coarser quantization step within the
get_dataof the variousAbstractCollectionProvider, since the higher level zone Ids must be fetched to get a match, and then quantized to coarser zones.In other words, some kind of "groupby(finer->coarser)" call of the result dataframe after each of the following:
pydggsapi/pydggsapi/dependencies/collections_providers/clickhouse_collection_provider.py
Lines 86 to 90 in e4f0e6b
pydggsapi/pydggsapi/dependencies/collections_providers/parquet_collection_provider.py
Lines 89 to 93 in e4f0e6b
pydggsapi/pydggsapi/dependencies/collections_providers/zarr_collection_provider.py
Lines 88 to 99 in e4f0e6b
Since I am aware you are working on https://github.com/LandscapeGeoinformatics/pydggsapi/compare/alternative_dggrs_representations with notable fixes for
datetimesupport in Zarr, I would like to synchronize to facilitate the PR merges/avoid conflicts with this feature.However, because of the
datetime-per-depth naming that creates repeated temporal dimensions (#65 (comment)), I cannot merge it directly, as I believe it defies the concept ofdatetimedimension in the first place.Do you think the unique
datetimecould be applied in the Zarr provider?