Skip to content

Commit

Permalink
Timezones and masking (#8)
Browse files Browse the repository at this point in the history
Adds searching using local time
Refactors code to make tackling #2 easier
Increases speed of execution using cached timezone information using json file
Makes it easier to reuse the ShadowFinder object
Solve duplicate figure in notebook
Rename functions to make symmetry between save load generate more apparent
Increase version to 0.2.0
  • Loading branch information
GalenReich authored May 17, 2024
1 parent 24475d3 commit 47eae26
Show file tree
Hide file tree
Showing 5 changed files with 419 additions and 36 deletions.
30 changes: 24 additions & 6 deletions ShadowFinderColab.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,30 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# @title Find a Shadow 🔎 { display-mode: \"form\" }\n",
"\n",
"# @markdown ### ⬅️ Click to find possible locations that match the below information (takes around 10 - 20 seconds)\n",
"# @markdown ### ⬅️ Click to find possible locations that match the below information\n",
"\n",
"# @markdown Object and shadow are measured at right angles in arbitrary units\n",
"object_height = 10 # @param {type:\"number\"} Height of object in arbitrary units\n",
"shadow_length = 8 # @param {type:\"number\"} Length of shadow in arbitrary units\n",
"\n",
"# @markdown Date and time must be given in UTC, using the time format hh:mm:ss\n",
"# @markdown Date and time can be given in UTC or local time (set `time type` accordingly), using the time format hh:mm:ss\n",
"date = \"2024-02-29\" # @param {type:\"date\"}\n",
"time = \"12:00:00\" # @param {type:\"string\"}\n",
"time_type = \"utc\" # @param [\"utc\", \"local\"]\n",
"\n",
"# Create output files\n",
"output = f\"./shadowfinder_{object_height}_{shadow_length}_{date}T{time}.png\"\n",
"logfile = f\"./shadowfinder_{object_height}_{shadow_length}_{date}T{time}.log\"\n",
"\n",
"# Imports\n",
"![ ! -f \"deps_loaded\" ] & pip install shadowfinder >> {logfile} 2>&1 & touch deps_loaded\n",
"![ ! -f \"timezone_grid.json\" ] && wget https://raw.githubusercontent.com/bellingcat/ShadowFinder/main/timezone_grid.json >> {logfile} 2>&1\n",
"![ ! -f \"deps_loaded\" ] && pip install shadowfinder >> {logfile} 2>&1 && touch deps_loaded\n",
"\n",
"from shadowfinder.shadowfinder import ShadowFinder\n",
"import datetime\n",
Expand All @@ -48,10 +50,26 @@
" datetime_date, datetime_time, tzinfo=datetime.timezone.utc\n",
") # Date and time of interest\n",
"\n",
"finder = ShadowFinder(object_height, shadow_length, date_time)\n",
"if \"finder\" not in locals():\n",
" finder = ShadowFinder()\n",
" # check if timezones.npz exists\n",
" try:\n",
" finder.load_timezone_grid()\n",
" except FileNotFoundError:\n",
" finder.generate_timezone_grid()\n",
" finder.save_timezone_grid()\n",
"\n",
"finder.set_details(object_height, shadow_length, date_time, time_format=time_type)\n",
"finder.find_shadows()\n",
"finder.plot_shadows()"
"fig = finder.plot_shadows()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand Down
Loading

0 comments on commit 47eae26

Please sign in to comment.