-
-
Notifications
You must be signed in to change notification settings - Fork 425
Euclid: upgrade the TAP method upload_table to upload tables in fits format #3295
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
Merged
bsipocz
merged 12 commits into
astropy:main
from
esdc-esac-esa-int:ESA_euclid_EUCLIDPCR-1971_upload_user_table_from_fits_file
Apr 22, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
6ceee04
EUCLIDPCR-1971 Unable to upload user table from fits file
1d8f999
EUCLIDPCR-1971 Update documentation
0e6c08b
EUCLIDPCR-1971 New tests
aacf3a2
EUCLIDPCR-1971 Update documentation for method upload_table
9b4b0f9
EUCLIDPCR-1971 reformat file
be08e62
EUCLIDPCR-1971 Update content of the file
05bd99f
EUCLIDPCR-1971 Update list of files in get_package_data
3e488cd
EUCLIDPCR-1971 Increase coverage
4ea0d9e
EUCLIDPCR-1971 Changed suggested in the PR: the astropy Table.read ma…
428b2a1
EUCLIDPCR-1971 Clean up unused parameters
ac60204
EUCLIDPCR-1971 Include PR reference
868c135
top of 13d9fda2b4a5e27fb46764ea608d0b1db239bc53
bsipocz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,12 @@ | |
| """ | ||
| import getpass | ||
| import os | ||
| import requests | ||
| import tempfile | ||
| from astropy.table.table import Table | ||
| from urllib.parse import urlencode | ||
|
|
||
| import requests | ||
| from astropy.table.table import Table | ||
|
|
||
| from astroquery import log | ||
| from astroquery.utils.tap import taputils | ||
| from astroquery.utils.tap.conn.tapconn import TapConn | ||
|
|
@@ -1341,8 +1342,9 @@ def upload_table(self, *, upload_resource=None, table_name=None, table_descripti | |
| resource temporary table name associated to the uploaded resource | ||
| table_description : str, optional, default None | ||
| table description | ||
| format : str, optional, default 'VOTable' | ||
| resource format | ||
| format : str, optional, default 'votable' | ||
| resource format. Only formats described in | ||
| https://docs.astropy.org/en/stable/io/unified.html#built-in-table-readers-writers are accepted. | ||
| verbose : bool, optional, default 'False' | ||
| flag to display information about the process | ||
| """ | ||
|
|
@@ -1381,9 +1383,7 @@ def upload_table(self, *, upload_resource=None, table_name=None, table_descripti | |
| log.info(f"Uploaded table '{table_name}'.") | ||
| return None | ||
|
|
||
| def __uploadTableMultipart(self, resource, *, table_name=None, | ||
| table_description=None, | ||
| resource_format="VOTable", | ||
| def __uploadTableMultipart(self, resource, *, table_name=None, table_description=None, resource_format="votable", | ||
| verbose=False): | ||
| connHandler = self.__getconnhandler() | ||
| if isinstance(resource, Table): | ||
|
|
@@ -1397,24 +1397,38 @@ def __uploadTableMultipart(self, resource, *, table_name=None, | |
| fh = tempfile.NamedTemporaryFile(delete=False) | ||
| resource.write(fh, format='votable') | ||
| fh.close() | ||
| f = open(fh.name, "r") | ||
| chunk = f.read() | ||
| f.close() | ||
|
|
||
| with open(fh.name, "r") as f: | ||
| chunk = f.read() | ||
|
|
||
| os.unlink(fh.name) | ||
| files = [['FILE', 'pytable', chunk]] | ||
| contentType, body = connHandler.encode_multipart(args, files) | ||
| content_type, body = connHandler.encode_multipart(args, files) | ||
| else: | ||
| if not (str(resource).startswith("http")): # upload from file | ||
| args = { | ||
| "TASKID": str(-1), | ||
| "TABLE_NAME": str(table_name), | ||
| "TABLE_DESC": str(table_description), | ||
| "FORMAT": str(resource_format)} | ||
| "FORMAT": 'votable'} | ||
|
Comment on lines
-1412
to
+1413
Member
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. Can we start adding tests that reaches the server? While the changes in this PR look good I have the sense that the previous version might not have worked as intended. |
||
| log.info(f"Sending file: {resource}") | ||
| with open(resource, "r") as f: | ||
| chunk = f.read() | ||
| files = [['FILE', os.path.basename(resource), chunk]] | ||
| contentType, body = connHandler.encode_multipart(args, files) | ||
| if resource_format.lower() == 'votable': | ||
| with open(resource, "r") as f: | ||
| chunk = f.read() | ||
| files = [['FILE', os.path.basename(resource), chunk]] | ||
| else: | ||
| table = Table.read(str(resource), format=resource_format) | ||
| fh = tempfile.NamedTemporaryFile(delete=False) | ||
| table.write(fh, format='votable') | ||
| fh.close() | ||
|
|
||
| with open(fh.name, "r") as f: | ||
| chunk = f.read() | ||
|
|
||
| os.unlink(fh.name) | ||
| files = [['FILE', 'pytable', chunk]] | ||
|
|
||
| content_type, body = connHandler.encode_multipart(args, files) | ||
| else: # upload from URL | ||
| args = { | ||
| "TASKID": str(-1), | ||
|
|
@@ -1423,8 +1437,8 @@ def __uploadTableMultipart(self, resource, *, table_name=None, | |
| "FORMAT": str(resource_format), | ||
| "URL": str(resource)} | ||
| files = [['FILE', "", ""]] | ||
| contentType, body = connHandler.encode_multipart(args, files) | ||
| response = connHandler.execute_upload(body, contentType) | ||
| content_type, body = connHandler.encode_multipart(args, files) | ||
| response = connHandler.execute_upload(body, content_type) | ||
| if verbose: | ||
| print(response.status, response.reason) | ||
| print(response.getheaders()) | ||
|
|
||
3 changes: 3 additions & 0 deletions
3
astroquery/utils/tap/tests/data/test_upload_file/1744351221317O-result.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| source_id,ra,dec | ||
| 3834447128563320320,149.8678677871318,1.12773018116361 | ||
| 3834447162923057280,149.8953864417848,1.1345712682426434 |
41 changes: 41 additions & 0 deletions
41
astroquery/utils/tap/tests/data/test_upload_file/1744351221317O-result.ecsv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # %ECSV 1.0 | ||
| # --- | ||
| # delimiter: ',' | ||
| # datatype: | ||
| # - | ||
| # name: source_id | ||
| # datatype: int64 | ||
| # description: Unique source identifier (unique within a particular Data Release) | ||
| # meta: | ||
| # ucd: meta.id | ||
| # - | ||
| # name: ra | ||
| # datatype: float64 | ||
| # unit: deg | ||
| # description: Right ascension | ||
| # meta: | ||
| # ucd: pos.eq.ra;meta.main | ||
| # utype: stc:AstroCoords.Position3D.Value3.C1 | ||
| # CoosysSystem: ICRS | ||
| # CoosysEpoch: J2016.0 | ||
| # - | ||
| # name: dec | ||
| # datatype: float64 | ||
| # unit: deg | ||
| # description: Declination | ||
| # meta: | ||
| # ucd: pos.eq.dec;meta.main | ||
| # utype: stc:AstroCoords.Position3D.Value3.C2 | ||
| # CoosysSystem: ICRS | ||
| # CoosysEpoch: J2016.0 | ||
| # meta: | ||
| # name: votable | ||
| # QUERY_STATUS: OK | ||
| # QUERY: 'SELECT TOP 2 source_id, ra, dec FROM gaiadr3.gaia_source ' | ||
| # CAPTION: 'How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html' | ||
| # CITATION: 'How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html' | ||
| # JOBID: 1744351221317O | ||
| # RELEASE: Gaia DR3 | ||
| source_id,ra,dec | ||
| 3834447128563320320,149.8678677871318,1.12773018116361 | ||
| 3834447162923057280,149.8953864417848,1.1345712682426434 |
Binary file added
BIN
+8.44 KB
astroquery/utils/tap/tests/data/test_upload_file/1744351221317O-result.fits
Binary file not shown.
95 changes: 95 additions & 0 deletions
95
astroquery/utils/tap/tests/data/test_upload_file/1744351221317O-result.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| { | ||
| "VOTABLE": { | ||
| "RESOURCE": { | ||
| "INFO": [ | ||
| { | ||
| "_name": "QUERY_STATUS", | ||
| "_value": "OK" | ||
| }, | ||
| { | ||
| "_name": "QUERY", | ||
| "_value": "SELECT TOP 20 * FROM user_jferna01.my_votable_fits ", | ||
| "__cdata": "SELECT TOP 20 *\nFROM user_jferna01.my_votable_fits " | ||
| }, | ||
| { | ||
| "_name": "CAPTION", | ||
| "_value": "How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html", | ||
| "__cdata": "How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html" | ||
| }, | ||
| { | ||
| "_name": "CITATION", | ||
| "_value": "How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html", | ||
| "_ucd": "meta.bib", | ||
| "__cdata": "How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html" | ||
| }, | ||
| { | ||
| "_name": "PAGE", | ||
| "_value": "" | ||
| }, | ||
| { | ||
| "_name": "PAGE_SIZE", | ||
| "_value": "" | ||
| }, | ||
| { | ||
| "_name": "JOBID", | ||
| "_value": "1744360074103O", | ||
| "__cdata": "1744360074103O" | ||
| }, | ||
| { | ||
| "_name": "JOBNAME", | ||
| "_value": "" | ||
| } | ||
| ], | ||
| "TABLE": { | ||
| "FIELD": [ | ||
| { | ||
| "DESCRIPTION": "Object Identifier", | ||
| "_datatype": "int", | ||
| "_name": "my_votable_fits_oid" | ||
| }, | ||
| { | ||
| "_datatype": "long", | ||
| "_name": "source_id" | ||
| }, | ||
| { | ||
| "_datatype": "double", | ||
| "_name": "ra", | ||
| "_unit": "deg" | ||
| }, | ||
| { | ||
| "_datatype": "double", | ||
| "_name": "dec", | ||
| "_unit": "deg" | ||
| } | ||
| ], | ||
| "DATA": { | ||
| "TABLEDATA": { | ||
| "TR": [ | ||
| { | ||
| "TD": [ | ||
| "1", | ||
| "3834447128563320320", | ||
| "149.8678677871318", | ||
| "1.12773018116361" | ||
| ] | ||
| }, | ||
| { | ||
| "TD": [ | ||
| "2", | ||
| "3834447162923057280", | ||
| "149.8953864417848", | ||
| "1.1345712682426434" | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| } | ||
| }, | ||
| "_type": "results" | ||
| }, | ||
| "_version": "1.4", | ||
| "_xmlns": "http://www.ivoa.net/xml/VOTable/v1.3", | ||
| "_xmlns:xsi": "http://www.w3.org/2001/XMLSchema-instance", | ||
| "_xsi:schemaLocation": "http://www.ivoa.net/xml/VOTable/v1.3 http://www.ivoa.net/xml/VOTable/votable-1.4.xsd" | ||
| } | ||
| } |
33 changes: 33 additions & 0 deletions
33
astroquery/utils/tap/tests/data/test_upload_file/1744351221317O-result.vot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ivoa.net/xml/VOTable/v1.3 http://www.ivoa.net/xml/VOTable/votable-1.4.xsd"> | ||
| <RESOURCE type="results"> | ||
| <INFO name="QUERY_STATUS" value="OK"/> | ||
|
|
||
| <INFO name="QUERY" value="SELECT TOP 20 * | ||
| FROM user_jferna01.my_votable_fits "><![CDATA[SELECT TOP 20 * | ||
| FROM user_jferna01.my_votable_fits ]]></INFO> | ||
| <INFO name="CAPTION" value="How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html"><![CDATA[How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html]]></INFO> | ||
| <INFO name="CITATION" value="How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html" ucd="meta.bib"><![CDATA[How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html]]></INFO> | ||
| <INFO name="PAGE" value=""/> | ||
| <INFO name="PAGE_SIZE" value=""/> | ||
| <INFO name="JOBID" value="1744360074103O"><![CDATA[1744360074103O]]></INFO> | ||
| <INFO name="JOBNAME" value=""></INFO> | ||
|
|
||
| <TABLE> | ||
| <FIELD datatype="int" name="my_votable_fits_oid"> | ||
| <DESCRIPTION>Object Identifier</DESCRIPTION> | ||
| </FIELD> | ||
| <FIELD datatype="long" name="source_id"/> | ||
| <FIELD datatype="double" name="ra" unit="deg"/> | ||
| <FIELD datatype="double" name="dec" unit="deg"/> | ||
| <DATA> | ||
| <BINARY2> | ||
| <STREAM encoding='base64'> | ||
| AAAAAAE1NrFZAAiGAEBiu8WSql90P/ILLs1s9TAAAAAAAjU2sWEACICAQGK8pwF3 | ||
| l+w/8ic0M8FVmA== | ||
| </STREAM> | ||
| </BINARY2> | ||
| </DATA> | ||
| </TABLE> | ||
| </RESOURCE> | ||
| </VOTABLE> |
31 changes: 31 additions & 0 deletions
31
astroquery/utils/tap/tests/data/test_upload_file/1744351221317O-result_plain.vot
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <VOTABLE version="1.4" xmlns="http://www.ivoa.net/xml/VOTable/v1.3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.ivoa.net/xml/VOTable/v1.3 http://www.ivoa.net/xml/VOTable/votable-1.4.xsd"> | ||
| <RESOURCE type="results"> | ||
| <INFO name="QUERY_STATUS" value="OK"/> | ||
|
|
||
| <INFO name="QUERY" value="SELECT TOP 20 * FROM user_jferna01.my_votable_fits "><![CDATA[SELECT TOP 20 * | ||
| FROM user_jferna01.my_votable_fits ]]></INFO> | ||
| <INFO name="CAPTION" value="How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html"><![CDATA[How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html]]></INFO> | ||
| <INFO name="CITATION" value="How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html" ucd="meta.bib"><![CDATA[How to cite and acknowledge Gaia: https://gea.esac.esa.int/archive/documentation/credits.html]]></INFO> | ||
| <INFO name="PAGE" value=""/> | ||
| <INFO name="PAGE_SIZE" value=""/> | ||
| <INFO name="JOBID" value="1744360074103O"><![CDATA[1744360074103O]]></INFO> | ||
| <INFO name="JOBNAME" value=""/> | ||
|
|
||
| <TABLE> | ||
| <FIELD datatype="int" name="my_votable_fits_oid"> | ||
| <DESCRIPTION>Object Identifier</DESCRIPTION> | ||
| </FIELD> | ||
| <FIELD datatype="long" name="source_id"/> | ||
| <FIELD datatype="double" name="ra" unit="deg"/> | ||
| <FIELD datatype="double" name="dec" unit="deg"/> | ||
| <DATA> | ||
| <TABLEDATA> | ||
| <TR><TD>1</TD><TD>3834447128563320320</TD><TD>149.8678677871318</TD><TD>1.12773018116361</TD></TR> | ||
| <TR><TD>2</TD><TD>3834447162923057280</TD><TD>149.8953864417848</TD><TD>1.1345712682426434</TD></TR> | ||
| </TABLEDATA> | ||
| </DATA> | ||
|
|
||
| </TABLE> | ||
| </RESOURCE> | ||
| </VOTABLE> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not a big deal as this is all private, but resource_format is kind of ignored in a few cases, and is contradictory with resource.