Skip to content

Commit

Permalink
Removed return value and make target_file positional
Browse files Browse the repository at this point in the history
We should convince the users to download the file first and then use it
instead of downloading it ever again. So the download function should
not return the xarray. Even though the download may take hours so it
does not make sense from this point of view.
  • Loading branch information
uvchik committed Jun 18, 2021
1 parent de067d2 commit 2576801
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
17 changes: 0 additions & 17 deletions src/feedinlib/cds_request_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
def _get_cds_data(
dataset_name="reanalysis-era5-single-levels",
target_file=None,
chunks=None,
cds_client=None,
**cds_params,
):
Expand All @@ -32,13 +31,10 @@ def _get_cds_data(
'Show API request', the short name is the string on the 6th line
after 'c.retrieve('
:param target_file: (str) name of the file to save downloaded locally
:param chunks: (dict)
:param cds_client: handle to CDS client (if none is provided, then it is
created)
:param cds_params: (dict) parameter to pass to the CDS request
:return: CDS data in an xarray format
"""

# https://cds.climate.copernicus.eu/api-how-to
Expand Down Expand Up @@ -102,18 +98,6 @@ def _get_cds_data(
# Download the data in the target file
result.download(target_file)

# Extract the data from the target file
answer = xr.open_dataset(target_file, chunks=chunks)

# Now that the data has been extracted the file path is removed if it was
# not provided. This will currently not work on windows if the dataset is
# too large as the file will be locked by the reading process.
if no_target_file_provided is True:
os.unlink(target_file)

# Here yield might be preferable in case of large datasets
return answer


def _format_cds_request_datespan(start_date, end_date):
"""
Expand Down Expand Up @@ -319,7 +303,6 @@ def get_cds_data_from_datespan_and_position(
after 'c.retrieve('
:param target_file: (str) name of the file in which downloading the data
locally
:param chunks: (dict)
:param cds_client: handle to CDS client (if none is provided, then it is
created)
:param cds_params: (dict) parameter to pass to the CDS request
Expand Down
4 changes: 1 addition & 3 deletions src/feedinlib/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,11 @@
def get_era5_data_from_datespan_and_position(
start_date,
end_date,
target_file,
variable="feedinlib",
latitude=None,
longitude=None,
grid=None,
target_file=None,
chunks=None,
cds_client=None,
):
"""
Expand All @@ -38,7 +37,6 @@ def get_era5_data_from_datespan_and_position(
resolutions in deg. It needs to be an integer fraction of 90 deg.
:param target_file: (str) name of the file in which to store downloaded
data locally
:param chunks: (dict)
:param cds_client: handle to CDS client (if none is provided, then it is
created)
:return: CDS data in an xarray format
Expand Down

0 comments on commit 2576801

Please sign in to comment.