Skip to content

Commit

Permalink
Refactor some more
Browse files Browse the repository at this point in the history
  • Loading branch information
frode-aarstad committed Jan 5, 2024
1 parent e70f8cd commit 6820413
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 51 deletions.
6 changes: 1 addition & 5 deletions src/ert/analysis/_es_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def _get_obs_and_measure_data(
for obs_key, obs_active_list in selected_observations:
observation = observations[obs_key]
group = observation.attrs["response"]

if obs_active_list:
index = observation.coords.to_index()[obs_active_list]
sub_selection = {
Expand All @@ -313,11 +314,6 @@ def _get_obs_and_measure_data(
observation = observation.sel(sub_selection)
ds = source_fs.load_responses(group, tuple(iens_active_index))

if "time" in observation.coords:
observation.coords["time"] = [
t[:-3] for t in observation.coords["time"].values.astype(str)
]

try:
filtered_ds = observation.merge(ds, join="left")
except KeyError as e:
Expand Down
13 changes: 3 additions & 10 deletions src/ert/data/_measured_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,6 @@ def _get_data(
except KeyError as e:
raise ResponseError(_msg) from e

if "time" in obs.coords:
obs.coords["time"] = [
t[:-3] for t in obs.coords["time"].values.astype(str)
]

ds = obs.merge(
response,
join="left",
Expand All @@ -136,11 +131,9 @@ def _get_data(
if "time" in ds.coords:
ds = ds.rename(time="key_index")
ds = ds.assign_coords({"name": [key]})

new_index = pd.DatetimeIndex(
response.indexes["time"].values.astype("datetime64[ns]")
)
data_index = [new_index.get_loc(date) for date in obs.time.values]
data_index = [
response.indexes["time"].get_loc(date) for date in obs.time.values
]
index_vals = ds.observations.coords.to_index(
["name", "key_index"]
).values
Expand Down
3 changes: 0 additions & 3 deletions src/ert/storage/local_ensemble.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,6 @@ def load_all_summary_data(
except (ValueError, KeyError):
return pd.DataFrame()

# Remove the time part of the 'time' index
df.index = df.index.set_levels([t[:-16] for t in df.index.levels[0]], level=0)

df = df.unstack(level="name")
df.columns = [col[1] for col in df.columns.values]
df.index = df.index.rename(
Expand Down
14 changes: 9 additions & 5 deletions src/ert/storage/local_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,15 @@ def response_configuration(self) -> Dict[str, ResponseConfig]:

@property
def observations(self) -> Dict[str, xr.Dataset]:
observations = list(self.mount_point.glob("observations/*"))
return {
observation.name: xr.open_dataset(observation, engine="scipy")
for observation in observations
}
dict = {}
for observation in list(self.mount_point.glob("observations/*")):
ds = xr.open_dataset(observation, engine="scipy")
if "time" in ds.coords:
ds.coords["time"] = [
t[:-3] for t in ds.coords["time"].values.astype(str)
]
dict[observation.name] = ds
return dict


class LocalExperimentAccessor(LocalExperimentReader):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Realization,Date,"BPR:1,3,8","BPR:5,5,5",FGIP,FGIPH,FGOR,FGORH,FGPR,FGPRH,FGPT,FGPTH,FOIP,FOIPH,FOPR,FOPRH,FOPT,FOPTH,FWCT,FWCTH,FWIP,FWIPH,FWPR,FWPRH,FWPT,FWPTH,WGOR:OP1,WGOR:OP2,WGORH:OP1,WGORH:OP2,WGPR:OP1,WGPR:OP2,WGPRH:OP1,WGPRH:OP2,WOPR:OP1,WOPR:OP2,WOPRH:OP1,WOPRH:OP2,WWCT:OP1,WWCT:OP2,WWCTH:OP1,WWCTH:OP2,WWPR:OP1,WWPR:OP2,WWPRH:OP1,WWPRH:OP2
0,2010-01-10,0.9996,0.9996,2499.4473,2499.9956,1.0,1.0,0.0557,0.0012,0.5528,0.0044,1999.4462,1999.994,0.056,0.0017,0.5538,0.0059,0.1776,0.0002,2249.4492,2249.9998,0.0551,0.0,0.5507,0.0001,1.0,1.0,1.0,1.0,0.0557,0.0,0.0006,0.0006,0.056,0.0,0.0008,0.0008,0.3552,0.0,0.0001,0.0002,0.0551,0.0,0.0,0.0
1,2010-01-10,0.9996,0.9996,2499.8467,2499.9956,1.0,1.0,0.0157,0.0012,0.1533,0.0044,1999.8458,1999.994,0.016,0.0017,0.1542,0.0059,0.0657,0.0002,2249.8489,2249.9998,0.0151,0.0,0.1512,0.0001,1.0,1.0,1.0,1.0,0.0,0.0157,0.0006,0.0006,0.0,0.016,0.0008,0.0008,0.0,0.1314,0.0001,0.0002,0.0,0.0151,0.0,0.0
2,2010-01-10,0.9996,0.9996,2500.0,2499.9956,1.0,1.0,0.0,0.0012,0.0,0.0044,2000.0,1999.994,0.0,0.0017,0.0,0.0059,0.0,0.0002,2250.0,2249.9998,0.0,0.0,0.0,0.0001,1.0,1.0,1.0,1.0,0.0,0.0,0.0006,0.0006,0.0,0.0,0.0008,0.0008,0.0,0.0,0.0001,0.0002,0.0,0.0,0.0,0.0
3,2010-01-10,0.9996,0.9996,2497.1733,2499.9956,0.9994,1.0,0.2835,0.0012,2.8267,0.0044,1997.1715,1999.994,0.284,0.0017,2.8285,0.0059,0.4825,0.0002,2247.1775,2249.9998,0.2823,0.0,2.8224,0.0001,1.0,0.9987,1.0,1.0,0.0879,0.1956,0.0006,0.0006,0.0882,0.1958,0.0008,0.0008,0.4661,0.4989,0.0001,0.0002,0.0873,0.195,0.0,0.0
0,2010-01-10T00:00:00.000000,0.9996,0.9996,2499.4473,2499.9956,1.0,1.0,0.0557,0.0012,0.5528,0.0044,1999.4462,1999.994,0.056,0.0017,0.5538,0.0059,0.1776,0.0002,2249.4492,2249.9998,0.0551,0.0,0.5507,0.0001,1.0,1.0,1.0,1.0,0.0557,0.0,0.0006,0.0006,0.056,0.0,0.0008,0.0008,0.3552,0.0,0.0001,0.0002,0.0551,0.0,0.0,0.0
1,2010-01-10T00:00:00.000000,0.9996,0.9996,2499.8467,2499.9956,1.0,1.0,0.0157,0.0012,0.1533,0.0044,1999.8458,1999.994,0.016,0.0017,0.1542,0.0059,0.0657,0.0002,2249.8489,2249.9998,0.0151,0.0,0.1512,0.0001,1.0,1.0,1.0,1.0,0.0,0.0157,0.0006,0.0006,0.0,0.016,0.0008,0.0008,0.0,0.1314,0.0001,0.0002,0.0,0.0151,0.0,0.0
2,2010-01-10T00:00:00.000000,0.9996,0.9996,2500.0,2499.9956,1.0,1.0,0.0,0.0012,0.0,0.0044,2000.0,1999.994,0.0,0.0017,0.0,0.0059,0.0,0.0002,2250.0,2249.9998,0.0,0.0,0.0,0.0001,1.0,1.0,1.0,1.0,0.0,0.0,0.0006,0.0006,0.0,0.0,0.0008,0.0008,0.0,0.0,0.0001,0.0002,0.0,0.0,0.0,0.0
3,2010-01-10T00:00:00.000000,0.9996,0.9996,2497.1733,2499.9956,0.9994,1.0,0.2835,0.0012,2.8267,0.0044,1997.1715,1999.994,0.284,0.0017,2.8285,0.0059,0.4825,0.0002,2247.1775,2249.9998,0.2823,0.0,2.8224,0.0001,1.0,0.9987,1.0,1.0,0.0879,0.1956,0.0006,0.0006,0.0882,0.1958,0.0008,0.0008,0.4661,0.4989,0.0001,0.0002,0.0873,0.195,0.0,0.0
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Realization,Date,WWCT:OP1,WWCT:OP2
0,2010-01-10,0.3551691770553589,0.0
1,2010-01-10,0.0,0.13138170540332794
2,2010-01-10,0.0,0.0
3,2010-01-10,0.46612998843193054,0.49889394640922546
0,2010-01-10T00:00:00.000000,0.3551691770553589,0.0
1,2010-01-10T00:00:00.000000,0.0,0.13138170540332794
2,2010-01-10T00:00:00.000000,0.0,0.0
3,2010-01-10T00:00:00.000000,0.46612998843193054,0.49889394640922546
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Realization,Date,WWCT:OP1,WWCT:OP2
4,2010-01-10,0.19479288160800934,0.0
4,2010-01-20,0.19516849517822266,0.0
4,2010-01-30,0.19581304490566254,0.0
4,2010-02-09,0.19672726094722748,0.0
4,2010-01-10T00:00:00.000000,0.19479288160800934,0.0
4,2010-01-20T00:00:00.000000,0.19516849517822266,0.0
4,2010-01-30T00:00:00.000000,0.19581304490566254,0.0
4,2010-02-09T00:00:00.000000,0.19672726094722748,0.0
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
,FOPR,FOPR,FOPR,FOPR,FOPR
Realization,0,1,2,3,4
Date,,,,,
2010-01-10,0.05596115440130234,0.015982799232006073,0.0,0.28399229049682617,0.02509653940796852
2010-01-20,0.05905991047620773,0.018984779715538025,0.0,0.2900899052619934,0.02827547676861286
2010-01-30,0.06433762609958649,0.024110613390803337,0.0,0.30051347613334656,0.03370004892349243
2010-02-09,0.07174286246299744,0.03132806345820427,0.0009306804859079421,0.31520578265190125,0.041331253945827484
2010-02-19,0.08120841532945633,0.040592338889837265,0.009585856460034847,0.3340320289134979,0.051114898175001144
2010-01-10T00:00:00.000000,0.05596115440130234,0.015982799232006073,0.0,0.28399229049682617,0.02509653940796852
2010-01-20T00:00:00.000000,0.05905991047620773,0.018984779715538025,0.0,0.2900899052619934,0.02827547676861286
2010-01-30T00:00:00.000000,0.06433762609958649,0.024110613390803337,0.0,0.30051347613334656,0.03370004892349243
2010-02-09T00:00:00.000000,0.07174286246299744,0.03132806345820427,0.0009306804859079421,0.31520578265190125,0.041331253945827484
2010-02-19T00:00:00.000000,0.08120841532945633,0.040592338889837265,0.009585856460034847,0.3340320289134979,0.051114898175001144
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
,FOPR,FOPR,FOPR,FOPR,FOPR
Realization,0,1,2,3,4
Date,,,,,
2015-05-14,0.05978194996714592,0.02822822891175747,0.0,0.2988854944705963,0.031847789883613586
2015-05-24,0.06022725999355316,0.02732691913843155,0.0,0.29930371046066284,0.03208010271191597
2015-06-03,0.060678575187921524,0.026679888367652893,0.0,0.29959961771965027,0.032258305698633194
2015-06-13,0.06101493909955025,0.026284758001565933,0.0,0.29972729086875916,0.032372280955314636
2015-06-23,0.06115317344665527,0.026137633249163628,0.0,0.2997667193412781,0.03241586685180664
2015-05-14T00:00:00.000000,0.05978194996714592,0.02822822891175747,0.0,0.2988854944705963,0.031847789883613586
2015-05-24T00:00:00.000000,0.06022725999355316,0.02732691913843155,0.0,0.29930371046066284,0.03208010271191597
2015-06-03T00:00:00.000000,0.060678575187921524,0.026679888367652893,0.0,0.29959961771965027,0.032258305698633194
2015-06-13T00:00:00.000000,0.06101493909955025,0.026284758001565933,0.0,0.29972729086875916,0.032372280955314636
2015-06-23T00:00:00.000000,0.06115317344665527,0.026137633249163628,0.0,0.2997667193412781,0.03241586685180664
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Realization,Date,FGIP,FGIR,FGIRH,FGIT,FGITH,FGLIR,FGLR,FGOR,FGORH,FGPP,FGPR,FGPRF,FGPRH,FGPRS,FGPT
0,2020-07-02,5737580544.0,0.0,0.0,0.0,0.0,0.0,68.79610443115234,146.78567504882812,146.78567504882812,2777220.0,853880.5625,165187.046875,853880.5625,688693.5625,1168540544.0
0,2020-08-01,5711617536.0,0.0,0.0,0.0,0.0,0.0,68.93971252441406,151.33901977539062,151.33901977539062,2757425.0,866019.9375,192419.359375,866019.9375,673600.5625,1194503808.0
0,2020-09-01,5684979200.0,0.0,0.0,0.0,0.0,0.0,68.25880432128906,154.72657775878906,154.72657775878906,2712226.0,856132.875,208552.921875,856132.875,647579.9375,1221141888.0
0,2020-10-01,5659591680.0,0.0,0.0,0.0,0.0,0.0,66.95653533935547,156.4752960205078,156.4752960205078,2654457.75,837970.5,214351.671875,837970.5,623618.875,1246529280.0
0,2020-11-01,5634260480.0,0.0,0.0,0.0,0.0,0.0,64.8019790649414,155.9357147216797,155.9357147216797,2580463.0,809597.9375,207660.796875,809597.9375,601937.125,1271860352.0
0,2020-12-01,5610946048.0,0.0,0.0,0.0,0.0,0.0,62.26524353027344,153.91632080078125,153.91632080078125,2505382.5,777148.4375,193741.40625,777148.4375,583407.0625,1295174912.0
0,2020-07-02T00:00:00.000000,5737580544.0,0.0,0.0,0.0,0.0,0.0,68.79610443115234,146.78567504882812,146.78567504882812,2777220.0,853880.5625,165187.046875,853880.5625,688693.5625,1168540544.0
0,2020-08-01T00:00:00.000000,5711617536.0,0.0,0.0,0.0,0.0,0.0,68.93971252441406,151.33901977539062,151.33901977539062,2757425.0,866019.9375,192419.359375,866019.9375,673600.5625,1194503808.0
0,2020-09-01T00:00:00.000000,5684979200.0,0.0,0.0,0.0,0.0,0.0,68.25880432128906,154.72657775878906,154.72657775878906,2712226.0,856132.875,208552.921875,856132.875,647579.9375,1221141888.0
0,2020-10-01T00:00:00.000000,5659591680.0,0.0,0.0,0.0,0.0,0.0,66.95653533935547,156.4752960205078,156.4752960205078,2654457.75,837970.5,214351.671875,837970.5,623618.875,1246529280.0
0,2020-11-01T00:00:00.000000,5634260480.0,0.0,0.0,0.0,0.0,0.0,64.8019790649414,155.9357147216797,155.9357147216797,2580463.0,809597.9375,207660.796875,809597.9375,601937.125,1271860352.0
0,2020-12-01T00:00:00.000000,5610946048.0,0.0,0.0,0.0,0.0,0.0,62.26524353027344,153.91632080078125,153.91632080078125,2505382.5,777148.4375,193741.40625,777148.4375,583407.0625,1295174912.0

0 comments on commit 6820413

Please sign in to comment.