Skip to content

Get supported bundles for a given item_type #680

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

Merged
merged 31 commits into from
Oct 12, 2022

Conversation

kevinlacaille
Copy link
Contributor

@kevinlacaille kevinlacaille commented Aug 24, 2022

PR #677 did not fully address this issue, however this PR should cover all the bases!

Validating item_type before product_bundle, so that the item type compatibility exception will propagate before the bundle validation exception.

  1. sepcs.validate_item_type() now just checks if input item_type is a valid input (i.e., if part of all item type)
  2. specs. validate_bundle() now checks if the input product bundle is a valid product bundle (i.e., if part of all product bundles), then checks if item type is compatible with the given product bundle
    • Important part! If the item type and product bundle are not compatible, it returns all valid product bundles for given item type with the new function specs.validate_supported_bundles()
  3. Created tests for new function, specs.validate_supported_bundles()
  4. Reformatted tests for specs.validate_bundle() and specs.validate_item_type()
  5. As per @jreiberkyle's new PR, propose new request-update command #616, item-type and bundle are now both arguments, instead of options
    • Changed all associated tests
  6. @cholmes We could not accomplish adding the feature that presents the user with a subset of valid bundles for a given item type when only providing the item type, as to do this we'd have to add the is_eagar flag to item_type, which 1. requires item_type to be an option and 2. requires an item type to be given when entering planet orders request --help.
    • So, now the user is presented with all compatible bundles only when the API is presented with an incompatible bundle. See New behaviour (1).

Previous behaviour (1): Incompatible item type with given bundle would return all compatible item types with given bundle.

❯ planet orders request --item-type PSScene --bundle analytic --id 20220919_183509_93_248f --name hood-stac 

Usage: planet orders request [OPTIONS]
Try 'planet orders request --help' for help.

Error: Invalid value: item_type - 'PSScene' is not one of 'REOrthoTile', 'PSOrthoTile', 'PSScene4Band', 'Sentinel1', 'SkySatScene', 'Landsat8L1G', 'Sentinel2L1C', 'PSScene3Band', 'SkySatCollect'.

New behaviour (1): Incompatible item type with given bundle now returns all compatible bundles with given item type.

❯ planet orders request PSScene analytic --id 20220919_183509_93_248f --name hood-stac

Usage: planet orders request [OPTIONS]
Try 'planet orders request --help' for help.

Error: Invalid value: bundle - 'analytic' is not one of 'analytic_udm2', 'analytic_3b_udm2', 'analytic_8b_udm2', 'visual', 'basic_analytic_udm2', 'basic_analytic_8b_udm2', 'analytic_sr_udm2', 'analytic_8b_sr_udm2'.

Previous behaviour (2): Only --name provided prompted user to enter a bundle.

> planet orders request --name "dude"                   
Usage: planet orders request [OPTIONS]
Try 'planet orders request --help' for help.

Error: Missing option '--bundle'. Choose from:
	analytic,
	analytic_udm2,
	analytic_3b_udm2,
	analytic_5b,
	analytic_5b_udm2,
	analytic_8b_udm2,
	visual,
	uncalibrated_dn,
	uncalibrated_dn_udm2,
	basic_analytic,
	basic_analytic_udm2,
	basic_analytic_8b_udm2,
	basic_uncalibrated_dn,
	basic_uncalibrated_dn_udm2,
	analytic_sr,
	analytic_sr_udm2,
	analytic_8b_sr_udm2,
	basic_uncalibrated_dn_nitf,
	basic_uncalibrated_dn_nitf_udm2,
	basic_analytic_nitf,
	basic_analytic_nitf_udm2,
	basic_panchromatic,
	basic_panchromatic_dn,
	panchromatic,
	panchromatic_dn,
	panchromatic_dn_udm2,
	pansharpened,
	pansharpened_udm2,
	basic_l1a_dn

New behaviour (2): Only --name provided now prompts the user to enter an item type and now provides all choices for item types.

❯ planet orders request --name "dude"        
Usage: planet orders request [OPTIONS] ITEM_TYPE BUNDLE
Try 'planet orders request --help' for help.

