3232from uuid import uuid4
3333
3434from harmony_service_lib .adapter import BaseHarmonyAdapter
35- from harmony_service_lib .util import stage
35+ from harmony_service_lib .util import generate_output_filename , stage
3636from pystac import Catalog , Item
3737from pystac .item import Asset
3838
@@ -98,7 +98,6 @@ def process_file(self, catalog: Catalog) -> list[Catalog]:
9898 netcdf_url = _get_item_url (items [0 ])
9999 if netcdf_url is None :
100100 raise ValueError ("No URL found for item" )
101- filename = Path (netcdf_url ).stem
102101
103102 with TemporaryDirectory () as temp_dir :
104103 # Download file
@@ -107,24 +106,25 @@ def process_file(self, catalog: Catalog) -> list[Catalog]:
107106 )
108107
109108 # Zip filename is the input filename without the file extension
110- zip_file_name = input_file . split ( "/" )[ - 1 ]. split ( "." )[ 0 ]
109+ zip_file_name = Path ( input_file ). stem
111110
112111 # Create the subdirectory
113112 self .logger .info ("Running Casper." )
114113
114+ # Use Harmony generated filename
115+ zip_file = generate_output_filename (zip_file_name , ext = "zip" , is_reformatted = True )
116+ zip_file = Path (temp_dir ) / zip_file
117+
115118 # --- Run Casper ---
116- zip_file = f"{ temp_dir } /{ zip_file_name } .zip"
117119 convert_to_csv (
118120 input_file ,
119121 zip_file ,
120122 logger = self .logger ,
121123 )
122124
123- self .logger .info (
124- f"Casper conversion completed. Zip file created { zip_file_name } .zip"
125- )
126- staged_url = self ._stage (zip_file , f"{ zip_file_name } .zip" , "application/zip" )
125+ self .logger .info (f"Casper conversion completed. Zip file created { zip_file } " )
127126
127+ staged_url = self ._stage (zip_file , zip_file .name , "application/zip" )
128128 # -- Output to STAC catalog --
129129 result .clear_items ()
130130 properties = {
@@ -138,11 +138,10 @@ def process_file(self, catalog: Catalog) -> list[Catalog]:
138138 None ,
139139 properties ,
140140 )
141- filename = f"{ zip_file_name } .zip"
142141
143142 asset = Asset (
144143 staged_url ,
145- title = filename ,
144+ title = zip_file . name ,
146145 media_type = "application/zip" ,
147146 roles = ["data" ],
148147 )
0 commit comments