Skip to content

Commit

Permalink
Merge pull request #1 from Aquaveo/troute_addition
Browse files Browse the repository at this point in the history
Troute Addition
  • Loading branch information
romer8 authored Nov 1, 2024
2 parents 5653630 + 0e95940 commit bafd333
Show file tree
Hide file tree
Showing 22 changed files with 759 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_and_push_dev_image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
platform:
- linux/amd64
- linux/arm64
- linux/arm64/v8
# - linux/arm64/v8
steps:
- name: Prepare
run: |
Expand Down
18 changes: 15 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,19 @@ ARG MICRO_TETHYS=true \
MAMBA_DOCKERFILE_ACTIVATE=1



#########################
# ADD APPLICATION FILES #
#########################
COPY . ${TETHYS_HOME}/apps/ngiab
COPY run.sh ${TETHYS_HOME}/run.sh



###############
# ENVIRONMENT #
###############
ENV TETHYS_DB_ENGINE=django.db.backends.sqlite3
ENV SKIP_DB_SETUP=True
ENV TETHYS_DB_NAME=
ENV TETHYS_DB_USERNAME=
ENV TETHYS_DB_PASSWORD=
Expand All @@ -30,14 +32,21 @@ ENV PORTAL_SUPERUSER_NAME=admin
ENV PORTAL_SUPERUSER_PASSWORD=pass
ENV PROJ_LIB=/opt/conda/envs/tethys/share/proj

