Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

excessive adding of "band" dimensions #205

Closed
soxofaan opened this issue Aug 31, 2022 · 4 comments
Closed

excessive adding of "band" dimensions #205

soxofaan opened this issue Aug 31, 2022 · 4 comments

Comments

@soxofaan
Copy link
Member

Originates from discussion on forum https://discuss.eodc.eu/t/exclusion-mask/441 (unfortunately user started this as private message instead of forum topic)

user does a couple of operations like

s2_cube_water = s2_cube.reduce_dimension(reducer = water_function, dimension = "bands")
s2_cube_water = s2_cube_water.add_dimension("bands", "water_prob", type = "bands") 

...

s2_cube_water_threshold = s2_cube_water.apply_dimension(dimension="bands", process=lambda x: if_(x > 0.75, x,0))
s2_cube_water_threshold = s2_cube_water_threshold.add_dimension("bands", "w_T75", type = "bands")

...

s2_cube_swf = s2_cube_water_sum.resample_cube_spatial(s2_count) / s2_count
s2_cube_swf = s2_cube_swf.add_dimension("bands", "swf", type = "bands") 

The first one is ok: first eliminate the "bands" dimension and add it back. But the other two cases are risky: apply_dimension or resample_cube_spatial do not eliminate the "bands" dimension, but the user is still adding another (?) "bands dimension.

Further down the line, when executing the whole graph, the user gets non-helping errors (e.g. "java.lang.IllegalArgumentException: Invalid band index 5, only 4 bands available.").

I think we should throw a more clear error here.
Maybe even this can be done client-side

@soxofaan
Copy link
Member Author

from https://processes.openeo.org/#add_dimension:

Errors/Exceptions

    DimensionExists
    Message: A dimension with the specified name already exists.

@soxofaan
Copy link
Member Author

should be covered now

@sulova
Copy link

sulova commented Sep 20, 2022

"reduce_dimension" is applied I am getting also an error message OpenEoApiError: [400] DimensionExists: A dimension with name bands already exists. (ref: r-49f1fdda306a4c8abd63667dd0e51653)

This is the script:

start_date           = '2021-06-01'
spatial_extent       = {'west': -74.06810760, 'east': -73.90597343, 'south': 4.689864510, 'north': 4.724080996, 'crs': 'epsg:4326'} #colombia
zone                 = "tropical"

start_date_dt_object = datetime.strptime(start_date, '%Y-%m-%d')

end_date             = (start_date_dt_object + relativedelta(months = +2)).date() ## End date, 1 month later (1st Feb. 2021)
start_date_exclusion = (start_date_dt_object + relativedelta(months = -2)).date() 
bands                = ['B02', 'B03', 'B04', 'B08', 'CLP', 'SCL' , 'sunAzimuthAngles', 'sunZenithAngles'] 



s2_cube = connection.load_collection(
    'SENTINEL2_L2A_SENTINELHUB',
    spatial_extent  = spatial_extent,
    temporal_extent = [start_date_exclusion, end_date],
    bands           = bands)


s2_count = s2_cube.filter_bands(bands = ["B08"])
s2_count = s2_count.reduce_dimension(reducer=lambda data: data.count(), dimension = "t")

s2_count = s2_count.add_dimension("bands", "count", type = "bands")
# s2_count = s2_count.rename_labels("bands",["count"])


s1_s2_mask_save = s2_count.save_result(format='netCDF') #GTiff #netCDF
my_job  = s1_s2_mask_save.create_job(title="s2_count")
results = my_job.start_and_wait().get_results()
results.download_files("s2_count") 

I thought that for reduce_dimension should not be a problem.

@soxofaan
Copy link
Member Author

s2_count = s2_count.reduce_dimension(reducer=lambda data: data.count(), dimension = "t")

s2_count = s2_count.add_dimension("bands", "count", type = "bands")

In first statement you do reduction of the "t" dimension, which indeed eliminates the "t" dimension, but the "bands" dimension is still there, so you can not add another bands dimension in the second statement

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants