Пример #1
0
    def save(self, event):
        atlmsk = numpy.where(self.ds.Oceans.values == 1, 1, 0)
        pacmsk = numpy.where(self.ds.Oceans.values == 2, 1, 0)
        indmsk = numpy.where(self.ds.Oceans.values == 3, 1, 0)
        ds = xr.Dataset(
            coords={},
            data_vars={
                "navlat": (["y", "x"], self.ds.nav_lat.values),
                "navlon": (["y", "x"], self.ds.nav_lon.values),
                "atlmsk": (["y", "x"], atlmsk),
                "pacmsk": (["y", "x"], pacmsk),
                "indmsk": (["y", "x"], indmsk),
            },
        )

        ds["navlon"].attrs = {"units": "degrees_east"}
        ds["navlat"].attrs = {"units": "degrees_north"}
        ds["atlmsk"].attrs = {}
        ds["pacmsk"].attrs = {}
        ds["indmsk"].attrs = {}

        with self.app.app_context():
            save_revision(self.data_file_id, ds, "sub_basins")
            if self.step is not None:
                save_step(
                    self.data_file_id,
                    step=self.step,
                    parameters={
                        "id": self.data_file_id,
                        "undo_list": json.dumps(self._undo_list),
                    },
                    up_to_date=True,
                )
                send_preprocessing_message(self.step + ".done",
                                           message={"id": self.data_file_id})
Пример #2
0
def regrid(_id):
    if request.method == "POST":
        limits = request.form["limits"]
        lon_step = float(request.form["Longitude Step"])
        lat_step = float(request.form["Latitude Step"])
        interpolator = request.form["interpolator"]
        error = ""

        if not lon_step or lon_step < 0:
            error += "Incorrect Longitude step; "
        elif not lat_step or lat_step < 0:
            error += "Incorrect Latitude step; "
        elif interpolator not in ["linear", "nearest"]:
            error += "Unknown interpolator"
        elif limits not in ["default", "data"]:
            error += "Unknown limit type"

        if not len(error):
            send_preprocessing_message("regrid", {"id": _id, **request.form})
            flash(
                "File regrided using {} interpolation with Longitude steps {} and Latitude steps {} and {} limits"
                .format(interpolator, lon_step, lat_step, limits))
            try:
                next_page = request.form["next"]
            except werkzeug.exceptions.BadRequestKeyError:
                next_page = url_for("app.steps", _id=_id)
            return redirect(next_page)

        flash(error)

    return render_template("app/regrid.html")
Пример #3
0
def pft(_id):
    if request.method == "POST":
        body = {"id": _id, **request.form}
        send_preprocessing_message("pft", body)
        return redirect(url_for("app.steps", _id=_id))

    seen_file_types = get_file_types(_id)
    not_seen = False
    if "routing" not in seen_file_types:
        not_seen = True

    return render_template("app/pft.html", _id=_id, not_seen=not_seen)
 def save(self, event):
     with self.app.app_context():
         info = {"changes": self.description.value}
         ds = self.cleanup_ds(self.ds)
         save_revision(self.data_file_id, ds, self.file_type, info)
         if self.step is not None:
             save_step(
                 self.data_file_id,
                 step=self.step,
                 parameters={
                     "id": self.data_file_id,
                     "undo_list": json.dumps(self._undo_list),
                 },
                 up_to_date=True,
             )
             send_preprocessing_message(self.step + ".done",
                                        message={"id": self.data_file_id})
Пример #5
0
def routing(_id):
    ds = load_file(_id, "raw")
    variable_names = list(ds.data_vars)
    lon, lat = get_lon_lat_names(_id)

    if request.method == "POST":
        topo_variable = request.form["topo_var"]
        error = ""
        if not len(topo_variable):
            error += "Topography Variable not understood; "
        elif topo_variable not in variable_names:
            error += "Topography Variable not in data set"

        if request.form["orcafile"] == "custom":
            file = _validate_file(request)
            upload_file(file, data_file_id=_id, file_type="paleorca")

        if not len(error):
            body = {"id": _id, **request.form}
            send_preprocessing_message("routing", body)

            flash("Routing succesfully sent to engine")

            return redirect(url_for("app.steps", _id=_id))

        flash(error)

    data_shape = tuple(ds.dims.values())
    show_regrid = False
    if data_shape != (180, 360):
        show_regrid = True

    return render_template(
        "app/routing.html",
        _id=_id,
        variable_names=variable_names,
        show_regrid=show_regrid,
        data_shape=data_shape,
    )
Пример #6
0
def calculate_weights(_id):
    if request.method == "POST":
        error = ""

        file = _validate_file(request)
        # TODO validate that the correct variables are in the file
        upload_file(file, data_file_id=_id, file_type="weight_coords")

        if not len(error):
            body = {"id": _id, **request.form}
            send_preprocessing_message("calculate_weights", body)

            return redirect(url_for("app.steps", _id=_id))

        flash(error)
    has_bathy = get_file_path(_id, "bathy") is not None
    has_subbasins = get_file_path(_id, "sub_basins") is not None
    return render_template(
        "app/calculate_weights.html",
        title="Calculate Weights",
        has_bathy=has_bathy,
        has_subbasins=has_subbasins,
        _id=_id,
    )