Skip to content

Commit

Permalink
Use HipsSurveyProperties to write the properties file
Browse files Browse the repository at this point in the history
  • Loading branch information
adonath committed Jul 4, 2018
1 parent d0ada76 commit 674e3e6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
18 changes: 9 additions & 9 deletions hips/draw/healpix.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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')
3 changes: 3 additions & 0 deletions hips/draw/tests/test_healpix.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
24 changes: 24 additions & 0 deletions hips/tiles/survey.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 674e3e6

Please sign in to comment.