Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
lily-tomkovic-DWR committed Jan 8, 2025
2 parents 89aa9ac + 81b3754 commit 73b9616
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/python-package-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ jobs:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Set up Python 3.7
- name: Set up Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.7
python-version: 3.11
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
Expand Down
34 changes: 26 additions & 8 deletions pydelmod/dsm2gis.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,33 @@ def get_distance_from_start(point: Point, closest_line: gpd.GeoDataFrame):


def read_stations(file_path):
# Read the CSV file
stations = pd.read_csv(file_path)
stations = gpd.GeoDataFrame(
stations, geometry=[Point(xy) for xy in zip(stations.lon, stations.lat)]
)
# Set the original CRS to WGS84 (latitude and longitude)
stations.crs = "EPSG:4326"
# Convert the geometries to EPSG:26910
stations = stations.to_crs(epsg=26910)
return stations
if "lat" in stations.columns and "lon" in stations.columns:
# Create GeoDataFrame with Point geometry and set the CRS to WGS84 (EPSG:4326)
stations = gpd.GeoDataFrame(
stations,
geometry=[Point(xy) for xy in zip(stations.lon, stations.lat)],
crs="EPSG:4326", # Define CRS during GeoDataFrame creation
)
stations.set_crs(epsg=4326, inplace=True)
stations_utm = stations.to_crs(epsg=26910)
stations.set_crs(epsg=4326, inplace=True) # Set CRS again to avoid warning
elif "x" in stations.columns and "y" in stations.columns:
# Create GeoDataFrame with Point geometry and set the CRS to UTM Zone 10N (EPSG:26910)
stations = gpd.GeoDataFrame(
stations,
geometry=[Point(xy) for xy in zip(stations.x, stations.y)],
crs="EPSG:26910", # Define CRS during GeoDataFrame creation
)
stations.set_crs(epsg=26910, inplace=True)
stations.set_crs(epsg=26910, inplace=True)
stations_utm = stations
else:
raise ValueError(
"Input file must contain 'lat' and 'lon' columns or 'x' and 'y' columns"
)
return stations_utm


def get_id_and_distance_from_start(point, gdf):
Expand Down
35 changes: 25 additions & 10 deletions pydelmod/schismcalibplotui.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,19 @@ def replace_with_paths_relative_to(base_dir, params):
params["obs_search_path"] = [
interpret_file_relative_to(base_dir, file) for file in params["obs_search_path"]
]
params["station_input"] = [
interpret_file_relative_to(base_dir, file) for file in params["station_input"]
]
if "station_input" in params:
params["station_input"] = [
interpret_file_relative_to(base_dir, file)
for file in params["station_input"]
]
params["obs_links_csv"] = interpret_file_relative_to(
base_dir, params["obs_links_csv"]
)
params["flow_station_input"] = [
interpret_file_relative_to(base_dir, file)
for file in params["flow_station_input"]
]
if "flow_station_input" in params:
params["flow_station_input"] = [
interpret_file_relative_to(base_dir, file)
for file in params["flow_station_input"]
]
return params


Expand All @@ -88,6 +91,10 @@ def __init__(self, config_file, base_dir=None, **kwargs):
# substitue the base_dir in config paths
if base_dir is None:
base_dir = pathlib.Path(self.config_file).parent
if "station_input" not in config:
config["station_input"] = "station.in"
if "flow_station_input" not in config:
config["flow_station_input"] = "fluxflag.prop"
config = replace_with_paths_relative_to(base_dir, config)
self.config = config
# load studies and datastore
Expand Down Expand Up @@ -186,10 +193,11 @@ def get_data(self, id, variable):
dfs.append(df)
dparam = self.get_datastore_param_name(variable)
try:
rd = self.dcat[self.dcat.eval(f'(id=="{id}") & (param=="{dparam}")')].iloc[
0
]
rd = self.dcat[
self.dcat.eval(f'(station_id=="{id}") & (param=="{dparam}")')
].iloc[0]
except IndexError:
print("No data found for", id, variable)
rd = None
if rd is not None:
dfobs, converted_unit = schismstudy.convert_to_SI(
Expand Down Expand Up @@ -322,6 +330,13 @@ def get_map_marker_columns(self):
"""return the columns that can be used to color the map"""
return ["variable", "unit"]

def get_name_to_color(self):
return {
"elev": "green",
"flow": "blue",
"salt": "orange",
}


import click

Expand Down
1 change: 0 additions & 1 deletion pydelmod/schismstudy.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ def __init__(
self.flux_out = self.interpret_file_relative_to(
self.base_dir, pathlib.Path(flux_out)
)
self.reftime = pd.Timestamp(kwargs.pop("reftime", "2020-01-01"))
super().__init__(**kwargs)
stations = read_station_in(self.station_in_file)
self.stations_in = stations
Expand Down

0 comments on commit 73b9616

Please sign in to comment.