-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add get all users add get all site groups to read functions * add functions get all users, get all site groups * add test for get all users, get all site groups * add new functions as imports in init file * add delete functions for users, site, site group * add passing tests for deleting site, user, site group * add create user and create site functions * add function for creating a user * add test for create user * add test for add site to site group * add update site group * test update site group * lint * remove make_user * add create_site + tests * add geopandas * add tests to download dno and gsp * lint * move download dno and gsp to script * simplify --------- Co-authored-by: Rachel Tipton <[email protected]>
- Loading branch information
1 parent
cbb5b78
commit 792fe28
Showing
24 changed files
with
1,036 additions
and
127 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
""" The script adds the relevant GSP to the sites. | ||
Might need to install nowcasting_dataset | ||
and we want to added the gsp as {gsp_id}|{gsp_nam} into the database | ||
1. Load in dno data from NG | ||
2. Load all sites | ||
3. For each site add dno | ||
""" | ||
import logging | ||
import os | ||
|
||
import geopandas as gpd | ||
from shapely.geometry import Point | ||
|
||
from pvsite_datamodel.write.data.utils import lat_lon_to_osgb | ||
|
||
logger = logging.getLogger(__name__) | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
dno_local_file = f"{dir_path}/dno" | ||
|
||
|
||
def get_dno(latitude, longitude) -> dict: | ||
""" | ||
Convert a latitude and longitude and returns the dno. | ||
:param latitude: | ||
:param longitude: | ||
:return: dno is this format {"dno_id": dno_id, "name": dno_name, "long_name": dno_long_name}= | ||
""" | ||
|
||
# load file | ||
dno = gpd.read_file(dno_local_file) | ||
|
||
# change lat lon to osgb | ||
x, y = lat_lon_to_osgb(lat=latitude, lon=longitude) | ||
point = Point(x, y) | ||
|
||
# select dno | ||
mask = dno.contains(point) | ||
dno = dno[mask] | ||
|
||
# format dno | ||
if len(dno) == 1: | ||
dno = dno.iloc[0] | ||
|
||
dno_id = dno["ID"] | ||
name = dno["Name"] | ||
long_name = dno["LongName"] | ||
|
||
dno_dict = {"dno_id": str(dno_id), "name": name, "long_name": long_name} | ||
logger.debug(dno_dict) | ||
else: | ||
dno_dict = {"dno_id": "999", "name": "unknown", "long_name": "unknown"} | ||
|
||
return dno_dict | ||
|
||
|
||
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ISO-8859-1 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]] |
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
""" GSP functions for UK regions. """ | ||
import logging | ||
import os | ||
|
||
import geopandas as gpd | ||
import pandas as pd | ||
from shapely.geometry import Point | ||
|
||
from pvsite_datamodel.write.data.utils import lat_lon_to_osgb | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
gsp_local_file = f"{dir_path}/gsp" | ||
gsp_names = pd.read_csv(f"{dir_path}/gsp_new_ids_and_names-edited.csv") | ||
|
||
|
||
def get_gsp(latitude, longitude) -> dict: | ||
""" | ||
Get a DNO from latitude and longitude. | ||
:param latitude: | ||
:param longitude: | ||
:return: dno is this format {"dno_id": dno_id, "name": dno_name, "long_name": dno_long_name}= | ||
""" | ||
|
||
# load file | ||
gsp = gpd.read_file(gsp_local_file) | ||
|
||
# change lat lon to osgb | ||
x, y = lat_lon_to_osgb(lat=latitude, lon=longitude) | ||
point = Point(x, y) | ||
|
||
# select gsp | ||
mask = gsp.contains(point) | ||
gsp = gsp[mask] | ||
|
||
# format gsp | ||
if len(gsp) == 1: | ||
gsp = gsp.iloc[0] | ||
gsp_details = gsp_names[gsp_names["gsp_name"] == gsp.GSPs] | ||
gsp_id = gsp_details.index[0] | ||
gsp_details = gsp_details.iloc[0] | ||
name = gsp_details["region_name"] | ||
|
||
gsp_dict = {"gsp_id": str(gsp_id), "name": name} | ||
else: | ||
gsp_dict = {"gsp_id": "999", "name": "unknown"} | ||
|
||
return gsp_dict |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ISO-8859-1 |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROJCS["British_National_Grid",GEOGCS["GCS_OSGB_1936",DATUM["D_OSGB_1936",SPHEROID["Airy_1830",6377563.396,299.3249646]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",400000.0],PARAMETER["False_Northing",-100000.0],PARAMETER["Central_Meridian",-2.0],PARAMETER["Scale_Factor",0.9996012717],PARAMETER["Latitude_Of_Origin",49.0],UNIT["Meter",1.0]] |
Binary file not shown.
Binary file not shown.
Oops, something went wrong.