Skip to content

Commit ce55c17

Browse files
authored
Merge pull request #87 from andrewdelman/ecco_access_fsspec
Fixes to ecco_access snapshot dates, and renamed ecco_podaac_to_xrdataset function
2 parents 8f1ca78 + 7f75752 commit ce55c17

File tree

5 files changed

+536
-234
lines changed

5 files changed

+536
-234
lines changed

ecco_access/__init__.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
from .ecco_access import ecco_podaac_access
2+
from .ecco_access import ecco_podaac_to_xrdataset
23

34
from .ecco_download import ecco_podaac_query
45
from .ecco_download import ecco_podaac_download
56
from .ecco_download import ecco_podaac_download_diskaware
67
from .ecco_download import ecco_podaac_download
78
from .ecco_download import ecco_podaac_download_subset
89

10+
from .ecco_s3_retrieve import setup_earthdata_login_auth
11+
from .ecco_s3_retrieve import init_S3FileSystem
912
from .ecco_s3_retrieve import ecco_podaac_s3_query
1013
from .ecco_s3_retrieve import ecco_podaac_s3_open
14+
from .ecco_s3_retrieve import ecco_podaac_s3_open_fsspec
1115
from .ecco_s3_retrieve import ecco_podaac_s3_get
1216
from .ecco_s3_retrieve import ecco_podaac_s3_get_diskaware
1317

18+
from .ecco_acc_dates import date_adjustment
19+
20+
1421
__all__ = ['ecco_access',
1522
'ecco_download',
16-
'ecco_s3_retrieve']
23+
'ecco_s3_retrieve',
24+
'ecco_acc_dates']

ecco_access/ecco_acc_dates.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
### This module contains date handling routines used in the other ecco_access modules.
2+
3+
4+
import numpy as np
5+
6+
7+
def date_adjustment(ShortName,StartDate,EndDate,CMR_query=True):
8+
"""
9+
Adjusts StartDate and EndDate, augmenting where day or month may be missing.
10+
Returns either strings ready for NASA Earthdata CMR query (CMR_query = True),
11+
or numpy.datetime64 values.
12+
"""
13+
14+
pass
15+
16+
17+
# # Adjust StartDate and EndDate
18+
19+
if StartDate=='yesterday':
20+
StartDate = yesterday()
21+
if EndDate==-1:
22+
EndDate = StartDate
23+
elif StartDate=='yesterday':
24+
StartDate = yesterday()
25+
elif EndDate=='today':
26+
EndDate = today()
27+
28+
if len(StartDate) == 4:
29+
StartDate += '-01-01'
30+
elif len(StartDate) == 7:
31+
StartDate += '-01'
32+
elif len(StartDate) != 10:
33+
sys.exit('\nStart date should be in format ''YYYY'', ''YYYY-MM'', or ''YYYY-MM-DD''!\n'\
34+
+'Program will exit now !\n')
35+
36+
if len(EndDate) == 4:
37+
EndDate += '-12-31'
38+
elif len(EndDate) == 7:
39+
EndDate = str(np.datetime64(str(np.datetime64(EndDate,'M')+np.timedelta64(1,'M'))+'-01','D')\
40+
-np.timedelta64(1,'D'))
41+
elif len(EndDate) != 10:
42+
sys.exit('\nEnd date should be in format ''YYYY'', ''YYYY-MM'', or ''YYYY-MM-DD''!\n'\
43+
+'Program will exit now !\n')
44+
45+
# for snapshot datasets, move EndDate one day later
46+
if 'SNAPSHOT' in ShortName:
47+
EndDate = str(np.datetime64(EndDate,'D') + np.timedelta64(1,'D'))
48+
49+
# CMR request adjustments
50+
if CMR_query:
51+
SingleDay_flag = False
52+
if (('MONTHLY' in ShortName) or ('DAILY' in ShortName)):
53+
if np.datetime64(EndDate,'D') - np.datetime64(StartDate,'D') \
54+
> np.timedelta64(1,'D'):
55+
# for monthly and daily datasets, do not include the month or day before
56+
StartDate = str(np.datetime64(StartDate,'D') + np.timedelta64(1,'D'))
57+
else:
58+
# for single day ranges we need to make the adjustment
59+
# after the CMR request
60+
SingleDay_flag = True
61+
62+
return StartDate,EndDate,SingleDay_flag
63+
64+
else:
65+
StartDate = np.datetime64(StartDate,'D')
66+
EndDate = np.datetime64(EndDate,'D')
67+
68+
return StartDate,EndDate

0 commit comments

Comments
 (0)