1414from functools import partial
1515from p_tqdm import p_map , p_umap
1616from dscim .menu .simple_storage import EconVars
17- from zarr .errors import GroupNotFoundError
1817
1918logger = logging .getLogger (__name__ )
2019
@@ -275,13 +274,21 @@ def concatenate_labor_damages(
275274 return concat_ds
276275
277276
278- def calculate_labor_batch_damages (batch , ec , input_path , save_path ):
277+ def calculate_labor_batch_damages (
278+ batch ,
279+ ec ,
280+ input_path ,
281+ save_path ,
282+ variable = "rebased" ,
283+ file_prefix = "uninteracted_main_model" ,
284+ ):
279285 print (f"Processing batch={ batch } damages in { os .getpid ()} " )
280286 concatenate_labor_damages (
281287 input_path = input_path ,
282288 save_path = save_path ,
283289 ec_cls = ec ,
284- variable = "rebased" ,
290+ variable = variable ,
291+ file_prefix = file_prefix ,
285292 val_type = "wage-levels" ,
286293 format_file = "zarr" ,
287294 query = f"exists==True&batch=='batch{ batch } '" ,
@@ -293,6 +300,8 @@ def calculate_labor_damages(
293300 path_econ ,
294301 input_path ,
295302 save_path ,
303+ variable = "rebased" ,
304+ file_prefix = "uninteracted_main_model" ,
296305):
297306 ec = EconVars (path_econ )
298307 # process in 3 rounds to limit memory usage
@@ -302,6 +311,8 @@ def calculate_labor_damages(
302311 input_path = input_path ,
303312 save_path = save_path ,
304313 ec = ec ,
314+ variable = variable ,
315+ file_prefix = file_prefix ,
305316 )
306317 print ("Processing batches:" )
307318 print (list (range (i * 5 , i * 5 + 5 )))
@@ -716,6 +727,7 @@ def prep_mortality_damages(
716727
717728 # longest-string gcm has to be processed first so the coordinate is the right str length
718729 gcms = sorted (gcms , key = len , reverse = True )
730+ max_gcm_len = len (gcms [0 ])
719731
720732 if mortality_version == 0 :
721733 scaling_deaths = "epa_scaled"
@@ -826,7 +838,7 @@ def prep(
826838 if damages [v ].dtype == object :
827839 damages [v ] = damages [v ].astype ("unicode" )
828840
829- damages . coords ["gcm" ] = damages . coords ["gcm" ].astype ("object" )
841+ damages ["gcm" ] = damages ["gcm" ].astype ("U" + str ( max_gcm_len ) )
830842
831843 if i == 0 :
832844 damages .to_zarr (
@@ -852,11 +864,7 @@ def coastal_inputs(
852864 adapt_type ,
853865 vsl_valuation = None ,
854866):
855- try :
856- d = xr .open_zarr (f"{ path } /coastal_damages_{ version } .zarr" )
857- except GroupNotFoundError :
858- print (f"Zarr not found: { path } /coastal_damages_{ version } .zarr" )
859- exit ()
867+ d = xr .open_zarr (f"{ path } /coastal_damages_{ version } .zarr" )
860868
861869 if "vsl_valuation" in d .coords :
862870 if vsl_valuation is None :
0 commit comments