-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data access api README/Docs update #744
base: dev
Are you sure you want to change the base?
Changes from 31 commits
f9ef107
72f1924
d415846
26135b0
4376bd7
9e06ca6
5b9f4c6
1deb7aa
713f0dd
8f3218a
923d74b
41952cd
7c70cea
ecf5ca8
73c5dce
3121b00
e9e3ced
8d2a93a
3211b72
dc3f937
d46c20a
37a9685
304e779
ac3274a
047ad5c
55a4681
2af4df7
a4e15e0
8952a5a
1182258
c9cf41b
510f551
e0858a5
1b76a68
56e626f
22fc75a
8598f0b
93295a6
b1f13ec
33be899
67600f1
51bba5b
a42e4f9
9e0bba6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -7,7 +7,7 @@ The `imap-data-access <https://github.com/IMAP-Science-Operations-Center/imap-da | |||||||||||||||||
repository provides programmatic access and a command-line utility for | ||||||||||||||||||
interacting with the API. It is the preferred way to use the API. | ||||||||||||||||||
|
||||||||||||||||||
The SDC provides a REST API that allows users to upload and download files, as | ||||||||||||||||||
The SDC further provides a REST API that allows users to upload and download files, as | ||||||||||||||||||
well as query for file metadata. The following documentation describes the | ||||||||||||||||||
various endpoints that are supported and how to use them. | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -16,21 +16,195 @@ that the full implementation of the functionality is yet to be completed.* | |||||||||||||||||
|
||||||||||||||||||
The API can be accessed from the following URL [WIP]: https://api.dev.imap-mission.com | ||||||||||||||||||
|
||||||||||||||||||
Command Line Utility | ||||||||||||||||||
==================== | ||||||||||||||||||
To Install | ||||||||||||||||||
---------- | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
It looks like these headings (and throughout this document) are still messing up the main RtD page layout. I think these need to be changed to another level 'down' in markdown. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! Sorry, Okay. I think I understand what you are saying now! Should I do this with every heading? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, except for the very first one (line 4), which is fine as is. |
||||||||||||||||||
|
||||||||||||||||||
Run the following command to use the API CLI. | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
pip install imap-data-access | ||||||||||||||||||
|
||||||||||||||||||
Base Command Arguments | ||||||||||||||||||
---------------------- | ||||||||||||||||||
|
||||||||||||||||||
The following are base command arguments for the CLI: | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
imap-data-access -h # or | ||||||||||||||||||
imap-data-access query # or | ||||||||||||||||||
imap-data-access download # or | ||||||||||||||||||
imap-data-access upload | ||||||||||||||||||
|
||||||||||||||||||
Add the -h flag with any base command for more information on use and functionality. | ||||||||||||||||||
|
||||||||||||||||||
.. openapi:: openapi.yml | ||||||||||||||||||
:group: | ||||||||||||||||||
:include: /query | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This part is describing the REST API specification, so it should be moved to under that section. |
||||||||||||||||||
|
||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
imap-data-access query --start-date 20240101 --end-date 20241231 --output-format json | ||||||||||||||||||
# The following line is returned: | ||||||||||||||||||
[{'file_path': 'imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_v001.pkts', 'instrument': 'swe', 'data_level': 'l0', 'descriptor': 'sci', 'start_date': '20240105', 'version': 'v001', 'extension': 'pkts'}, {'file_path': 'imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_v001.pkts', 'instrument': 'swe', 'data_level': 'l0', 'descriptor': 'sci', 'start_date': '20240105', 'version': 'v001', 'extension': 'pkts'}] | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
.. openapi:: openapi.yml | ||||||||||||||||||
:group: | ||||||||||||||||||
:include: /download | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the last comment, this is describing the REST API so should also be moved (same with the |
||||||||||||||||||
|
||||||||||||||||||
It is important to note that your working directory will be established as the default directory. I.e, the ``data`` | ||||||||||||||||||
directory (to which files are downloaded) will automatically be placed in this file path. Choose your working directory | ||||||||||||||||||
accordingly to suit your desires. | ||||||||||||||||||
|
||||||||||||||||||
When downloading a file from the API, different folders within the ``data`` directory will be made to better | ||||||||||||||||||
organize the downloaded files. See the example path: ``data/imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_20240105_v00-01.pkts`` | ||||||||||||||||||
anamanica marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
imap-data-access upload /imap/swe/l1a/2024/01/imap_swe_l1a_sci_20240105_v001.cdf | ||||||||||||||||||
|
||||||||||||||||||
.. openapi:: openapi.yml | ||||||||||||||||||
:group: | ||||||||||||||||||
:include: /upload | ||||||||||||||||||
|
||||||||||||||||||
When uploading files to the API, ensure these files are stored properly in a ``data`` directory. Then, | ||||||||||||||||||
ensure your working directory is one level above the ``data`` directory in order to properly upload files. | ||||||||||||||||||
When uploading files to the API, ensure these files are stored properly in a ``data`` directory (see the Data Directory section below for more information). Then, | ||||||||||||||||||
ensure your working directory is one level above ``data`` in order to properly upload files. | ||||||||||||||||||
|
||||||||||||||||||
[WIP] Certain ancillary files can also be uploaded to the API. For more specific information regarding these files, visit | ||||||||||||||||||
`Ancillary Files <https://imap-processing.readthedocs.io/en/latest/data-access-api/calibration-files.html>`_ | ||||||||||||||||||
|
||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
imap-data-access upload /imap/swe/l1a/2024/01/imap_swe_l1a_sci_20240105_v001.cdf | ||||||||||||||||||
|
||||||||||||||||||
Importing as a package | ||||||||||||||||||
====================== | ||||||||||||||||||
Imap data access can also be imported and used as a python package if desired. | ||||||||||||||||||
|
||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
import imap_data_access | ||||||||||||||||||
|
||||||||||||||||||
# Search for files | ||||||||||||||||||
results = imap_data_access.query(instrument="mag", data_level="l0") | ||||||||||||||||||
# results is a list of dictionaries | ||||||||||||||||||
# [{'file_path': 'imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_v001.pkts', 'instrument': 'swe', 'data_level': 'l0', 'descriptor': 'sci', 'start_date': '20240105','version': 'v001', 'extension': 'pkts'}, {'file_path': 'imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_v001.pkts', 'instrument': 'swe', 'data_level': 'l0', 'descriptor': 'sci', 'start_date': '20240105', 'version': 'v001', 'extension': 'pkts'}] | ||||||||||||||||||
anamanica marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
||||||||||||||||||
# Download a file that was returned from the search | ||||||||||||||||||
imap_data_access.download("imap/mag/l0/2024/01/imap_mag_l0_raw_202040101_v001.pkts") | ||||||||||||||||||
|
||||||||||||||||||
# Upload a calibration file that exists locally | ||||||||||||||||||
imap_data_access.upload("imap/swe/l1a/2024/01/imap_swe_l1a_sci_20240105_v001.cdf") | ||||||||||||||||||
|
||||||||||||||||||
Configuration | ||||||||||||||||||
============= | ||||||||||||||||||
Data Directory | ||||||||||||||||||
-------------- | ||||||||||||||||||
|
||||||||||||||||||
The folder structure for data files within the IMAP SDC is rigidly defined, so the data access will mimic that structure to make sure all data is stored in the same hierarchical structure as the SDC. This will enable seamless transition between a user's local system and the SDC. This is only used for downloads. | ||||||||||||||||||
A user's root data location can be specified as an environment variable IMAP_DATA_DIR or through a configuration dictionary within the package itself imap_data_access.config["DATA_DIR"]. If the IMAP_DATA_DIR variable is not set, the program defaults to the user's current working directory + data/. | ||||||||||||||||||
anamanica marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
The following is the directory structure the IMAP SDC uses. | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
<IMAP_DATA_DIR>/ | ||||||||||||||||||
imap/ | ||||||||||||||||||
<instrument>/ | ||||||||||||||||||
<data_level>/ | ||||||||||||||||||
<year>/ | ||||||||||||||||||
<month>/ | ||||||||||||||||||
<filename> | ||||||||||||||||||
|
||||||||||||||||||
curl -X GET -H "Accept: application/json" https://api.dev.imap-mission.com/upload/imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_20240105_v00-01.pkts | ||||||||||||||||||
for example, with ``IMAP_DATA_DIR=/data:`` | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
/data/ | ||||||||||||||||||
imap/ | ||||||||||||||||||
swe/ | ||||||||||||||||||
l0/ | ||||||||||||||||||
2024/ | ||||||||||||||||||
01/ | ||||||||||||||||||
imap_swe_l0_sci_20240105_v001.pkts | ||||||||||||||||||
|
||||||||||||||||||
Data Access URL | ||||||||||||||||||
--------------- | ||||||||||||||||||
|
||||||||||||||||||
To change the default URL that the package accesses, you can set the environment variable ``IMAP_DATA_ACCESS_URL`` or within the package ``imap_data_access.config["DATA_ACCESS_URL"]``. The default is the development server https://api.dev.imap-mission.com. | ||||||||||||||||||
anamanica marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
|
||||||||||||||||||
File Validation | ||||||||||||||||||
=============== | ||||||||||||||||||
|
||||||||||||||||||
This package validates filenames and paths to check they follow our standards, as defined by the filename conventions. There is also a class available for use by other packages to create filepaths and filenames that follow the IMAP SDC conventions. | ||||||||||||||||||
anamanica marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||
To use this class, use ``imap_data_access.ScienceFilePath``. | ||||||||||||||||||
|
||||||||||||||||||
Usage: | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
science_file = imap_data_access.ScienceFilePath("imap_swe_l0_sci_20240101_v001.pkts") | ||||||||||||||||||
|
||||||||||||||||||
# Filepath = /imap/swe/l0/2024/01/imap_swe_l0_sci_20240101_v001.pkts | ||||||||||||||||||
filepath = science_file.construct_path() | ||||||||||||||||||
|
||||||||||||||||||
Troubleshooting | ||||||||||||||||||
=============== | ||||||||||||||||||
Network Issues | ||||||||||||||||||
-------------- | ||||||||||||||||||
|
||||||||||||||||||
**SSL** | ||||||||||||||||||
|
||||||||||||||||||
If you encounter SSL errors similar to the following: | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
urllib.error.URLError: <urlopen error [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:997)> | ||||||||||||||||||
|
||||||||||||||||||
That generally means the Python environment you're using is not finding your system's root certificates properly. This means you need to tell Python how to find those certificates with the following potential solutions. | ||||||||||||||||||
|
||||||||||||||||||
#. Upgrade the certifi package | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
pip install --upgrade certifi | ||||||||||||||||||
|
||||||||||||||||||
#. Install system certificates -- Depending on the Python version you installed the program with the command will look something like this: | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
/Applications/Python\ 3.10/Install\ Certificates.command | ||||||||||||||||||
|
||||||||||||||||||
**HTTP Error 502: BadGateway** | ||||||||||||||||||
|
||||||||||||||||||
This could mean that the service is temporarily down. If you continue to encounter this, reach out to the IMAP SDC at imap-sdc@lasp.colorado.edu. | ||||||||||||||||||
|
||||||||||||||||||
FileNotFoundError | ||||||||||||||||||
----------------- | ||||||||||||||||||
|
||||||||||||||||||
This could mean that the local data directory is not set up with the same paths as the SDC. See the data directory section for an example of how to set this up. | ||||||||||||||||||
|
||||||||||||||||||
REST API Specification | ||||||||||||||||||
====================== | ||||||||||||||||||
Upload | ||||||||||||||||||
------ | ||||||||||||||||||
|
||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
||||||||||||||||||
curl -X GET -H "Accept: application/json" https://api.dev.imap-mission.com/upload/imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_20240105_v00-01.pkts | ||||||||||||||||||
|
||||||||||||||||||
**Possible Responses:** | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -48,16 +222,8 @@ ensure your working directory is one level above the ``data`` directory in order | |||||||||||||||||
{"statusCode": 409, "body": "https://sds-data-<aws_account_number>.s3.amazon.com/imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_20240105_v00-01.pkts already exists."} | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
.. openapi:: openapi.yml | ||||||||||||||||||
:group: | ||||||||||||||||||
:include: /download | ||||||||||||||||||
|
||||||||||||||||||
It is important to note that your working directory will be established as the default directory. I.e, the ``data`` | ||||||||||||||||||
directory--which files are downloaded to--will automatically be placed in this file path. Choose your working directory | ||||||||||||||||||
accordingly to suit your desires. | ||||||||||||||||||
|
||||||||||||||||||
When downloading a file from the API, different folders within the ``data`` directory will be made to better | ||||||||||||||||||
organize the files. See the example file path: ``data/imap/swe/l0/2024/01/imap_swe_l0_sci_20240105_20240105_v00-01.pkts`` | ||||||||||||||||||
Download | ||||||||||||||||||
-------- | ||||||||||||||||||
|
||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -73,11 +239,8 @@ organize the files. See the example file path: ``data/imap/swe/l0/2024/01/imap_s | |||||||||||||||||
{"statusCode": 400, "body": "No file requested for download. Please provide a filename in the path. Eg. /download/path/to/file/filename.pkts"} | ||||||||||||||||||
{"statusCode": 404, "body": "File not found, make sure you include the full path to the file in the request, e.g. /download/path/to/file/filename.pkts"} | ||||||||||||||||||
|
||||||||||||||||||
|
||||||||||||||||||
.. openapi:: openapi.yml | ||||||||||||||||||
:group: | ||||||||||||||||||
:include: /query | ||||||||||||||||||
|
||||||||||||||||||
Query | ||||||||||||||||||
------ | ||||||||||||||||||
**Example Usage:** | ||||||||||||||||||
|
||||||||||||||||||
.. code-block:: bash | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this document is quite lengthy now and have several sections and subsections, I suggest to add a table of contents somewhere towards the top. (Could be done in a future PR if desired)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, Ana pointed out to me that there is a built-in table of contents on ReadTheDocs, which I totally missed!