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 Aug 1, 2024
2 parents 645975f + d263aea commit cc70c28
Show file tree
Hide file tree
Showing 57 changed files with 674 additions and 642 deletions.
33 changes: 0 additions & 33 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,6 @@ and it is used in our development and testing process.

`Install using Anaconda <./Installing.rst>`_

Compiling PyGnome
=================
Move to the repository directory and activate the ``gnome`` conda environment with:

(base) conda activate gnome

Delete ``py3buildenv_.txt`` if re-compiling code after making software changes. The text file `py3buildenv_.txt` is used to cache software versions to avoid repitious prompts but will cause path problems if changes have been made and needs to be deleted to avoid these erroneous path defs.

Copy ``python Py3Env.py`` to an untracked file that defines local setup, e.g. ``python Py3Env_RDM.py``, and edit
``places`` to point to the right directory on your local system:

places = [r"put-your-VisualStudio-vcvars64.bat-directory-path-here"]

This file can remain untracked in version control because it is unique to each user and easily reproducible from the tracked file ``Py3Env.py`` that will be updated with future advancements. Once this path is corrected to local path, run the script in gnome environment:

(base) conda activate gnome

(gnome) python Py3Env_RDM.py

A command terminal ``cmd.exe`` prompt will open. Change directories and run ``setup.py``

(gnome) cd py_gnome

(gnome) python setup.py develop

After many, many messages, you will see something like:

Installed c:\users\rachael.mueller\projects\pygnome\py_gnome

Processing dependencies for pyGnome==1.1.7

Finished processing dependencies for pyGnome==1.1.7


The WebGNOME Interface:
=======================
Expand Down
2 changes: 1 addition & 1 deletion py_gnome/conda_requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pyzmq
# tblib

## Base numerical libs
numpy <2
numpy >=1.24,<2
scipy

## Modeling libs
Expand Down
5 changes: 3 additions & 2 deletions py_gnome/conda_requirements_build.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

cython=3.*
setuptools>=62 # older versions uses different build dirs
setuptools-scm>=6.2
# setuptools-scm>=6.2
gitpython
python-build
cmake
ninja
scikit-build-core>=0.7.*
scikit-build-core>=0.9.9
# hatchling
2 changes: 1 addition & 1 deletion py_gnome/gnome/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
# just so it will be in the namespace.
from .gnomeobject import GnomeId, AddLogger

__version__ = '1.1.12'
__version__ = "1.1.13dev"


if os.name == 'nt':
Expand Down
3 changes: 3 additions & 0 deletions py_gnome/gnome/cy_gnome/cy_cats_mover.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@ cdef class CyCatsMover(CyCurrentMover):
Takes a CyShioTime object as input and sets C++ Cats mover properties
from the Shio object.
"""
print("in set_shio")
print("CyShioTime:", CyShioTime)
print("cy_shio:", cy_shio)
self.cats.SetTimeDep(cy_shio.shio)

if cy_shio.station_location is not None and self.ref_point is None:
Expand Down
3 changes: 2 additions & 1 deletion py_gnome/gnome/cy_gnome/cy_ossm_time.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ cdef class CyOSSMTime(object):
wp['z'][:] = wp['z']

g_wp = np.zeros((1,), dtype=basic_types.world_point)
g_wp[0] = (wp['long'], wp['lat'], 0)
g_wp[0] = (wp['long'][0], wp['lat'][0], 0)


return tuple(g_wp[0])

Expand Down
36 changes: 19 additions & 17 deletions py_gnome/gnome/cy_gnome/cy_shio_time.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -144,25 +144,27 @@ cdef class CyShioTime(CyOSSMTime):
'yeardata={0.yeardata!r}'
')'.format(self))

def __str__(self):
"""Return string representation of this object"""
"""info = {'Long': round(g_wp[0]['long'], 2),
'Lat': round( g_wp[0]['lat'], 2),
'StationName': sName, 'StationType': sType,
'DaylightSavingsOff': self.shio.daylight_savings_off}
"""

info = ("CyShioTime object - Info read from file:\n"
" File: {1.path_filename} \n"
" StationName : {0[StationName]},"
" StationType : {0[StationType]}\n"
" (Long, Lat) : ({0[Long]}, {0[Lat]})\n"
" DaylightSavingsOff : {0[DaylightSavingsOff]}"
"".format(self.get_info(), self))

return info
# this is broken -- no get_info method ????
# def __str__(self):
# """Return string representation of this object"""
# """info = {'Long': round(g_wp[0]['long'], 2),
# 'Lat': round( g_wp[0]['lat'], 2),
# 'StationName': sName, 'StationType': sType,
# 'DaylightSavingsOff': self.shio.daylight_savings_off}
# """

# info = ("CyShioTime object - Info read from file:\n"
# " File: {1.path_filename} \n"
# " StationName : {0[StationName]},"
# " StationType : {0[StationType]}\n"
# " (Long, Lat) : ({0[Long]}, {0[Lat]})\n"
# " DaylightSavingsOff : {0[DaylightSavingsOff]}"
# "".format(self.get_info(), self))

# return info

def __eq(self, CyShioTime other):
# used by __richcmp__
attrs = ('filename', 'daylight_savings_off', 'scale_factor',
'station', 'station_type', 'station_location',
'yeardata')
Expand Down
2 changes: 1 addition & 1 deletion py_gnome/gnome/environment/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def __init__(self, make_default_refs=True, **kwargs):
self.array_types = {}
super().__init__(**kwargs)

def at(self, points, time, *, units=None, extrapolate=False, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, **kwargs):
"""
Find the value of the property at positions P at time T
Expand Down
28 changes: 18 additions & 10 deletions py_gnome/gnome/environment/environment_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def v(self):
return self._v


def at(self, points, time, *, units=None, extrapolate=False, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, **kwargs):
"""
Find the value of the property at positions of points at time T
Expand Down Expand Up @@ -486,7 +486,7 @@ class GridCurrent(VelocityGrid, Environment):
# 'surface_northward_sea_water_velocity'],
# 'w': ['upward_sea_water_velocity']}

def at(self, points, time, *, units=None, extrapolate=False, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, **kwargs):
'''
Find the value of the property at positions P at time T
Expand Down Expand Up @@ -516,7 +516,9 @@ def at(self, points, time, *, units=None, extrapolate=False, **kwargs):
if res is not None:
return res

extrapolate = self.extrapolation_is_allowed or extrapolate
if extrapolate is None:
extrapolate = self.extrapolation_is_allowed


value = super(GridCurrent, self).at(points, time,
units=units,
Expand Down Expand Up @@ -580,7 +582,7 @@ def __init__(self,

self.wet_dry_mask = wet_dry_mask

def at(self, points, time, *, units=None, extrapolate=False, coord_sys='uv', _auto_align=True, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, coord_sys='uv', _auto_align=True, **kwargs):
'''
Find the value of the property at positions P at time T
Expand Down Expand Up @@ -628,7 +630,8 @@ def at(self, points, time, *, units=None, extrapolate=False, coord_sys='uv', _au
return self.transform_result(value, coord_sys)

if value is None:
extrapolate = self.extrapolation_is_allowed or extrapolate
if extrapolate is None:
extrapolate = self.extrapolation_is_allowed
value = super(GridWind, self).at(pts, time,
units=units,
extrapolate=extrapolate,
Expand Down Expand Up @@ -711,7 +714,7 @@ def __init__(self, *args, **kwargs):

kwargs['data'] = data

def at(self, points, time, *, units=None, extrapolate=False,
def at(self, points, time, *, units=None, extrapolate=None,
_hash=None, _mem=True, **kwargs):

if _hash is None:
Expand All @@ -728,6 +731,9 @@ def at(self, points, time, *, units=None, extrapolate=False,
_time_idx = self.time.index_of(time)
order = self.dimension_ordering

if extrapolate is None:
extrapolate = self.extrapolation_is_allowed

if order[0] == 'time':
value = self._time_interp(points, time, units=units, extrapolate=extrapolate,
_mem=_mem, _hash=_hash, **kwargs)
Expand Down Expand Up @@ -840,8 +846,9 @@ def init_from_netCDF(self,
**kwargs
)

def at(self, points, time, *, units=None, extrapolate=False, **kwargs):
extrapolate = self.extrapolation_is_allowed or extrapolate
def at(self, points, time, *, units=None, extrapolate=None, **kwargs):
if extrapolate is None:
extrapolate = self.extrapolation_is_allowed
cctn = (self.ice_concentration.at(points, time,
extrapolate=extrapolate, **kwargs)
.copy())
Expand Down Expand Up @@ -907,13 +914,14 @@ def from_netCDF(cls,
ice_velocity=ice_velocity,
**kwargs))

def at(self, points, time, *, units=None, extrapolate=False, min_val=0, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, min_val=0, **kwargs):
"""
:param min_val: Minimum value for wind speed. If computed wind speed is less than this
value, it will be set to this value.
:type min_val: float
"""
extrapolate = self.extrapolation_is_allowed or extrapolate
if extrapolate is None:
extrapolate = self.extrapolation_is_allowed

cctn = self.ice_concentration.at(points, time, extrapolate=extrapolate, **kwargs)
wind_v = super(IceAwareWind, self).at(points, time,
Expand Down
21 changes: 13 additions & 8 deletions py_gnome/gnome/environment/gridded_objects_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,10 @@ def from_netCDF(cls, *args, **kwargs):
return var

@combine_signatures
def at(self, points, time, *, units=None, extrapolate=False, unmask=True, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, unmask=True, **kwargs):

if extrapolate is None:
extrapolate = self.extrapolation_is_allowed

value = super(Variable, self).at(points, time,
units=units,
Expand Down Expand Up @@ -744,7 +747,7 @@ def __init__(self,
**kwargs):
super(VectorVariable, self).__init__(*args, **kwargs)
self.extrapolation_is_allowed = extrapolation_is_allowed

#Adding this so unit conversion happens properly in the components
#I really don't think we will be doing mixed units in one of these
#anytime soon.
Expand All @@ -755,8 +758,8 @@ def __init__(self,
warnings.warn("Variable {0} has units {1} which are not the same as the VectorVariable {2} units {3}.".format(var.name, var._gnome_unit, self.name, self._gnome_unit))
else:
var._gnome_unit = self._gnome_unit



def __repr__(self):
try:
Expand Down Expand Up @@ -939,7 +942,7 @@ def constant(cls,
:param values: vector of values
:type values: array-like
'''

Grid = Grid_S
Time = cls._default_component_types['time']
_node_lon = np.array(([-360, 0, 360], [-360, 0, 360], [-360, 0, 360]))
Expand All @@ -952,9 +955,11 @@ def constant(cls,
_vars = [Variable(grid=_grid, units=units[i], time=_time, data=d) for i, d in enumerate(_datas)]
return cls(name=name, grid=_grid, time=_time, variables=_vars)

def at(self, points, time, *, units=None, extrapolate=False, unmask=True, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, unmask=True, **kwargs):
units = units if units else self._gnome_unit #no need to convert here, its handled in the subcomponents
value = super(VectorVariable, self).at(points, time,
if extrapolate is None:
extrapolate = self.extrapolation_is_allowed
value = super(VectorVariable, self).at(points, time,
units=units,
extrapolate=extrapolate,
unmask=unmask,
Expand Down Expand Up @@ -1013,7 +1018,7 @@ def get_data_vectors(self):
xt = x.shape[0]
y = raw_v[:]
yt = y.shape[0]
if raw_u.shape[-2:] == raw_v.shape[-2:] and raw_u.shape[-2:] == self.grid.center_mask.shape:
if raw_u.shape[-2:] == raw_v.shape[-2:] and raw_u.shape[-2:] == self.grid.center_mask.shape:
#raw u/v are same shape and on center
#need to padding_slice the variable since they are not interpolated from u/v
x = x[(np.s_[:],) + ctr_padding_slice]
Expand Down
17 changes: 12 additions & 5 deletions py_gnome/gnome/environment/wind.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ def get_value(self, time):

return tuple(data[0]['value'])

def at(self, points, time, *, units=None, extrapolate=False, coord_sys='uv',_auto_align=True, **kwargs):
def at(self, points, time, *, units=None, extrapolate=None, coord_sys='uv',_auto_align=True, **kwargs):
# fixme: this isn't quite aligned with the Environment base class signature.
# it should be:
# def at(self, points, time, units=None, extrapolate=False, coord_sys='uv', _auto_align=True):
Expand Down Expand Up @@ -553,17 +553,24 @@ def at(self, points, time, *, units=None, extrapolate=False, coord_sys='uv',_aut
else:
raise ValueError('invalid coordinate system {0}'.format(coord_sys))

if extrapolate:
self.extrapolation_is_allowed = True
else:
self.extrapolation_is_allowed = False
# since extrapolation_is_allowed is not passed into the C code we need
# to temporarily set it if extrapolate is passed in, and then change it back
original_extrapolation = self.extrapolation_is_allowed # save value
if extrapolate is not None: # passed in a value, assume this is what we want
self.extrapolation_is_allowed = extrapolate
else: # otherwise probably set on the wind_mover
if self.extrapolation_is_allowed is None: # shouldn't happen
self.extrapolation_is_allowed = False
#print(f"{self.extrapolation_is_allowed=}")
try:
data = self.get_wind_data(time, 'm/s', cs)[0]['value']
except IndexError:
# CyTimeseries is raising an IndexError
raise ValueError(f'time specified ({time}) is not within the bounds of the time: '
f'({self.data_start} to {self.data_stop})')
finally: # make sure it gets restored even if there's an error
self.extrapolation_is_allowed = original_extrapolation # put it back the way it was

if idx is None:
ret_data[:, 0] = data[0]
ret_data[:, 1] = data[1]
Expand Down
Loading

0 comments on commit cc70c28

Please sign in to comment.