~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to install/hvpull/image/jp2.py

  • Committer: Keith Hughitt
  • Date: 2012-04-23 16:02:25 UTC
  • mto: This revision was merged to the branch mainline in revision 732.
  • Revision ID: keith.hughitt@nasa.gov-20120423160225-xzoh82ejf37c8yr7
Incorporated HVPull code

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
'''
 
2
Created on Nov 15, 2011
 
3
 
 
4
@author: ireland
 
5
'''
 
6
import os
 
7
import re
 
8
from datetime import datetime
 
9
 
 
10
class JPEG2000Image:
 
11
    """A JPEG 2000 Image"""
 
12
    def __init__(self, filename, filename_regex):
 
13
        """JPEG2000Image constructor"""
 
14
        self.filename = filename
 
15
        self.filename_regex = filename_regex
 
16
        
 
17
        # First check to see if the filename follows the
 
18
        # convention.  If not, use other methods to determine if the file is
 
19
        # allowable.
 
20
        
 
21
        # Parse filename
 
22
        m = re.match(self.filename_regex, self.filename)
 
23
        
 
24
        if m is None:
 
25
            raise UnrecognizedFilename
 
26
        
 
27
        self.observatory = m.group('obs')
 
28
        self.instrument = m.group('inst')
 
29
        self.detector = m.group('det')
 
30
        self.measurement = m.group('meas')
 
31
    
 
32
        self.datetime = datetime(
 
33
            int(m.group('year')), int(m.group('month')), int(m.group('day')),
 
34
            int(m.group('hour')), int(m.group('min')), int(m.group('sec')),
 
35
            int(m.group('microsec'))
 
36
        )
 
37
        
 
38
class UnrecognizedFilename(NameError):
 
39
    """Filename encountered does not follow any known convention"""
 
40
    pass