Skip to content

Migrate Bing Maps API to Azure Maps API#2093

Merged
cpaulgilman merged 12 commits into
patchfrom
SAM-2092-timezone-api
Jul 21, 2025
Merged

Migrate Bing Maps API to Azure Maps API#2093
cpaulgilman merged 12 commits into
patchfrom
SAM-2092-timezone-api

Conversation

@cpaulgilman

@cpaulgilman cpaulgilman commented Jul 17, 2025

Copy link
Copy Markdown
Collaborator

Pull Request Template

Description

Migrate deprecated Bing Maps API to Azure Maps API. This pull requests modifies the following functions to use the Azure API, which currently do not work because we don't have an Azure API key for SAM:

  1. Time zone API for geocode function.
  2. Static map API for 3D shade calculator map underlay

Make time zone optional for geocode() function to address (1) above.

Update 3D Shade Calculator to handle failed static map API calls for image underlays to address (2).

Update LK geocode() function to add optional parameter

This is a temporary fix. For a more permanent fix:

  1. Request update to NREL Developer Geocode API to return time zone. Or, consider an offline implementation such as one of the options listed in Stack Overflow here . Note that time zones do not correlate well with latitudes as can be seen in this map from timeanddate.com.

  2. See if NREL Developer API can return a static map for 3D shade calculator. If not, investigate getting a Microsoft Azure key for SAM, or finding another static map service.

See https://github.com/NREL/SAM-private/pull/129 for more discussion of next steps.

Fixes #2092

Goes with https://github.com/NREL/SAM-private/pull/129

To Test

  1. Build SAM from sam-private.
  2. Create a Detailed PV / Residential case.
  3. On the Location and Resource page, try to download a weather file using a street address or location name. Download should work without crashing SAM.
  4. On the Shading and Layout page, click Open 3D shade calculator, go to the Location tab and try clicking Lookup address and Update map from coordinates. SAM should display error messages without crashing.
  5. Click File, New script and run the following LK script:
// return lat, lon
x = geocode("portland, or");
outln(x);

// return lat, lon, tz=0 with error message
x = geocode("portland, or", true);
outln(x);

An optional test is to set the value of azure_api_key in SAM-private/src/private.h to a valid Microsoft Azure API key -- this should make Steps 4 and 5 work properly without error messages.

Checklist

  • requires help revision and I added that label
  • adds, removes, modifies, or deletes variables in existing compute modules
  • adds a new compute module
  • changes defaults
  • I've tagged this PR to a milestone

@cpaulgilman cpaulgilman added this to the SAM 2025 release patch 1 milestone Jul 17, 2025
@cpaulgilman cpaulgilman added bug UI User interface issue that applies across performance and financial models labels Jul 17, 2025
@cpaulgilman cpaulgilman self-assigned this Jul 17, 2025

@sjanzou sjanzou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tests do not crash with or without the Azure key.

The question is what to do for the tz return value when there is no key - should it stay 0?

Also, test 4 without a key has four messages to click through - all informative - I think that is a good workflow...but the invalid tz is set to NaN here which makes more sense than the script return value of 0 when there is a tz failure

image image

Comment thread src/invoke.cpp Outdated
// use GeoTools::GeocodeGoogle for non-NREL builds and set google_api_key in private.h
if (get_tz) {
ok = GeoTools::GeocodeDeveloper(cxt.arg(0).as_string(), &lat, &lon, &tz);
cxt.result().hash_item("tz").assign(tz); // converts NULL to 0

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to return 0 if the tz fails (no key)? tz=0 is valid for Greenwich.

No Azure key results
image

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TZ should be null or nan when it is not valid, thanks.

@sjanzou sjanzou left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@cpaulgilman cpaulgilman merged commit b3a34d3 into patch Jul 21, 2025
8 checks passed
@cpaulgilman cpaulgilman deleted the SAM-2092-timezone-api branch July 21, 2025 20:27
@cpaulgilman cpaulgilman added the added to release notes PR and/or issue has been added to release notes for a public release label Jul 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

added to release notes PR and/or issue has been added to release notes for a public release bug UI User interface issue that applies across performance and financial models

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Weather file downloads with address cause SAM to crash

2 participants