Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisBarker-NOAA committed Nov 25, 2024
2 parents b68453d + d690052 commit 19059fe
Show file tree
Hide file tree
Showing 39 changed files with 17,875 additions and 222 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ test_image_save.gif
test_image_save.jpg
test_image_save.png
test_image_text.png
py_gnome/MapBounds_Island_anim.gif
py_gnome/scripts/script_long_island/CLISShio.txt
py_gnome/scripts/script_long_island/LI_tidesWAC.CUR
py_gnome/scripts/script_long_island/LongIslandSoundMap.BNA
Expand Down
30 changes: 17 additions & 13 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,16 @@ compile_pygnome:

- apt-get install git g++ make libxext-dev libsm-dev libxrender-dev -y

# get the adios_db code: needed for tests and requirements
- git clone --depth 1 -b develop https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git
# # get the adios_db code: needed for tests and requirements
# no longer needed -- pygnome is pulling adios_db from conda-forge
# - git clone --depth 1 -b develop https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git
- cd ./py_gnome
- conda install -y python=$PYTHON_VER --file conda_requirements.txt
--file conda_requirements_build.txt
--file ../oil_database/adios_db/conda_requirements.txt
# --file ../oil_database/adios_db/conda_requirements.txt

# install adios_db
- pip install ../oil_database/adios_db/
# # install adios_db
# - pip install ../oil_database/adios_db/

# Install pygnome
# If you want verbose output including the compiler/linker commands,
Expand All @@ -62,6 +63,7 @@ compile_pygnome:
# And there may be times we want to build a wheel file (.whl)
# The following command will build a wheel in the current directory:
# python -m pip wheel ./

- echo "compiling PyGNOME"
- python -m pip install ./

Expand Down Expand Up @@ -169,19 +171,20 @@ test_pygnome_windows:
script:
- echo "Building and testing PyGNOME"

# pulled from conda-forge now
# get the adios_db code: needed for tests and requirements
- git clone --depth 1 -b develop https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git
# - git clone --depth 1 -b develop https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git

- conda install -y python=$PYTHON_VER mamba
- cd ./py_gnome
- echo "Setting up conda environment"
- mamba install -y python=$PYTHON_VER --file conda_requirements.txt
--file conda_requirements_build.txt
--file conda_requirements_test.txt
--file ../oil_database/adios_db/conda_requirements.txt
# --file ../oil_database/adios_db/conda_requirements.txt

# install adios_db
- pip install ../oil_database/adios_db/
# - pip install ../oil_database/adios_db/

# Install pygnome
# If you want verbose output including the compiler/linker commands,
Expand All @@ -208,8 +211,8 @@ build_develop:
- echo '' # manual override of before_script because we're on runner 12.3 and inherit options are only 12.9+
script:
# get the adios_db code, so we can install it in the docker image
# note -- is should already be there
- git clone --depth 1 -b develop https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git
# note -- is should already be there from conda-forge
# - git clone --depth 1 -b develop https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git

# build the py_gnome image
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
Expand All @@ -228,8 +231,8 @@ build_main:
- echo '' # manual override of before_script because we're on runner 12.3 and inherit options are only 12.9+
script:
# get the adios_db code, so we can install it in the docker image
# note -- is should already be there
- git clone --depth 1 -b production https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git
# note -- is should already be there -- from conda-forge
# - git clone --depth 1 -b production https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git

# build the docs image
- docker build -f dockerfile-docs ./py_gnome/documentation/build/html -t registry.orr.noaa.gov/gnome/pygnome/docs
Expand All @@ -253,7 +256,8 @@ build_production:
- echo ''
script:
# get the adios_db code, so we can install it in the docker image
- git clone --depth 1 -b production https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git
# should be there from conda-forge
# - git clone --depth 1 -b production https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.orr.noaa.gov/gnome/oil_database/oil_database.git

- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- docker build . --build-arg PYTHON_VER=$PYTHON_VER -t registry.orr.noaa.gov/gnome/pygnome:production
Expand Down
2 changes: 1 addition & 1 deletion Installing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Create an environment for PyGNOME with all requirements:

If you only need to run PyGNOME::

> conda create -n gnome --file python=3.10 conda_requirements.txt
> conda create -n gnome python=3.10 --file conda_requirements.txt

If you need to build, etc PyGNOME::

Expand Down
6 changes: 3 additions & 3 deletions dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ WORKDIR /pygnome/

RUN conda install python=$PYTHON_VER \
--file py_gnome/conda_requirements.txt \
--file py_gnome/conda_requirements_build.txt \
--file oil_database/adios_db/conda_requirements.txt
--file py_gnome/conda_requirements_build.txt
# --file oil_database/adios_db/conda_requirements.txt

RUN cd oil_database/adios_db && python -m pip install ./
# RUN cd oil_database/adios_db && python -m pip install ./

RUN cd py_gnome && python -m pip install ./

