Skip to content

Commit

Permalink
now result is sortet by location and datetime
Browse files Browse the repository at this point in the history
  • Loading branch information
prayer007 committed Sep 7, 2021
1 parent 08ec858 commit f67efe9
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions dwdGribExtractor/icon.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def createDownloadUrl(self, var):

urls = []

now_utc = datetime.now(timezone.utc)
urlDate = now_utc.strftime("%Y%m%d")

url = "{src}{run}/{var}".format(src = self._src, var = var, run = self._currentRun)
Expand Down Expand Up @@ -185,17 +186,29 @@ def downloadAndExtractBzFile(self, url, destFp):

def _getVarnameFromNcFile(self, ncFile):

'''Extracts the nc intern weather variable name from the netCDF file
Parameters
----------
ncFile : xarray
The netCDF file
Returns
-------
string
The nc intern weather variable name
'''

var = None

for var in ncFile.variables:

varDims = len(ncFile.variables[var].shape)

if varDims == 3:
if varDims >= 2:
ncVarName = var

return var

return ncVarName


def extractValuesFromGrib(self, fp, data):
Expand Down Expand Up @@ -329,7 +342,7 @@ def collectData(self, varList, cores = None):

result = []

for item in varList.items():
for item in varList:
res = self.mainDataCollector(item)
result.append(res)

Expand All @@ -348,6 +361,9 @@ def collectData(self, varList, cores = None):

data[key] = val

# Sort data
data = data.sort_values(["location", "datetime"])

# Remove all .idx files in the tmp folder
path = "{tfp}/*grib*".format(tfp = self._tmpFp)
fileList = glob.glob(path)
Expand Down

0 comments on commit f67efe9

Please sign in to comment.