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

AWS and GUI additions #3

Merged
merged 19 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,17 @@ jobs:
with:
path: ${{ github.workspace }}/source

- name: Make Executable
- name: Install pyinstaller and requirements.txt
shell: pwsh
run: |
cd ${{ github.workspace }}/source
pip install pyinstaller
pip install -r requirements.txt

- name: Make Executables
shell: pwsh
run: |
cd ${{ github.workspace }}/source
pyinstaller grib2pf.spec

- name: Copy Files to Output
Expand All @@ -131,9 +136,11 @@ jobs:
cd ${{ github.workspace }}/source
Copy-Item README.md dist/grib2pf/
Copy-Item ACKNOWLEDGMENTS.md dist/grib2pf/
Copy-Item products.txt dist/grib2pf/_internal
Copy-Item examples dist/grib2pf/examples -Recurse
Copy-Item palettes dist/grib2pf/_internal/palettes -Recurse
Copy-Item presets dist/grib2pf/_internal/presets -Recurse
Copy-Item icon dist/grib2pf/_internal/icon -Recurse


- name: Upload grib2pf Executable
Expand Down
3 changes: 2 additions & 1 deletion ACKNOWLEDGMENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ of this project.
| [zlib](https://zlib.net/) | [Zlib](https://spdx.org/licenses/Zlib.html) |
| [libexpat](https://libexpat.github.io/) | [MIT License](https://spdx.org/licenses/MIT.html) |
| [liblzma](https://tukaani.org/xz/) | [0BSD](https://spdx.org/licenses/0BSD.html) |

| [PySide6](https://doc.qt.io/qtforpython-6/) | [LGPL-3.0-only](https://spdx.org/licenses/LGPL-3.0-only.html) |
| [boto3](https://github.com/boto/boto3) | [Apache-2.0 License](https://spdx.org/licenses/Apache-2.0.html) |
Source
------

Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ Download the executable form the latest release and extract it. You will want
to extract it to a permanent location. This program does not install itself, so
where you place it is where it will be installed.

### Running the GUI
`grib2pf-ui.exe` or `grib2pf-ui` can be run by double clicking it. This will
launch a settings UI. You can select a preset to start with by clicking `Load
Preset`. From there you can modify the settings to your liking. Clicking `Run`
will save your settings and run `grib2pf`. Once your settings are saved, you
can simply run `grib2pf` directly, without the GUI.

### Run It
For a basic run, you can simply double click on `grib2pf.exe` or `grib2pf`.
This will put a basic settings file (`settings.json`) in the `_internal` folder.
Expand Down Expand Up @@ -98,6 +105,12 @@ with `--help`. The arguments align with the settings described below.
## Settings
Below are all the settings supported by this program.

`aws`: Boolean describing if AWS data should be used

`product`: AWS product to use

`pullTime`: How often to pull AWS for new data

`url`: The URL to pull from. Should probably come from
"https://mrms.ncep.noaa.gov/data"
"https://mrms.ncep.noaa.gov/data/2D/MergedBaseReflectivity/MRMS\_MergedBaseReflectivity.latest.grib2.gz"
Expand Down
64 changes: 64 additions & 0 deletions aws.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/usr/bin/env python3

import boto3
from botocore import UNSIGNED
from botocore.config import Config
import time

class AWSHandler:
def __init__(self, product, bucketName = "noaa-mrms-pds", config = None):
if config is None:
config = Config(signature_version = UNSIGNED)

self.product = product
self.bucketName = bucketName
self.client = boto3.client("s3", config=config)
self.mostRecentKey = None

def update_key(self):
now = time.gmtime()
args = {
"Bucket": self.bucketName,
"Prefix": self.product + time.strftime("%Y%m%d/", now)
}
if self.mostRecentKey is not None:
args["StartAfter"] = self.mostRecentKey

pager = self.client.get_paginator("list_objects_v2")
pages = pager.paginate(**args)

mostRecent = None
for page in pages:
if 'Contents' not in page:
continue

last = page["Contents"][-1]
if mostRecent is None or last["LastModified"] > mostRecent["LastModified"]:
mostRecent = last

if mostRecent is not None:
self.mostRecentKey = mostRecent["Key"]

return mostRecent is not None

def get_url(self, expires = 60):
return self.client.generate_presigned_url(
'get_object',
Params = {
'Bucket': self.bucketName,
'Key': self.mostRecentKey,
},
ExpiresIn = expires,
)

if __name__ == "__main__":
def test():
handler = AWSHandler("CONUS/MergedBaseReflectivity_00.50/")
handler.update_key()
print(handler.get_url())
while not handler.update_key():
time.sleep(10)

print(handler.get_url())

test()
Loading
Loading