-
Notifications
You must be signed in to change notification settings - Fork 63
feat: Add BigFrames.bigquery.st_regionstats method #2200
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
Closed
Closed
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
03a153c
feat: Add BigFrames.bigquery.st_regionstats method
google-labs-jules[bot] ab46078
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 92c69aa
feat: Add BigFrames.bigquery.st_regionstats method
google-labs-jules[bot] 8b681c0
Merge branch 'main' into feat-st-regionstats
tswast 21243e4
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 459c5b2
Merge branch 'feat-st-regionstats' of https://github.com/googleapis/p…
gcf-owl-bot[bot] 350d241
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] b4db49c
Merge branch 'feat-st-regionstats' of https://github.com/googleapis/p…
gcf-owl-bot[bot] a680526
feat: Add BigFrames.bigquery.st_regionstats method
google-labs-jules[bot] 9775fb6
Merge branch 'main' into feat-st-regionstats
tswast bcd4047
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 01edd21
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] bf00055
Merge branch 'feat-st-regionstats' of https://github.com/googleapis/p…
gcf-owl-bot[bot] 3c172bb
feat: Add BigFrames.bigquery.st_regionstats method
google-labs-jules[bot] 13a67bd
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 6a4b1c9
Merge remote-tracking branch 'origin/main' into feat-st-regionstats
tswast 745211e
add arguments to st_regionstats and make it into a unary op
tswast 4252e90
move to geo_ops
tswast b44d520
fix the sqlgot compiler
tswast 18a6c76
fix sqlgot compiler
tswast 1b007b9
attempt at ibis compiler
tswast 2483e80
use JSON literals for options parameter
tswast c8eb266
fix sample
tswast 6d436ff
Merge remote-tracking branch 'origin/main' into feat-st-regionstats
tswast ad021b7
Merge branch 'main' into feat-st-regionstats
tswast 7a57ddd
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Copyright 2025 Google LLC | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
|
|
||
| def test_st_regionstats(): | ||
| project_id = "bigframes-dev" | ||
|
|
||
| # [START bigquery_dataframes_st_regionstats] | ||
| from typing import cast | ||
|
|
||
| import bigframes.bigquery as bq | ||
|
Collaborator
Author
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. Let's use bbq instead of bq. |
||
| import bigframes.pandas as bpd | ||
|
|
||
| # TODO: Set the project_id to your Google Cloud project ID. | ||
| # project_id = "your-project-id" | ||
| # | ||
| # TODO: Set the dataset_id to the ID of the dataset that contains the | ||
| # `climate` table. This is likely a linked dataset to Earth Engine. | ||
| # See: https://cloud.google.com/bigquery/docs/link-earth-engine | ||
| linked_dataset = "era5_land_daily_aggregated" | ||
|
|
||
| # Load the table of country boundaries. | ||
| bpd.options.bigquery.project = project_id | ||
| countries = bpd.read_gbq("bigquery-public-data.overture_maps.division_area") | ||
|
|
||
| # Filter to just the countries. | ||
| countries = countries[countries["subtype"] == "country"].copy() | ||
| countries["name"] = countries["names"].struct.field("primary") | ||
|
|
||
| # TODO: Add st_simplify when it is available in BigFrames. | ||
| # https://github.com/googleapis/python-bigquery-dataframes/issues/1497 | ||
| # countries["simplified_geometry"] = bq.st_simplify(countries["geometry"], 10000) | ||
|
Comment on lines
+41
to
+43
Collaborator
Author
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. I'd like to add |
||
| countries["simplified_geometry"] = countries["geometry"] | ||
|
|
||
| # Get the reference to the temperature data from a linked dataset. | ||
| # Note: This sample assumes you have a linked dataset to Earth Engine. | ||
| # See: https://cloud.google.com/bigquery/docs/link-earth-engine | ||
| image_href = bpd.read_gbq(f"{project_id}.{linked_dataset}.climate").where( | ||
| lambda df: df["start_datetime"] == "2025-01-01 00:00:00" | ||
| ) | ||
| raster_id = image_href["assets"].struct.field("image").struct.field("href").item | ||
| stats = bq.st_regionstats( | ||
| countries["simplified_geometry"], | ||
| raster_id=cast(str, raster_id), | ||
| band="temperature_2m", | ||
| ) | ||
|
|
||
| # Extract the mean and convert from Kelvin to Celsius. | ||
| countries["mean_temperature"] = stats.struct.field("mean") - 273.15 | ||
|
|
||
| # Sort by the mean temperature to find the warmest countries. | ||
| result = countries[["name", "mean_temperature"]].sort_values( | ||
| "mean_temperature", ascending=False | ||
| ) | ||
| print(result.head()) | ||
| # [END bigquery_dataframes_st_regionstats] | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.