Skip to content

Commit 0a74bf7

Browse files
Merge pull request #660 from cal-adapt/feature/new-core-clip
Feature/new core clip
2 parents 1fdd35e + 93102a9 commit 0a74bf7

26 files changed

Lines changed: 5069 additions & 44 deletions

climakitae/core/data_export.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,8 @@ def _export_to_csv(data: xr.DataArray | xr.Dataset, save_name: str):
756756
if csv_nrows > excel_row_limit or csv_ncolumns > excel_column_limit:
757757
warnings.warn(
758758
f"Dataset exceeds Excel limits of {excel_row_limit} rows "
759-
f"and {excel_column_limit} columns."
759+
f"and {excel_column_limit} columns.",
760+
stacklevel=999,
760761
)
761762

762763
def _metadata_to_file(ds: xr.Dataset, output_name: str):

climakitae/core/data_load.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ def load(xr_da: xr.DataArray, progress_bar: bool = False) -> xr.DataArray:
9696
print("Available memory: {0}".format(readable_bytes(avail_mem)))
9797
print("Total memory of input data: {0}".format(readable_bytes(xr_data_nbytes)))
9898
warnings.warn(
99-
"Your input dataset may be too large to read into memory!", UserWarning
99+
"Your input dataset may be too large to read into memory!",
100+
UserWarning,
101+
stacklevel=999,
100102
)
101103
# take user input on continuing
102104
proceed = input(

climakitae/explore/threshold_tools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,8 @@ def get_block_maxima(
231231
warnings.warn(
232232
f"\n\nWARNING: Found NaN values in block maxima but unable to determine appropriate dropping strategy for dimensions {bms.dims}"
233233
"\nNo NaN values will be dropped from the block maxima DataArray."
234-
"\nPlease inspect the data and handle NaN values appropriately before proceeding."
234+
"\nPlease inspect the data and handle NaN values appropriately before proceeding.",
235+
stacklevel=999,
235236
)
236237

237238
return bms

climakitae/new_core/data_access/boundaries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ def load(self) -> None:
633633
"The load() method is deprecated. Data now loads automatically when accessed. "
634634
"Use preload_all() for explicit preloading.",
635635
DeprecationWarning,
636-
stacklevel=2,
636+
stacklevel=999,
637637
)
638638
self.preload_all()
639639

climakitae/new_core/data_access/data_access.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,33 +228,38 @@ def set_catalog_key(self, key: str) -> "DataCatalog":
228228
if key not in self:
229229
warnings.warn(
230230
f"\n\nCatalog key '{key}' not found."
231-
f"\nAttempting to find intended catalog key.\n\n"
231+
f"\nAttempting to find intended catalog key.\n\n",
232+
stacklevel=999,
232233
)
233234
print(f"Available catalog keys: {list(self.keys())}")
234235
closest = _get_closest_options(key, list(self.keys()))
235236
if not closest:
236237
warnings.warn(
237238
f"No validator registered for '{key}'. "
238-
f"Available options: {list(self.keys())}"
239+
f"Available options: {list(self.keys())}",
240+
stacklevel=999,
239241
)
240242
return None
241243

242244
match len(closest):
243245
case 0:
244246
warnings.warn(
245247
f"No validator registered for '{key}'. "
246-
"Available options: {list(self._validator_registry.keys())}"
248+
"Available options: {list(self._validator_registry.keys())}",
249+
stacklevel=999,
247250
)
248251
return None # type: ignore[return-value]
249252
case 1:
250253
warnings.warn(
251-
f"\n\nUsing closest match '{closest[0]}' for validator '{key}'."
254+
f"\n\nUsing closest match '{closest[0]}' for validator '{key}'.",
255+
stacklevel=999,
252256
)
253257
key = closest[0]
254258
case _:
255259
warnings.warn(
256260
f"Multiple closest matches found for '{key}': {closest}. "
257-
"Please specify a more precise key."
261+
"Please specify a more precise key.",
262+
stacklevel=999,
258263
)
259264
key = None # type: ignore[return-value]
260265
self.catalog_key = key

climakitae/new_core/dataset.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ def execute(self, parameters: Dict[str, Any] = UNSET) -> xr.Dataset:
211211
if current_result is None:
212212
warnings.warn(
213213
f"\n\nProcessing step {step.name} returned None. "
214-
"\nEnsure that the step is implemented correctly."
214+
"\nEnsure that the step is implemented correctly.",
215+
UserWarning,
216+
stacklevel=999,
215217
)
216218

217219
return current_result
@@ -247,7 +249,8 @@ def with_param_validator(
247249
"""
248250
if not parameter_validator:
249251
warnings.warn(
250-
"No parameter validator provided. This may lead to unvalidated queries."
252+
"No parameter validator provided. This may lead to unvalidated queries.",
253+
stacklevel=999,
251254
)
252255
if not isinstance(parameter_validator, ParameterValidator):
253256
raise TypeError(

climakitae/new_core/dataset_factory.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,8 @@ def _get_list_of_processing_steps(
294294
for key, value in query[PROC_KEY].items():
295295
if key not in self._processing_step_registry:
296296
warnings.warn(
297-
f"Processing step '{key}' not found in registry. Skipping."
297+
f"Processing step '{key}' not found in registry. Skipping.",
298+
stacklevel=999,
298299
)
299300
continue
300301

@@ -408,26 +409,30 @@ def create_validator(self, val_reg_key: str) -> ParameterValidator:
408409
if not closest:
409410
warnings.warn(
410411
f"No validator registered for '{val_reg_key}'. "
411-
"Available options: {list(self._validator_registry.keys())}"
412+
"Available options: {list(self._validator_registry.keys())}",
413+
stacklevel=999,
412414
)
413415
return None
414416

415417
match len(closest):
416418
case 0:
417419
warnings.warn(
418420
f"No validator registered for '{val_reg_key}'. "
419-
"Available options: {list(self._validator_registry.keys())}"
421+
"Available options: {list(self._validator_registry.keys())}",
422+
stacklevel=999,
420423
)
421424
return None # type: ignore[return-value]
422425
case 1:
423426
warnings.warn(
424-
f"\n\nUsing closest match '{closest[0]}' for validator '{val_reg_key}'."
427+
f"\n\nUsing closest match '{closest[0]}' for validator '{val_reg_key}'.",
428+
stacklevel=999,
425429
)
426430
return self._validator_registry[closest[0]](self._catalog)
427431
case _:
428432
warnings.warn(
429433
f"Multiple closest matches found for '{val_reg_key}': {closest}. "
430-
"Please specify a more precise key."
434+
"Please specify a more precise key.",
435+
stacklevel=999,
431436
)
432437
return None # type: ignore[return-value]
433438

@@ -462,12 +467,13 @@ def _get_catalog_key_from_query(self, query: Dict[str, Any]) -> str:
462467
] # filter rows with matching keys
463468
match len(subset):
464469
case 0:
465-
warnings.warn("No matching catalogs found initially.")
470+
warnings.warn("No matching catalogs found initially.", stacklevel=999)
466471
case 1:
467472
return subset.iloc[0]["catalog"]
468473
case _:
469474
warnings.warn(
470-
"Multiple matching datasets found. Please refine your query."
475+
"Multiple matching datasets found. Please refine your query.",
476+
stacklevel=999,
471477
)
472478

473479
return None

climakitae/new_core/param_validation/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Import param validation classes ensuring they are registered."""
22

33
from .concat_param_validator import validate_concat_param
4+
from .clip_param_validator import validate_clip_param
45
from .data_param_validator import DataValidator
56
from .filter_unadjusted_models_param_validator import (
67
validate_filter_unadjusted_models_param,

climakitae/new_core/param_validation/abc_param_validation.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,7 @@ def _is_valid_query(self, query: Dict[str, Any]) -> Dict[str, Any] | None:
304304
warnings.warn(
305305
f"Query did not match any datasets: {e}\n\nSearching for close matches...",
306306
UserWarning,
307+
stacklevel=999,
307308
)
308309

309310
if len(subset) != 0:
@@ -324,7 +325,8 @@ def _is_valid_query(self, query: Dict[str, Any]) -> Dict[str, Any] | None:
324325
# check if the key is in the catalog
325326
if key not in df.columns:
326327
warnings.warn(
327-
f"Key {key} not found in catalog. Did you specify the correct catalog?"
328+
f"Key {key} not found in catalog. Did you specify the correct catalog?",
329+
stacklevel=999,
328330
)
329331
continue # skip to the next key
330332

@@ -335,7 +337,8 @@ def _is_valid_query(self, query: Dict[str, Any]) -> Dict[str, Any] | None:
335337
):
336338
warnings.warn(
337339
f"Experiment ID {value} is not valid. "
338-
"Please check the available options using `show_experiment_id_options()`."
340+
"Please check the available options using `show_experiment_id_options()`.",
341+
stacklevel=999,
339342
)
340343
else:
341344
self.all_catalog_keys[key] = value
@@ -360,14 +363,16 @@ def _is_valid_query(self, query: Dict[str, Any]) -> Dict[str, Any] | None:
360363
if closest_options is not None:
361364
# probably a typo in the value
362365
warnings.warn(
363-
f"\n\nDid you mean one of these options for {key}: {closest_options}?"
366+
f"\n\nDid you mean one of these options for {key}: {closest_options}?",
367+
stacklevel=999,
364368
)
365369
else:
366370
# no close matches found
367371
warnings.warn(
368372
f"\n\nNo close matches found for {key} = {value}. "
369373
"\nBased on your query, the available options for this key are: "
370-
f"{remaining_key_values}."
374+
f"{remaining_key_values}.",
375+
stacklevel=999,
371376
)
372377
else:
373378
# the value is in the catalog, but no datasets were found
@@ -382,7 +387,8 @@ def _is_valid_query(self, query: Dict[str, Any]) -> Dict[str, Any] | None:
382387
f"\nThis is constrained by the earlier key {last_key} = {self.all_catalog_keys[last_key]}. "
383388
f"\nPlease check your query and try again. "
384389
f"\n\nTo explore available options, "
385-
f"\n please use the `show_*_options()` methods."
390+
f"\n please use the `show_*_options()` methods.",
391+
stacklevel=999,
386392
)
387393
break
388394
# else:
@@ -439,13 +445,15 @@ def _has_valid_processes(self, query: Dict[str, Any]) -> bool:
439445
if not valid_value_for_processor:
440446
warnings.warn(
441447
f"\n\nProcessor {key} with value {value} is not valid. "
442-
"\nPlease check the processor documentation for valid options."
448+
"\nPlease check the processor documentation for valid options.",
449+
stacklevel=999,
443450
)
444451
return False
445452
else:
446453
warnings.warn(
447454
f"\n\nProcessor {key} is not registered. "
448-
"\nThis processor input has not been validated."
455+
"\nThis processor input has not been validated.",
456+
stacklevel=999,
449457
)
450458

451459
return True

0 commit comments

Comments
 (0)