Skip to content

Commit

Permalink
add extra range/time criteria (10 x 10 x 10yr) used by Hidy2 to evalu…
Browse files Browse the repository at this point in the history
…ate range average of anomalies
  • Loading branch information
cywhale committed Dec 23, 2024
1 parent be8293c commit 8a35337
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 2 additions & 0 deletions API/change_log.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ ODB API of Marine Heatwaves
#### ver 0.2.3 fix API month_mean (should not) mixed with area_mean method bug
#### ver 0.2.4 Try to shared dask worker leak by unique naming scheme for Dask tasks/major package upgrade (numpy v2)
#### ver 0.2.5 Add LONG_TERM_RANGE (10x10) and LONG_TERM_LIMIT (10yr) criteria/package upgrade

-- add extra range/time criteria (10 x 10 x 10yr) used by Hidy2 to evaluate range average of anomalies
15 changes: 8 additions & 7 deletions API/mhw_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ async def lifespan(app: FastAPI):
config.dz = xr.open_zarr('data/mhw.zarr', chunks='auto',
group='anomaly', decode_times=True)
config.gridSz = 0.25
config.timeLimit = 366
config.timeLimit = 365
config.LON_RANGE_LIMIT = 90
config.LAT_RANGE_LIMIT = 90
config.LONG_TERM_RANGE = 10 # 10 * 10 degree for lon/lat in region
Expand Down Expand Up @@ -93,7 +93,6 @@ async def custom_swagger_ui_html():
### Global variables ###
### move to config.py ##


class MHWResponse(BaseModel):
lon: float
lat: float
Expand Down Expand Up @@ -124,8 +123,9 @@ async def read_mhw(
#### Usage
* One-point MHWs without time-span limitation: e.g. /api/mhw?lon0=135&lat0=15
* Bounding-box <= 90x90 in degrees: 1-year time-span limitation: e.g. /api/mhw?lon0=135&lon1&=140&lat0=15&lat1=30&start=2021-01-01
* Bounding-box > 90x90 in degrees: 1-month time-span limitation: e.g. /api/mhw?lon0=-180&lon1&=180&lat0=-90&lat1=90&start=2021-01-01
* Bounding-box <= 10 x 10 in degrees: 10-years time-span limitation: e.g. /api/mhw?lon0=135&lon1=140&lat0=15&lat1=30&start=2013-01-01 (data from 2013/01/01 to 2022/12/01)
* Bounding-box > 10 x 10 in degrees: 1-year time-span limitation: e.g. /api/mhw?lon0=135&lon1=150&lat0=15&lat1=30&start=2013-01-01 (data from 2013/01/01 to 2013/12/01)
* Bounding-box > 90 x 90 in degrees: 1-month time-span limitation: e.g. /api/mhw?lon0=-180&lon1=180&lat0=-90&lat1=90&start=2013-01-01 (data of 2013/01/01)
"""

try:
Expand Down Expand Up @@ -164,9 +164,10 @@ async def read_mhw_csv(
Query MHW data by longitude/latitude/date (in csv).
#### Usage
* One-point MHWs without time-span limitation: e.g. /api/mhw?lon0=135&lat0=15
* Bounding-box <= 90x90 in degrees: 1-year time-span limitation: e.g. /api/mhw?lon0=135&lon1&=140&lat0=15&lat1=30&start=2021-01-01
* Bounding-box > 90x90 in degrees: 1-month time-span limitation: e.g. /api/mhw?lon0=-180&lon1&=180&lat0=-90&lat1=90&start=2021-01-01
* One-point MHWs without time-span limitation: e.g. /api/mhw/csv?lon0=135&lat0=15
* Bounding-box <= 10 x 10 in degrees: 10-years time-span limitation: e.g. /api/mhw/csv?lon0=135&lon1=140&lat0=15&lat1=30&start=2013-01-01 (data from 2013/01/01 to 2022/12/01)
* Bounding-box > 10 x 10 in degrees: 1-year time-span limitation: e.g. /api/mhw/csv?lon0=135&lon1=150&lat0=15&lat1=30&start=2013-01-01 (data from 2013/01/01 to 2013/12/01)
* Bounding-box > 90 x 90 in degrees: 1-month time-span limitation: e.g. /api/mhw/csv?lon0=-180&lon1=180&lat0=-90&lat1=90&start=2013-01-01 (data of 2013/01/01)
"""

try:
Expand Down
6 changes: 3 additions & 3 deletions API/src/mhw_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,10 @@ async def process_mhw_data(lon0: float, lat0: float, lon1: Optional[float], lat1
elif ((lon_range > config.LONG_TERM_RANGE and lat_range > config.LONG_TERM_RANGE) or (
area_range > config.LONG_TERM_RANGE * config.LONG_TERM_RANGE)) and (
end_date - start_date).days > config.timeLimit:
end_date = start_date + timedelta(days=config.timeLimit)
elif (end_date - start_date).days > config.LONG_TERM_LIMIT * 366:
end_date = start_date + timedelta(days=config.timeLimit - 1)
elif (end_date - start_date).days > config.LONG_TERM_LIMIT * 365:
# Smaller spatial range, limit to one year of data
end_date = start_date + timedelta(days=config.LONG_TERM_LIMIT * 366)
end_date = start_date + timedelta(days=config.LONG_TERM_LIMIT * 365 - 1)

if lon0 > lon1 and np.sign(orig_lon0) == np.sign(orig_lon1):
# Swap if lon0 > lon1 but the same sign
Expand Down

0 comments on commit 8a35337

Please sign in to comment.