def get_ramon(self, token, channel, anno_id, resolution, metadata_only=False): """ Download a RAMON object by ID. Arguments: token (str): Project to use channel (str): The channel to use anno_id (int, str): The ID of a RAMON object to gather. Coerced str resolution (int): Resolution (if not working, try a higher num) metadata_only (bool): True = returns `get_ramon_metadata` instead Returns: ndio.ramon.RAMON Raises: RemoteDataNotFoundError: If the requested anno_id cannot be found. """ if metadata_only: return self.get_ramon_metadata(token, channel, anno_id) # Download the data itself req = requests.get(self.url() + "{}/{}/{}/cutout/{}".format(token, channel, anno_id, resolution)) if req.status_code is not 200: raise RemoteDataNotFoundError("No data for id {}.".format(anno_id)) else: with tempfile.NamedTemporaryFile() as tmpfile: tmpfile.write(req.content) tmpfile.seek(0) h5file = h5py.File(tmpfile.name, "r") r = ramon.hdf5_to_ramon(h5file) return r
def _get_single_ramon_metadata(self, token, channel, anno_id): req = requests.get(self.url() + "{}/{}/{}/nodata/".format(token, channel, anno_id)) if req.status_code is not 200: raise RemoteDataNotFoundError('No data for id {}.'.format(anno_id)) else: with tempfile.NamedTemporaryFile() as tmpfile: tmpfile.write(req.content) tmpfile.seek(0) h5file = h5py.File(tmpfile.name, "r") r = ramon.hdf5_to_ramon(h5file) return r