diff --git a/hips/draw/healpix.py b/hips/draw/healpix.py index 6602fe4..b74dc64 100644 --- a/hips/draw/healpix.py +++ b/hips/draw/healpix.py @@ -1,8 +1,9 @@ # Licensed under a 3-clause BSD style license - see LICENSE.rst from pathlib import Path +from collections import OrderedDict import numpy as np from astropy_healpix import healpy as hp -from ..tiles import HipsTile, HipsTileMeta +from ..tiles import HipsTile, HipsTileMeta, HipsSurveyProperties from ..utils.healpix import hips_tile_healpix_ipix_array @@ -76,12 +77,11 @@ def healpix_to_hips(hpx_data, tile_width, base_path, file_format='fits'): filename.parent.mkdir(exist_ok=True, parents=True) tile.write(filename=filename) - # Write a minimal property file - properties = f""" - hips_tile_format = {file_format} - hips_tile_width = {tile_width} - hips_frame = {tile.meta.frame} - """ - with (base_path / 'properties').open('w') as f: - f.write(properties) + data = OrderedDict() + data['hips_tile_format'] = file_format + data['hips_tile_width'] = tile_width + data['hips_frame'] = tile.meta.frame + + properties = HipsSurveyProperties(data=data) + properties.write(base_path / 'properties') diff --git a/hips/draw/tests/test_healpix.py b/hips/draw/tests/test_healpix.py index 9d8c548..67f3bd1 100644 --- a/hips/draw/tests/test_healpix.py +++ b/hips/draw/tests/test_healpix.py @@ -32,3 +32,6 @@ def test_healpix_to_hips(tmpdir, file_format): data = np.array(Image.open(filename)) data = data.T assert_allclose(val, data) + + properties = (tmpdir / 'properties').read_text(encoding=None) + assert file_format in properties diff --git a/hips/tiles/survey.py b/hips/tiles/survey.py index 88ef3ce..06ef36e 100644 --- a/hips/tiles/survey.py +++ b/hips/tiles/survey.py @@ -2,6 +2,7 @@ from collections import OrderedDict from io import StringIO from csv import DictWriter +from pathlib import Path import urllib.request from typing import List, Union from astropy.table import Table @@ -178,6 +179,29 @@ def tile_url(self, tile_meta: HipsTileMeta) -> str: """Tile URL on the server (str).""" return self.base_url + '/' + tile_meta.tile_default_url + def to_string(self): + """Convert properties to string""" + properties = '' + for key, value in self.data.items(): + line = f'{key} = {value}\n' + properties += line + + return properties + + def write(self, path): + """ + Write properties to text file. + + Parameters + ---------- + path : str or `~pathlib.Path` + Base path where to write the properties file. + """ + text = self.to_string() + Path(path).write_text(text) + + + class HipsSurveyPropertiesList: """HiPS survey properties list.