Skip to content

Commit

Permalink
Merge pull request #106 from c-hydro/tools_v1.3.3
Browse files Browse the repository at this point in the history
Tools v1.3.3
  • Loading branch information
ltrotter authored Oct 6, 2024
2 parents db17562 + 0cf1dc0 commit e9487a6
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions door/base_downloaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ def set_bounds(self, bounds: None|BoundingBox|list[float]|tuple[float]) -> None:
if bounds is None:
return
elif isinstance(bounds, (list, tuple)):
bounds = BoundingBox(*bounds)
_bounds = BoundingBox(*bounds)
elif isinstance(bounds, Dataset):
_bounds = BoundingBox.from_dataset(bounds)
elif isinstance(bounds, str):
_bounds = BoundingBox.from_file(bounds)

self.bounds = bounds
self.bounds = _bounds

def set_destination(self, destination: Dataset|dict|str|None) -> None:
"""
Expand Down
2 changes: 1 addition & 1 deletion door/data_sources/cds/cds_downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class CDSDownloader(APIDownloader):

name = "CDS_downloader"
apikey_env_vars = 'CDSAPI_KEY' # this should be in the form UID:API_KEY already
cds_url = 'https://cds-beta.climate.copernicus.eu/api'
cds_url = 'https://cds.climate.copernicus.eu/api'

def __init__(self, dataset) -> None:

Expand Down
11 changes: 11 additions & 0 deletions door/utils/space.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import xarray as xr
import rioxarray as rxr

from ..tools.data import Dataset

class BoundingBox():

default_datum = 'EPSG:4326'
Expand All @@ -34,6 +36,15 @@ def __init__(self,

# buffer the bounding box
self.buffer_bbox(buffer)

@staticmethod
def from_dataset(dataset: Dataset, buffer: float = 0.0):
data:xr.DataArray = dataset.get_data()

# get the bounding box of the data
left, bottom, right, top = data.rio.bounds()

return BoundingBox(left, bottom, right, top, datum = data.rio.crs.to_wkt(), buffer = buffer)

@staticmethod
def from_file(grid_file, buffer: float = 0.0):
Expand Down
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,14 @@
'dask',
'scipy',
'ecmwf-opendata >= 0.2.0',
'cdsapi',
'cdsapi >= 0.7.2',
'ftpretty',
'pandas',
'drops2 @ git+https://github.com/CIMAFoundation/drops2.git',
'matplotlib',
'geopandas',
'boto3'
'boto3',
'img2pdf'
],
python_requires='>=3.10',
test_suite='tests',
Expand Down

0 comments on commit e9487a6

Please sign in to comment.