#๐Ÿ”’ NTL Resilience and Number of Pixels

8 messages ยท Page 1 of 1 (latest)

patent hedgeBOT
#

@north apex

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

north apex
#

I wanna know if how to convert the nan-nan pixels or how to count the pixels in tabular form. It should have the latitude and the longitude of the specific area and the NTL values before and after the typhoon was hit. On the other hand, I also want to graph an NTL Resilience using the raw data of the NTL Radiance in a specific area. The graph should look like the Recovery Curve. It's my first time to do this one and I really don't know what to do. Here is the code that I want to convert and I can also provided the Colab link if you want to see the rest of the code. Thank you.

#

Here is the code, if you can't find the file.

#@title Plot one municipality at a time.

Display municipality details

def show_municipality(m):
display(municipality_dropdown)

municipality_dataset_daily = region_dataset_daily[region_dataset_daily['NAME_2']==m]

make a list where to make grey areas

no_nan = municipality_dataset_daily[municipality_dataset_daily['ntl_mean'].notna()]

mean_by_date = no_nan.groupby('date')['ntl_mean'].sum()
availability_by_date = no_nan.groupby('date')['availability'].mean()

window by 1 week

mean_by_date_windowed = mean_by_date.rolling(window=7, min_periods=1).mean()
all_dates = municipality_dataset_daily['date'].unique()
mean_dates_list = mean_by_date.index.tolist()
nan_truth = [date in mean_dates_list for date in all_dates]
nan_dates = [date for date in all_dates if date not in mean_dates_list]
nan_dict = dict(zip(all_dates, nan_truth))

prev = True
greylist = []

dlist = list(nan_dict.items())
for i in range(len(dlist)):

if i==0 or i==len(dlist)-1:
  if not dlist[i][1]:
    greylist.append(dlist[i][0])

elif not dlist[i][1]: # if it's currently nan
  if dlist[i-1][1]!=dlist[i][1]: # if previous has value
    greylist.append(dlist[i-1][0])
  if dlist[i+1][1]!=dlist[i][1]: # if next has value
    greylist.append(dlist[i+1][0])
#

greylist = sorted(greylist)

fig, ax = plt.subplots(1,1,figsize=(17,5))

mean_by_date_windowed.plot(linestyle='-', label='NTL windowed 7 days', ax=ax)
gray_plotted_once = False
for i in range(len(greylist)//2):
if not gray_plotted_once:
ax.axvspan(greylist[i2], greylist[i2+1], color='gray', alpha=0.3, label='no reading')
gray_plotted_once = True
else:
ax.axvspan(greylist[i2], greylist[i2+1], color='gray', alpha=0.3)

Add vertical line at a specific timestamp

specific_timestamp = pd.Timestamp('2021-12-16')
ax.axvline(x=specific_timestamp, color='red', linestyle='--', label='Odette started')

ax.legend(loc='upper right')
ax.set_title(f'NTL Radiance for the Municipality of {m}')
ax.set_xlabel('Date')
ax.set_ylabel('NTL Radiance (nW/cmยฒsr)')
ax.tick_params(axis='x',rotation=90)

plt.show()
print()

fig, ax = plt.subplots(1,1,figsize=(17,5))

availability_by_date.plot(linestyle='-', label='NTL Availability', ax=ax)

Add vertical line at a specific timestamp

specific_timestamp = pd.Timestamp('2021-12-16')
ax.axvline(x=specific_timestamp, color='red', linestyle='--', label='Odette started')

ax.legend(loc='upper right')
ax.set_title(f'NTL non-nan values for the Municipality of {m}')
ax.set_xlabel('Date')
ax.set_ylabel('NTL Availability (non_nan/(non_nan+nan))')
ax.tick_params(axis='x',rotation=90)

plt.show()

def on_change(change):
if change['type'] == 'change' and change['name'] == 'value':
selected_municipality = change['new']
clear_output(wait=True)
show_municipality(selected_municipality)

municipality_dropdown = widgets.Dropdown(
options=district_list,
description='Municipality:'
)
municipality_dropdown.observe(on_change)
display(municipality_dropdown)

#

I really need help and my grades are at stake

patent hedgeBOT
#

@north apex

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ NTL Resilience and Number of Pixels