Constructs an Earth Engine image. Args: args: This constructor accepts a variety of arguments: - A string - an Earth Engine asset id, - A string and a number - an Earth Engine asset id and version, - A number - creates a constant image, - An ee.Arra
(self, args: Any | None = None, version: float | None = None)
| 53 | |
| 54 | @deprecation.WarnForDeprecatedAsset('args') |
| 55 | def __init__(self, args: Any | None = None, version: float | None = None): |
| 56 | """Constructs an Earth Engine image. |
| 57 | |
| 58 | Args: |
| 59 | args: This constructor accepts a variety of arguments: |
| 60 | - A string - an Earth Engine asset id, |
| 61 | - A string and a number - an Earth Engine asset id and version, |
| 62 | - A number - creates a constant image, |
| 63 | - An ee.Array - creates a constant array image, |
| 64 | - A list - creates an image out of each element of the array and |
| 65 | combines them into a single image, |
| 66 | - An ee.Image - returns the argument, |
| 67 | - Nothing - results in an empty transparent image. |
| 68 | version: An optional asset version. |
| 69 | |
| 70 | Raises: |
| 71 | EEException: if passed something other than the above. |
| 72 | """ |
| 73 | self.initialize() |
| 74 | |
| 75 | if version is not None: |
| 76 | if ee_types.isString(args) and ee_types.isNumber(version): |
| 77 | # An ID and version. |
| 78 | super().__init__( |
| 79 | apifunction.ApiFunction.lookup('Image.load'), |
| 80 | {'id': args, 'version': version}) |
| 81 | else: |
| 82 | raise ee_exception.EEException( |
| 83 | 'If version is specified, the arg to Image() must be a string. ' |
| 84 | 'Received: %s' % (args,)) |
| 85 | return |
| 86 | |
| 87 | if ee_types.isNumber(args): |
| 88 | # A constant image. |
| 89 | super().__init__( |
| 90 | apifunction.ApiFunction.lookup('Image.constant'), {'value': args}) |
| 91 | elif ee_types.isString(args): |
| 92 | # An ID. |
| 93 | super().__init__( |
| 94 | apifunction.ApiFunction.lookup('Image.load'), {'id': args}) |
| 95 | elif isinstance(args, (list, tuple)): |
| 96 | # Make an image out of each element. |
| 97 | image = Image.combine_([Image(i) for i in args]) |
| 98 | super().__init__(image.func, image.args) |
| 99 | elif isinstance(args, computedobject.ComputedObject): |
| 100 | if args.name() == 'Array': |
| 101 | # A constant array image. |
| 102 | super().__init__( |
| 103 | apifunction.ApiFunction.lookup('Image.constant'), {'value': args}) |
| 104 | else: |
| 105 | # A custom object to reinterpret as an Image. |
| 106 | super().__init__(args.func, args.args, args.varName) |
| 107 | elif args is None: |
| 108 | super().__init__( |
| 109 | apifunction.ApiFunction.lookup('Image.mask'), |
| 110 | {'image': Image(0), 'mask': Image(0)}) |
| 111 | else: |
| 112 | raise ee_exception.EEException( |
nothing calls this directly
no test coverage detected