Beispiel #1
0
 def __init__(self, output_def):
     super(OutputHandlerBase, self).__init__(self.__class__.__name__)
     self.pysiral_config = ConfigInfo()
     self.error = ErrorStatus()
     self._basedir = "n/a"
     self._init_from_output_def(output_def)
     self.output_def_filename = output_def
Beispiel #2
0
def get_l1bdata_files(mission_id, hemisphere, year, month, config=None,
                      version="default"):
    import glob
    if config is None:
        config = ConfigInfo()
    l1b_repo = config.local_machine.l1b_repository[mission_id][version].l1bdata
    directory = os.path.join(
        l1b_repo, hemisphere, "%04g" % year, "%02g" % month)
    l1bdata_files = sorted(glob.glob(os.path.join(directory, "*.nc")))
    return l1bdata_files
Beispiel #3
0
    def __init__(self,
                 l1p_settings_id_or_file,
                 tcs,
                 tce,
                 exclude_month=[],
                 hemisphere="global",
                 platform=None,
                 output_handler_cfg={},
                 source_repo_id=None):
        """
        The settings for the Level-1 pre-processor job
        :param l1p_settings_id_or_file: An id of an proc/l1 processor config file (filename excluding the .yaml
                                        extension) or an full filepath to a yaml config file
        :param tcs: [int list] Time coverage start (YYYY MM [DD])
        :param tce: [int list] Time coverage end (YYYY MM [DD]) [int list]
        :param exclude_month: [int list] A list of month that will be ignored
        :param hemisphere: [str] The target hemisphere (`north`, `south`, `global`:default).
        :param platform: [str] The target platform (pysiral id). Required if l1p settings files is valid for
                               multiple platforms (e.g. ERS-1/2, ...)
        :param output_handler_cfg: [dict] An optional dictionary with options of the output handler
                                   (`overwrite_protection`: [True, False], `remove_old`: [True, False])
        :param source_repo_id: [str] The tag in local_machine_def.yaml (l1b_repository.<platform>.<source_repo_id>)
                                  -> Overwrites the default source repo in the l1p settings
                                     (input_handler.options.local_machine_def_tag &
                                      output_handler.options.local_machine_def_tag)
        """

        super(Level1PreProcJobDef, self).__init__(self.__class__.__name__)
        self.error = ErrorStatus()

        # Get pysiral configuration
        # TODO: Move to global
        self._cfg = ConfigInfo()

        # Store command line options
        self._hemisphere = hemisphere
        self._platform = platform
        self._source_repo_id = source_repo_id

        # Parse the l1p settings file
        self.set_l1p_processor_def(l1p_settings_id_or_file)

        # Get full requested time range
        self._time_range = TimeRangeRequest(tcs,
                                            tce,
                                            exclude_month=exclude_month)
        self.log.info("Requested time range is %s" % self.time_range.label)

        # Store the data handler options
        self._output_handler_cfg = output_handler_cfg

        # Measure execution time
        self.stopwatch = StopWatch()
Beispiel #4
0
    def __init__(self, cfg):

        cls_name = self.__class__.__name__
        super(Level1POutputHandler, self).__init__(cls_name)
        self.error = ErrorStatus(caller_id=cls_name)
        self.cfg = cfg

        self.pysiral_cfg = ConfigInfo()

        # Init class properties
        self._path = None
        self._filename = None
Beispiel #5
0
def get_local_l1bdata_files(mission_id, time_range, hemisphere, config=None,
                            version="default", allow_multiple_baselines=True):
    """
    Returns a list of l1bdata files for a given mission, hemisphere, version
    and time range
    XXX: Note: this function will slowly replace `get_l1bdata_files`, which
         is limited to full month
    """

    # parse config data (if not provided)
    if config is None or not isinstance(config, ConfigInfo):
        config = ConfigInfo()

    # Validate time_range (needs to be of type TimeRangeIteration)
    try:
        time_range_is_correct_object = time_range.base_period == "monthly"
    except:
        time_range_is_correct_object = False
    if not time_range_is_correct_object:
        error = ErrorStatus()
        msg = "Invalid type of time_range, required: %s, was %s" % (
            type(time_range), type(TimeRangeIteration))
        error.add_error("invalid-timerange-type", msg)
        error.raise_on_error()

    # 1) get list of all files for monthly folders
    yyyy, mm = "%04g" % time_range.start.year, "%02g" % time_range.start.month
    l1b_repo = config.local_machine.l1b_repository[mission_id][version].l1bdata
    directory = os.path.join(l1b_repo, hemisphere, yyyy, mm)
    all_l1bdata_files = sorted(glob.glob(os.path.join(directory, "*.nc")))

    # 2) First filtering step: Check if different algorithm baseline values
    # exist in the list of l1bdata files
    algorithm_baselines = [l1bdata_get_baseline(f) for f in all_l1bdata_files]
    baselines = np.unique(np.array(algorithm_baselines))
    n_baselines = len(baselines)
    if not allow_multiple_baselines and n_baselines > 1:
        error = ErrorStatus()
        baseline_str_list = ", ".join(baselines)
        msg = "Multiple l1bdata baselines (%g) [%s] found in directory: %s" % (
                n_baselines, baseline_str_list, directory)
        error.add_error("multiple-l1b-baselines", msg)
        error.raise_on_error()

    # 3) Check if files are in requested time range
    # This serves two purporses: a) filter out files with timestamps that do
    # not belong in the directory. b) get a subset if required
    l1bdata_files_checked = [l1bdata_file for l1bdata_file in all_l1bdata_files
                             if l1bdata_in_trange(l1bdata_file, time_range)]

    # Done return list (empty or not)
    return l1bdata_files_checked, directory
