-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove delr and delc from ds #346
Merged
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -92,6 +92,30 @@ def get_xy_mid_structured(extent, delr, delc, descending_y=True): | |
raise TypeError("unexpected type for delr and/or delc") | ||
|
||
|
||
def get_delr(ds): | ||
"""Get the distance along rows (delr) fromythe x-coordinate of a model dataset""" | ||
assert ds.gridtype == "structured" | ||
x = (ds.x - ds.extent[0]).values | ||
delr = _get_delr_from_x(x) | ||
return delr | ||
|
||
|
||
def get_delc(ds): | ||
"""Get the distance along columns (delr) from the x-coordinate of a model dataset""" | ||
assert ds.gridtype == "structured" | ||
y = (ds.extent[3] - ds.y).values | ||
delc = _get_delr_from_x(y) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kind of counterintuitive to call _get_delr_from_x to get_delc_from_y. Maybe rename the private method to _get_delta_along_axis or something similar? |
||
return delc | ||
|
||
|
||
def _get_delr_from_x(x): | ||
"""Internal method to determine delr or delc from x or y relative to xmin or ymax""" | ||
delr = [x[0] * 2] | ||
for xi in x[1:]: | ||
delr.append((xi - np.sum(delr)) * 2) | ||
return np.array(delr) | ||
|
||
|
||
def ds_to_structured_grid( | ||
ds_in, | ||
extent, | ||
|
@@ -163,17 +187,11 @@ def ds_to_structured_grid( | |
x=x, y=y, method=method, kwargs={"fill_value": "extrapolate"} | ||
) | ||
ds_out.attrs = attrs | ||
# ds_out = ds_out.expand_dims({"ncol": len(x), "nrow": len(y)}) | ||
ds_out["delr"] = ("ncol",), delr | ||
ds_out["delc"] = ("nrow",), delc | ||
return ds_out | ||
|
||
ds_out = xr.Dataset(coords={"y": y, "x": x, "layer": ds_in.layer.data}, attrs=attrs) | ||
for var in ds_in.data_vars: | ||
ds_out[var] = structured_da_to_ds(ds_in[var], ds_out, method=method) | ||
# ds_out = ds_out.expand_dims({"ncol": len(x), "nrow": len(y)}) | ||
ds_out["delr"] = ("x",), delr | ||
ds_out["delc"] = ("y",), delc | ||
return ds_out | ||
|
||
|
||
|
@@ -658,9 +676,13 @@ def get_affine(ds, sx=None, sy=None): | |
"""Get the affine-transformation, from pixel to real-world coordinates.""" | ||
attrs = _get_attrs(ds) | ||
if sx is None: | ||
sx = attrs["delr"] | ||
sx = get_delr(ds) | ||
assert len(np.unique(sx)) == 1, "Affine-transformation needs a constant delr" | ||
sx = sx[0] | ||
if sy is None: | ||
sy = -attrs["delc"] | ||
sy = get_delc(ds) | ||
assert len(np.unique(sy)) == 1, "Affine-transformation needs a constant delc" | ||
sy = sy[0] | ||
|
||
if "angrot" in attrs: | ||
xorigin = attrs["xorigin"] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you make a full docstring with in-and output types?