Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Generic Metadata
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Operate
Terraform modules
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
umr-tetis
STAC
extensions
Generic Metadata
Commits
4e877729
Commit
4e877729
authored
5 months ago
by
Cresson Remi
Browse files
Options
Downloads
Plain Diff
Merge branch 'support_collections' into 'main'
enh: support collections See merge request
!5
parents
0e98a1fd
7ca5b000
No related branches found
No related tags found
1 merge request
!5
enh: support collections
Pipeline
#243016
passed with warnings
5 months ago
Changes
3
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
stac_extension_genmeta/__init__.py
+1
-1
1 addition, 1 deletion
stac_extension_genmeta/__init__.py
stac_extension_genmeta/core.py
+12
-5
12 additions, 5 deletions
stac_extension_genmeta/core.py
stac_extension_genmeta/testing.py
+20
-3
20 additions, 3 deletions
stac_extension_genmeta/testing.py
with
33 additions
and
9 deletions
stac_extension_genmeta/__init__.py
+
1
−
1
View file @
4e877729
from
.core
import
create_extension_cls
__version__
=
"
0.0.21
"
\ No newline at end of file
__version__
=
"
0.0.22
"
\ No newline at end of file
This diff is collapsed.
Click to expand it.
stac_extension_genmeta/core.py
+
12
−
5
View file @
4e877729
...
...
@@ -44,7 +44,7 @@ def create_extension_cls(
def
__init__
(
self
,
obj
:
T
):
if
isinstance
(
obj
,
pystac
.
Item
):
self
.
properties
=
obj
.
properties
elif
isinstance
(
obj
,
pystac
.
Asset
):
elif
isinstance
(
obj
,
(
pystac
.
Asset
,
pystac
.
Collection
)
):
self
.
properties
=
obj
.
extra_fields
else
:
raise
pystac
.
ExtensionTypeError
(
...
...
@@ -109,12 +109,12 @@ def create_extension_cls(
)
->
model_cls
.
__name__
:
if
isinstance
(
obj
,
pystac
.
Item
):
cls
.
ensure_has_extension
(
obj
,
add_if_missing
)
return
cast
(
CustomExtension
[
T
],
ItemCustomExtension
(
obj
))
return
cast
(
CustomExtension
[
T
],
ItemCustomExtension
(
obj
))
elif
isinstance
(
obj
,
pystac
.
Asset
):
cls
.
ensure_owner_has_extension
(
obj
,
add_if_missing
)
return
cast
(
CustomExtension
[
T
],
AssetCustomExtension
(
obj
))
return
cast
(
CustomExtension
[
T
],
AssetCustomExtension
(
obj
))
elif
isinstance
(
obj
,
pystac
.
Collection
):
return
cast
(
CustomExtension
[
T
],
CollectionCustomExtension
(
obj
))
raise
pystac
.
ExtensionTypeError
(
f
"
{
model_cls
.
__name__
}
does not apply to type
"
f
"
{
type
(
obj
).
__name__
}
"
...
...
@@ -134,5 +134,12 @@ def create_extension_cls(
if
asset
.
owner
and
isinstance
(
asset
.
owner
,
pystac
.
Item
):
self
.
additional_read_properties
=
[
asset
.
owner
.
properties
]
class
CollectionCustomExtension
(
CustomExtension
[
pystac
.
Collection
]):
properties
:
dict
[
str
,
Any
]
additional_read_properties
:
Iterable
[
dict
[
str
,
Any
]]
|
None
=
None
def
__init__
(
self
,
collection
:
pystac
.
Collection
):
self
.
properties
=
collection
.
extra_fields
CustomExtension
.
__name__
=
f
"
CustomExtensionFrom
{
model_cls
.
__name__
}
"
return
CustomExtension
This diff is collapsed.
Click to expand it.
stac_extension_genmeta/testing.py
+
20
−
3
View file @
4e877729
...
...
@@ -50,7 +50,7 @@ def create_dummy_item(date=None):
)
col
.
add_item
(
item
)
return
item
return
item
,
col
def
basic_test
(
...
...
@@ -58,6 +58,7 @@ def basic_test(
ext_cls
,
item_test
:
bool
=
True
,
asset_test
:
bool
=
True
,
collection_test
:
bool
=
True
,
validate
:
bool
=
True
):
print
(
...
...
@@ -92,7 +93,7 @@ def basic_test(
"""
Test extension against item
"""
item
=
create_dummy_item
()
item
,
_
=
create_dummy_item
()
apply
(
item
)
print_item
(
item
)
if
validate
:
...
...
@@ -104,7 +105,7 @@ def basic_test(
"""
Test extension against asset
"""
item
=
create_dummy_item
()
item
,
_
=
create_dummy_item
()
apply
(
item
.
assets
[
"
ndvi
"
])
print_item
(
item
)
if
validate
:
...
...
@@ -112,12 +113,28 @@ def basic_test(
# Check that we can retrieve the extension metadata from the asset
comp
(
item
.
assets
[
"
ndvi
"
])
def
test_collection
():
"""
Test extension against collection
"""
item
,
col
=
create_dummy_item
()
print_item
(
col
)
apply
(
col
)
print_item
(
col
)
if
validate
:
col
.
validate
()
# <--- This will try to read the actual schema URI
# Check that we can retrieve the extension metadata from the asset
comp
(
col
)
if
item_test
:
print
(
"
Test item
"
)
test_item
()
if
asset_test
:
print
(
"
Test asset
"
)
test_asset
()
if
collection_test
:
print
(
"
Test collection
"
)
test_collection
()
def
is_schema_url_synced
(
cls
):
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment