Skip to content

Commit

Permalink
pull projection from file
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanLaserGit committed Jan 12, 2024
1 parent e67b89c commit f8eec70
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
12 changes: 8 additions & 4 deletions forcingprocessor/src/forcingprocessor/weight_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,18 @@ def generate_weights_file(geopackage,grid_file,weights_filepath):
try:
ds = xr.open_dataset(grid_file,engine='h5netcdf')
grid = ds['RAINRATE']
try:
projection = ds.crs.esri_pe_string
except:
try:
projection = ds.ProjectionCoordinateSystem.esri_pe_string
except:
raise Exception(f'\n\nCan\'t find projection!\n')
except:
raise Exception(f'\n\nThere\'s a problem with {example_grid_filepath}!\n')

g_df = gpd.read_file(geopackage, layer='divides')
gdf_proj = g_df.to_crs('PROJCS["Lambert_Conformal_Conic",GEOGCS["GCS_Sphere",DATUM["D_Sphere",SPHEROID["Sphere",6370000.0,0.0]], \
PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Lambert_Conformal_Conic_2SP"],PARAMETER["false_easting",0.0],\
PARAMETER["false_northing",0.0],PARAMETER["central_meridian",-97.0],PARAMETER["standard_parallel_1",30.0],\
PARAMETER["standard_parallel_2",60.0],PARAMETER["latitude_of_origin",40.0],UNIT["Meter",1.0]]')
gdf_proj = g_df.to_crs(projection)

crosswalk_dict = {}
start_time = datetime.datetime.now()
Expand Down
17 changes: 9 additions & 8 deletions forcingprocessor/tests/test_forcingprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,23 @@
from pathlib import Path
from datetime import datetime
import requests
from datetime import datetime

from forcingprocessor.forcingprocessor import prep_ngen_data
from forcingprocessor.nwm_filenames_generator import generate_nwmfiles
from forcingprocessor.weight_generator import generate_weights_file

grid_filename = "nwm.t00z.medium_range.forcing.f001.conus.nc"
geopkg_filename = "Gages-04185000.gpkg"
grid_filename = "nwm.t00z.short_range.forcing.f001.conus.nc"
weight_name = "Gages-04185000-weights.json"

geopkg_file = f"https://ngenresourcesdev.s3.us-east-2.amazonaws.com/{geopkg_filename}"
grid_file = f"https://storage.googleapis.com/national-water-model/nwm.20180923/forcing_short_range/{grid_filename}"

@pytest.fixture()
def get_time():
date = datetime.now()
pytest.date = date.strftime('%Y%m%d')
pytest.hourminute = '0000'

@pytest.fixture()
def get_paths():
Expand All @@ -31,12 +37,6 @@ def get_paths():

pytest.filenamelist = (pwd/"filenamelist.txt").resolve()

@pytest.fixture()
def get_time():
date = datetime.now()
pytest.date = date.strftime('%Y%m%d')
pytest.hourminute = '0000'

def test_generate_filenames(get_paths, get_time):
conf = {
"forcing_type" : "operational_archive",
Expand All @@ -63,6 +63,7 @@ def test_generate_weights(get_paths):
if not geopkg_local.exists():
os.system(f'wget {geopkg_file} -P {pytest.data_dir}')

grid_file = f"https://noaa-nwm-pds.s3.amazonaws.com/nwm.{pytest.date}/forcing_medium_range/{grid_filename}"
grid_local = (pytest.data_dir/grid_filename).resolve()
if not grid_local.exists():
os.system(f'wget {grid_file} -P {pytest.data_dir}')
Expand Down

0 comments on commit f8eec70

Please sign in to comment.