Expand Down
9 changes: 5 additions & 4 deletions py_gnome/conda_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,19 @@
# if you want a full development environment,
# you can install the whole thing at once:
#
# conda create -n gnome python=3.10 --file conda_requirements.txt --file conda_requirements_build.txt --file conda_requirements_test.txt --file conda_requirements_docs.txt
# conda create -n gnome python=3.12 --file conda_requirements.txt --file conda_requirements_build.txt --file conda_requirements_test.txt --file conda_requirements_docs.txt


# These packages should all be in one of the following channels:
# defaults
# conda-forge

# it'll probably work with 3.9 -- 3.12, but CI is testing with 3.10
# it'll probably work with 3.9 -- 3.13, but CI is testing with 3.10

python>=3.9,<3.12
python>=3.9,<=3.12

## System libs
awesome-slugify
colander <2
progressbar
psutil
Expand Down Expand Up @@ -55,7 +56,7 @@ pyproj
shapely>=2.0.6 # older one broken with numpy2

# NOAA maintained packages
gridded>=0.6.9
gridded>=0.6.10
pynucos>=3.3.0
cell_tree2d
py_gd>=2.3
Expand Down
3 changes: 2 additions & 1 deletion py_gnome/conda_requirements_build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
# NOTE: you also need a compiler set up to build Python extensions

