def profile(profiler): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') m = getMapping(imagePath, wcsPath, fastCenterCalculation=True) profiler(_profileLatsLons)(m) profiler(_profileBoundingBox)(m) profiler(_profileMeanResampling)(m)
def profile(profiler): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') m = getMapping(imagePath, wcsPath, fastCenterCalculation=True) profiler(_profileLatsLons)(m) profiler(_profileBoundingBox)(m) profiler(_profileMeanResampling)(m)
def testRawNetCDFExport(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) mapping.checkGuarantees() path = tempfile.mktemp(suffix='.nc') try: auromat.export.netcdf.write(path, mapping) with Dataset(path, 'r') as root: var = root.variables assert set(var.keys()) == set(['time', 'lat', 'lon', 'altitude', 'lat_bounds', 'lon_bounds', 'mlat', 'mlt', 'mlat_bounds', 'mlt_bounds', 'mcrs', 'img_red', 'img_green', 'img_blue', 'zenith_angle', 'camera_pos', 'crs']) cdfmapping = NetCDFMapping(path) cdfmapping.checkGuarantees() check_equal(cdfmapping, mapping) finally: if os.path.exists(path): os.remove(path)
def seq(): for frame in range(102170,102172): wcsPath = getResourcePath('seq3/ISS030-E-%i.wcs' % frame) mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) mapping = mapping.maskedByElevation(10) print('SENDING MAPPING', frame, 'TO COROUTINES') yield mapping
def _getISSMapping(): imagePath = getResourcePath('ISS029-E-8492.jpg') wcsPath = getResourcePath('ISS029-E-8492.wcs') mapping = spacecraft.getMapping(imagePath, wcsPath, fastCenterCalculation=True) return mapping
def testRawNetCDFExport(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) mapping.checkGuarantees() path = tempfile.mktemp(suffix='.nc') try: auromat.export.netcdf.write(path, mapping) with Dataset(path, 'r') as root: var = root.variables assert set(var.keys()) == set([ 'time', 'lat', 'lon', 'altitude', 'lat_bounds', 'lon_bounds', 'mlat', 'mlt', 'mlat_bounds', 'mlt_bounds', 'mcrs', 'img_red', 'img_green', 'img_blue', 'zenith_angle', 'camera_pos', 'crs' ]) cdfmapping = NetCDFMapping(path) cdfmapping.checkGuarantees() check_equal(cdfmapping, mapping) finally: if os.path.exists(path): os.remove(path)
def testParallelsMeridiansPlot(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') m = getMapping(imagePath, wcsPath, altitude=0, fastCenterCalculation=True) figax = loadFigImage(imagePath) drawParallelsAndMeridians(m, figax=figax) drawConstellations(figax, wcsPath, clipPoly=outline(~m.intersectsEarth)) saveFig('test_parallelsmeridians.jpg', figax)
def _testConstellationPlot(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') m = getMapping(imagePath, wcsPath) figax = loadFigImage(imagePath) drawConstellations(figax, wcsPath, clipPoly=outline(~m.intersectsEarth)) saveFig('test_constellations.jpg', figax)
def _getmapping(frame): gc.collect() if frame > 8494: # at this place we only have exactly 1 resampled mapping floating around assert_equal(len(list(filter(lambda o: isinstance(o, BaseMapping), gc.get_objects()))), 1) print('Process memory:', proc.get_memory_info()[0]/1024/1024, 'MB') wcsPath = getResourcePath('seq/ISS029-E-%i.wcs' % frame) mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True, identifier=str(frame)) mapping = mapping.maskedByElevation(10) # save some memory by removing additional data mapping = GenericMapping.fromMapping(mapping) print('SENDING MAPPING', frame, 'TO COROUTINES') return mapping
def testPlateCarreeNetCDFExport(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) mapping = resample(mapping, arcsecPerPx=200) path = tempfile.mktemp(suffix='.nc') try: auromat.export.netcdf.write(path, mapping) cdfmapping = NetCDFMapping(path) cdfmapping.checkGuarantees() cdfmapping.checkPlateCarree() check_equal(cdfmapping, mapping) finally: if os.path.exists(path): os.remove(path)
def testPlateCarreeNetCDFExport(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) mapping = resample(mapping, arcsecPerPx=200) path = tempfile.mktemp(suffix='.nc') try: auromat.export.netcdf.write(path, mapping) cdfmapping = NetCDFMapping(path) cdfmapping.checkGuarantees() cdfmapping.checkPlateCarree() check_equal(cdfmapping, mapping) finally: if os.path.exists(path): os.remove(path)
def get(self, date): idx, offset = self._getIdxWithOffset(date) if offset > self.maxTimeOffset: raise ValueError('No image found') key = list(self.apiImages.keys())[idx] self._downloadFiles(key) wcsPath = self.wcsPaths[key] imagePathOrArray = self._processedImage(key) metadata = dict(list(self.metadata['sequence_metadata'].items()) + list(self.metadata['image_metadata'][key].items())) mapping = getMapping(imagePathOrArray, wcsPath, altitude=self.altitude, fastCenterCalculation=self.fastCenterCalculation, metadata=metadata, identifier=key) return mapping
def _testParallelsMeridiansPlotOptimized(self): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') # As we precalculated the bounding box and the lat/lon label position # we only need to access the 'latCenter', 'lonCenter' and 'intersectsEarth' # attributes of the spacecraft mapping. This means that we don't need # any sanitization applied on the corner coordinate arrays ('lats','lons'). # For this reason, and because we don't use masking, we set nosanitize=True # and can cut the required time in half. m = getMapping(imagePath, wcsPath, altitude=0, fastCenterCalculation=False, nosanitize=True) # the following values must be precalculated to use the optimization # the bounding box at altitude=0 without any masking bb = BoundingBox(latSouth=49.3401757697, lonWest=-116.368770925, latNorth=64.288454984, lonEast=-91.8890098192) # center of bounding box at altitude=0 when masked below 10deg elevation labelLat, labelLon = 53.133, -98.684 figax = loadFigImage(imagePath) drawParallelsAndMeridians(figax, m, boundingBox=bb, labelLat=labelLat, labelLon=labelLon) drawConstellations(figax, wcsPath, clipPoly=outline(~m.intersectsEarth)) saveFig('test_parallelsmeridians_optimized.jpg', figax)
def get(self, date): idx, offset = self._getIdxWithOffset(date) if offset > self.maxTimeOffset: raise ValueError('No image found') key = list(self.apiImages.keys())[idx] self._downloadFiles(key) wcsPath = self.wcsPaths[key] imagePathOrArray = self._processedImage(key) metadata = dict( list(self.metadata['sequence_metadata'].items()) + list(self.metadata['image_metadata'][key].items())) mapping = getMapping(imagePathOrArray, wcsPath, altitude=self.altitude, fastCenterCalculation=self.fastCenterCalculation, metadata=metadata, identifier=key) return mapping
def _getMappingSouth(): imagePath = getResourcePath('ISS029-E-8492.jpg') wcsPath = getResourcePath('ISS029-E-8492.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) return mapping
def _getMapping(): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) return mapping
assert bounds.shape == (arr.shape[0]-1, 2) return bounds def _bounds2d(arr): assert arr.ndim == 2 arr = arr[:,:,None] bounds = np.concatenate(( arr[0:-1, 0:-1], arr[0:-1, 1: ], arr[1: , 1: ], arr[1: , 0:-1], ), axis=2) assert bounds.shape == (arr.shape[0]-1, arr.shape[1]-1, 4) return bounds def _unix(dt): return (dt - datetime(1970, 1, 1)).total_seconds() if __name__ == '__main__': import os from auromat.mapping.spacecraft import getMapping m = getMapping('/home/mriecher/data/arrrgh/img/ISS030-E/102100/ISS030-E-102170.jpg', '/home/mriecher/data/arrrgh/wcs/ISS030-E/102100/ISS030-E-102170_1727.wcs') path = '/user_data/mriecher/test.nc' if os.path.exists(path): os.remove(path) write(path, m, includeBounds=True, includeMagCoords=True, zlib=True)
def _getMappingNorth(): imagePath = getResourcePath('ISS030-E-102170_dc.jpg') wcsPath = getResourcePath('ISS030-E-102170_dc.wcs') mapping = getMapping(imagePath, wcsPath, fastCenterCalculation=True) return mapping