From 6af729022e8e079c253ea56492a510d11a7f281a Mon Sep 17 00:00:00 2001 From: amandaha8 Date: Wed, 27 Sep 2023 15:48:21 +0000 Subject: [PATCH 1/2] updated new shared_utils ref --- starter_kit/basics_04.ipynb | 2 +- starter_kit/basics_04_steps.ipynb | 11 ++--------- starter_kit/basics_05.ipynb | 4 ++-- starter_kit/basics_05_steps.ipynb | 4 ++-- starter_kit/basics_06.ipynb | 2 +- starter_kit/data_sampling.ipynb | 2 +- starter_kit/shared_utils_examples.ipynb | 10 +++++----- starter_kit/style-guide-examples.ipynb | 6 +++--- 8 files changed, 17 insertions(+), 24 deletions(-) diff --git a/starter_kit/basics_04.ipynb b/starter_kit/basics_04.ipynb index 5fc7462f6..cf24faac6 100644 --- a/starter_kit/basics_04.ipynb +++ b/starter_kit/basics_04.ipynb @@ -123,7 +123,7 @@ "source": [ "## Turn lat/lon into point geometry\n", "\n", - "* There is a [function in shared_utils](https://github.com/cal-itp/data-analyses/blob/main/_shared_utils/shared_utils/geography_utils.py#L170-L192) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", + "* There is a [function in shared_utils](https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-analysis/calitp_data_analysis/geography_utils.py#L57-L84) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", "* Use `geography_utils.create_point_geometry??` to see what goes into that function, and what that function looks like under the hood." ] }, diff --git a/starter_kit/basics_04_steps.ipynb b/starter_kit/basics_04_steps.ipynb index 97c1b5d59..3562e2240 100644 --- a/starter_kit/basics_04_steps.ipynb +++ b/starter_kit/basics_04_steps.ipynb @@ -38,6 +38,7 @@ "\n", "from calitp_data_analysis.tables import tbls\n", "from calitp_data_analysis.sql import query_sql\n", + "\n", "from siuba import *" ] }, @@ -123,18 +124,10 @@ "source": [ "## Turn lat/lon into point geometry\n", "\n", - "* There is a [function in shared_utils](https://github.com/cal-itp/data-analyses/blob/main/_shared_utils/shared_utils/geography_utils.py#L170-L192) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", + "* There is a [function in shared_utils](https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-analysis/calitp_data_analysis/geography_utils.py#L57-L84) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", "* Use `geography_utils.create_point_geometry??` to see what goes into that function, and what that function looks like under the hood." ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "6c845296-73bc-4a82-9e4a-5e88f2343f4c", - "metadata": {}, - "outputs": [], - "source": [] - }, { "cell_type": "markdown", "id": "8a21eac3-ac67-47d8-b4c8-694192fdd796", diff --git a/starter_kit/basics_05.ipynb b/starter_kit/basics_05.ipynb index 06c06d402..0cfb23e4f 100644 --- a/starter_kit/basics_05.ipynb +++ b/starter_kit/basics_05.ipynb @@ -230,8 +230,8 @@ "outputs": [], "source": [ "# To add styleguide\n", - "from shared_utils import styleguide\n", - "from shared_utils import calitp_color_palette as cp" + "from calitp_data_analysis import styleguide\n", + "from calitp_data_analysis import calitp_color_palette as cp" ] } ], diff --git a/starter_kit/basics_05_steps.ipynb b/starter_kit/basics_05_steps.ipynb index 2c550b69c..486bd1fa9 100644 --- a/starter_kit/basics_05_steps.ipynb +++ b/starter_kit/basics_05_steps.ipynb @@ -343,8 +343,8 @@ "outputs": [], "source": [ "# To add styleguide\n", - "from shared_utils import styleguide\n", - "from shared_utils import calitp_color_palette as cp" + "from calitp_data_analysis import styleguide\n", + "from calitp_data_analysis import calitp_color_palette as cp" ] }, { diff --git a/starter_kit/basics_06.ipynb b/starter_kit/basics_06.ipynb index 7d50cdc24..8d1faf0ae 100644 --- a/starter_kit/basics_06.ipynb +++ b/starter_kit/basics_06.ipynb @@ -31,7 +31,7 @@ "\n", "# Hint: if this doesn't import: refer to docs for correctly import\n", "# cd into _shared_utils folder, run the make setup_env command\n", - "import shared_utils" + "from calitp_data_analysis import geography_utils" ] }, { diff --git a/starter_kit/data_sampling.ipynb b/starter_kit/data_sampling.ipynb index 12793fb6b..5f6fc346b 100644 --- a/starter_kit/data_sampling.ipynb +++ b/starter_kit/data_sampling.ipynb @@ -35,7 +35,7 @@ "import geopandas as gpd\n", "import numpy as np\n", "import pandas as pd\n", - "import shared_utils\n", + "from shared_utils import gtfs_utils_v2\n", "from calitp_data_analysis.sql import to_snakecase" ] }, diff --git a/starter_kit/shared_utils_examples.ipynb b/starter_kit/shared_utils_examples.ipynb index 24889e801..bb7e5dab5 100644 --- a/starter_kit/shared_utils_examples.ipynb +++ b/starter_kit/shared_utils_examples.ipynb @@ -52,6 +52,7 @@ "from calitp_data_analysis.tables import tbls\n", "from siuba import *\n", "\n", + "from calitp_data_analysis import geography_utils\n", "from shared_utils import geography_utils, utils" ] }, @@ -621,8 +622,7 @@ "import pandas as pd\n", "import seaborn as sns\n", "\n", - "from shared_utils import geography_utils, styleguide\n", - "from shared_utils import calitp_color_palette as cp" + "from calitp_data_analysis import geography_utils,styleguide, calitp_color_palette as cp" ] }, { @@ -983,7 +983,7 @@ "import geopandas as gpd\n", "import pandas as pd\n", "\n", - "import shared_utils " + "from calitp_data_analysis import geography_utils" ] }, { @@ -1132,7 +1132,7 @@ } ], "source": [ - "shared_utils.geography_utils.CA_NAD83Albers" + "geography_utils.CA_NAD83Albers" ] }, { @@ -1160,7 +1160,7 @@ ], "source": [ "print(f\"original CRS: {gdf.crs}\")\n", - "gdf = gdf.to_crs(shared_utils.geography_utils.CA_StatePlane)\n", + "gdf = gdf.to_crs(geography_utils.CA_StatePlane)\n", "print(f\"new CRS: {gdf.crs}\")" ] }, diff --git a/starter_kit/style-guide-examples.ipynb b/starter_kit/style-guide-examples.ipynb index bb287c2bb..c749cf33e 100644 --- a/starter_kit/style-guide-examples.ipynb +++ b/starter_kit/style-guide-examples.ipynb @@ -44,8 +44,8 @@ "from IPython.display import Markdown\n", "from plotnine import *\n", "\n", - "from shared_utils import geography_utils, styleguide\n", - "from shared_utils import calitp_color_palette as cp " + "from calitp_data_analysis import geography_utils, styleguide\n", + "from calitp_data_analysis import calitp_color_palette as cp " ] }, { @@ -614,7 +614,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.9.13" } }, "nbformat": 4, From af27ca1b8afe90bbc158ab007675a2635c17ca91 Mon Sep 17 00:00:00 2001 From: amandaha8 Date: Thu, 28 Sep 2023 16:58:02 +0000 Subject: [PATCH 2/2] commented out calitp-data-analysis pckg, double checked exercises --- _shared_utils/shared_utils/__init__.py | 16 ++--- ah_starterkit/testing_calitp.ipynb | 99 ++++++++++++++++++++++++++ starter_kit/basics_04.ipynb | 3 +- starter_kit/basics_04_steps.ipynb | 2 +- 4 files changed, 109 insertions(+), 11 deletions(-) create mode 100644 ah_starterkit/testing_calitp.ipynb diff --git a/_shared_utils/shared_utils/__init__.py b/_shared_utils/shared_utils/__init__.py index e2f22ccf8..a7f28142d 100644 --- a/_shared_utils/shared_utils/__init__.py +++ b/_shared_utils/shared_utils/__init__.py @@ -1,27 +1,27 @@ from . import ( - calitp_color_palette, + #calitp_color_palette, dask_utils, - geography_utils, + #geography_utils, gtfs_utils, gtfs_utils_v2, portfolio_utils, rt_dates, rt_utils, schedule_rt_utils, - styleguide, - utils, + #styleguide, + #utils, ) __all__ = [ - "calitp_color_palette", + #"calitp_color_palette", "dask_utils", - "geography_utils", + #"geography_utils", "gtfs_utils", "gtfs_utils_v2", "portfolio_utils", "schedule_rt_utils", "rt_dates", "rt_utils", - "styleguide", - "utils", + #"styleguide", + #"utils", ] diff --git a/ah_starterkit/testing_calitp.ipynb b/ah_starterkit/testing_calitp.ipynb new file mode 100644 index 000000000..a3662dfc0 --- /dev/null +++ b/ah_starterkit/testing_calitp.ipynb @@ -0,0 +1,99 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "ff67558c-867f-45d0-94fd-ea6c75f56a61", + "metadata": {}, + "outputs": [], + "source": [ + "import geopandas as gpd\n", + "import pandas as pd\n", + "\n", + "# Hint: if this doesn't import: refer to docs for correctly import\n", + "# cd into _shared_utils folder, run the make setup_env command" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "403c09a4-a798-4bf6-a46c-502517d632e9", + "metadata": {}, + "outputs": [], + "source": [ + "my_gdf = pd.read_csv('gs://calitp-analytics-data/data-analyses/csuyat_folder/stops_caltrain_merced.csv')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "3154ca2e-0845-44c0-be95-377cd979eb93", + "metadata": {}, + "outputs": [], + "source": [ + "my_gdf2 = my_gdf.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "3160ecf0-3c52-4e70-99e2-34f6ce9f8905", + "metadata": {}, + "outputs": [], + "source": [ + "from calitp_data_analysis import geography_utils, utils" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "e0f92cce-cd64-414e-95d9-7e223434040a", + "metadata": {}, + "outputs": [], + "source": [ + "stops_ptg = geography_utils.create_point_geometry(\n", + " my_gdf2,\n", + " 'stop_lon',\n", + " 'stop_lat',\n", + " crs = 'EPSG:2229'\n", + ")" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "f4e0d3a3-ad9d-47f7-a36a-b179c83f81af", + "metadata": {}, + "outputs": [], + "source": [ + "utils.geojson_gcs_export(\n", + " stops_ptg,\n", + " 'gs://calitp-analytics-data/data-analyses/project_list',\n", + " \"my-testgeojson.geojson\",\n", + " geojson_type = \"geojson\",\n", + ")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.13" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/starter_kit/basics_04.ipynb b/starter_kit/basics_04.ipynb index cf24faac6..aa7c2d967 100644 --- a/starter_kit/basics_04.ipynb +++ b/starter_kit/basics_04.ipynb @@ -122,8 +122,7 @@ "metadata": {}, "source": [ "## Turn lat/lon into point geometry\n", - "\n", - "* There is a [function in shared_utils](https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-analysis/calitp_data_analysis/geography_utils.py#L57-L84) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", + "* There is a [function in calitp_data_analysis](https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-analysis/calitp_data_analysis/geography_utils.py#L57-L84) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", "* Use `geography_utils.create_point_geometry??` to see what goes into that function, and what that function looks like under the hood." ] }, diff --git a/starter_kit/basics_04_steps.ipynb b/starter_kit/basics_04_steps.ipynb index 3562e2240..230fe2d71 100644 --- a/starter_kit/basics_04_steps.ipynb +++ b/starter_kit/basics_04_steps.ipynb @@ -124,7 +124,7 @@ "source": [ "## Turn lat/lon into point geometry\n", "\n", - "* There is a [function in shared_utils](https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-analysis/calitp_data_analysis/geography_utils.py#L57-L84) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", + "* There is a [function in calitp_data_analysis](https://github.com/cal-itp/data-infra/blob/main/packages/calitp-data-analysis/calitp_data_analysis/geography_utils.py#L57-L84) that does it. Show the steps within the function (the long way), and also create the `geometry` column using `shared_utils`.\n", "* Use `geography_utils.create_point_geometry??` to see what goes into that function, and what that function looks like under the hood." ] },