Skip to content

Commit f9ef00b

Browse files
committed
Merge branch 'reduce_etas' of https://github.com/ClimateImpactLab/dscim into reduce_etas
2 parents 5db2861 + 698058a commit f9ef00b

File tree

3 files changed

+22
-13
lines changed

3 files changed

+22
-13
lines changed

requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# This is used to build the CI test environment and so Github can track dependencies.
2-
xarray==2024.3.0
2+
xarray==2025.1.2
33
pandas==2.2.3
44
numpy==1.26.4
55
matplotlib==3.10.1
66
dask[array, distributed]==2025.2.0
77
requests==2.32.3
88
statsmodels==0.14.4
99
pytest==8.3.5
10-
pytest-cov==6.0.0
10+
pytest-cov==6.2.1
1111
zarr==2.18.4
1212
ruff==0.8.6
1313
netcdf4==1.7.2
1414
h5netcdf==1.6.1
1515
impactlab-tools==0.6.0
1616
p_tqdm==1.4.2
1717
pyarrow==19.0.1
18+
numcodecs==0.15.1

src/dscim/preprocessing/input_damages.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from functools import partial
1515
from p_tqdm import p_map, p_umap
1616
from dscim.menu.simple_storage import EconVars
17-
from zarr.errors import GroupNotFoundError
1817

1918
logger = 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:

tests/test_main_recipe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,11 @@ def test_weitzman_min(menu_instance):
258258
diff = censored_values_slower[0:index] - censored_values[0:index]
259259
assert all(x > 0 for x in diff)
260260
as_share = menu_instance.weitzman_min(
261-
[20, 50, 100], [5, 30, 60], as_share
261+
np.array([20, 50, 100]), np.array([5, 30, 60]), as_share
262262
) # the first value only should be censored
263263
assert as_share[0] != 5 and [as_share[1], as_share[2]] == [30, 60]
264264
all_cons = menu_instance.weitzman_min(
265-
[20, 50, 100], [5, 30, 60], all_cons
265+
np.array([20, 50, 100]), np.array([5, 30, 60]), all_cons
266266
) # all values should be changed
267267
assert all([x != 0 for x in all_cons - [5, 30, 60]])
268268

0 commit comments

Comments
 (0)