예제 #1
0
def parameterise(
    collection=None, area=None, level=None, time=None, time_components=None
):
    """
    Parameterises inputs to instances of parameter classes which allows
    them to be used throughout roocs.
    For supported formats for each input please see their individual classes.

    :param collection: Collection input in any supported format.
    :param area: Area input in any supported format.
    :param level: Level input in any supported format.
    :param time: Time input in any supported format.
    :param time_components: Time Components input in any supported format.
    :return: Parameters as instances of their respective classes.
    """

    # if collection is a dataset/dataarray it doesn't need to be parameterised
    if type(collection) not in (xr.core.dataarray.DataArray, xr.core.dataset.Dataset):
        collection = collection_parameter.CollectionParameter(collection)

    area = area_parameter.AreaParameter(area)
    level = level_parameter.LevelParameter(level)
    time = time_parameter.TimeParameter(time)
    time_components = time_components_parameter.TimeComponentsParameter(time_components)

    return locals()
예제 #2
0
    def _handler(self, request, response):
        response.update_status("Usage started.", 0)
        if "time" in request.inputs:
            time = request.inputs["time"][0].data
            time_start, time_end = time_parameter.TimeParameter(
                time).get_bounds()
        else:
            time = None
            time_start = time_end = None
        # usage
        try:
            usage = WPSUsage()
            response.outputs["wpsusage"].file = usage.collect(
                time_start=time_start, time_end=time_end, outdir=self.workdir)
            response.update_status("WPSUsage completed.", 50)
        except Exception as e:
            raise ProcessError(f"{e}")
        # downloads
        try:
            usage = Downloads()
            downloads_csv = usage.collect(time_start=time_start,
                                          time_end=time_end,
                                          outdir=self.workdir)
            response.outputs["downloads"].file = downloads_csv
        except Exception:
            LOGGER.exception("downloads collection failed")
            response.outputs["downloads"].data = EMPTY_CSV
        finally:
            response.update_status("Downloads usage completed.", 90)

        return response
예제 #3
0
def parameterise(collection=None, area=None, level=None, time=None):

    # if collection is a dataset/dataarray it doesn't need to be parameterised
    if type(collection) not in (xr.core.dataarray.DataArray, xr.core.dataset.Dataset):
        collection = collection_parameter.CollectionParameter(collection)

    area = area_parameter.AreaParameter(area)
    time = time_parameter.TimeParameter(time)
    level = level_parameter.LevelParameter(level)

    return locals()
예제 #4
0
def test_parameter_classes_as_args(tmpdir, load_esgf_test_data):
    collection = collection_parameter.CollectionParameter(CMIP5_IDS[1])
    time = time_parameter.TimeParameter(("2085-01-16", "2120-12-16"))
    area = area_parameter.AreaParameter((0, -10, 120, 40))

    result = subset(
        collection, time=time, area=area, output_dir=tmpdir, file_namer="simple"
    )
    _check_output_nc(result)

    ds_subset = xr.open_dataset(result.file_uris[0], use_cftime=True)
    assert ds_subset.tas.shape == (433, 1, 1)
예제 #5
0
파일: util.py 프로젝트: roocs/daops
def parse_time(time):
    # TODO: refactor code ... maybe we need this only in the catalog. allow dicts in time parameter?
    if isinstance(time, dict):
        time = (time["start_time"], time["end_time"])
    start, end = time_parameter.TimeParameter(time).tuple

    if not start:
        start = MIN_DATETIME
    if not end:
        end = MAX_DATETIME

    return start, end
예제 #6
0
def test_subset_args_as_parameter_classes(tmpdir):
    """Tests clisops subset function with a time subset
    with the arguments as parameter classes from roocs-utils."""

    time = time_parameter.TimeParameter(
        ("2000-01-01T00:00:00", "2020-12-30T00:00:00"))
    area = area_parameter.AreaParameter((0, -90.0, 360.0, 90.0))

    result = subset(
        ds=CMIP5_TAS_FILE,
        time=time,
        area=area,
        output_dir=tmpdir,
        output_type="nc",
        file_namer="simple",
    )
    _check_output_nc(result)
예제 #7
0
    def _deduce_alignment(self, inputs):
        # At present, we reject alignment if any "time_components", "area" or "level" subset is requested
        if (inputs.get("time_components", None) or inputs.get("area", None)
                or inputs.get("level", None)):
            return

        time = inputs.get("time", None)

        # add in a catch for if time bounds are None
        # this means is_aligned = True and all files are needed
        if time is None:
            self.is_aligned = True
            self.aligned_files = self.input_files
            return

        else:
            start, end = time_parameter.TimeParameter(time).get_bounds()
            self._check_time_alignment(start, end)
예제 #8
0
파일: wps_dashboard.py 프로젝트: roocs/rook
 def _handler(self, request, response):
     response.update_status("Dashboard started.", 0)
     if "time" in request.inputs:
         time = request.inputs["time"][0].data
         time_start, time_end = time_parameter.TimeParameter(
             time).get_bounds()
     else:
         time = None
         time_start = time_end = None
     try:
         usage = Combine(site=request.inputs["site"][0].data)
         fusage, fdownloads = usage.collect(time_start=time_start,
                                            time_end=time_end,
                                            outdir=self.workdir)
         response.update_status("Combine completed.", 80)
         dashboard = Dashboard(output_dir=self.workdir)
         dashboard.load(url=fusage, filter="orchestrate")
         dashboard.load_downloads(url=fdownloads)
         response.outputs["dashboard"].file = dashboard.write()
         response.update_status("Dashboard completed.", 90)
     except Exception as e:
         raise ProcessError(f"{e}")
     return response