# fix error for numpy not being imported. libquadmath not found
RUN apt-get update \
&& apt-get -y install gfortran \
&& rm -rf /var/lib/apt/lists/*

#######################
# INSTALL APPLICATION #
#######################

RUN cd ${TETHYS_HOME}/apps/ngiab && \
micromamba install --yes -c conda-forge --file requirements.txt && \
micromamba remove pyarrow && micromamba install --yes -c conda-forge pyarrow && \
micromamba clean --all --yes && \
npm install && npm run build && \
tethys install -d -N
tethys install -d -N -w

#########
# PORTS #
Expand All @@ -48,4 +57,7 @@ EXPOSE 80
# RUN #
#######

CMD bash run.sh
CMD bash run.sh

HEALTHCHECK --start-period=1s \
CMD ./liveness-probe.sh
Empty file added cli/__init__.py
Empty file.
69 changes: 58 additions & 11 deletions cli/convert_geom.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import geopandas as gpd
import argparse
from geo.Geoserver import Geoserver
import os
import geopandas as gpd
import zipfile
import os


def read_and_transform(gpkg_path, layer_name):
def _read_and_transform(gpkg_path, layer_name):
gdf = gpd.read_file(gpkg_path, layer=layer_name)
if gdf.crs.to_string() != "EPSG:5070":
gdf = gdf.to_crs(epsg=5070)
return gdf


def create_and_publish_shp(
def _create_and_publish_shp(
gdf,
shp_path,
store_name,
geoserver_host,
geoserver_port,
geoserver_username,
Expand All @@ -36,20 +37,36 @@ def create_and_publish_shp(
username=geoserver_username,
password=geoserver_password,
)
geo.create_workspace(workspace="nextgen")

geo.create_shp_datastore(
path=f"{shp_path}.zip",
store_name="hydrofabrics",
store_name=f"{store_name}",
workspace="nextgen",
)
# remove zip file
os.remove(f"{shp_path}.zip")


def create_workspace(
geoserver_host, geoserver_port, geoserver_username, geoserver_password
):
try:
geo = Geoserver(
f"http://{geoserver_host}:{geoserver_port}/geoserver",
username=geoserver_username,
password=geoserver_password,
)
geo.create_workspace(workspace="nextgen")

except Exception as e:
print(f"Error in create_workspace: {e}")
return 1
return 0


def convert_gpkg_to_geojson(gpkg_path, layer_name, output_path):
try:
gdf = read_and_transform(gpkg_path, layer_name)
gdf = _read_and_transform(gpkg_path, layer_name)
gdf.to_file(output_path, driver="GeoJSON")
return 0
except Exception as e:
Expand All @@ -61,16 +78,18 @@ def publish_gpkg_layer_to_geoserver(
gpkg_path,
layer_name,
shp_path,
store_name,
geoserver_host,
geoserver_port,
geoserver_username,
geoserver_password,
):
try:
gdf = read_and_transform(gpkg_path, layer_name)
create_and_publish_shp(
gdf = _read_and_transform(gpkg_path, layer_name)
_create_and_publish_shp(
gdf,
shp_path,
store_name,
geoserver_host,
geoserver_port,
geoserver_username,
Expand All @@ -85,16 +104,18 @@ def publish_gpkg_layer_to_geoserver(
def publish_geojson_layer_to_geoserver(
geojson_path,
shp_path,
store_name,
geoserver_host,
geoserver_port,
geoserver_username,
geoserver_password,
):
try:
gdf = read_and_transform(geojson_path, None)
create_and_publish_shp(
gdf = _read_and_transform(geojson_path, None)
_create_and_publish_shp(
gdf,
shp_path,
store_name,
geoserver_host,
geoserver_port,
geoserver_username,
Expand Down Expand Up @@ -123,6 +144,11 @@ def main():
action="store_true",
help="Publish the GeoJSON layer to GeoServer",
)
parser.add_argument(
"--create_workspace",
action="store_true",
help="Create a workspace in GeoServer",
)

# Optional Arguments
parser.add_argument(
Expand All @@ -142,6 +168,7 @@ def main():
parser.add_argument(
"--shp_path", help="Path to save the shapefile for GeoServer", required=False
)
parser.add_argument("--store_name", help="Shapefile store name", required=False)
parser.add_argument("--geoserver_host", help="GeoServer host", required=False)
parser.add_argument("--geoserver_port", help="GeoServer port", required=False)
parser.add_argument(
Expand Down Expand Up @@ -172,6 +199,7 @@ def main():
args.gpkg_path,
args.layer_name,
args.shp_path,
args.store_name,
args.geoserver_host,
args.geoserver_port,
args.geoserver_username,
Expand All @@ -185,6 +213,25 @@ def main():
result = publish_geojson_layer_to_geoserver(
args.geojson_path,
args.shp_path,
args.store_name,
args.geoserver_host,
args.geoserver_port,
args.geoserver_username,
args.geoserver_password,
)
exit(result)

if args.create_workspace:
if (
not args.geoserver_host
or not args.geoserver_port
or not args.geoserver_username
or not args.geoserver_password
):
parser.error(
"--create_workspace requires --geoserver_host, --geoserver_port, --geoserver_username, and --geoserver_password."
)
result = create_workspace(
args.geoserver_host,
args.geoserver_port,
args.geoserver_username,
Expand Down
1 change: 0 additions & 1 deletion reactapp/features/Map/providers/MapProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export const MapProvider = ({ children, layers= [] }) => {

useEffect(() => {
if (!state.state.extent) return;
console.log(state.state.extent)
state.state.mapObject.getView().fit(state.state.extent, {duration: 1300, padding: [50, 50, 50, 50]});
}, [state.state.extent]);

Expand Down
102 changes: 102 additions & 0 deletions reactapp/features/hydroFabric/components/catchmentsSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@


import {useEffect, Suspense, Fragment,lazy} from 'react';
import { useHydroFabricContext } from 'features/hydroFabric/hooks/useHydroFabricContext';
import appAPI from 'services/api/app';

import SelectComponent from './selectComponent';

// const SelectComponent = lazy(() => import('selectComponent'));

const CatchmentSelect = (props) => {
const {state,actions} = useHydroFabricContext();

useEffect(() => {
if (!state.catchment.id) return;
actions.reset_nexus();
props.setIsLoading(true);
var params = {
catchment_id: state.catchment.id
}
appAPI.getCatchmentTimeSeries(params).then((response) => {
actions.set_catchment_series(response.data);
actions.set_catchment_variable_list(response.variables);
actions.set_catchment_variable(null);
actions.set_catchment_list(response.catchment_ids);
actions.set_troute_id(state.catchment.id);
props.toggleSingleRow(false);
props.setIsLoading(false);
}).catch((error) => {
props.setIsLoading(false);
console.log("Error fetching catchment time series", error);
})
return () => {
if (state.catchment.id) return;
actions.reset_catchment();
}

}, [state.catchment.id]);


useEffect(() => {
if (!state.catchment.variable) return;
props.setIsLoading(true);

var params = {
catchment_id: state.catchment.id,
variable_column: state.catchment.variable
}
appAPI.getCatchmentTimeSeries(params).then((response) => {
actions.set_catchment_series(response.data);
props.toggleSingleRow(false);
props.setIsLoading(false);
}).catch((error) => {
props.setIsLoading(false);
console.log("Error fetching nexus time series", error);
})
return () => {

}

}, [state.catchment.variable]);


return (
<Fragment>
{state.catchment.id &&
<Fragment>
<h5>Catchment Metadata</h5>
<p><b>ID</b>: {state.catchment.id}</p>
<label>Current Catchment ID </label>
<SelectComponent
optionsList={state.catchment.list}
onChangeHandler={actions.set_catchment_id}
defaultValue={
{
'value': state.catchment.id,
'label': state.catchment.id
}
}
/>
<label>Current Variable</label>
<SelectComponent
optionsList={state.catchment.variable_list}
onChangeHandler={actions.set_catchment_variable}
defaultValue={
{
'value': state.catchment.variable ? state.catchment.variable : state.catchment.variable_list ? state.catchment.variable_list[0].value : 'select variable',
'label': state.catchment.variable ? state.catchment.variable.toLowerCase().replace(/_/g, " ") : state.catchment.variable_list ? state.catchment.variable_list[0].label : 'select variable',
}

}
/>
</Fragment>
}
</Fragment>



);
};

export default CatchmentSelect;
Loading

0 comments on commit bafd333

Please sign in to comment.