import h5py
import numpy
from gavo.utils import pyfits

hdus = pyfits.open("data/ROME-FIELD-01_field_crossmatch.fits")
cur_data = hdus[1].data
object_index = numpy.logical_and(
	numpy.logical_and(
		cur_data["quadrant_id"]<70005,
		cur_data["quadrant_id"]>70000),
	cur_data["quadrant"]==1)
hdus[1].data = hdus[1].data[object_index]
hdus[3].data = hdus[3].data[object_index]
# we don't do anything with STAMPS yet, so let's drop it
del hdus[5]
hdus.writeto("ROME-FIELD-01_field_crossmatch.fits")

# now pick the photometry points, which are in quadrant_id arrays.
# We need special test instrumentation because indexes change with this,
# but we don't want the full stupid photometry on the test system
indexes = hdus[1].data["quadrant_id"]
srchdf = h5py.File("data/ROME-FIELD-01_quad1_photometry.hdf5")
desthdf = h5py.File("ROME-FIELD-01_quad1_photometry.hdf5", "w")
for colName, col in srchdf.items():
	desthdf.create_dataset(colName, data=col[indexes])
desthdf.close()
