Skip to content

Make time of moon measurement clearer - #5

Open
iansaxon wants to merge 6 commits into
isaacbernat:mainfrom
iansaxon:makeTimeOfMoonMeasurementClearer
Open

Make time of moon measurement clearer#5
iansaxon wants to merge 6 commits into
isaacbernat:mainfrom
iansaxon:makeTimeOfMoonMeasurementClearer

Conversation

@iansaxon

@iansaxon iansaxon commented Jul 5, 2026

Copy link
Copy Markdown

Issue: the original time of measurement was implicitly 00:00:00 (zero hundred hours, or midnight), but this was not explicitly stated in the readme, moon_data_ephem.py script, or outputs.

Proposed resolutions in this pull request:

  • Make time of measurement explicit in the readme, script, and outputs. Place user settings at the top of the script to facilitate easy changes, with a practical example given.
  • Name the CSV with the time (if 00:00:00 chosen then the file gets the special name 'AtZeroHundredHours', otherwise the 24 hour UTC time format is used).

Known tradeoffs:

  • The time column is inefficient in terms of storage space, but gives clarity to the outputs and will facilitate creating multiple outputs and later concatenating them if the user wishes.
  • Arguably the timestamp in the filename should appear at the end, to follow a general to specific naming scheme, which will be easier to work with if a user has multiple CSV outputs. However, this script includes the time statement in its original location for consistency.

Checks: I've included an Excel check zero file to compare the previous output to the new output, which is identical except for the insertion of a new time column.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces user-configurable measurement times and date ranges to the lunar data calculation script, updating the README documentation accordingly. Feedback on the changes suggests avoiding the introduction of pandas as a heavy dependency by reverting to Python's built-in csv and datetime modules. Additionally, the reviewer noted that the download link in the README needs to be updated to match the new default filename, and pointed out a syntax error in the configuration examples within both the README and the script comments.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread moon_data_ephem.py
import ephem
import datetime
import csv
import pandas as pd

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Introducing pandas as a dependency solely for generating a date range and writing a CSV file adds significant overhead and a heavy external dependency. The script can easily achieve the same functionality using Python's built-in csv module, which was used in the previous version.

Suggested change
import pandas as pd
import csv

Comment thread moon_data_ephem.py
Comment on lines +52 to +81
rows = []
current_decade = None
for date in pd.date_range(start=start_date, end=end_date, freq="D"):
measurement_datetime = datetime.datetime.combine(date.date(), measurement_time_utc)
decade = (measurement_datetime.year // 10) * 10
if decade != current_decade:
current_decade = decade
print(f"Processing decade {decade}s")

ephem_date = ephem.Date(measurement_datetime)
prev_new = ephem.previous_new_moon(measurement_datetime)
next_new = ephem.next_new_moon(measurement_datetime)
moon_phase = (ephem_date - prev_new) / (next_new - prev_new)

rows.append({
'Date': date.strftime('%Y-%m-%d'), # ISO 8601
'Time_UTC': measurement_datetime.strftime('%H:%M:%S'), # 24-hour format
'Area': round(illuminated_area(moon_phase), 4),
'Category': calculate_moon_phase_category(moon_phase),
'Phase': round(moon_phase, 4),
})

df = pd.DataFrame(rows, columns=['Date', 'Time_UTC', 'Area', 'Category', 'Phase'])
df.to_csv(filename, index=False)
print(
f"Run completed successfully for {filename}: "
f"start={start_datetime:%Y-%m-%d %H:%M:%S} UTC, "
f"end={end_datetime:%Y-%m-%d %H:%M:%S} UTC, "
f"rows={len(df)}"
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Instead of using pandas to generate the date range and write the CSV, we can use Python's built-in datetime and csv modules. This avoids loading all rows into memory at once and removes the heavy pandas dependency entirely.

current_decade = None
total_rows = 0
with open(filename, 'w', newline='') as csvfile:
    fieldnames = ['Date', 'Time_UTC', 'Area', 'Category', 'Phase']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()

    for n in range((end_date - start_date).days + 1):
        date = start_date + datetime.timedelta(days=n)
        measurement_datetime = datetime.datetime.combine(date, measurement_time_utc)
        decade = (measurement_datetime.year // 10) * 10
        if decade != current_decade:
            current_decade = decade
            print(f"Processing decade {decade}s")

        ephem_date = ephem.Date(measurement_datetime)
        prev_new = ephem.previous_new_moon(measurement_datetime)
        next_new = ephem.next_new_moon(measurement_datetime)
        moon_phase = (ephem_date - prev_new) / (next_new - prev_new)

        writer.writerow({
            'Date': date.strftime('%Y-%m-%d'),
            'Time_UTC': measurement_datetime.strftime('%H:%M:%S'),
            'Area': round(illuminated_area(moon_phase), 4),
            'Category': calculate_moon_phase_category(moon_phase),
            'Phase': round(moon_phase, 4),
        })
        total_rows += 1

print(
    f"Run completed successfully for {filename}: "
    f"start={start_datetime:%Y-%m-%d %H:%M:%S} UTC, "
    f"end={end_datetime:%Y-%m-%d %H:%M:%S} UTC, "
    f"rows={total_rows}"
)

Comment thread README.md
Comment thread README.md Outdated
Comment thread moon_data_ephem.py Outdated
@iansaxon

iansaxon commented Jul 5, 2026

Copy link
Copy Markdown
Author

@isaacbernat please let me know if you're put off by the pandas approach. I was hoping to get a speed boost by getting all the data from ephem, then writing as a single dataframe to CSV. It turns out though that you have to call ephem for one date at a time, so the time savings are limited only to the writing stage.

If you prefer to eliminate pandas as a dependency, to keep this repo as lightweight as possible, no problem from my perspective.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant