Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EO Time Series Viewer
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Benjamin Jakimow
EO Time Series Viewer
Commits
9a2da9aa
Commit
9a2da9aa
authored
7 years ago
by
benjamin.jakimow@geo.hu-berlin.de
Browse files
Options
Downloads
Patches
Plain Diff
fixed date parsing
parent
9a61462b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
timeseriesviewer/dateparser.py
+32
-16
32 additions, 16 deletions
timeseriesviewer/dateparser.py
with
32 additions
and
16 deletions
timeseriesviewer/dateparser.py
+
32
−
16
View file @
9a2da9aa
...
@@ -23,23 +23,37 @@ def matchOrNone(regex, text):
...
@@ -23,23 +23,37 @@ def matchOrNone(regex, text):
else
:
else
:
return
None
return
None
def
extractDateTimeGroup
(
regex
,
text
):
def
extractDateTimeGroup
(
text
):
match
=
regISODate
.
search
(
text
)
if
match
:
return
np
.
datetime64
(
match
.
group
())
match
=
regex
.
search
(
text
)
match
=
regYYYYMMDD
.
search
(
text
)
if
match
is
not
None
:
if
match
:
return
datetime64FromYYYYMMDD
(
match
.
group
())
match
=
regYYYYDOY
.
search
(
text
)
if
match
:
return
datetime64FromYYYYDOY
(
match
.
group
())
match
=
regYYYYMM
.
search
(
text
)
if
match
:
return
np
.
datetime64
(
match
.
group
())
return
np
.
datetime64
(
match
.
group
())
else
:
return
None
return
None
def
datetime64FromYYYYMMDD
(
yyyymmdd
):
def
getDateTime64FromYYYYDOY
(
yyyydoy
):
return
np
.
datetime64
(
'
{}-{}-{}
'
.
format
(
yyyymmdd
[
0
:
4
],
yyyymmdd
[
4
:
6
],
yyyymmdd
[
6
:
8
]))
return
getDatetime64FromDOY
(
yyyydoy
[
0
:
4
],
yyyydoy
[
4
:
7
])
def
getDOYfromDatetime64
(
dt
):
def
datetime64FromYYYYDOY
(
yyyydoy
):
return
datetime64FromDOY
(
yyyydoy
[
0
:
4
],
yyyydoy
[
4
:
7
])
def
DOYfromDatetime64
(
dt
):
return
(
dt
.
astype
(
'
datetime64[D]
'
)
-
dt
.
astype
(
'
datetime64[Y]
'
)).
astype
(
int
)
+
1
return
(
dt
.
astype
(
'
datetime64[D]
'
)
-
dt
.
astype
(
'
datetime64[Y]
'
)).
astype
(
int
)
+
1
def
getD
atetime64FromDOY
(
year
,
doy
):
def
d
atetime64FromDOY
(
year
,
doy
):
if
type
(
year
)
is
str
:
if
type
(
year
)
is
str
:
year
=
int
(
year
)
year
=
int
(
year
)
if
type
(
doy
)
is
str
:
if
type
(
doy
)
is
str
:
...
@@ -87,12 +101,12 @@ class ImageDateReaderDefault(ImageDateReader):
...
@@ -87,12 +101,12 @@ class ImageDateReaderDefault(ImageDateReader):
# search for ISO date in basename
# search for ISO date in basename
# search in basename
# search in basename
for
reg
in
[
regISODate
,
regYYYYMMDD
,
regYYYYDOY
,
regYYYYMM
]:
dtg
=
extractDateTimeGroup
(
self
.
baseName
)
dtg
=
extractDateTimeGroup
(
reg
,
self
.
baseName
)
if
dtg
:
if
dtg
:
return
dtg
return
dtg
for
reg
in
[
regISODate
,
regYYYYMMDD
,
regYYYYDOY
,
regYYYYMM
]:
dtg
=
extractDateTimeGroup
(
self
.
dirName
)
dtg
=
extractDateTimeGroup
(
reg
,
self
.
dirName
)
if
dtg
:
if
dtg
:
return
dtg
return
dtg
return
None
return
None
class
ImageDateReaderPLEIADES
(
ImageDateReader
):
class
ImageDateReaderPLEIADES
(
ImageDateReader
):
...
@@ -140,7 +154,7 @@ class ImageDateParserLandsat(ImageDateReader):
...
@@ -140,7 +154,7 @@ class ImageDateParserLandsat(ImageDateReader):
#search for LandsatSceneID (old) and Landsat Product IDs (new)
#search for LandsatSceneID (old) and Landsat Product IDs (new)
sceneID
=
matchOrNone
(
ImageDateParserLandsat
.
regLandsatSceneID
,
self
.
baseName
)
sceneID
=
matchOrNone
(
ImageDateParserLandsat
.
regLandsatSceneID
,
self
.
baseName
)
if
sceneID
:
if
sceneID
:
return
getD
ate
T
ime64FromYYYYDOY
(
sceneID
[
9
:
16
])
return
d
ate
t
ime64FromYYYYDOY
(
sceneID
[
9
:
16
])
productID
=
matchOrNone
(
ImageDateParserLandsat
.
regLandsatProductID
,
self
.
baseName
)
productID
=
matchOrNone
(
ImageDateParserLandsat
.
regLandsatProductID
,
self
.
baseName
)
if
productID
:
if
productID
:
...
@@ -166,4 +180,6 @@ if __name__ == '__main__':
...
@@ -166,4 +180,6 @@ if __name__ == '__main__':
p
=
r
'
E:\_EnMAP\temp\temp_bj\landsat\37S\EB\LE71720342015009SG100\LE71720342015009SG100_sr.tif
'
p
=
r
'
E:\_EnMAP\temp\temp_bj\landsat\37S\EB\LE71720342015009SG100\LE71720342015009SG100_sr.tif
'
p
=
r
'
D:\Repositories\QGIS_Plugins\hub-timeseriesviewer\example\Images\2012-04-07_LE72270652012098EDC00_BOA.bsq
'
p
=
r
'
D:\Repositories\QGIS_Plugins\hub-timeseriesviewer\example\Images\2012-04-07_LE72270652012098EDC00_BOA.bsq
'
ds
=
gdal
.
Open
(
p
)
ds
=
gdal
.
Open
(
p
)
print
(
datetime64FromYYYYMMDD
(
'
20141212
'
))
print
(
parseDateFromDataSet
(
ds
))
print
(
parseDateFromDataSet
(
ds
))
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment