Skip to content

Commit

Permalink
1.1.0 release
Browse files Browse the repository at this point in the history
  • Loading branch information
CalebBell committed Dec 7, 2024
1 parent 7975d79 commit 277a91b
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 50 deletions.
14 changes: 12 additions & 2 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,21 @@

## [Unreleased]

## [1.0.28] - 2024-11-28
## [1.1.0] - 2024-12-07

### Added
- Numerous examples showing how to use fluids from other programming langues (inspired by advent of code)

### Fixed
- Fixed differential_pressure_meter_solver to use meter-specific beta calculation; cone and wedge meters were not calculated correctly before this change
- Fixed `differential_pressure_meter_solver` to use meter-specific beta calculation; cone and wedge meters were not calculated correctly in that function before this change

### Changed
- Internal cleanup
- Corrected a constant `venuri nozzle` to `venturi nozzle` in the flow meter section
- Second argument of `entrance_beveled_orifice` was renamed from `do` to `Do` for consistency

### Removed
- Removed unloved and not installed by default components hwm93 and hwm07; the pyglow (https://github.com/timduly4/pyglow) package provides excellent interfaces to those models and more and is recommended by the author


## [1.0.27] - 2024-11-10
Expand Down
12 changes: 8 additions & 4 deletions docs/language_examples/index.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Language Integration Examples
=============================
Calling Fluids/Python from Other Languages
==========================================

Fluids can be called from many different programming languages through various Python bindings and interfaces.
These examples demonstrate some of the ways to communicate with or embed Python into a program written in another language.
Expand All @@ -10,8 +10,12 @@ The author has developed these examples with AI assistance and does not claim to
The difficulty of a language integration varies from trivial in Julia to manually managing reference counts and dealing with the C API in Fortran.
The intent of these examples is to show possibilities, not to provide complete wrappers for all functionality.

Available Languages
-------------------
These examples should also show how the `ht <https://github.com/CalebBell/ht>`_,
`chemicals <https://github.com/CalebBell/chemicals>`_, and `thermo <https://github.com/CalebBell/thermo>`_ libraries can be used from other languages.


Languages
---------

.. toctree::
:maxdepth: 1
Expand Down
2 changes: 1 addition & 1 deletion fluids/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def load_types():
type_module(m)


__version__ = '1.0.27'
__version__ = '1.1.0'

try:
fluids_dir = os.path.dirname(__file__)
Expand Down
109 changes: 74 additions & 35 deletions fluids/design_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ def cooling_degree_days(T, T_base=283.15, truncate=True):


def get_clean_isd_history(dest=os.path.join(folder, 'isd-history-cleaned.tsv'),
url="ftp://ftp.ncdc.noaa.gov/pub/data/noaa/isd-history.csv"): # pragma: no cover
url="https://www.ncei.noaa.gov/pub/data/noaa/isd-history.csv"): # pragma: no cover
"""Basic method to update the isd-history file from the NOAA. This is useful
as new weather stations are updated all the time.
Expand Down Expand Up @@ -592,40 +592,77 @@ def percentile_extreme_condition(self, older_year=None, newer_year=None,



stations = []
_latlongs = []
"""Read in the parsed data into
1) a list of latitudes and longitudes, temporary, which will get converted to
a numpy array for use in KDTree
2) a list of IntegratedSurfaceDatabaseStation objects; the query will return
the index of the nearest weather stations.
"""
with open(os.path.join(folder, 'isd-history-cleaned.tsv')) as f:
for line in f:
values = line.split('\t')
for i in range(11):
# First two are not values
v = values[i]
if v == '':
values[i] = None # '' case
else:
try:
if i > 2:
values[i] = float(v)
if int(v) == 99999:
values[i] = None
except:
continue
lat, lon = values[6], values[7]
if lat and lon:
# Some stations have no lat-long; this isn't useful
stations.append(IntegratedSurfaceDatabaseStation(*values))
_latlongs.append((lat, lon))
_latlongs = np.array(_latlongs)
station_count = len(stations)

_stations = None
_latlongs = None
_station_count = None
_kd_tree = None

kd_tree = cKDTree(_latlongs) # _latlongs must be unchanged as data is not copied
def _load_station_data():
"""Read in the parsed data into
1) a list of latitudes and longitudes, temporary, which will get converted to
a numpy array for use in KDTree
2) a list of IntegratedSurfaceDatabaseStation objects; the query will return
the index of the nearest weather stations.
"""
global _stations, _latlongs, _station_count, _kd_tree
if _stations is None:
_stations = []
temp_latlongs = []

history_file = os.path.join(folder, 'isd-history-cleaned.tsv')
if not os.path.exists(history_file):
get_clean_isd_history(dest=history_file)

with open(os.path.join(folder, history_file)) as f:
for line in f:
values = line.split('\t')
for i in range(11):
v = values[i]
if v == '':
values[i] = None
else:
try:
if i > 2:
values[i] = float(v)
if int(v) == 99999:
values[i] = None
except:
continue
lat, lon = values[6], values[7]
# Some stations have no lat-long; this isn't useful
if lat and lon:
_stations.append(IntegratedSurfaceDatabaseStation(*values))
temp_latlongs.append((lat, lon))

# _latlongs must be unchanged as data is not copied
_latlongs = np.array(temp_latlongs)
_station_count = len(_stations)
_kd_tree = cKDTree(_latlongs)

def get_station_count():
"""Get the total number of stations."""
if _station_count is None:
_load_station_data()
return _station_count

def get_stations():
"""Get the list of weather stations."""
if _stations is None:
_load_station_data()
return _stations

def get_latlongs():
"""Get the array of station coordinates."""
if _latlongs is None:
_load_station_data()
return _latlongs

def get_kd_tree():
"""Get the KD-tree for spatial queries."""
if _kd_tree is None:
_load_station_data()
return _kd_tree


def get_closest_station(latitude, longitude, minumum_recent_data=20140000,
Expand Down Expand Up @@ -666,13 +703,15 @@ def get_closest_station(latitude, longitude, minumum_recent_data=20140000,
Examples
--------
>>> get_closest_station(51.02532675, -114.049868485806, 20150000)
<Weather station registered in the Integrated Surface Database, name CALGARY INTL CS, country CA, USAF 713930, WBAN None, coords (51.1, -114.0) Weather data from 2004 to 2020>
<Weather station registered in the Integrated Surface Database, name CALGARY INTL CS, country CA, USAF 713930, WBAN None, coords (51.1, -114.0) Weather data from 2004 to 2024>
"""
# Both station strings may be important
# Searching for 100 stations is fine, 70 microseconds vs 50 microsecond for 1
# but there's little point for more points, it gets slower.
# bad data is returned if k > station_count
distances, indexes = kd_tree.query([latitude, longitude], k=min(match_max, station_count))
station_count = get_station_count()
stations = get_stations()
distances, indexes = get_kd_tree().query([latitude, longitude], k=min(match_max, station_count))
for i in indexes:
latlon = _latlongs[i]
enddate = stations[i].END
Expand Down
8 changes: 4 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
name='fluids',
packages=['fluids'],
license='MIT',
version='1.0.27',
download_url='https://github.com/CalebBell/fluids/tarball/1.0.27',
version='1.1.0',
download_url='https://github.com/CalebBell/fluids/tarball/1.1.0',
description=description,
long_description=open('README.rst').read(),
install_requires=["numpy>=1.5.0", "scipy>=1.6.0"],
Expand All @@ -83,8 +83,8 @@
classifiers=classifiers,
package_data={
'fluids': [
'data/*', 'nrlmsise00/*',
'optional/*.py', 'optional/*.dat', 'optional/*.f90', 'optional/*.for', 'optional/*.pyf', 'optional/*.bin',
'data/*.csv', 'nrlmsise00/*',
'optional/*.py',
'numerics/*', 'constants/*'
]
},
Expand Down
8 changes: 4 additions & 4 deletions tests/test_design_climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
from fluids.design_climate import (
IntegratedSurfaceDatabaseStation,
StationDataGSOD,
_latlongs,
get_latlongs,
cooling_degree_days,
geocode,
get_closest_station,
get_station_year_text,
heating_degree_days,
stations,
get_stations,
)
from fluids.numerics import assert_close, assert_close1d

Expand Down Expand Up @@ -82,8 +82,8 @@ def test_IntegratedSurfaceDatabaseStation():
assert value == getattr(test_station, attr)

def test_data():
assert _latlongs.shape[0] >= 27591
for station in stations:
assert get_latlongs().shape[0] >= 27591
for station in get_stations():
assert abs(station.LAT) <= 90
assert abs(station.LON) <= 180

Expand Down

0 comments on commit 277a91b

Please # to comment.