Error: Missing argument 'ITEM_TYPE'. Choose from:
        PSScene3Band,
        SkySatScene,
        PSScene,
        MYD09GA,
        PSOrthoTile,
        MYD09GQ,
        MOD09GA,
        Sentinel1,
        REOrthoTile,
        REScene,
        SkySatCollect,
        Sentinel2L1C,
        MOD09GQ,
        Landsat8L1G,
        PSScene4Band

Closing #618, #698

@kevinlacaille kevinlacaille marked this pull request as ready for review September 21, 2022 19:05
@kevinlacaille kevinlacaille force-pushed the compatible_bundle_with_item_type_error_2 branch from c6028fb to 800cbc7 Compare September 22, 2022 16:48
@jreiberkyle
Copy link
Contributor

When I run planet orders request --help I get the following:

Usage: planet orders [OPTIONS] COMMAND [ARGS]...
Try 'planet orders --help' for help.

Error: No such command 'requests'.
planet-client-python$> planet orders request --help
Usage: planet orders request [OPTIONS]
Try 'planet orders request --help' for help.

Error: Missing option '--item-type'. Choose from:
	SkySatCollect,
	PSScene,
	MYD09GQ,
	SkySatScene,
	Landsat8L1G,
	MOD09GA,
	MYD09GA,
	Sentinel1,
	PSScene3Band,
	PSScene4Band,
	REOrthoTile,
	REScene,
	MOD09GQ,
	PSOrthoTile,
	Sentinel2L1C

This is due to using the is_eager flag in the item-type option.

I imagine the is_eager flag is set to True to allow filtering bundles by item-type.

What if, instead, we to keep the CLI option logic pretty simple here. That is, the bundle option lists all possible bundles, the item-types option lists all possible item types, and the determination of whether the bundle and item-type are compatible, and creation of the error message and raising of BadParameter with the subset of bundles valid for the specified item-type is done within the command function.

@kevinlacaille
Copy link
Contributor Author

When I run planet orders request --help I get the following:

Usage: planet orders [OPTIONS] COMMAND [ARGS]...
Try 'planet orders --help' for help.

Error: No such command 'requests'.
planet-client-python$> planet orders request --help
Usage: planet orders request [OPTIONS]
Try 'planet orders request --help' for help.

Error: Missing option '--item-type'. Choose from:
	SkySatCollect,
	PSScene,
	MYD09GQ,
	SkySatScene,
	Landsat8L1G,
	MOD09GA,
	MYD09GA,
	Sentinel1,
	PSScene3Band,
	PSScene4Band,
	REOrthoTile,
	REScene,
	MOD09GQ,
	PSOrthoTile,
	Sentinel2L1C

This is due to using the is_eager flag in the item-type option.

I imagine the is_eager flag is set to True to allow filtering bundles by item-type.

What if, instead, we to keep the CLI option logic pretty simple here. That is, the bundle option lists all possible bundles, the item-types option lists all possible item types, and the determination of whether the bundle and item-type are compatible, and creation of the error message and raising of BadParameter with the subset of bundles valid for the specified item-type is done within the command function.

That's a great catch, thanks, @jreiberkyle!

I'd love to find a way around the is_eager flag, but I can't see a solution.

I'm not against presenting all bundle options to the users, then raising a BadParameter with the subset of valid bundles, if they enter an incompatible bundle, like you mentioned. This would vastly reduce the function's dependencies, but would come at the cost of not giving the user precisely the information they need, right away.

Thoughts @sgillies @cholmes ?

@jreiberkyle
Copy link
Contributor

Another thing to bring into consideration is that with #616, item-type and bundle will become required arguments instead of options. Not sure how, if at all, this would affect this interaction between item-type and bundle.

Copy link
Contributor

@jreiberkyle jreiberkyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to work as I'd expect:

> planet orders request bop boop
Usage: planet orders request [OPTIONS] ITEM_TYPE BUNDLE
Try 'planet orders request --help' for help.

