def getADDEImage(localEntry=None, server=None, dataset=None, descriptor=None, accounting=DEFAULT_ACCOUNTING, location=None, coordinateSystem=CoordinateSystems.LATLON, place=Places.CENTER, mag=(1, 1), position=0, unit='BRIT', day=None, time=None, debug=False, track=False, band=None, size=DEFAULT_SIZE, showUrls=True, **kwargs): """Requests data from an ADDE Image server - returns both data and metadata objects. An ADDE request must include values for either localEntry or the combination of server, dataset and descriptor. ***Note to users: testADDEImage is test code, some of which may be used to improve the getADDEImage function in the future. It will not be included in future versions so should not be used in user scripts. Required Args: localEntry: Local data set defined by makeLocalADDEEntry. server: ADDE server. dataset: ADDE dataset group name. descriptor: ADDE dataset descriptor. Optional Args: day: Day range ('begin date','end date') time: ('begin time', 'end time') coordinateSystem: coordinate system to use for retrieving data AREA AREA file coordinates - zero based LATLON latitude and longitude coordinates IMAGE image coordinates - one based location: (x,y) x AREA line, latitude, or IMAGE line y AREA element, longitude, or IMAGE element place: CENTER places specified location (x,y) at center of panel ULEFT places specified location (x,y) at upper-left coordinate of panel band: McIDAS band number; must be specified if requesting data from multi-banded image; default=band in image unit: calibration unit to request; default = 'BRIT' position: time relative (negative values) or absolute (positive values) position in the dataset; default=0 (most recent image) size: number of lines and elements to request; default=(480,640) mag: magnification of data (line,element), negative number used for sampling data; default=(1,1) accounting: ('user', 'project number') user and project number required by servers using McIDAS accounting; default = ('idv','0') debug: send debug information to file; default=False track: default=False. """ if localEntry: server = localEntry.getAddress() dataset = localEntry.getGroup() descriptor = localEntry.getDescriptor().upper() elif (server is None) or (dataset is None) or (descriptor is None): raise TypeError("must provide localEntry or server, dataset, and descriptor values.") if server == "localhost" or server == "127.0.0.1": port = EntryStore.getLocalPort() else: port = "112" # server = '%s:%s' % (server, port) # still need to handle dates+times # todo: don't break! user = accounting[0] proj = accounting[1] debug = str(debug).lower() mag = '%s %s' % (mag[0], mag[1]) if place is Places.CENTER: place = 'CENTER' elif place is Places.ULEFT: place = 'ULEFT' else: raise ValueError() if coordinateSystem is CoordinateSystems.LATLON: coordSys = 'LATLON' coordType = 'E' elif coordinateSystem is CoordinateSystems.AREA: coordSys = 'LINELE' coordType = 'A' elif coordinateSystem is CoordinateSystems.IMAGE: coordSys = 'LINELE' coordType = 'I' else: raise ValueError() if location: location = '&%s=%s %s %s' % (coordSys, location[0], location[1], coordType) else: location = '' if day: if isinstance(day, tuple): day = '&DAY=%s %s' % (day[0], day[1]) else: day = '&DAY=%s %s' % (day, day) else: day = '' if size: if size == 'ALL': size = '&SIZE=99999 99999' else: size = '&SIZE=%s %s' % (size[0], size[1]) else: size = '' if time: if isinstance(time, (str, unicode, String)): time = '%s %s I' % (str(time), str(time)) elif len(time) == 2: time = '%s %s I' % (str(time[0]), str(time[1])) else: raise ValueError("could not understand the given time value: %s" % (time)) else: time = '' if band: try: band = int(band) band = '&BAND=%s' % (str(band)) except: raise ValueError("band must be a single integer value; could not convert '%s' to an integer." % (band)) else: band = '' addeUrlFormat = "adde://%(server)s/imagedata?&PORT=%(port)s&COMPRESS=gzip&USER=%(user)s&PROJ=%(proj)s&VERSION=1&DEBUG=%(debug)s&TRACE=0&GROUP=%(dataset)s&DESCRIPTOR=%(descriptor)s%(band)s%(location)s&PLACE=%(place)s%(size)s&UNIT=%(unit)s&MAG=%(mag)s&SPAC=4&NAV=X&AUX=YES&DOC=X%(day)s&TIME=%(time)s&POS=%(position)s&TRACK=%(track)d" formatValues = { 'server': server, 'port': port, 'user': user, 'proj': proj, 'debug': debug, 'dataset': dataset, 'descriptor': descriptor, 'band': band, 'location': location, 'place': place, 'size': size, 'unit': unit, 'mag': mag, 'day': day, 'time': time, 'position': position, 'track': track, } url = addeUrlFormat % formatValues if showUrls: print url # build an object that returns the SATBAND file. satBandRequest = _SatBandReq(_satBandUrl(**formatValues)) # submit the request futureSatband = ecs.submit(satBandRequest) try: mapped = _MappedAreaImageFlatField.fromUrl(url) # the commented code will immediately attempt to grab the SATBAND file; # the uncommented code *should* be lazy-loaded. # mapped.addeSatBands = futureSatband.get() mapped.addeSatBands = futureSatband return mapped.getDictionary(), mapped except AreaFileException, e: raise AddeJythonError(e)
def listADDEImageTimes(localEntry=None, server=None, dataset=None, descriptor=None, accounting=DEFAULT_ACCOUNTING, location=None, coordinateSystem=CoordinateSystems.LATLON, place=None, mag=None, position=None, unit=None, day=None, time=None, debug=False, band=None, size=None, showUrls=True): if localEntry: server = localEntry.getAddress() dataset = localEntry.getGroup() descriptor = localEntry.getDescriptor().upper() elif (server is None) or (dataset is None) or (descriptor is None): raise TypeError("must provide localEntry or server, dataset, and descriptor values.") if server == "localhost" or server == "127.0.0.1": port = EntryStore.getLocalPort() else: port = "112" # server = '%s:%s' % (server, port) user = accounting[0] proj = accounting[1] debug = str(debug).lower() if mag: mag = '&MAG=%s %s' % (mag[0], mag[1]) else: mag = '' if unit: origUnit = unit unit = '&UNIT=%s' % (unit) else: # origUnit = None unit = '' if place is Places.CENTER: place = '&PLACE=CENTER' elif place is Places.ULEFT: place = '&PLACE=ULEFT' else: # raise ValueError() place = '' if coordinateSystem is CoordinateSystems.LATLON: coordSys = 'LATLON' elif coordinateSystem is CoordinateSystems.AREA or coordinateSystem is CoordinateSystems.IMAGE: coordSys = 'LINELE' else: raise ValueError() if location: location = '&%s=%s %s' % (coordSys, location[0], location[1]) else: location = '' if size: if size == 'ALL': size = '&SIZE=99999 99999' else: size = '&SIZE=%s %s' % (size[0], size[1]) else: size = '' if time: time = '&TIME=%s %s I' % (time[0], time[1]) else: time = '' if band: band = '&BAND=%s' % (str(band)) else: band = '&BAND=ALL' if position is not None: if isinstance(position, int): position = '&POS=%s' % (position) elif isinstance(position, tuple): if len(position) != 2: raise ValueError('position range may only contain values for the beginning and end of a range.') position = '&POS=%s %s' % (str(position[0]), str(position[1])) else: position = '&POS=%s' % (str(position).upper()) else: position = '&POS=0' tz = TimeZone.getTimeZone('Z') dateFormat = SimpleDateFormat() dateFormat.setTimeZone(tz) dateFormat.applyPattern('yyyyDDD') timeFormat = SimpleDateFormat(); timeFormat.setTimeZone(tz) timeFormat.applyPattern('HH:mm:ss') addeUrlFormat = "adde://%(server)s/imagedirectory?&PORT=%(port)s&COMPRESS=gzip&USER=%(user)s&PROJ=%(proj)s&VERSION=1&DEBUG=%(debug)s&TRACE=0&GROUP=%(dataset)s&DESCRIPTOR=%(descriptor)s%(band)s%(location)s%(place)s%(size)s%(unit)s%(mag)s%(day)s%(time)s%(position)s" urls = [] areaDirectories = [] dates = _normalizeDates(day) for date in dates: formatValues = { 'server': server, 'port': port, 'user': user, 'proj': proj, 'debug': debug, 'dataset': dataset, 'descriptor': descriptor, 'band': band, 'location': location, 'place': place, 'size': size, 'unit': unit, 'mag': mag, 'day': date, 'time': time, 'position': position, } url = addeUrlFormat % formatValues if showUrls: print url adl = AreaDirectoryList(url) results = adl.getSortedDirs() for imageTimes in results: for areaDirectory in imageTimes: urls.append(url) areaDirectories.append(areaDirectory) uniques = set() times = [] for d in areaDirectories: dt = DateTime(d.getNominalTime()) if dt not in uniques: d = { 'day': str(dt.formattedString('yyyyDDD', tz)), 'time': str(dt.formattedString('HH:mm:ss', tz)), } times.append(d) uniques.add(dt) uniques = None return sorted(times)
def listADDEImages(localEntry=None, server=None, dataset=None, descriptor=None, accounting=DEFAULT_ACCOUNTING, location=None, coordinateSystem=CoordinateSystems.LATLON, place=None, mag=None, position=None, unit=None, day=None, time=None, debug=False, band=None, size=None, showUrls=True): """Creates a list of ADDE images. Args: localEntry: Local ADDE dataset. server: ADDE server. dataset: ADDE dataset group name. descriptor: ADDE dataset descriptor. day: Day range. ('begin date', 'end date') time: ('begin time', 'end time') position: Position number. Values may be integers or the string "ALL". (default=0) band: McIDAS band number; only images that have matching band number will be returned. accounting: ('user', 'project number') User and project number required by servers using McIDAS accounting. default = ('idv','0') Returns: ADDE image matching the given criteria, if any. """ if localEntry: server = localEntry.getAddress() dataset = localEntry.getGroup() descriptor = localEntry.getDescriptor().upper() elif (server is None) or (dataset is None) or (descriptor is None): raise TypeError("must provide localEntry or server, dataset, and descriptor values.") if server == "localhost" or server == "127.0.0.1": port = EntryStore.getLocalPort() else: port = "112" # server = '%s:%s' % (server, port) user = accounting[0] proj = accounting[1] debug = str(debug).lower() if mag: mag = '&MAG=%s %s' % (mag[0], mag[1]) else: mag = '' if unit: origUnit = unit unit = '&UNIT=%s' % (unit) else: # origUnit = None unit = '' if place is Places.CENTER: place = '&PLACE=CENTER' elif place is Places.ULEFT: place = '&PLACE=ULEFT' else: # raise ValueError() place = '' if coordinateSystem is CoordinateSystems.LATLON: coordSys = 'LATLON' elif coordinateSystem is CoordinateSystems.AREA or coordinateSystem is CoordinateSystems.IMAGE: coordSys = 'LINELE' else: raise ValueError() if location: location = '&%s=%s %s' % (coordSys, location[0], location[1]) else: location = '' if size: if size == 'ALL': size = '&SIZE=99999 99999' else: size = '&SIZE=%s %s' % (size[0], size[1]) else: size = '' if time: time = '&TIME=%s %s I' % (time[0], time[1]) else: time = '' if band: band = '&BAND=%s' % (str(band)) else: band = '&BAND=ALL' if position is not None: if isinstance(position, int): position = '&POS=%s' % (position) elif isinstance(position, tuple): if len(position) != 2: raise ValueError('position range may only contain values for the beginning and end of a range.') position = '&POS=%s %s' % (str(position[0]), str(position[1])) else: position = '&POS=%s' % (str(position).upper()) else: position = '&POS=0' tz = TimeZone.getTimeZone('Z') dateFormat = SimpleDateFormat() dateFormat.setTimeZone(tz) dateFormat.applyPattern('yyyyDDD') timeFormat = SimpleDateFormat(); timeFormat.setTimeZone(tz) timeFormat.applyPattern('HH:mm:ss') addeUrlFormat = "adde://%(server)s/imagedirectory?&PORT=%(port)s&COMPRESS=gzip&USER=%(user)s&PROJ=%(proj)s&VERSION=1&DEBUG=%(debug)s&TRACE=0&GROUP=%(dataset)s&DESCRIPTOR=%(descriptor)s%(band)s%(location)s%(place)s%(size)s%(unit)s%(mag)s%(day)s%(time)s%(position)s" urls = [] areaDirectories = [] dates = _normalizeDates(day) for date in dates: formatValues = { 'server': server, 'port': port, 'user': user, 'proj': proj, 'debug': debug, 'dataset': dataset, 'descriptor': descriptor, 'band': band, 'location': location, 'place': place, 'size': size, 'unit': unit, 'mag': mag, 'day': date, 'time': time, 'position': position, } url = addeUrlFormat % formatValues if showUrls: print url adl = AreaDirectoryList(url) results = adl.getSortedDirs() for imageTimes in results: for areaDirectory in imageTimes: urls.append(url) areaDirectories.append(areaDirectory) temp = _AreaDirectoryList() for i, d in enumerate(areaDirectories): nominalTime = d.getNominalTime() tempDay = str(dateFormat.format(nominalTime, StringBuffer(), FieldPosition(0))) tempTime = str(timeFormat.format(nominalTime, StringBuffer(), FieldPosition(0))) bandList = list(d.getBands()) # tempUnitList = list(d.getCalInfo()[0]) # unitList = tempUnitList[::2] # unitDescList = tempUnitList[1::2] # calInfo = dict(zip(unitList, unitDescList)) if unit: unitList = [origUnit] else: unitList = map(str, list(d.getCalInfo()[0])[::2]) for band in bandList: for calUnit in unitList: dt = { 'server': server, 'dataset': dataset, 'descriptor': descriptor, 'bandNumber': band, 'bandList': bandList, 'debug': debug, 'accounting': accounting, 'day': tempDay, 'time': tempTime, 'imageSize': (d.getLines(), d.getElements()), 'centerLocation': (d.getCenterLatitude(), d.getCenterLongitude()), 'resolution': (d.getCenterLatitudeResolution(), d.getCenterLongitudeResolution()), 'unitList': unitList, 'unitType': calUnit, 'bands': bandList, 'band-count': d.getNumberOfBands(), 'calinfo': map(str, list(d.getCalInfo()[0])), 'calibration-scale-factor': d.getCalibrationScaleFactor(), 'calibration-type': str(d.getCalibrationType()), 'calibration-unit-name': d.getCalibrationUnitName(), 'center-latitude': d.getCenterLatitude(), 'center-latitude-resolution': d.getCenterLatitudeResolution(), 'center-longitude': d.getCenterLongitude(), 'center-longitude-resolution': d.getCenterLongitudeResolution(), 'directory-block': list(d.getDirectoryBlock()), 'elements': d.getElements(), 'lines': d.getLines(), 'memo-field': str(d.getMemoField()), 'nominal-time': DateTime(d.getNominalTime()), 'sensor-id': d.getSensorID(), 'sensor-type': str(d.getSensorType()), 'source-type': str(d.getSourceType()), 'start-time': DateTime(d.getStartTime()), 'url': urls[i], } temp.append(dt) return temp
def disableAddeDebug(): EntryStore.setAddeDebugEnabled(False)
def isAddeDebugEnabled(defaultValue=False): return EntryStore.isAddeDebugEnabled(defaultValue)
def listADDEImages(localEntry=None, server=None, dataset=None, descriptor=None, accounting=DEFAULT_ACCOUNTING, location=None, coordinateSystem=CoordinateSystems.LATLON, place=None, mag=None, position=None, unit=None, day=None, time=None, debug=False, band=None, size=None, showUrls=True): """Creates a list of ADDE images. Args: localEntry: Local ADDE dataset. server: ADDE server. dataset: ADDE dataset group name. descriptor: ADDE dataset descriptor. day: Day range. ('begin date', 'end date') time: ('begin time', 'end time') position: Position number. Values may be integers or the string "ALL". (default=0) band: McIDAS band number; only images that have matching band number will be returned. accounting: ('user', 'project number') User and project number required by servers using McIDAS accounting. default = ('idv','0') Returns: ADDE image matching the given criteria, if any. """ if localEntry: server = localEntry.getAddress() dataset = localEntry.getGroup() descriptor = localEntry.getDescriptor().upper() elif (server is None) or (dataset is None) or (descriptor is None): raise TypeError( "must provide localEntry or server, dataset, and descriptor values." ) if server == "localhost" or server == "127.0.0.1": port = EntryStore.getLocalPort() else: port = "112" # server = '%s:%s' % (server, port) user = accounting[0] proj = accounting[1] debug = str(debug).lower() if mag: mag = '&MAG=%s %s' % (mag[0], mag[1]) else: mag = '' if unit: origUnit = unit unit = '&UNIT=%s' % (unit) else: # origUnit = None unit = '' if place is Places.CENTER: place = '&PLACE=CENTER' elif place is Places.ULEFT: place = '&PLACE=ULEFT' else: # raise ValueError() place = '' if coordinateSystem is CoordinateSystems.LATLON: coordSys = 'LATLON' elif coordinateSystem is CoordinateSystems.AREA or coordinateSystem is CoordinateSystems.IMAGE: coordSys = 'LINELE' else: raise ValueError() if location: location = '&%s=%s %s' % (coordSys, location[0], location[1]) else: location = '' if size: if size == 'ALL': size = '&SIZE=99999 99999' else: size = '&SIZE=%s %s' % (size[0], size[1]) else: size = '' if time: time = '&TIME=%s %s I' % (time[0], time[1]) else: time = '' if band: band = '&BAND=%s' % (str(band)) else: band = '&BAND=ALL' if position is not None: if isinstance(position, int): position = '&POS=%s' % (position) elif isinstance(position, tuple): if len(position) != 2: raise ValueError( 'position range may only contain values for the beginning and end of a range.' ) position = '&POS=%s %s' % (str(position[0]), str(position[1])) else: position = '&POS=%s' % (str(position).upper()) else: position = '&POS=0' tz = TimeZone.getTimeZone('Z') dateFormat = SimpleDateFormat() dateFormat.setTimeZone(tz) dateFormat.applyPattern('yyyyDDD') timeFormat = SimpleDateFormat() timeFormat.setTimeZone(tz) timeFormat.applyPattern('HH:mm:ss') addeUrlFormat = "adde://%(server)s/imagedirectory?&PORT=%(port)s&COMPRESS=gzip&USER=%(user)s&PROJ=%(proj)s&VERSION=1&DEBUG=%(debug)s&TRACE=0&GROUP=%(dataset)s&DESCRIPTOR=%(descriptor)s%(band)s%(location)s%(place)s%(size)s%(unit)s%(mag)s%(day)s%(time)s%(position)s" urls = [] areaDirectories = [] dates = _normalizeDates(day) for date in dates: formatValues = { 'server': server, 'port': port, 'user': user, 'proj': proj, 'debug': debug, 'dataset': dataset, 'descriptor': descriptor, 'band': band, 'location': location, 'place': place, 'size': size, 'unit': unit, 'mag': mag, 'day': date, 'time': time, 'position': position, } url = addeUrlFormat % formatValues if showUrls: print url adl = AreaDirectoryList(url) results = adl.getSortedDirs() for imageTimes in results: for areaDirectory in imageTimes: urls.append(url) areaDirectories.append(areaDirectory) temp = _AreaDirectoryList() for i, d in enumerate(areaDirectories): nominalTime = d.getNominalTime() tempDay = str( dateFormat.format(nominalTime, StringBuffer(), FieldPosition(0))) tempTime = str( timeFormat.format(nominalTime, StringBuffer(), FieldPosition(0))) bandList = list(d.getBands()) # tempUnitList = list(d.getCalInfo()[0]) # unitList = tempUnitList[::2] # unitDescList = tempUnitList[1::2] # calInfo = dict(zip(unitList, unitDescList)) if unit: unitList = [origUnit] else: unitList = map(str, list(d.getCalInfo()[0])[::2]) for band in bandList: for calUnit in unitList: dt = { 'server': server, 'dataset': dataset, 'descriptor': descriptor, 'bandNumber': band, 'bandList': bandList, 'debug': debug, 'accounting': accounting, 'day': tempDay, 'time': tempTime, 'imageSize': (d.getLines(), d.getElements()), 'centerLocation': (d.getCenterLatitude(), d.getCenterLongitude()), 'resolution': (d.getCenterLatitudeResolution(), d.getCenterLongitudeResolution()), 'unitList': unitList, 'unitType': calUnit, 'bands': bandList, 'band-count': d.getNumberOfBands(), 'calinfo': map(str, list(d.getCalInfo()[0])), 'calibration-scale-factor': d.getCalibrationScaleFactor(), 'calibration-type': str(d.getCalibrationType()), 'calibration-unit-name': d.getCalibrationUnitName(), 'center-latitude': d.getCenterLatitude(), 'center-latitude-resolution': d.getCenterLatitudeResolution(), 'center-longitude': d.getCenterLongitude(), 'center-longitude-resolution': d.getCenterLongitudeResolution(), 'directory-block': list(d.getDirectoryBlock()), 'elements': d.getElements(), 'lines': d.getLines(), 'memo-field': str(d.getMemoField()), 'nominal-time': DateTime(d.getNominalTime()), 'sensor-id': d.getSensorID(), 'sensor-type': str(d.getSensorType()), 'source-type': str(d.getSourceType()), 'start-time': DateTime(d.getStartTime()), 'url': urls[i], } temp.append(dt) return temp
def enableAddeDebug(): EntryStore.setAddeDebugEnabled(True)
def listADDEImageTimes(localEntry=None, server=None, dataset=None, descriptor=None, accounting=DEFAULT_ACCOUNTING, location=None, coordinateSystem=CoordinateSystems.LATLON, place=None, mag=None, position=None, unit=None, day=None, time=None, debug=False, band=None, size=None, showUrls=True): if localEntry: server = localEntry.getAddress() dataset = localEntry.getGroup() descriptor = localEntry.getDescriptor().upper() elif (server is None) or (dataset is None) or (descriptor is None): raise TypeError( "must provide localEntry or server, dataset, and descriptor values." ) if server == "localhost" or server == "127.0.0.1": port = EntryStore.getLocalPort() else: port = "112" # server = '%s:%s' % (server, port) user = accounting[0] proj = accounting[1] debug = str(debug).lower() if mag: mag = '&MAG=%s %s' % (mag[0], mag[1]) else: mag = '' if unit: origUnit = unit unit = '&UNIT=%s' % (unit) else: # origUnit = None unit = '' if place is Places.CENTER: place = '&PLACE=CENTER' elif place is Places.ULEFT: place = '&PLACE=ULEFT' else: # raise ValueError() place = '' if coordinateSystem is CoordinateSystems.LATLON: coordSys = 'LATLON' elif coordinateSystem is CoordinateSystems.AREA or coordinateSystem is CoordinateSystems.IMAGE: coordSys = 'LINELE' else: raise ValueError() if location: location = '&%s=%s %s' % (coordSys, location[0], location[1]) else: location = '' if size: if size == 'ALL': size = '&SIZE=99999 99999' else: size = '&SIZE=%s %s' % (size[0], size[1]) else: size = '' if time: time = '&TIME=%s %s I' % (time[0], time[1]) else: time = '' if band: band = '&BAND=%s' % (str(band)) else: band = '&BAND=ALL' if position is not None: if isinstance(position, int): position = '&POS=%s' % (position) elif isinstance(position, tuple): if len(position) != 2: raise ValueError( 'position range may only contain values for the beginning and end of a range.' ) position = '&POS=%s %s' % (str(position[0]), str(position[1])) else: position = '&POS=%s' % (str(position).upper()) else: position = '&POS=0' tz = TimeZone.getTimeZone('Z') dateFormat = SimpleDateFormat() dateFormat.setTimeZone(tz) dateFormat.applyPattern('yyyyDDD') timeFormat = SimpleDateFormat() timeFormat.setTimeZone(tz) timeFormat.applyPattern('HH:mm:ss') addeUrlFormat = "adde://%(server)s/imagedirectory?&PORT=%(port)s&COMPRESS=gzip&USER=%(user)s&PROJ=%(proj)s&VERSION=1&DEBUG=%(debug)s&TRACE=0&GROUP=%(dataset)s&DESCRIPTOR=%(descriptor)s%(band)s%(location)s%(place)s%(size)s%(unit)s%(mag)s%(day)s%(time)s%(position)s" urls = [] areaDirectories = [] dates = _normalizeDates(day) for date in dates: formatValues = { 'server': server, 'port': port, 'user': user, 'proj': proj, 'debug': debug, 'dataset': dataset, 'descriptor': descriptor, 'band': band, 'location': location, 'place': place, 'size': size, 'unit': unit, 'mag': mag, 'day': date, 'time': time, 'position': position, } url = addeUrlFormat % formatValues if showUrls: print url adl = AreaDirectoryList(url) results = adl.getSortedDirs() for imageTimes in results: for areaDirectory in imageTimes: urls.append(url) areaDirectories.append(areaDirectory) uniques = set() times = [] for d in areaDirectories: dt = DateTime(d.getNominalTime()) if dt not in uniques: d = { 'day': str(dt.formattedString('yyyyDDD', tz)), 'time': str(dt.formattedString('HH:mm:ss', tz)), } times.append(d) uniques.add(dt) uniques = None return sorted(times)
def getADDEImage(localEntry=None, server=None, dataset=None, descriptor=None, accounting=DEFAULT_ACCOUNTING, location=None, coordinateSystem=CoordinateSystems.LATLON, place=Places.CENTER, mag=(1, 1), position=0, unit='BRIT', day=None, time=None, debug=False, track=False, band=None, size=DEFAULT_SIZE, showUrls=True, **kwargs): """Requests data from an ADDE Image server - returns both data and metadata objects. An ADDE request must include values for either localEntry or the combination of server, dataset and descriptor. ***Note to users: testADDEImage is test code, some of which may be used to improve the getADDEImage function in the future. It will not be included in future versions so should not be used in user scripts. Required Args: localEntry: Local data set defined by makeLocalADDEEntry. server: ADDE server. dataset: ADDE dataset group name. descriptor: ADDE dataset descriptor. Optional Args: day: Day range ('begin date','end date') time: ('begin time', 'end time') coordinateSystem: coordinate system to use for retrieving data AREA AREA file coordinates - zero based LATLON latitude and longitude coordinates IMAGE image coordinates - one based location: (x,y) x AREA line, latitude, or IMAGE line y AREA element, longitude, or IMAGE element place: CENTER places specified location (x,y) at center of panel ULEFT places specified location (x,y) at upper-left coordinate of panel band: McIDAS band number; must be specified if requesting data from multi-banded image; default=band in image unit: calibration unit to request; default = 'BRIT' position: time relative (negative values) or absolute (positive values) position in the dataset; default=0 (most recent image) size: number of lines and elements to request; default=(480,640) mag: magnification of data (line,element), negative number used for sampling data; default=(1,1) accounting: ('user', 'project number') user and project number required by servers using McIDAS accounting; default = ('idv','0') debug: send debug information to file; default=False track: default=False. """ if localEntry: server = localEntry.getAddress() dataset = localEntry.getGroup() descriptor = localEntry.getDescriptor().upper() elif (server is None) or (dataset is None) or (descriptor is None): raise TypeError( "must provide localEntry or server, dataset, and descriptor values." ) if server == "localhost" or server == "127.0.0.1": port = EntryStore.getLocalPort() else: port = "112" # server = '%s:%s' % (server, port) # still need to handle dates+times # todo: don't break! user = accounting[0] proj = accounting[1] debug = str(debug).lower() mag = '%s %s' % (mag[0], mag[1]) if place is Places.CENTER: place = 'CENTER' elif place is Places.ULEFT: place = 'ULEFT' else: raise ValueError() if coordinateSystem is CoordinateSystems.LATLON: coordSys = 'LATLON' coordType = 'E' elif coordinateSystem is CoordinateSystems.AREA: coordSys = 'LINELE' coordType = 'A' elif coordinateSystem is CoordinateSystems.IMAGE: coordSys = 'LINELE' coordType = 'I' else: raise ValueError() if location: location = '&%s=%s %s %s' % (coordSys, location[0], location[1], coordType) else: location = '' if day: if isinstance(day, tuple): day = '&DAY=%s %s' % (day[0], day[1]) else: day = '&DAY=%s %s' % (day, day) else: day = '' if size: if size == 'ALL': size = '&SIZE=99999 99999' else: size = '&SIZE=%s %s' % (size[0], size[1]) else: size = '' if time: if isinstance(time, (str, unicode, String)): time = '%s %s I' % (str(time), str(time)) elif len(time) == 2: time = '%s %s I' % (str(time[0]), str(time[1])) else: raise ValueError("could not understand the given time value: %s" % (time)) else: time = '' if band: try: band = int(band) band = '&BAND=%s' % (str(band)) except: raise ValueError( "band must be a single integer value; could not convert '%s' to an integer." % (band)) else: band = '' addeUrlFormat = "adde://%(server)s/imagedata?&PORT=%(port)s&COMPRESS=gzip&USER=%(user)s&PROJ=%(proj)s&VERSION=1&DEBUG=%(debug)s&TRACE=0&GROUP=%(dataset)s&DESCRIPTOR=%(descriptor)s%(band)s%(location)s&PLACE=%(place)s%(size)s&UNIT=%(unit)s&MAG=%(mag)s&SPAC=4&NAV=X&AUX=YES&DOC=X%(day)s&TIME=%(time)s&POS=%(position)s&TRACK=%(track)d" formatValues = { 'server': server, 'port': port, 'user': user, 'proj': proj, 'debug': debug, 'dataset': dataset, 'descriptor': descriptor, 'band': band, 'location': location, 'place': place, 'size': size, 'unit': unit, 'mag': mag, 'day': day, 'time': time, 'position': position, 'track': track, } url = addeUrlFormat % formatValues if showUrls: print url # build an object that returns the SATBAND file. satBandRequest = _SatBandReq(_satBandUrl(**formatValues)) # submit the request futureSatband = ecs.submit(satBandRequest) try: mapped = _MappedAreaImageFlatField.fromUrl(url) # the commented code will immediately attempt to grab the SATBAND file; # the uncommented code *should* be lazy-loaded. # mapped.addeSatBands = futureSatband.get() mapped.addeSatBands = futureSatband return mapped.getDictionary(), mapped except AreaFileException, e: raise AddeJythonError(e)