10
10
import pystac
11
11
import yaml
12
12
from colorlog import ColoredFormatter
13
+ from pystac .validation import validate as pystac_validate
13
14
14
15
from STACpopulator .models import Geometry , STACItemProperties
15
16
@@ -181,21 +182,18 @@ def STAC_item_from_metadata(
181
182
cfmeta = attrs ["groups" ]["CFMetadata" ]["attributes" ]
182
183
183
184
# Create pydantic STAC item
185
+ props = item_props_data_model (** attrs ["attributes" ])
186
+ geom = item_geometry_model (** ncattrs_to_geometry (attrs ))
184
187
item = pystac .Item (
185
188
id = iid ,
186
- geometry = item_geometry_model ( ** ncattrs_to_geometry ( attrs )),
189
+ geometry = json . loads ( geom . model_dump_json ( by_alias = True )),
187
190
bbox = ncattrs_to_bbox (attrs ),
188
- properties = item_props_data_model (
189
- ** attrs ["attributes" ],
190
- ),
191
+ properties = json .loads (props .model_dump_json (by_alias = True )),
191
192
datetime = None ,
192
193
start_datetime = dt_parser .parse (cfmeta ["time_coverage_start" ]),
193
194
end_datetime = dt_parser .parse (cfmeta ["time_coverage_end" ]),
194
195
)
195
196
196
- # Convert pydantic STAC item to a PySTAC Item
197
- item = pystac .Item (** json .loads (item .model_dump_json (by_alias = True )))
198
-
199
197
root = attrs ["access_urls" ]
200
198
201
199
for name , url in root .items ():
@@ -205,7 +203,7 @@ def STAC_item_from_metadata(
205
203
item .add_asset (name , asset )
206
204
207
205
item .add_link (magpie_resource_link (root ["HTTPServer" ]))
208
-
206
+ item . validate ()
209
207
return item
210
208
211
209
0 commit comments