Skip to content
This repository has been archived by the owner on Sep 27, 2023. It is now read-only.

Add universal weather data downloader #1021

Merged
merged 34 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8f65179
Add NSRDB data tool
Oct 20, 2021
dee000a
Update nsrdb_weather.py
Oct 20, 2021
7aaa7ad
Update nsrdb_weather.py
Oct 20, 2021
f2a348d
Update nsrdb_weather.py
Oct 20, 2021
16d23f8
Update nsrdb_weather.py
Oct 20, 2021
16d84a1
Update nsrdb_weather.py
Oct 20, 2021
b855718
Update nsrdb_weather.py
Oct 20, 2021
fa9725b
Update nsrdb_weather.py
Oct 20, 2021
38f7dc8
Update nsrdb_weather.py
Oct 20, 2021
afeab47
Update nsrdb_weather.py
Oct 20, 2021
1419b02
Update nsrdb_weather.py
Oct 20, 2021
5011944
Update nsrdb_weather.py
Oct 20, 2021
305ce79
Update nsrdb_weather.py
Oct 21, 2021
5bd0f1e
Add support for direct call using subcommand
dchassin Oct 22, 2021
2bd3c3e
Update nsrdb_weather.py
dchassin Oct 22, 2021
feaf52f
Update nsrdb_weather.py
dchassin Oct 22, 2021
5e681f9
Update handling of email
dchassin Oct 22, 2021
0bd3d97
Update nsrdb_weather.py
dchassin Oct 22, 2021
863cd2b
Update gridlabd.in
dchassin Oct 22, 2021
bb90a81
Update nsrdb_weather.py
Oct 22, 2021
b59d67e
Update gridlabd.m4sh
Oct 22, 2021
e2587a4
Update gridlabd.in
Oct 22, 2021
709ee00
Update player.cpp
Oct 22, 2021
04254d5
Update nsrdb_weather.py
Oct 22, 2021
9bcae2b
Fix shared data caching
Oct 22, 2021
393d309
Update nsrdb_weather.py
Oct 22, 2021
7c66da0
Update nsrdb_weather.py
dchassin Oct 23, 2021
2cc322c
Update nsrdb_weather.py
dchassin Oct 23, 2021
adecd35
Update nsrdb_weather.py
dchassin Oct 24, 2021
dd507f4
Update nsrdb_weather.py
dchassin Oct 24, 2021
25e32e1
Add pseudo global GEOCODE
Oct 25, 2021
61df803
Update Geocode.md
Oct 25, 2021
1e80008
Update docs, examples, and macros
Oct 25, 2021
b209fa3
Merge branch 'develop' into develop-add-nrel-weather-converter
aivanova5 Oct 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions docs/GLM/Global/Geocode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[[/GLM/Global/Geocode]] -- Geohash encoder

# Synopsis

GLM:

