') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ', 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); })(); get_extent() refactoring by LucaMarconato · Pull Request #318 · scverse/spatialdata · GitHub
Skip to content

get_extent() refactoring - #318

Merged
LucaMarconato merged 51 commits into
mainfrom
feature/get_extent
Oct 10, 2023
Merged

get_extent() refactoring#318
LucaMarconato merged 51 commits into
mainfrom
feature/get_extent

Conversation

@LucaMarconato

@LucaMarconatoLucaMarconato commented Jul 11, 2023

Copy link
Copy Markdown
Member

Starting a PR to rework and move the get_extent() function from @timtreis from spatialdata-plot to spatialdata. This PR is needed for some tiles generation code that @EliHei2 is working on.

@codecov

codecovBot commented Jul 11, 2023

Copy link
Copy Markdown

Codecov Report

Merging #318 (13da8cd) into main (14bf585) will increase coverage by 0.67%.
The diff coverage is 97.20%.

❗ Current head 13da8cd differs from pull request most recent head d6bd822. Consider uploading reports for the commit d6bd822 to get more accurate results

Additional details and impacted files
@@ Coverage Diff @@## main #318 +/- ##
==========================================
+ Coverage 90.61% 91.28% +0.67% 
==========================================
Files 36 36 Lines 4700 4845 +145 ==========================================
+ Hits 4259 4423 +164 + Misses 441 422 -19 
FilesCoverage Δ
src/spatialdata/__init__.py100.00% <100.00%> (ø)
src/spatialdata/_core/operations/rasterize.py83.41% <100.00%> (ø)
src/spatialdata/_core/query/spatial_query.py92.01% <100.00%> (+0.08%)⬆️
src/spatialdata/_types.py66.66% <100.00%> (+4.16%)⬆️
src/spatialdata/datasets.py100.00% <100.00%> (ø)
src/spatialdata/models/_utils.py89.89% <100.00%> (-0.11%)⬇️
src/spatialdata/_core/query/_utils.py92.00% <92.85%> (+1.09%)⬆️
src/spatialdata/_core/data_extent.py97.33% <97.27%> (+97.33%)⬆️

... and 1 file with indirect coverage changes

@LucaMarconato
LucaMarconato marked this pull request as ready for review July 11, 2023 15:22
@LucaMarconato

LucaMarconato commented Jul 11, 2023

Copy link
Copy Markdown
MemberAuthor

Actually it's completed and ready for review. Talked with @timtreis and he may add some extra functionalities/convenience parameters (used in spatialdata-plot) in a follow up PR.

@LucaMarconatoLucaMarconato linked an issue Aug 15, 2023 that may be closed by this pull request
Comment threadsrc/spatialdata/_core/data_extent.py Outdated
@LucaMarconato

LucaMarconato commented Aug 26, 2023

Copy link
Copy Markdown
MemberAuthor

@Sonja-Stockhaus thanks for the bugfix and the refactoring! Please let me know when you finish with the additions and the PR is ready for review. You can tag me here/write me in Zulip.

Comment threadsrc/spatialdata/_core/data_extent.py Outdated
@Sonja-StockhausSonja-Stockhaus linked an issue Aug 29, 2023 that may be closed by this pull request
Comment threadsrc/spatialdata/_core/data_extent.py Outdated
# remove potentially empty geometries
e_temp = e[e["geometry"].apply(lambda geom: not geom.is_empty)]

# separate points from (multi-)polygons

@LucaMarconatoLucaMarconatoOct 9, 2023

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

This is not needed because we assume that the GeoDataFrame doesn't mix Point with Polygon/MultiPolygon types. I'll removed it to simplify the code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Very similar to a bugfix @Sonja-Stockhaus implemented in scverse/spatialdata-plot#133. Don't know if I'd delete this

Copy link
Copy Markdown
MemberAuthor

Choose a reason for hiding this comment

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

In the PR I kept the removal of empty points, but I have removed the split of shapes and points. It can be easily restored inside the function _get_extent_of_shapes() if you want. We don't expect to need it now, but it would be still ok to have, just to make the code more future proof.

Comment threadsrc/spatialdata/models/_utils.py Outdated
@LucaMarconato

Copy link
Copy Markdown
MemberAuthor

I applied the code review from Giovanni and added a test for the xy swap bug: #335.

@LucaMarconato

Copy link
Copy Markdown
MemberAuthor

As you can see, the Python 3.9 tests fail in a0e26ba (#318), but they succeed in 184dd82 (#318). Not sure why it happens, but as a workaround @timtreis suggested to replace the | with Union, and to silence Ruff.

@LucaMarconato
LucaMarconato merged commit cf925c5 into mainOct 10, 2023
@LucaMarconato
LucaMarconato deleted the feature/get_extent branch October 10, 2023 15:49
@giovpgiovp mentioned this pull request Nov 27, 2023
6 tasks
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

get_extent switches x and y Refactor get_extent() from spatialdata-plot and push upstream

4 participants

@LucaMarconato@timtreis@giovp@Sonja-Stockhaus