Exemple #1
0
    def __init__(self,
                 source,
                 target,
                 axes_names=['lon', 'lat'],
                 cdo_remapper=None):
        """ This class maps a source grid to a target grid using second-
            order conservative remapping by calling the re-implementation of
            SCRIP within CDO. The source grid should be a structured grid
            the target grid can be of any type. This class is able to deal
            with staggered grids for both source and target grid.
            Instantiating this class may take a while, as the remapping
            weights are being computed.
        """
        self.src_staggered = False
        self.source = source
        self.src_elements = source
        if type(source) is StaggeredGrid:
            self.src_staggered = True
            self.src_elements = source.elements
        if not type(self.src_elements) is StructuredGrid:
            raise Exception("Source grid should be of type StructuredGrid")

        self.tgt_staggered = False
        self.target = target
        self.tgt_elements = target
        if type(target) is StaggeredGrid:
            self.tgt_staggered = True
            self.tgt_elements = target.elements

        self._axes_names = list(axes_names)

        try:
            from omuse.community.cdo.interface import CDORemapper
        except:
            raise Exception(
                "conservative spherical remapper requires omuse.community.cdo.interface"
            )

        if cdo_remapper == None:
            self.cdo_remapper = CDORemapper(channel="sockets",
                                            redirection="none")
            self.cdo_remapper.parameters.src_grid = self.src_elements
            self.cdo_remapper.parameters.dst_grid = self.tgt_elements

            #force start of the computation of remapping weights
            self.cdo_remapper.commit_parameters()
        else:
            self.cdo_remapper = cdo_remapper
    def test2(self):
        r = CDORemapper(**default_options)
        self.assertEquals(r.state_machine._current_state.name, 'UNINITIALIZED')

        filename = "weights/src_dst_con.nc"
        r.parameters.weights_file = filename
        self.assertEquals(r.state_machine._current_state.name, 'INITIALIZED')

        get_file = r.parameters.weights_file
        self.assertEquals(get_file, filename)

        src_grid_size = r.get_src_grid_size()
        self.assertEquals(src_grid_size, 16200)
        self.assertEquals(r.state_machine._current_state.name, 'RUN')

        r.stop()
 def test1(self):
     r = CDORemapper(**default_options)
     print(r)
     r.stop()