cython=3.*
pip
setuptools>=62 # older versions uses different build dirs
# setuptools-scm>=6.2
pip
gitpython
python-build
cmake
ninja
scikit-build-core>=0.9.9
# hatchling
7 changes: 4 additions & 3 deletions create_conda_env.py → py_gnome/create_conda_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
default is "all" -- full dev environment
"run" will only give you wnat you need to run the code
"run" will only give you what you need to run the code
"build" will add what's needed to build PYGNOME
Expand All @@ -28,10 +28,10 @@
Will create and environment called "gnome" with everything needed to
build, run and test PyGNOME
NOTE: currently hard-coded for Python 3.10
NOTE: currently hard-coded for Python 3.12
"""

PYTHON="3.10"
PYTHON="3.12"

if __name__ == "__main__":
try:
Expand All @@ -57,6 +57,7 @@
for req in reqs:
cmd.extend(["--file", req])
print("running\n", cmd)
# subprocess.run(cmd, shell=True)
subprocess.run(cmd)


Expand Down
2 changes: 1 addition & 1 deletion py_gnome/documentation/source/scripting/model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Wind, currents, and diffusion all have uncertainty parameters with default value
You can set the coefficients that control the size and distribution of the uncertainty on the individual movers.
The uncertainty only applies to the model transport. Uncertainty for weathering is under development.

To run the model backwards, set both the time_step and the duration to negative values
To run the model backwards, include run_backwards=True. The model will start at the start_time and step backwards through the duration.


Configuring the Model
Expand Down
6 changes: 6 additions & 0 deletions py_gnome/documentation/source/scripting/sample_scripts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ A script that demonstrates how to use gridded currents and winds from netcdf fil
Demonstration of adding uncertainty to a model, and adjusting the uncertainty parameters of a current mover.


``polygon_release_script.py``
---------------------

A script that demonstrates how to create a spill from a shape file or list of polygons.


Testing Scripts
===============

Expand Down
4 changes: 2 additions & 2 deletions py_gnome/documentation/source/scripting/scripting_intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ This example does not load any external data, but creates a simple map and mover
The "spill" is a conservative substance, i.e. a "passive tracer."

This example is in the PyGNOME source under "scripts/example_scripts", or can be downloaded here:
.. this download link is getting rendered oddly -- and why do I need so many ../?
:download:`simple_script.py <../../../../../scripts/example_scripts/simple_script.py`

:download:`simple_script.py <../../../../../scripts/example_scripts/simple_script.py>`

Initialize the Model
--------------------
Expand Down
Binary file not shown.
49 changes: 49 additions & 0 deletions py_gnome/documentation/source/scripting/spills.rst
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,29 @@ Polygon Releases
The :class:`gnome.spills.release.PolygonRelease` Object releases particles distributed over a polygon or set
of polygons. The particles are distributed randomly over the polygons with a simple weighting by polygon area (i.e., geographically larger polygons will be seeded with more particles). The subclass :class:`gnome.spills.release.NESDISRelease` can be used specifically with the |nesdis_reports| operationally produced by NOAA's Office of Satellite and Product Operations.

Here's an example setting up a spill from a polygon. The polygon file used in the example can be accessed :download:`here <spatial_example.zip>`. A list of polygons can be used instead of a shapefile:

.. code-block:: python
import gnome.scripting as gs
start_time = "2024-10-01T00:00"
model = gs.Model(start_time=start_time,
duration=gs.days(2),
time_step=60 * 60 # 1 hour in seconds
)
release = gs.PolygonRelease(filename='spatial_example.zip',
release_time=start_time
)
spill = gs.Spill(release=release)
model.spills += spill
You can find a complete script using a PolygonRelease in:

``pygnome/py_gnome/scripts/example_scripts/polygon_release_script.py``

Or download it here:
:download:`polygon_release_script.py <../../../scripts/example_scripts/polygon_release_script.py>`


Using Helper Functions
----------------------
Expand Down Expand Up @@ -126,6 +149,32 @@ The helper function creates both the ``Release`` and the ``Substance`` objects a
model.full_run()
Similarly we can use the :func:`gnome.scripting.polygon_release_spill` helper function to initialize a polygon spill.
The oil type is specified using the sample oil file provided above with a spill volume of 1000 barrels. The polygon shapefile used is the sample file provided above.

.. code-block:: python
import gnome.scripting as gs
start_time = gs.asdatetime("2024-10-01T00:00")
model = gs.Model(start_time=start_time,
duration=gs.days(2),
time_step=60 * 60, # 1 hour in seconds
)
spill = gs.polygon_release_spill(filename='spatial_example.zip',
release_time=start_time,
amount=1000,
substance=gs.GnomeOil(filename='alaska-north-slope_AD00020.json'),
units='bbl',
windage_range=(0.01, 0.02),
windage_persist=-1,
name='polygon spill')
model.spills += spill
# ... add movers/weatherers
model.full_run()
.. _subsurface_plume:

Subsurface plume
Expand Down
2 changes: 1 addition & 1 deletion py_gnome/gnome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def ver_check(required, installed):
else:
return True

libs = [('gridded', '0.6.9', ''),
libs = [('gridded', '0.6.10', ''),
('nucos', '3.3.0', ''),
('py_gd', '2.3.0', ''),
('adios_db', '1.2.4', 'Only required to use the ADIOS Database '
Expand Down
15 changes: 10 additions & 5 deletions py_gnome/gnome/cy_gnome/cy_cats_mover.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -261,12 +261,17 @@ cdef class CyCatsMover(CyCurrentMover):
cdef OSErr err

err = self.cats.InitMover()
if err is not False:
raise ValueError('CATSMover.compute_velocity_scale(..) '
'returned an error. Reference point not valid. OSErr: {0}'
.format(err))
if err:
return err

return True
# Make this a runtime error or warning, let calling function decide
# if err is not False:
# raise ValueError('CATSMover.compute_velocity_scale(..) '
# 'returned an error. Reference point not valid. OSErr: {0}'
# .format(err))

#return True
return 0

def get_move(self,
model_time,
Expand Down
8 changes: 6 additions & 2 deletions py_gnome/gnome/environment/environment_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,13 @@ def get_data_vectors(self):
if 'degree' in self.angle.units:
raw_ang = raw_ang * np.pi/180.

ctr_mask = gridded.utilities.gen_celltree_mask_from_center_mask(self.grid.center_mask, angle_padding_slice)
if self.grid.center_mask is not None:
ctr_mask = gridded.utilities.gen_celltree_mask_from_center_mask(self.grid.center_mask, angle_padding_slice)
ctr_mask = ctr_mask.reshape(-1)
else:
ctr_mask = False
ang = raw_ang.reshape(-1)
ang = np.ma.MaskedArray(ang, mask = ctr_mask.reshape(-1))
ang = np.ma.MaskedArray(ang, mask = ctr_mask)
ang = ang.compressed()

x = lin_u[:] * np.cos(ang) - lin_v[:] * np.sin(ang)
Expand Down
2 changes: 1 addition & 1 deletion py_gnome/gnome/environment/gridded_objects_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def get_centers(self):
lats = (self.node_lat[0:-1, 0:-1] + self.node_lat[1:, 1:]) / 2
return np.stack((lons, lats), axis=-1).reshape(-1, 2)
else:
if self._get_geo_mask('center'):
if self._get_geo_mask('center') is not None:
if not self._cell_tree:
self.build_celltree(use_mask=True)
ctr_padding_slice = self.get_padding_slices(self.center_padding)
Expand Down
16 changes: 9 additions & 7 deletions py_gnome/gnome/environment/names.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
**nc_names:**
These are common variable names used for the variables PyGNOME uses. If you set the variable names in
a netcdf files to one these names, PYGNOME should be able to load the file.
These are common variable names used for the variables PyGNOME uses.
If you set the variable names in a netcdf files to one these names,
PyGNOME should be able to load the file.
**Name Mapping:**
**grid_temperature**
Default Names: temp, water_t, TEMP, WATER_T
Expand Down Expand Up @@ -175,15 +175,17 @@ def capitalize_name_mapping(name_map):
for variable, data in name_map.items():
def_names = data['default_names']
try:
for name in def_names[:]:
def_names.append(name.upper())
def_names[:] = list(set(def_names))
except TypeError: # it's nested
for sub_var in def_names.values():
for name in sub_var[:]:
sub_var.append(name.upper())
# eliminate the duplicates
sub_var[:] = list(set(sub_var))
except AttributeError: # it's not nested
for name in def_names[:]:
def_names.append(name.upper())
def_names[:] = list(set(def_names))


capitalize_name_mapping(nc_names)

def insert_names_table(table_text):
Expand Down
Loading

0 comments on commit 19059fe

Please sign in to comment.