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 4 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
35 changes: 20 additions & 15 deletions pyresample/_formatting_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,25 +244,30 @@
- 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 = "{resolution}/{resolution}".format(resolution="Na")
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about all caps:

Suggested change
resolution_str = "{resolution}/{resolution}".format(resolution="Na")
height, width = "Na", "Na"
resolution_str = "{resolution}/{resolution}".format(resolution="N/A")
height, width = "N/A", "N/A"

Or maybe "NA"? For the resolution string, why not just hardcode "NA/NA" instead of formatting? Otherwise, should resolution use a different separator than /? Maybe x?

Not sure why I didn't ask this before, but what is 40075000?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah you are right, I will just hard code it. I just took the code from the other cases but does not make sense here. Good idea with the "x" instead of "/" definitely makes more sense.

Well as mentioned somewhere before the resolution calculation in case of the attributes not having resolution set is just a rough estimate and therefore the circumference of the earth (40075000) is just hard coded.

area_units = "m"
else:
lon_attrs = area.lons.attrs
lat_attrs = area.lats.attrs
if isinstance(area.lons, np.ndarray) & isinstance(area.lats, np.ndarray):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if isinstance(area.lons, np.ndarray) & isinstance(area.lats, np.ndarray):
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}/{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 = "/".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")

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