Skip to content

Commit

Permalink
Added relative orbit as described in #1
Browse files Browse the repository at this point in the history
  • Loading branch information
whisperingpixel committed Feb 8, 2019
1 parent 6a26a0d commit 700da42
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 37 deletions.
27 changes: 21 additions & 6 deletions README.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"*Disclaimer: This not yet ready-to-use. Seriously ... come back later.*"
"*Disclaimer: This not yet ready-to-use. Seriously ... come back later.*\n",
"\n",
"\n",
"*This README was generated by a jupyter notebook and automatically exported into Markdown. You might want to open the README.ipynb file to see the original outputs. Do not edit the Markdown file directly as any changes will be overwritten.*"
]
},
{
Expand Down Expand Up @@ -68,7 +71,16 @@
"#\n",
"# Example:\n",
"#\n",
"acquisition_time = '20170105T013442'"
"acquisition_time = '20170105T013442'\n",
"\n",
"#\n",
"# Relative orbit\n",
"#\n",
"# General pattern: integer\n",
"#\n",
"# Example:\n",
"#\n",
"rel_orbit = 122"
]
},
{
Expand Down Expand Up @@ -139,9 +151,9 @@
"\n",
"Version 1:\n",
"\n",
"> {granule-id}-{acquisitionyear}-{acquisitiondayofyear}-{acquisitionhour}-{acquisitiontime (minutes / 5)}\n",
"> {granule-id}-{rel_orbit}-{acquisitionyear}-{acquisitiondayofyear}-{acquisitionhour}-{acquisitiontime (minutes / 5)}\n",
">\n",
"> t33uvp-2017-005-01-6\n",
"> t33uvp-122-2017-005-01-6\n",
"\n",
"Version 2 might be something like this:\n",
"> {instrument}-{platform}-{processinglevel}-{...?}\n",
Expand All @@ -166,7 +178,7 @@
{
"data": {
"text/plain": [
"'t33uvp-2017-005-01-6'"
"'t33uvp-122-2017-005-01-6'"
]
},
"execution_count": 2,
Expand All @@ -183,7 +195,10 @@
"#\n",
"# Generate a new id\n",
"#\n",
"id = s2_idgen.Generator(granule_id = 'T33UVP', acquisition_time = '20170105T013442')\n",
"id = s2_idgen.Generator(\n",
" granule_id = 'T33UVP',\n",
" acquisition_time = '20170105T013442',\n",
" rel_orbit = 122)\n",
"\n",
"#\n",
"# Access the id\n",
Expand Down
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

*Disclaimer: This not yet ready-to-use. Seriously ... come back later.*


*This README was generated by a jupyter notebook and automatically exported into Markdown. You might want to open the README.ipynb file to see the original outputs. Do not edit the Markdown file directly as any changes will be overwritten.*

## 1. Problem

There is no unique universal identifier (uuid) for Sentinel data, which is valid across all data hubs and is unique for the distinct images. Even within a data hub (e.g. the Copernicus Open Data Hub) the same image might have different uuids.
Expand Down Expand Up @@ -34,6 +37,15 @@ granule_id = 'T33UVP'
# Example:
#
acquisition_time = '20170105T013442'

#
# Relative orbit
#
# General pattern: integer
#
# Example:
#
rel_orbit = 122
```

## 3. Initial considerations
Expand Down Expand Up @@ -71,9 +83,9 @@ Images might be re-processed by ESA using a different software version. The vers

Version 1:

> {granule-id}-{acquisitionyear}-{acquisitiondayofyear}-{acquisitionhour}-{acquisitiontime (minutes / 5)}
> {granule-id}-{rel_orbit}-{acquisitionyear}-{acquisitiondayofyear}-{acquisitionhour}-{acquisitiontime (minutes / 5)}
>
> t33uvp-2017-005-01-6
> t33uvp-122-2017-005-01-6
Version 2 might be something like this:
> {instrument}-{platform}-{processinglevel}-{...?}
Expand All @@ -94,7 +106,10 @@ from s2_idgen import s2_idgen
#
# Generate a new id
#
id = s2_idgen.Generator(granule_id = 'T33UVP', acquisition_time = '20170105T013442')
id = s2_idgen.Generator(
granule_id = 'T33UVP',
acquisition_time = '20170105T013442',
rel_orbit = 122)

#
# Access the id
Expand All @@ -105,7 +120,7 @@ id.getID()



't33uvp-2017-005-01-6'
't33uvp-122-2017-005-01-6'



Expand Down
29 changes: 23 additions & 6 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ proof-of-concept.]]

_Disclaimer: This not yet ready-to-use. Seriously … come back later._

_This README was generated by a jupyter notebook and automatically
exported into Markdown. You might want to open the README.ipynb file to
see the original outputs. Do not edit the Markdown file directly as any
changes will be overwritten._

== 1. Problem

There is no unique universal identifier (uuid) for Sentinel data, which
Expand Down Expand Up @@ -52,6 +57,15 @@ granule_id = 'T33UVP'
# Example:
#
acquisition_time = '20170105T013442'

#
# Relative orbit
#
# General pattern: integer
#
# Example:
#
rel_orbit = 122
----

== 3. Initial considerations
Expand Down Expand Up @@ -96,12 +110,12 @@ The version should be reflected in the id.

Version 1:

__________________________________________________________________________________________________________
\{granule-id}-\{acquisitionyear}-\{acquisitiondayofyear}-\{acquisitionhour}-\{acquisitiontime
_______________________________________________________________________________________________________________________
\{granule-id}-\{rel_orbit}-\{acquisitionyear}-\{acquisitiondayofyear}-\{acquisitionhour}-\{acquisitiontime
(minutes / 5)}

t33uvp-2017-005-01-6
__________________________________________________________________________________________________________
t33uvp-122-2017-005-01-6
_______________________________________________________________________________________________________________________

Version 2 might be something like this: >
\{instrument}-\{platform}-\{processinglevel}-\{…?} > > MSI-A-1C-…?
Expand All @@ -122,7 +136,10 @@ from s2_idgen import s2_idgen
#
# Generate a new id
#
id = s2_idgen.Generator(granule_id = 'T33UVP', acquisition_time = '20170105T013442')
id = s2_idgen.Generator(
granule_id = 'T33UVP',
acquisition_time = '20170105T013442',
rel_orbit = 122)

#
# Access the id
Expand All @@ -132,7 +149,7 @@ id.getID()


+*Out[2]:*+
----'t33uvp-2017-005-01-6'----
----'t33uvp-122-2017-005-01-6'----

== 6. Development

Expand Down
35 changes: 28 additions & 7 deletions s2_idgen/s2_idgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,25 @@

class Generator:

def __init__(self, granule_id, acquisition_time):
def __init__(self, granule_id, acquisition_time, rel_orbit, version = None):
"""
Constructor
:param granule_id: string (formatted as Txxxxx, e.g 'T33UVP')
:param acquisition_time: string (formatted as YYYYMMDDHHMMSS, e.g. '20170105T013442')
"""

self.granule_id = self.__checkGranuleId(granule_id)
self.granule_id = self._checkGranuleId(granule_id)

self.acquisition_time = self.__checkTimestamp(acquisition_time)
self.acquisition_time = self._checkTimestamp(acquisition_time)

self.rel_orbit = self._checkRelativeOrbit(rel_orbit)

def __checkGranuleId(self, granule_id):
if version is None:
version = 1

self.version = version

def _checkGranuleId(self, granule_id):
"""
Checks whether the value for the granule id is reasonable or not
Expand Down Expand Up @@ -63,7 +69,7 @@ def __checkGranuleId(self, granule_id):
return granule_id_candidate


def __checkTimestamp(self, acquisition_time):
def _checkTimestamp(self, acquisition_time):
"""
Checks whether the value for the acquisition time is reasonable or not
Expand Down Expand Up @@ -95,6 +101,20 @@ def __checkTimestamp(self, acquisition_time):
return acquisition_time_candidate


def _checkRelativeOrbit(self, rel_orbit):

if rel_orbit is None:
raise Exception("Invalid relative orbit, must be integer")

if type(rel_orbit) != int:
raise Exception("Invalid relative orbit: {}. Must be integer".format(rel_orbit))

if rel_orbit < 1:
raise Exception("Invalid relative orbit: {}. Must be larger than 1".format(rel_orbit))

return rel_orbit


def getID(self):
"""
getId.
Expand All @@ -106,10 +126,11 @@ def getID(self):
acquisitionhour = self.acquisition_time.tm_hour
acquisitiontime = int(math.floor(self.acquisition_time.tm_min / 5))

return '{granule_id}-{acquisitionyear}-{acquisitiondayofyear}-{acquisitionhour}-{acquisitiontime}'.format(
return '{granule_id}-{rel_orbit}-{acquisitionyear}-{acquisitiondayofyear}-{acquisitionhour}-{acquisitiontime}'.format(
granule_id = self.granule_id,
acquisitionyear = acquisitionyear,
acquisitiondayofyear = '{0:03d}'.format(acquisitiondayofyear),
acquisitionhour = '{0:02d}'.format(acquisitionhour),
acquisitiontime = acquisitiontime
acquisitiontime = acquisitiontime,
rel_orbit = '{0:03d}'.format(self.rel_orbit)
)
34 changes: 20 additions & 14 deletions s2_idgen/test_s2_idgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,35 @@
class TestGenerator(unittest.TestCase):

def setUp(self):
self.s2_id = s2_idgen.Generator(granule_id = 'T33UVP', acquisition_time = '20170105T013442')
self.s2_id = s2_idgen.Generator(granule_id = 'T33UVP', acquisition_time = '20170105T013442', rel_orbit=122)

def test_getid(self):
self.assertEqual(self.s2_id.getID(), 't33uvp-2017-005-01-6')
self.assertEqual(self.s2_id.getID(), 't33uvp-122-2017-005-01-6')


class TestGenerator2(unittest.TestCase):

def test_checkgranuleid(self):
self.assertRaises(Exception,s2_idgen.Generator,granule_id = None, acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = '33UVVP', acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVVP', acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'TXXXXX', acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UV1', acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T00UV1', acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T70UV1', acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 6, acquisition_time = '20170105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = None, acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = '33UVVP', acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVVP', acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'TXXXXX', acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UV1', acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T00UV1', acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T70UV1', acquisition_time = '20170105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 6, acquisition_time = '20170105T013442', rel_orbit = 122)

def test_checktimestamp(self):
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = None)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = '20140105T013442')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = 'somedummystuffhere')
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = 1244)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = None, rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = '20140105T013442', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = 'somedummystuffhere', rel_orbit = 122)
self.assertRaises(Exception,s2_idgen.Generator,granule_id = 'T33UVP', acquisition_time = 1244, rel_orbit = 122)

def test_checkrelativeorbit(self):
self.assertRaises(Exception,s2_idgen.Generator, granule_id = 'T33UVP', acquisition_time = '20170105T013442', rel_orbit = None)
self.assertRaises(Exception,s2_idgen.Generator, granule_id = 'T33UVP', acquisition_time = '20170105T013442', rel_orbit = 'dummy')
self.assertRaises(Exception,s2_idgen.Generator, granule_id = 'T33UVP', acquisition_time = '20170105T013442', rel_orbit = -1)


if __name__ == '__main__':
unittest.main()

0 comments on commit 700da42

Please sign in to comment.