guts-base 1.0.6__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of guts-base might be problematic. Click here for more details.

guts_base/__init__.py CHANGED
@@ -4,7 +4,7 @@ from . import data
4
4
  from . import prob
5
5
  from . import plot
6
6
 
7
- __version__ = "1.0.6"
7
+ __version__ = "1.0.8"
8
8
 
9
9
  from .sim import (
10
10
  GutsBase,
@@ -251,6 +251,8 @@ def import_data_to_database(path, database, preprocessing: Optional[Callable] =
251
251
 
252
252
  experiment.to_database(database=database)
253
253
 
254
+ print("Import to database successful.")
255
+
254
256
 
255
257
  def create_database_and_import_data_main(datasets_path, database_path, preprocessing=None, preprocessing_out=None):
256
258
  print("\n")
@@ -225,7 +225,7 @@ def make_openguts_observation_table(
225
225
  experiment_start = get_unique_value(df["time_start_experiment"])
226
226
  experiment_end = get_unique_value(df["time_end_experiment"])
227
227
 
228
- time = pd.date_range(experiment_start, experiment_end, freq=observation_schedule)
228
+ times_nominal = pd.date_range(experiment_start, experiment_end, freq=observation_schedule)
229
229
  timecol_name = f"time [{observation_schedule.lower()}]"
230
230
 
231
231
 
@@ -234,13 +234,17 @@ def make_openguts_observation_table(
234
234
  # calculate survival time
235
235
  df[timecol_name] = df["time_death"] - df["time_start_experiment"]
236
236
 
237
- time_remainder = df[timecol_name] % pd.Timedelta(1, observation_schedule)
238
- if (time_remainder > pd.Timedelta(0)).any():
239
- raise ValueError(
240
- "Observations should be entered at the same time as the experiment start "+
241
- "df['time_death] - df['time_experiment_start'] should be a multiple of "+
242
- f"the time resolution of the observation schedule. Here: 1{observation_schedule}"
243
- )
237
+ # this seems to have been necessary, because reindexing removed times smaller than
238
+ # the observation_schedule interval. This is now resolved by concatenating true
239
+ # times and nominal times
240
+ # TODO: remove this commented block when there appear no more errors
241
+ # time_remainder = df[timecol_name] % pd.Timedelta(1, observation_schedule)
242
+ # if (time_remainder > pd.Timedelta(0)).any():
243
+ # raise ValueError(
244
+ # "Observations should be entered at the same time as the experiment start "+
245
+ # "df['time_death] - df['time_experiment_start'] should be a multiple of "+
246
+ # f"the time resolution of the observation schedule. Here: 1{observation_schedule}"
247
+ # )
244
248
 
245
249
  if observation == "censored":
246
250
  # sum IDs that were marked as censored at time t
@@ -258,8 +262,12 @@ def make_openguts_observation_table(
258
262
  # df to wide frame
259
263
  df_wide = long_to_wide(df_long.reset_index(), id_columns, timecol_name, observation)
260
264
 
265
+ # get a time vector that contains all nominal observation times and also actually
266
+ # occurred days
267
+ observation_times = np.unique(np.concatenate([df_wide.index, times_nominal-experiment_start]))
268
+
261
269
  # reindex wide dataframe on time
262
- df_wide = df_wide.reindex(index=time-experiment_start, method=None)
270
+ df_wide = df_wide.reindex(index=observation_times, method=None)
263
271
  df_wide.index = df_wide.index.set_names(timecol_name)
264
272
  df_wide = df_wide.fillna(0)
265
273
 
@@ -299,8 +307,10 @@ class TimeOfDeathIO:
299
307
  self.data = self.from_file()
300
308
 
301
309
  def main(file: str, sheet: str, out:str, intervention_columns: List[str],
310
+ extra_observation_columns: List[str] = [],
302
311
  observation_schedule="d", rect_interpolate=False):
303
312
  intervention_columns = clean_column_names(list(intervention_columns))
313
+ extra_observation_columns = clean_column_names(list(extra_observation_columns))
304
314
  processed_file = f"{out}/openguts_{os.path.basename(file)}"
305
315
 
306
316
  print("\n")
@@ -454,6 +464,17 @@ def main(file: str, sheet: str, out:str, intervention_columns: List[str],
454
464
  observation_schedule=observation_schedule,
455
465
  )
456
466
 
467
+ _extra_observations = []
468
+ for eob in extra_observation_columns:
469
+ ob_wide = make_openguts_observation_table(
470
+ data,
471
+ observation=eob,
472
+ observation_schedule=observation_schedule
473
+ )
474
+ _extra_observations.append(ob_wide)
475
+ excel_writer(ob_wide, file=processed_file, sheet=eob)
476
+
477
+
457
478
  deaths = lethality - censored
458
479
 
459
480
  # excel export
@@ -537,6 +558,7 @@ def main(file: str, sheet: str, out:str, intervention_columns: List[str],
537
558
  else:
538
559
  warnings.warn("No metadata found in sheets 'meta' or 'Info'.")
539
560
 
561
+ return processed_file
540
562
 
541
563
  @click.command()
542
564
  @click.option("--file", "-f", help="Path to the xlsx file")
@@ -544,12 +566,14 @@ def main(file: str, sheet: str, out:str, intervention_columns: List[str],
544
566
  @click.option("--out", "-o", help="Output directory", default="processed_data")
545
567
  @click.option("--observation_schedule", help="Schedule of the observations: d - daily, h - hourly", default="d")
546
568
  @click.option("--intervention_columns", "-c", multiple=True, type=str, help="Names of the columns that carry the exposure information")
547
- def time_of_death_to_openguts(file, sheet, out, observation_schedule, intervention_columns):
548
- main(
569
+ @click.option("--extra_observation_columns", "-e", multiple=True, type=str, default=[], help="Names of the columns that carry additional observations beside time-of-death and censoring")
570
+ def time_of_death_to_openguts(file, sheet, out, observation_schedule, intervention_columns, extra_observation_columns):
571
+ _ = main(
549
572
  file=file,
550
573
  sheet=sheet,
551
574
  out=out,
552
575
  intervention_columns=intervention_columns,
576
+ extra_observation_columns=extra_observation_columns,
553
577
  observation_schedule=observation_schedule
554
578
  )
555
579
 
guts_base/sim/base.py CHANGED
@@ -49,6 +49,10 @@ class GutsBase(SimulationBase):
49
49
  results_interpolation: Tuple[float,float,int] = (np.nan, np.nan, 100)
50
50
  _skip_data_processing: bool = False
51
51
  ecx_mode: Literal["mean", "draws"] = "mean"
52
+ exposure_scenarios = {
53
+ "acute_1day": {"start": 0.0, "end": 1.0},
54
+ "chronic": {"start": 0.0, "end": None},
55
+ }
52
56
 
53
57
  def initialize(self, input: Optional[Dict] = None):
54
58
  """Initiaization goes through a couple of steps:
@@ -99,6 +103,8 @@ class GutsBase(SimulationBase):
99
103
  self.unit_time: Literal["day", "hour", "minute", "second"] = "day"
100
104
  if hasattr(self.config.simulation, "unit_time"):
101
105
  self.unit_time = self.config.simulation.unit_time # type: ignore
106
+ else:
107
+ self.config.simulation.unit_time = self.unit_time
102
108
 
103
109
  if hasattr(self.config.simulation, "skip_data_processing"):
104
110
  self._skip_data_processing = not (
@@ -254,8 +260,9 @@ class GutsBase(SimulationBase):
254
260
  observations=self.observations
255
261
  )
256
262
 
257
- if "exposure" in self.observations:
258
- self.config.data_structure.exposure.observed=False
263
+ if "exposure" not in self.observations:
264
+ self.observations["exposure"] = self.observations[self.config.simulation.substance]
265
+ self.config.data_structure.exposure.observed=False
259
266
 
260
267
  def _convert_exposure_units(self):
261
268
  """
@@ -485,21 +492,26 @@ class GutsBase(SimulationBase):
485
492
  for coord in exposure_coordinates:
486
493
  concentrations = np.where(coord == exposure_coordinates, 1.0, 0.0)
487
494
 
488
- exposure_dict = {
489
- coord: ExposureDataDict(start=0, end=1, concentration=conc)
490
- for coord, conc in zip(exposure_coordinates, concentrations)
491
- }
492
-
493
- scenario = design_exposure_scenario(
494
- exposures=exposure_dict,
495
- t_max=time_max,
496
- dt=1/24,
497
- exposure_dimension=exposure_dimension
498
- )
495
+ for _name, _expo_scenario in self.exposure_scenarios.items():
496
+ exposure_dict = {
497
+ coord: ExposureDataDict(
498
+ start=_expo_scenario["start"],
499
+ end=_expo_scenario["end"],
500
+ concentration=conc
501
+ )
502
+ for coord, conc in zip(exposure_coordinates, concentrations)
503
+ }
504
+
505
+ scenario = design_exposure_scenario(
506
+ exposures=exposure_dict,
507
+ t_max=time_max,
508
+ dt=1/24,
509
+ exposure_dimension=exposure_dimension
510
+ )
499
511
 
500
- scenarios.update({
501
- f"1day_exposure_{coord}": scenario
502
- })
512
+ scenarios.update({
513
+ f"{_name}_{coord}": scenario
514
+ })
503
515
 
504
516
  return scenarios
505
517
 
guts_base/sim/report.py CHANGED
@@ -23,12 +23,13 @@ class GutsReport(Report):
23
23
  table_parameter_stat_focus = "mean"
24
24
  units = xr.Dataset({
25
25
  "metric": ["unit"],
26
- "k_d": ("metric", ["1/t"])
26
+ "k_d": ("metric", ["1/T"])
27
27
  })
28
28
 
29
29
 
30
30
  def additional_reports(self, sim: "SimulationBase"):
31
31
  super().additional_reports(sim=sim)
32
+ self.model_input(sim)
32
33
  self.model_fits(sim)
33
34
  self.LCx_estimates(sim)
34
35
 
@@ -246,6 +247,7 @@ def flatten_coords(dataset: xr.Dataset, keep_dims):
246
247
  producing a array with harmonized dimensions
247
248
  """
248
249
  ds = dataset.copy()
250
+ ds = ds.reset_coords(drop=True)
249
251
  for var_name, data_var in ds.data_vars.items():
250
252
  extra_coords = [k for k in list(data_var.coords.keys()) if k not in keep_dims]
251
253
  if len(extra_coords) == 0:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: guts_base
3
- Version: 1.0.6
3
+ Version: 1.0.8
4
4
  Summary: Basic GUTS model implementation in pymob
5
5
  Author-email: Florian Schunck <fluncki@protonmail.com>
6
6
  License: GNU GENERAL PUBLIC LICENSE
@@ -1,25 +1,25 @@
1
- guts_base/__init__.py,sha256=mqsDPsRl9TvFmIRICGE6wDPG-d1TEAzO0Sj1Rfurl5A,227
1
+ guts_base/__init__.py,sha256=YhfEv2scUmsDc-3-9-MK3-xNQJ_tIRQndJaQHDDDl8U,227
2
2
  guts_base/mod.py,sha256=AzOCg1A8FP5EtVfp-66HT7G7h_wnHkenieaxTc9qCyk,5796
3
3
  guts_base/plot.py,sha256=Sr_d0sXHNajPLPelcGl72yCOEEqB7NGNWhViKYAiTng,6692
4
4
  guts_base/prob.py,sha256=ITwo5dAGMHr5xTldilHMbKU6AFsWo4_ZwbfaXh97Gew,5443
5
5
  guts_base/data/__init__.py,sha256=JBgft1DTledwvB5hRZnyGiKWv-RXo1OIpb5kJXloOmo,826
6
6
  guts_base/data/expydb.py,sha256=Kcc6CeZMl3oEelk5UBN9VEfwgNF3CzTh13ooVkufAjE,8218
7
7
  guts_base/data/generator.py,sha256=rGOZU3B0Ho8V6KtfjcAmely8lnlqNFV8cRyGboayTRc,2910
8
- guts_base/data/openguts.py,sha256=WvhYl_AOdvNgzrcVS2f_PYbXNH_wSAz2uIBSR6BMSh0,11078
8
+ guts_base/data/openguts.py,sha256=7C2wknBQBVxOYVgBL9UzuC9PEoqI2xaVp2pOyZwaIqY,11123
9
9
  guts_base/data/preprocessing.py,sha256=qggYkx2x62ingU1BNhJFyL1eQdFQsDJR2lefVfVWW2U,1732
10
10
  guts_base/data/survival.py,sha256=U-Ehloo8vnD81VeIglXLEUHX9lt7SjtEs2YEB0D9FHE,5096
11
- guts_base/data/time_of_death.py,sha256=hwngUwfRP3u8WmD3dHyXrphuu5d8ZJTKyBovGRwAHNQ,21014
11
+ guts_base/data/time_of_death.py,sha256=dHG5jhK--WkemTxJtHVgfdo-FWlFHslBQ0PcYape9fI,22296
12
12
  guts_base/data/utils.py,sha256=u3gGDJK15MfRUP4iIxsS-I1oqxD2qH_ugsT7o_Eac18,236
13
13
  guts_base/sim/__init__.py,sha256=sbHmT1p2saN0MJ-iYnCDOHjkHtTcKgm7X-dHX5o0tYA,435
14
- guts_base/sim/base.py,sha256=xd4VroOS7KM8Ap7hYGaD85hB3n_8IT8GuEvecYu3TnE,37549
14
+ guts_base/sim/base.py,sha256=eMhdkdSit0aa0JbpfwVD_8E03-ooiFDI4UA9bAmC3j8,38110
15
15
  guts_base/sim/constructors.py,sha256=Kz9FHIH3EHsSIKd9sQgHa3eveniFifFlk1Hf-QR69Pg,875
16
16
  guts_base/sim/ecx.py,sha256=PeX8UVF1HMMNHaIU-jL6dml4JGezhWwiGSqPFJbOFM4,20808
17
17
  guts_base/sim/mempy.py,sha256=IHd87UrmdXpC7y7q0IjYQJH075frjbp2a-dMVBeqZ0U,10164
18
- guts_base/sim/report.py,sha256=o19MBhKcwty2auPjYWoz4QY91jjJFkA80UTzUuZo1oE,12720
18
+ guts_base/sim/report.py,sha256=NmrnU8Xr1LKKg5ObdjSXaQ8a-Dv8k8xC8oq_EKDbgMo,12786
19
19
  guts_base/sim/utils.py,sha256=Qj_FPH6kywVxOwgCerS7w5CyuYR9HKmvBWFpmxwDFgk,256
20
- guts_base-1.0.6.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
- guts_base-1.0.6.dist-info/METADATA,sha256=scr05XWOqcMi7XsHVrlyflI-4WuDq1B-w6OFz9mu6Ho,45426
22
- guts_base-1.0.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
- guts_base-1.0.6.dist-info/entry_points.txt,sha256=icsHzG2jQ90ZS7XvLsI5Qj0-qGuPv2T0RBVN5daGCPU,183
24
- guts_base-1.0.6.dist-info/top_level.txt,sha256=PxhBgUd4r39W_VI4FyJjARwKbV5_glgCVnd6v_zAGdE,10
25
- guts_base-1.0.6.dist-info/RECORD,,
20
+ guts_base-1.0.8.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
21
+ guts_base-1.0.8.dist-info/METADATA,sha256=RWswqGo_hTMejbTs7WlK40-4v_Kr-E0zFpLUOzKlYc0,45426
22
+ guts_base-1.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
23
+ guts_base-1.0.8.dist-info/entry_points.txt,sha256=icsHzG2jQ90ZS7XvLsI5Qj0-qGuPv2T0RBVN5daGCPU,183
24
+ guts_base-1.0.8.dist-info/top_level.txt,sha256=PxhBgUd4r39W_VI4FyJjARwKbV5_glgCVnd6v_zAGdE,10
25
+ guts_base-1.0.8.dist-info/RECORD,,