Skip to content

Commit

Permalink
Update references to original URL and fix API script bugs (#1173)
Browse files Browse the repository at this point in the history
* update urls in code

* update url in api scripts

* fix variable name in subset script generation

* fix csv saving in python API script

* fix file save in python subset script
  • Loading branch information
JustinElms authored Nov 26, 2024
1 parent cc99dd0 commit 1f7c5a1
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 56 deletions.
4 changes: 2 additions & 2 deletions config/oceannavigator-nginx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ server {
listen 80 default_server;
server_name localhost ;

return 301 http://navigator.oceansdata.ca$request_uri;
return 301 https://oceannavigator.ca$request_uri;
}

server {
listen 80;
server_name .navigator.oceansdata.ca ;
server_name .oceannavigator.ca ;
charset utf-8;
client_max_body_size 75M;

Expand Down
4 changes: 2 additions & 2 deletions data/netcdf_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def regrid(
)
ds.description = "Converted " + dataset_name
ds.history = "Created: " + str(datetime.datetime.now())
ds.source = "www.navigator.oceansdata.ca"
ds.source = "www.oceannavigator.ca"

# Create the netcdf dimensions
ds.createDimension("lat", GRID_RESOLUTION)
Expand Down Expand Up @@ -642,7 +642,7 @@ def regrid(
"%s%s.nc" % (working_dir, filename),
Path("%s%s.nc" % (working_dir, filename)).name,
)
myzip.comment = b"Generated from www.navigator.oceansdata.ca"
myzip.comment = b"Generated from www.oceannavigator.ca"
myzip.close() # Must be called to actually create zip
return working_dir, filename + ".zip"

Expand Down
4 changes: 2 additions & 2 deletions oceannavigator/frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,12 @@ <h2>Identification of Data Sources</h2>
generated by this application:
<br />
<span class="example-span">
(dataset name), https://navigator.oceansdata.ca, (year)
(dataset name), https://oceannavigator.ca, (year)
</span>
Example:
<br />
<span class="example-span">
GIOPS daily averages, https://navigator.oceansdata.ca, 2023
GIOPS daily averages, https://oceannavigator.ca, 2023
</span>
<br />
If you would like further information about how to reference the
Expand Down
2 changes: 1 addition & 1 deletion oceannavigator/frontend/src/components/InfoHelpWindow.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ function InfoHelpWindow(props) {
url = `https://youtu.be/${selectedItem}`;
break;
case 5:
url = "https://navigator.oceansdata.ca/docs";
url = "https://oceannavigator.ca/docs";
break;
}

Expand Down
2 changes: 1 addition & 1 deletion oceannavigator/frontend/src/components/SubsetPanel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function SubsetPanel(props) {

const saveScript = (key) => {
let query = {
outputFormat: outputFormat,
output_format: outputFormat,
dataset_name: props.dataset.id,
variables: outputVariables.join(),
time: [outputStarttime, outputEndtime].join(),
Expand Down
2 changes: 0 additions & 2 deletions plotting/scriptGenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ def generateR(url, plot_type: str, script_Type: str) -> BytesIO:
query = query.replace("true", "1")
if "false" in query:
query = query.replace("false", "0")
if "null" in query:
query = query.replace("null", "None")

with open(f"plotting/templates/r_{script_Type}_template.txt", "r") as f:
template = str(f.read())
Expand Down
13 changes: 2 additions & 11 deletions plotting/templates/python_csv_template.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import requests
import os
import shutil
from urllib.request import urlopen
from urllib.parse import urlencode
from contextlib import closing
try:
from PIL import Image
except:
print("If you are on a Windows machine, please install PIL (imaging library) using 'python -m pip install Pillow' in the Anaconda Prompt")
exit()
import json


Expand All @@ -18,20 +10,19 @@ def requestFile():


# Assemble full request
base_url = "https://navigator.oceansdata.ca/api/v2.0/plot/{p}?"
base_url = "https://oceannavigator.ca/api/v2.0/plot/{p}?"
url = base_url + urlencode({{"query": json.dumps(query)}}) + '&save=True&format=csv&size=10x7&dpi=144'
print(url)


# Save file and finish
data_file = requests.get(url, stream=True)
dump = data_file.raw
# change this if you want a different save location
location = os.getcwd()
fname = {f} + ".csv"
with open(fname, "wb") as location:
print('Saving File')
shutil.copyfileobj(dump, location)
location.write(data_file.content)
print('Done')


Expand Down
2 changes: 1 addition & 1 deletion plotting/templates/python_plot_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def requestFile():


# Assemble full request
base_url = "https://navigator.oceansdata.ca/api/v2.0/plot/{p}?"
base_url = "https://oceannavigator.ca/api/v2.0/plot/{p}?"
url = base_url + urlencode({{"query": json.dumps(query)}}) + "&format=png&size=10x7&dpi=" + str(dpi)
print(url)

Expand Down
7 changes: 2 additions & 5 deletions plotting/templates/python_subset_template.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import requests
import os
import shutil
from urllib.request import urlopen
from contextlib import closing


def requestFile():
Expand All @@ -11,7 +8,7 @@ def requestFile():


# Assemble full request
base_url = "https://navigator.oceansdata.ca/api/v2.0/subset/?"
base_url = "https://oceannavigator.ca/api/v2.0/subset/"+query["dataset_name"]+"/"+query["variables"]+"?"
url = base_url
for key in query:
url += f"&{{key}}={{query[key]}}"
Expand All @@ -25,7 +22,7 @@ def requestFile():
location = os.getcwd()
with open("script_output.nc", "wb") as location:
print('Saving File')
shutil.copyfileobj(dump, location)
location.write(data_file.content)
print('Done')


Expand Down
20 changes: 0 additions & 20 deletions plotting/templates/rSUBSETtemplate.txt

This file was deleted.

2 changes: 1 addition & 1 deletion plotting/templates/r_csv_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ dpi <- 144
queryObj <- fromJSON(query)
fname <- paste("ONAV_CSV_", queryObj["dataset"],"_", queryObj["variable"],".csv", sep="")
gsub("[\r\n]", "", query)
base_url <- "https://navigator.oceansdata.ca/api/v2.0/plot/{p}?"
base_url <- "https://oceannavigator.ca/api/v2.0/plot/{p}?"
url <- paste(base_url,"&query=",URLencode(query),"&save=True&format=csv&size=10x7&dpi=",toString(dpi), sep="")
print(url)

Expand Down
4 changes: 2 additions & 2 deletions plotting/templates/r_plot_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ queryObj <- fromJSON(query)
fname <- paste("ONAV_PLOT_", queryObj["dataset"],"_", queryObj["variable"],".png", sep="")

gsub("[\r\n]", "", query)
base_url <- "https://navigator.oceansdata.ca/api/v2.0/plot/{p}?"
url <- paste(base_url,"&query=",URLencode(query),"&dpi=",toString(dpi), sep="")
base_url <- "https://oceannavigator.ca/api/v2.0/plot/{p}?"
url <- paste(base_url,"&query=",URLencode(query),"&save=True&format=png&size=10x7&dpi=",toString(dpi), sep="")
print(url)


Expand Down
18 changes: 16 additions & 2 deletions plotting/templates/r_subset_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,20 @@
library(jsonlite)


query <- '{q}'

print("NOT IMPLEMENTED")
queryObj <- fromJSON(query)
fname <- "script_output.nc"

base_url <- paste("https://oceannavigator.ca/api/v2.0/subset/", queryObj["dataset_name"], "/", queryObj["variables"], "?", sep="")
url <- base_url

for (key in names(queryObj))
{{
url <- paste(url, "&", key, "=", queryObj[key], sep="")
}}

url <- gsub(",[\r\n]", "", url)
print(url)

print(paste("Downloading file in location ",getwd(), " and exiting..."))
download.file(url, fname, method="auto", mode="wb")
2 changes: 1 addition & 1 deletion scripts/pregen_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
required=True,
help=(
"Root URL to Navigator instance. Ex: "
+ "https://navigator.oceansdata.ca or http://10.5.166.251:5000"
+ "https://oceannavigator.ca or http://10.5.166.251:5000"
),
)
args = parser.parse_args()
Expand Down
4 changes: 2 additions & 2 deletions scripts/profiling_scripts/api_profiling_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ def run(self):
the command line with flags specifying file locaitons and options as described in
the example below:
python api_profiling_driver.py --url https://navigator.oceansdata.ca
python api_profiling_driver.py --url https://oceannavigator.ca
--config api_profiling_config.json --id usr -a 1 -t 120
where:
Expand All @@ -566,7 +566,7 @@ def run(self):
"""

# default options
url = "https://navigator.oceansdata.ca"
url = "https://oceannavigator.ca"
config = "scripts/profiling_scripts/api_profiling_config.json"
csv_file = None
prof_path = None
Expand Down
2 changes: 1 addition & 1 deletion tests/disabled/test_datasetconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def test_required_datasets_have_cache_attribute(self):

def test_all_urls_point_to_localhost(self):

prog = re.compile(r"^.*navigator.oceansdata.ca.*$")
prog = re.compile(r"^.*oceannavigator.ca.*$")

for ds in self.datasetConfig:
self.assertFalse(prog.match(self.datasetConfig[ds]["url"]))
Expand Down

0 comments on commit 1f7c5a1

Please sign in to comment.