Skip to content

Commit

Permalink
Merge pull request #3130 from esdc-esac-esa-int/ESA_gaia_GAIAMNGT-170…
Browse files Browse the repository at this point in the history
…0_load_data

Gaia: update the output file name built by the method load_data to include microsecond resolution
  • Loading branch information
bsipocz authored Nov 11, 2024
2 parents e150df1 + ce16157 commit 5639442
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ gaia

- New retrieval types for datalink (Gaia DR4 release). [#3110]

- The output file name built by the method load_data, includes microsecond resolution. This is based on the previous PR [#3014]. [#3130]


jplhorizons
^^^^^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions astroquery/gaia/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr
dump_to_file: boolean, optional, default False.
If it is true, a compressed directory named "datalink_output_<time_stamp>.zip" with all the DataLink
files is made in the current working directory. The <time_stamp> format follows the ISO 8601 standard:
"yyyymmddThhmmss".
"YYYYMMDD_HHMMSS.mmmmmm".
overwrite_output_file : boolean, optional, default False
To overwrite the output file ("datalink_output.zip") if it already exists.
verbose : bool, optional, default 'False'
Expand All @@ -239,13 +239,13 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr

now = datetime.datetime.now(datetime.timezone.utc)
if not dump_to_file:
now_formatted = now.strftime("%Y%m%d_%H%M%S")
now_formatted = now.strftime("%Y%m%d_%H%M%S.%f")
temp_dirname = "temp_" + now_formatted
downloadname_formated = "download_" + now_formatted
output_file = os.path.join(os.getcwd(), temp_dirname, downloadname_formated)

else:
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'
output_file_specified = True
output_file = os.path.abspath(output_file)
log.info(f"DataLink products will be stored in the {output_file} file")
Expand All @@ -258,7 +258,7 @@ def load_data(self, ids, *, data_release=None, data_structure='INDIVIDUAL', retr

log.debug(f"Directory where the data will be saved: {path}")

if path != '':
if path:
if not os.path.isdir(path):
try:
os.mkdir(path)
Expand Down
37 changes: 26 additions & 11 deletions astroquery/gaia/tests/test_gaiatap.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
RADIUS = 1 * u.deg
SKYCOORD = SkyCoord(ra=19 * u.deg, dec=20 * u.deg, frame="icrs")

FAKE_TIME = datetime.datetime(2024, 1, 1, 0, 0, 59)
FAKE_TIME = datetime.datetime(2024, 1, 1, 0, 0, 59, 1)


@pytest.fixture
Expand Down Expand Up @@ -999,9 +999,12 @@ def test_datalink_querier_load_data_fits(mock_datalink_querier_fits):
assert not os.path.exists(datalink_output)


def test_load_data_vot(monkeypatch, tmp_path, tmp_path_factory):
def test_load_data_vot(monkeypatch, tmp_path, tmp_path_factory, patch_datetime_now):

assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME

now = datetime.datetime.now(datetime.timezone.utc)
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'

path = Path(os.getcwd(), output_file)

Expand Down Expand Up @@ -1076,9 +1079,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
path.unlink()


def test_load_data_csv(monkeypatch, tmp_path, tmp_path_factory):
def test_load_data_csv(monkeypatch, tmp_path, tmp_path_factory, patch_datetime_now):

assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME

now = datetime.datetime.now(datetime.timezone.utc)
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'

path = Path(os.getcwd(), output_file)

Expand Down Expand Up @@ -1112,9 +1118,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
path.unlink()


def test_load_data_ecsv(monkeypatch, tmp_path, tmp_path_factory):
def test_load_data_ecsv(monkeypatch, tmp_path, tmp_path_factory, patch_datetime_now):

assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME

now = datetime.datetime.now(datetime.timezone.utc)
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'

path = Path(os.getcwd(), output_file)

Expand Down Expand Up @@ -1148,9 +1157,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):
path.unlink()


def test_load_data_linking_parameter(monkeypatch, tmp_path):
def test_load_data_linking_parameter(monkeypatch, tmp_path, patch_datetime_now):

assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME

now = datetime.datetime.now(datetime.timezone.utc)
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'

path = Path(os.getcwd(), output_file)

Expand Down Expand Up @@ -1185,9 +1197,12 @@ def load_data_monkeypatched(self, params_dict, output_file, verbose):


@pytest.mark.parametrize("linking_param", ['TRANSIT_ID', 'IMAGE_ID'])
def test_load_data_linking_parameter_with_values(monkeypatch, tmp_path, linking_param):
def test_load_data_linking_parameter_with_values(monkeypatch, tmp_path, linking_param, patch_datetime_now):

assert datetime.datetime.now(datetime.timezone.utc) == FAKE_TIME

now = datetime.datetime.now(datetime.timezone.utc)
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S") + '.zip'
output_file = 'datalink_output_' + now.strftime("%Y%m%dT%H%M%S.%f") + '.zip'

path = Path(os.getcwd(), output_file)

Expand Down

0 comments on commit 5639442

Please sign in to comment.