Skip to content
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

Fix SwathDefinition html representation error when lons/lats 1D #610

Merged
merged 6 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 21 additions & 16 deletions pyresample/_formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,33 +244,38 @@
- Improve resolution estimation from lat/lon arrays. Maybe use CoordinateDefinition.geocentric_resolution?

"""
if isinstance(area.lons, np.ndarray) & isinstance(area.lats, np.ndarray):
# Calculate and estimated resolution from lats/lons in meter
area_name = "Arbitrary Swath"
resolution_y = np.mean(area.lats[0:-1, :] - area.lats[1::, :])
resolution_x = np.mean(area.lons[:, 1::] - area.lons[:, 0:-1])
resolution = np.mean(np.array([resolution_x, resolution_y]))
resolution = np.round(40075000 * resolution / 360, 1)
resolution_str = f"{resolution}/{resolution}"
if np.ndim(area.lons) == 1:
area_name = "1D Swath"
resolution_str = "NA/NA"
djhoese marked this conversation as resolved.
Show resolved Hide resolved
height, width = "NA", "NA"

Check warning on line 250 in pyresample/_formatting_html.py

View check run for this annotation

Codecov / codecov/patch

pyresample/_formatting_html.py#L248-L250

Added lines #L248 - L250 were not covered by tests
area_units = "m"
else:
lon_attrs = area.lons.attrs
lat_attrs = area.lats.attrs
if isinstance(area.lons, np.ndarray) and isinstance(area.lats, np.ndarray):
# Calculate and estimated resolution from lats/lons in meter
area_name = "Arbitrary Swath"
resolution_y = np.mean(area.lats[0:-1, :] - area.lats[1::, :])
resolution_x = np.mean(area.lons[:, 1::] - area.lons[:, 0:-1])
resolution = np.mean(np.array([resolution_x, resolution_y]))
resolution = np.round(40075000 * resolution / 360, 1)
resolution_str = f"{resolution}x{resolution}"
else:
lon_attrs = area.lons.attrs
lat_attrs = area.lats.attrs

# use resolution from lat/lons dataarray attributes -> are these always set? -> Maybe try/except?
area_name = f"{lon_attrs.get('sensor')} Swath"
resolution_str = "x".join([str(round(x.get("resolution"), 1)) for x in [lat_attrs, lon_attrs]])

# use resolution from lat/lons dataarray attributes -> are these always set? -> Maybe try/except?
area_name = f"{lon_attrs.get('sensor')} swath"
resolution_str = "/".join([str(round(x.get("resolution"), 1)) for x in [lat_attrs, lon_attrs]])
area_units = "m"

height, width = area.lons.shape
height, width = area.lons.shape

attrs_icon = _icon("icon-file-text2")

area_attrs = ("<dl>"
# f"<dt>Area name</dt><dd>{area_name}</dd>"
f"<dt>Description</dt><dd>{area_name}</dd>"
f"<dt>Width/Height</dt><dd>{width}/{height} Pixel</dd>"
f"<dt>Resolution x/y (SSP)</dt><dd>{resolution_str} {area_units}</dd>"
f"<dt>Resolution XxY (SSP)</dt><dd>{resolution_str} {area_units}</dd>"
"</dl>"
)

Expand Down
15 changes: 1 addition & 14 deletions pyresample/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body.vscode-dark {
.pyresample-wrap {
display: block !important;
min-width: 700px;
max-width: 900px;
max-width: 1050px;
}

.pyresample-text-repr-fallback {
Expand Down Expand Up @@ -90,19 +90,6 @@ body.vscode-dark {
margin-right: 0.5em;
}

/* und noch der Doppelpunkt */
.pyresample-area-section-details dt:after {
content: ": ";
}

/* ein Clearfix für Folge-dd-Elemente */
.pyresample-area-section-details dd:after {
clear: left;
content: " ";
display: block;
}
/* end attribute list formatting */

.pyresample-area-sections {
display: grid;
grid-template-columns: auto;
Expand Down
Loading