Skip to content

Commit

Permalink
Rename reference_date -> start_date
Browse files Browse the repository at this point in the history
fixes #122
  • Loading branch information
Huite committed Oct 27, 2023
1 parent 2e3e807 commit 8bee491
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
18 changes: 9 additions & 9 deletions gistim/compute.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _(
ymin: float,
ymax: float,
spacing: float,
reference_date: str,
start_date: str,
time: List[float],
) -> Union[None, xr.DataArray]:
if time is None:
Expand All @@ -134,7 +134,7 @@ def _(

# Other coordinates
layer = [i for i in range(nlayer)]
time = pd.to_datetime(reference_date) + pd.to_timedelta(time, "D")
time = pd.to_datetime(start_date) + pd.to_timedelta(time, "D")
return xr.DataArray(
data=head,
name="head",
Expand Down Expand Up @@ -169,7 +169,7 @@ def _(

@head_observations.register
def _(
model: ttim.ModelMaq, observations: Dict, reference_date: pd.Timestamp
model: ttim.ModelMaq, observations: Dict, start_date: pd.Timestamp
) -> Dict[str, pd.DataFrame]:
d = {
"geometry": [],
Expand All @@ -179,13 +179,13 @@ def _(
"observation_id": [],
}
heads = []
reference_date = pd.to_datetime(reference_date, utc=False)
start_date = pd.to_datetime(start_date, utc=False)
for observation_id, kwargs in enumerate(observations):
x = kwargs["x"]
y = kwargs["y"]
t = kwargs["t"]
n_time = len(t)
datetime = reference_date + pd.to_timedelta([0] + t, "day")
datetime = start_date + pd.to_timedelta([0] + t, "day")
d["geometry"].extend([{"type": "Point", "coordinates": [x, y]}] * n_time)
d["datetime_start"].extend(datetime[:-1])
d["datetime_end"].extend(datetime[1:] - pd.to_timedelta(1, "minute"))
Expand Down Expand Up @@ -250,12 +250,12 @@ def write_output(
crs = CoordinateReferenceSystem(**data["crs"])
output_options = data["output_options"]
observations = data["observations"]
reference_date = pd.to_datetime(data.get("reference_date"))
start_date = pd.to_datetime(data.get("start_date"))

# Compute gridded head data and write to netCDF.
head = None
if output_options["raster"] or output_options["mesh"]:
head = headgrid(model, **data["headgrid"], reference_date=reference_date)
head = headgrid(model, **data["headgrid"], start_date=start_date)

if head is not None:
if output_options["raster"]:
Expand All @@ -266,15 +266,15 @@ def write_output(
# Compute observations and discharge, and write to geopackage.
if output_options["discharge"]:
tables = extract_discharges(
elements, model.aq.nlayers, reference_date=reference_date
elements, model.aq.nlayers, start_date=start_date
)
else:
tables = {}

if output_options["head_observations"] and observations:
for layername, content in observations.items():
tables[layername] = head_observations(
model, content["data"], reference_date=reference_date
model, content["data"], start_date=start_date
)

write_geopackage(tables, crs, path)
Expand Down
4 changes: 2 additions & 2 deletions plugin/qgistim/core/elements/aquifer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TemporalSettingsSchema(SingleRowSchema):
ttim_schemata = {
"time_min": Required(StrictlyPositive()),
"laplace_inversion_M": Required(StrictlyPositive()),
"reference_date": Required(),
"start_date": Required(),
}


Expand All @@ -64,7 +64,7 @@ class Aquifer(TransientElement):
ttim_attributes = (
QgsField("time_min", QVariant.Double),
QgsField("laplace_inversion_M", QVariant.Int),
QgsField("reference_date", QVariant.DateTime),
QgsField("start_date", QVariant.DateTime),
)
ttim_defaults = {
"time_min": QgsDefaultValue("0.01"),
Expand Down
6 changes: 3 additions & 3 deletions plugin/qgistim/core/formatting.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def ttim_script(timml_data: Dict[str, Any], ttim_data: Dict[str, Any]) -> str:
data = ttim_data.copy() # avoid side-effects
aquifer_data = data.pop("timml Aquifer:Aquifer")
domain_data = data.pop("timml Domain:Domain")
data.pop("reference_date")
data.pop("start_date")

strings.append(
f"\nttim_model = ttim.ModelMaq(\n{format_kwargs(aquifer_data)}\n{PREFIX}timmlmodel=timml_model,\n)"
Expand Down Expand Up @@ -302,12 +302,12 @@ def ttim_json(

data = ttim_data.copy()
domain_data = data.pop("timml Domain:Domain")
reference_date = data.pop("reference_date")
start_date = data.pop("start_date")
ttim_json, observations = json_elements_and_observations(data, mapping=TTIM_MAPPING)

json_data["ttim"] = ttim_json
json_data["headgrid"] = headgrid_entry(domain_data, cellsize)
json_data["reference_date"] = reference_date
json_data["start_date"] = start_date
json_data["observations"] = observations
return json_data

Expand Down
2 changes: 1 addition & 1 deletion plugin/qgistim/widgets/dataset_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ def extract_data(self, transient: bool) -> Tuple[Dict[str, Any], Dict[str, Any]]
aquifer_data = aquifer.aquifer_data(raw_data, transient=transient)
data[name] = aquifer_data
if transient:
data["reference_date"] = str(raw_data["reference_date"].toPyDateTime())
data["start_date"] = str(raw_data["start_date"].toPyDateTime())

times = set()
other = {"aquifer layers": raw_data["layer"], "global_aquifer": raw_data}
Expand Down

0 comments on commit 8bee491

Please sign in to comment.