Beispiel #6
0
 def __init__(self, config=None, load_config=True):
     self.error = ErrorStatus()
     self.data_level = None
     self.path = None
     self.version = "default"
     self.mission_id = None
     self.year = None
     self.month = None
     if not load_config:
         return
     if config is None or not isinstance(config, ConfigInfo):
         self.config = ConfigInfo()
     else:
         self.config = config
Beispiel #7
0
 def _init_product_directory(self):
     """ Get main product directory from local_machine_def, add mandatory
     runtag subdirectory, optional second subdirectory for overwrite
     protection and product level id subfolder"""
     pysiral_config = ConfigInfo()
     basedir = pysiral_config.local_machine.product_repository
     if not isinstance(self.subdirectory, list):
         basedir = os.path.join(basedir, self.subdirectory)
     else:
         basedir = os.path.join(basedir, *self.subdirectory)
     if self.overwrite_protection:
         basedir = os.path.join(basedir, self.now_directory)
     basedir = os.path.join(basedir, self.product_level_subfolder)
     self._set_basedir(basedir)
Beispiel #8
0
    def __init__(self):

        super(L1bPreProcJob, self).__init__(self.__class__.__name__)

        # Save pointer to pysiral configuration
        self.pysiral_config = ConfigInfo()

        # Initialize the time range and set to monthly per default
        self.time_range = None

        # Error Status
        self.error = ErrorStatus()

        # Initialize job parameter
        self.options = L1bPreProcJobOptions()

        # List for iterations (currently only month-wise)
        self.iterations = []
Beispiel #9
0
    def __init__(self, product_def, auxclass_handler=None):
        """ Setup of the Level-2 Processor """

        super(Level2Processor, self).__init__(self.__class__.__name__)

        # Error Status Handler
        self.error = ErrorStatus(caller_id=self.__class__.__name__)

        # Level-2 Algorithm Definition
        # NOTE: This object should ony be called through the property self.l2def
        self._l2def = product_def.l2def

        # Auxiliary Data Handler
        # NOTE: retrieves and initializes the auxdata classes based on the l2 processor definition config file
        if auxclass_handler is None:
            auxclass_handler = DefaultAuxdataClassHandler()
        self._auxclass_handler = auxclass_handler

        # This variable will contain a list with the auxiliary data handlers
        self._registered_auxdata_handlers = []
        self._auxhandlers = {}

        # Output_handler (can be one or many)
        self._output_handler = product_def.output_handler

        # List of Level-2 (processed) orbit segments
        self._orbit = deque()

        # List of Level-1b input files
        self._l1b_files = []

        # pysiral config
        self._config = ConfigInfo()

        # Processor Initialization Flag
        self._initialized = False

        # Processor summary report
        self.report = L2ProcessorReport()

        # Initialize the class
        self._initialize_processor()
Beispiel #10
0
    def __init__(self, name):

        # Enable logging capability (self.log)
        super(L1bPreProc, self).__init__(name)

        # Error handler
        self.error = ErrorStatus()

        # Job definition ( class L1bPreProcJob)
        self._jobdef = None

        # Mission Options
        self._mdef = None

        # List of l1b input files
        # Needs to be filled by the mission specific classes
        self._l1b_file_list = []

        # pysiral configuration
        self._pysiral_config = ConfigInfo()
Beispiel #11
0
def MaskSourceFile(mask_name, mask_cfg):
    """ Wrapper method for different mask source file classes """

    error = ErrorStatus(caller_id="MaskSourceFile")

    # Get the full mask filename
    pysiral_cfg = ConfigInfo()
    try:
        mask_dir = pysiral_cfg.local_machine.auxdata_repository.mask[mask_name]
    except KeyError:
        msg = "path to mask %s not in local_machine_def.yaml" % mask_name
        error.add_error("missing-lmd-def", msg)
        error.raise_on_error()

    # Return the Dataset class
    try:
        return globals()[mask_cfg.pyclass_name](mask_dir, mask_name, mask_cfg)
    except KeyError:
        msg = "pysiral.mask.%s not implemented" % str(mask_cfg.pyclass_name)
        error.add_error("missing-mask-class", msg)
        error.raise_on_error()
Beispiel #12
0
    def mask_filepath(self):

        # Get config info
        pysiral_cfg = ConfigInfo()

        # Get the path to the mask file
        # (needs to be in local_machine_def.yaml)
        mask_dir = pysiral_cfg.local_machine.auxdata_repository.mask
        try:
            mask_dir = mask_dir[self.mask_name]
        except KeyError:
            msg = "cannot find mask entry [%s] in local_machine_def.yaml"
            self.error.add_error("lmd-error", msg % self.mask_name)
            return None

        mask_filename = "%s_%s.nc" % (self.mask_name, self.grid_id)
        filepath = os.path.join(mask_dir, mask_filename)

        if not os.path.isfile(filepath):
            msg = "cannot find mask file: %s" % filepath
            self.error.add_error("io-error", msg)
            return None

        return filepath
Beispiel #13
0
 def __init__(self):
     super(Level3ProcArgParser, self).__init__(self.__class__.__name__)
     self.error = ErrorStatus()
     self.pysiral_config = ConfigInfo()
     self._args = None
Beispiel #14
0
 def __init__(self):
     super(DefaultAuxdataClassHandler,
           self).__init__(self.__class__.__name__)
     self.pysiral_config = ConfigInfo()
     self.error = ErrorStatus(caller_id=self.__class__.__name__)
Beispiel #15
0
 def default_output_def_filename(self):
     pysiral_config = ConfigInfo()
     local_settings_path = pysiral_config.pysiral_local_path
     return os.path.join(local_settings_path, *self.default_file_location)