def getStartMonth(timeSet): """ Get the starting month number (1-12) from a timeset. """ from visad.util import DataUtility as du from visad import DateTime r = du.getSample(timeSet, 0).getComponent(0) dt = DateTime(r) month = dt.formattedString("MM", DateTime.getFormatTimeZone()) return int(month)
def getStartMonth(timeSet): """ Get the starting month number (1-12) from a timeset. """ from visad.util import DataUtility as du from visad import DateTime r = du.getSample(timeSet, 0).getComponent(0) dt = DateTime(r) month = dt.formattedString("MM",DateTime.getFormatTimeZone()) return int(month)
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 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)