Skip to content

Commit

Permalink
Fixing issue #20
Browse files Browse the repository at this point in the history
  • Loading branch information
sam-laptop-vm committed Jan 3, 2025
1 parent c4497f3 commit 2f6d8b6
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions pixutils/era_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,22 @@ def download_utci_data(dates: Union[date, List[date]],
os.mkdir(yfolder)
for year in years:
request = {
'variable': ['universal_thermal_climate_index'],
'version': '1_1',
'product_type': 'consolidated_dataset',
'year': [str(year)],
'month': sorted(months),
'day': sorted(days),
#'time': ['00:00'],
'area': [vals[0], vals[1], vals[2], vals[3]]
"variable": ["universal_thermal_climate_index","mean_radiant_temperature"],
"version": "1_1",
"product_type": "consolidated_dataset",
"year": [str(year)],
"month": sorted(months),
"day": sorted(days),
"area": [vals[0], vals[1], vals[2], vals[3]]
}
print("Requesting: {}".format(request))
fpath = os.path.join(yfolder,str(year)+ext)
#c.retrieve('derived-utci-historical',
# request, fpath)
try:
c.retrieve('derived-utci-historical',
request, fpath)
except:
print("Request to CDS for UTCI failed")
return
if os.path.exists(fpath):
print("Downloaded: {}".format(fpath))
# Check if zip file rather than NetCDF
Expand Down Expand Up @@ -288,7 +291,7 @@ def parse_variables() -> List[str]:

# lat and lon should be float
vals = [float(v) for v in vals]
ymfiles=[]
yfiles=[]

# for UTCI restrict to summer months
utci = False
Expand Down Expand Up @@ -332,18 +335,20 @@ def parse_variables() -> List[str]:

# merge according to time
merge(ymfiles, fn_yrmn, latitude=True, file_merge=True)
del ymfiles
shutil.rmtree(zfolder)

# add each date to the merge list
ymfiles.append(fn_yrmn)
if os.path.exists(fn_yrmn):
yfiles.append(fn_yrmn)

# merge all months and years into single file
if utci:
ds = xr.open_dataset(fn_yrmn)
lat = ds.latitude.values
lon = ds.longitude.values
del ds
merge(ymfiles,file_path,month_merge=True)
merge(yfiles,file_path,month_merge=True)
ds = xr.open_dataset(file_path)
ds['latitude'] = lat
ds.latitude.attrs["units"] = 'degrees_north'
Expand All @@ -361,7 +366,7 @@ def parse_variables() -> List[str]:
ds.to_netcdf(file_path)
del ds
else:
merge(ymfiles, file_path, latitude=True, month_merge=True)
merge(yfiles, file_path, latitude=True, month_merge=True)

elif area_box:
c.retrieve(
Expand Down

0 comments on commit 2f6d8b6

Please sign in to comment.