Error: Invalid value for 'ITEM_TYPE': 'bop' is not one of 'MYD09GQ', 'PSScene3Band', 'SkySatCollect', 'Landsat8L1G', 'PSScene4Band', 'Sentinel1', 'SkySatScene', 'PSScene', 'REOrthoTile', 'MYD09GA', 'MOD09GA', 'Sentinel2L1C', 'REScene', 'PSOrthoTile', 'MOD09GQ'.
> planet orders request psscene boop
Usage: planet orders request [OPTIONS] ITEM_TYPE BUNDLE
Try 'planet orders request --help' for help.

Error: Invalid value for 'BUNDLE': 'boop' is not one of 'analytic', 'analytic_udm2', 'analytic_3b_udm2', 'analytic_5b', 'analytic_5b_udm2', 'analytic_8b_udm2', 'visual', 'uncalibrated_dn', 'uncalibrated_dn_udm2', 'basic_analytic', 'basic_analytic_udm2', 'basic_analytic_8b_udm2', 'basic_uncalibrated_dn', 'basic_uncalibrated_dn_udm2', 'analytic_sr', 'analytic_sr_udm2', 'analytic_8b_sr_udm2', 'basic_uncalibrated_dn_nitf', 'basic_uncalibrated_dn_nitf_udm2', 'basic_analytic_nitf', 'basic_analytic_nitf_udm2', 'basic_panchromatic', 'basic_panchromatic_dn', 'panchromatic', 'panchromatic_dn', 'panchromatic_dn_udm2', 'pansharpened', 'pansharpened_udm2', 'basic_l1a_dn'.

The one thing I'd add is some helpful text in the docstring that indicates that the valid bundle is item-type specific, and I'd also consider adding that to the error message that comes up for 'BUNDLE', something like

"Error: Invalid value for 'BUNDLE': 'boop' is not one of the following valid bundles for PsScene 'analytic', ..."

@kevinlacaille
Copy link
Contributor Author

The one thing I'd add is some helpful text in the docstring that indicates that the valid bundle is item-type specific, and I'd also consider adding that to the error message that comes up for 'BUNDLE', something like

"Error: Invalid value for 'BUNDLE': 'boop' is not one of the following valid bundles for PsScene 'analytic', ..."

The error message bubbles up from an exception from click.Choice() when building the request (planet.cli.orders.request()). Having the item type known by the @click.option decorator is impossible without having a callback function in bundle's argument, which is a known issue (see point no.6 #680 (comment)).

I think for now the exception message will have to remain the same.

@cholmes
Copy link
Member

cholmes commented Oct 12, 2022

Tried this out, and overall it looks pretty good. I agree that it'd be ideal if we can just return the actual valid bundles after a user puts the item type in. But the experience is 'good enough' to merge this in - if I select a wrong one it tells me on the next step. As a user I'll wonder why they didn't just tell me, but I'll get to the right spot.

So let's merge this in. I would like to see if there's any way to do a better warning, but can just make a ticket for the future - it's no longer 'must fix this', more in 'that'd be nice'.

Copy link
Member

@cholmes cholmes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for all your hard work on this Kevin.

@cholmes
Copy link
Member

cholmes commented Oct 12, 2022

Oh, also - I added in #712, since this brings a material change to how the CLI works, and we need to be sure the docs stay up to date with the code. But I think we can merge this, just need to be sure to get #712 in before the next release.

@kevinlacaille kevinlacaille merged commit 27fc825 into main Oct 12, 2022
@kevinlacaille kevinlacaille deleted the compatible_bundle_with_item_type_error_2 branch October 12, 2022 16:50
@kevinlacaille
Copy link
Contributor Author

Thanks for all of your reviews, @sgillies, @jreiberkyle, and @cholmes!

I agree the UX isn't the best it could be, but we'll need to think hard about a workaround with or without click for the solution we are hoping for, in a future ticket.

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

Successfully merging this pull request may close these issues.

Validate item-type information before bundle information planet order request: be more helpful on what bundles are available for a given item_type
4 participants