~~~
${GEOCODE <latitude>,<longitude>[#<resolution>]}
${GEOCODE <objname>[#<resolution>]}
~~~

# Description

Return the geohash code corresponding to the latitude/longitude given or the object name. This can be helpful is connecting object based on location, such as linking an object to weather.

The default resolution is 5. The resolution corresponds to the following distances:

1 2500 km
2 600 km
3 80 km
4 20 km
5 2.5 km
6 0.2 km
7 0.08 km
8 0.02 km
9 0.0025 km
10 0.0006 km
11 0.000075 km

# Example

The following example prints the geohash codes for a position and an object:

~~~
class test
{
char32 geocode;
}
object test
{
name "test";
latitude 37.5;
longitude -122.2;
}
#print ${GEOCODE 37.5,-122.2#6}
#print ${GEOCODE test#6}
~~~

# See also

* [[/GLM/Subcommand/Geodata]]
5 changes: 1 addition & 4 deletions docs/GLM/Macro/Ifexist.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ The `#ifexist` macro is used to conditionally process GLM lines when a file is f
#endif
~~~

# Caveats

1. TODO enumerate known issues using Ifexist

# See also

* [[/Glm/Macro/If]]
* [[/Glm/Macro/Ifmissing]]

41 changes: 41 additions & 0 deletions docs/GLM/Macro/Ifmissing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[[/Glm/Macro/Ifmissing]] -- Macro to conditionally process GLM lines when a file missing

# Synopsis

GLM:

~~~
#ifmissing <path-name>
...
[#else]
...
#endif
~~~

or

~~~
#ifmissing "<path-name>"
...
[#else]
...
#endif
~~~

# Description

The `#ifmissing` macro is used to conditionally process GLM lines when a file is not found.

# Examples

~~~
#ifmissing "myfile.glm"
#print didn't find it
#endif
~~~

# See also

* [[/Glm/Macro/If]]
* [[/Glm/Macro/Ifexist]]

21 changes: 21 additions & 0 deletions gldcore/autotest/test_geocode.glm
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#set suppress_repeat_messages=false

class test
{
char32 geocode;
}

object test
{
name "test";
latitude 37.5;
longitude -122.2;
}

#if ${GEOCODE 37.5,-122.2#6} != 9q9j76
#error geocode "37.5,-122.2#6" does not match "9q9j76"
#endif

#if ${GEOCODE test#6} != 9q9j76
#error geocode "test#6" does not match "9q9j76"
#endif
91 changes: 91 additions & 0 deletions gldcore/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,93 @@ DEPRECATED const char *global_findobj(char *buffer, int size, const char *spec)
return buffer;
}

const char *geocode_encode(char *buffer, int len, double lat, double lon, int resolution=12)
{
static const char *base32 = "0123456789bcdefghjkmnpqrstuvwxyz";
if ( len < resolution+1 )
{
output_warning("geocode_encode(buffer=%p, len=%d, lat=%g, lon=%g, resolution=%d): buffer too small for specified resolution, result truncated",
buffer, len, lat, lon, resolution);
resolution = len-1;
}
double lat_interval[] = {-90,90};
double lon_interval[] = {-180,180};
char *geohash = buffer;
geohash[0] = '\0';
int bits[] = {16,8,4,2,1};
int bit = 0;
int ch = '\0';
bool even = true;
int i = 0;
while ( i < resolution )
{
if ( even )
{
double mid = (lon_interval[0]+lon_interval[1])/2;
if ( lon > mid )
{
ch |= bits[bit];
lon_interval[0] = mid;
}
else
{
lon_interval[1] = mid;
}
}
else
{
double mid = (lat_interval[0]+lat_interval[1])/2;
if ( lat > mid )
{
ch |= bits[bit];
lat_interval[0] = mid;
}
else
{
lat_interval[1] = mid;
}
}
even = !even;
if ( bit < 4 )
{
bit += 1;
}
else
{
*geohash++ = base32[ch];
i++;
bit = 0;
ch = 0;
}
}
*geohash++ = '\0';
return buffer;
}

DEPRECATED const char *global_geocode(char *buffer, int size, const char *spec)
{
double lat, lon;
OBJECT *obj;
unsigned int res = 5; // about 2.4 km resolution by default
char name[64];
if ( sscanf(spec,"%lg,%lg#%u",&lat,&lon,&res) >= 2 )
{
return geocode_encode(buffer,size,lat,lon,res);
}
else if ( sscanf(spec,"%63[^#]#%u",name,&res) >= 1 && (obj=object_find_name(name)) != NULL )
{
lat = obj->latitude;
lon = obj->longitude;
if ( isfinite(lat) && isfinite(lon) && lat>=-90 && lat<=+90 && lon>=-180 && lon<=180 )
{
return geocode_encode(buffer,size,lat,lon,res);
}
}
output_warning("${GEOCODE %s}: geocode spec is not valid",spec);
buffer[0] = '\0';
return buffer;
}

/** Get the value of a global variable in a safer fashion
@return a \e char * pointer to the buffer holding the buffer where we wrote the data,
\p NULL if insufficient buffer space or if the \p name was not found.
Expand Down Expand Up @@ -1531,6 +1618,10 @@ const char *GldGlobals::getvar(const char *name, char *buffer, size_t size)
if ( strncmp(name,"FIND ",5) == 0 )
{
return global_findobj(buffer,size,name+5);
}
if ( strncmp(name,"GEOCODE ",8) == 0 )
{
return global_geocode(buffer,size,name+8);
}
/* expansions */
if ( parameter_expansion(buffer,size,name) )
Expand Down
Loading